org.apache.webbeans.el22.WebBeansELResolver Maven / Gradle / Ivy
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.webbeans.el22;
import java.beans.FeatureDescriptor;
import java.lang.reflect.Type;
import java.util.Iterator;
import java.util.Set;
import javax.el.ELContext;
import javax.el.ELException;
import javax.el.ELResolver;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import org.apache.webbeans.component.OwbBean;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.el.ELContextStore;
/**
* JSF or JSP expression language a.k.a EL resolver.
*
*
* EL is registered with the JSF in faces-config.xml if there exist a faces-config.xml
* in the application location WEB-INF/
. Otherwise it is registered with
* JspApplicationContext at start-up.
*
*
*
* All @Dependent
scoped contextual instances created during an EL
* expression evaluation are destroyed when the evaluation completes.
*
*
* @version $Rev: 1307826 $ $Date: 2012-03-31 18:24:37 +0300 (Sat, 31 Mar 2012) $
*
*/
public class WebBeansELResolver extends ELResolver
{
private WebBeansContext webBeansContext;
public WebBeansELResolver()
{
webBeansContext = WebBeansContext.getInstance();
}
/**
* {@inheritDoc}
*/
@Override
public Class> getCommonPropertyType(ELContext arg0, Object arg1)
{
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Iterator getFeatureDescriptors(ELContext arg0, Object arg1)
{
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Class> getType(ELContext arg0, Object arg1, Object arg2) throws ELException
{
return null;
}
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings({"unchecked","deprecation"})
public Object getValue(ELContext context, Object base, Object property) throws ELException
{
BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
//we only check root beans
// Check if the OWB actually got used in this application
if (base != null || !beanManager.isInUse())
{
return null;
}
//Name of the bean
String beanName = (String) property;
//Local store, create if not exist
ELContextStore elContextStore = ELContextStore.getInstance(true);
Object contextualInstance = elContextStore.findBeanByName(beanName);
if(contextualInstance != null)
{
context.setPropertyResolved(true);
return contextualInstance;
}
//Get beans
Set> beans = beanManager.getBeans(beanName);
//Found?
if(beans != null && !beans.isEmpty())
{
//Managed bean
Bean
© 2015 - 2025 Weber Informatics LLC | Privacy Policy