Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.el » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.el;
   15   
   16   import java.beans.FeatureDescriptor;
   17   import java.util.Iterator;
   18   
   19   import javax.el.ELContext;
   20   import javax.el.ELException;
   21   import javax.el.ELResolver;
   22   import javax.el.PropertyNotFoundException;
   23   import javax.el.PropertyNotWritableException;
   24   import javax.enterprise.context.Dependent;
   25   import javax.enterprise.inject.spi.Bean;
   26   import javax.servlet.jsp.JspApplicationContext;
   27   
   28   import org.apache.webbeans.container.BeanManagerImpl;
   29   
   30   /**
   31    * JSF or JSP expression language a.k.a EL resolver.
   32    * 
   33    * <p>
   34    * EL is registered with the JSF in faces-config.xml if there exist a faces-config.xml
   35    * in the application location <code>WEB-INF/</code>. Otherwise it is registered with
   36    * {@link JspApplicationContext} at start-up. 
   37    * </p>
   38    * 
   39    * <p>
   40    * All <code>@Dependent</code> scoped contextual instances created during an EL 
   41    * expression evaluation are destroyed when the evaluation completes.
   42    * </p>
   43    * 
   44    * @version $Rev: 811507 $ $Date: 2009-09-04 21:18:41 +0300 (Fri, 04 Sep 2009) $
   45    *
   46    */
   47   public class WebBeansELResolver extends ELResolver
   48   {    
   49   
   50       /**
   51        * {@inheritDoc}
   52        */
   53       @Override
   54       public Class<?> getCommonPropertyType(ELContext arg0, Object arg1)
   55       {
   56           return null;
   57       }
   58   
   59       /**
   60        * {@inheritDoc}
   61        */
   62       @Override
   63       public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1)
   64       {
   65           return null;
   66       }
   67   
   68       /**
   69        * {@inheritDoc}
   70        */    
   71       @Override
   72       public Class<?> getType(ELContext arg0, Object arg1, Object arg2) throws NullPointerException, PropertyNotFoundException, ELException
   73       {
   74           return null;
   75       }
   76   
   77       /**
   78        * {@inheritDoc}
   79        */    
   80       @Override
   81       public Object getValue(ELContext context, Object obj, Object property) throws NullPointerException, PropertyNotFoundException, ELException
   82       {
   83           BeanManagerImpl manager = BeanManagerImpl.getManager();
   84   
   85           Object object = null;
   86           Bean<?> bean = null;
   87   
   88           boolean isResolution = false;
   89           try
   90           {
   91               if (obj == null)
   92               {
   93                   String name = (String) property;
   94                   object = manager.getInstanceByName(name);
   95                   
   96                   if (object != null)
   97                   {
   98                       isResolution = true;
   99                       context.setPropertyResolved(true);
  100                       //It is used for destroying
  101                       bean = manager.resolveByName(name).iterator().next();
  102                   }
  103   
  104               }
  105   
  106           }
  107           finally
  108           {
  109               if (isResolution)
  110               {
  111                   if (bean != null)
  112                   {
  113                       destroyBean(bean, object);
  114                   }                
  115               }
  116           }
  117   
  118           return object;
  119       }
  120   
  121       /**
  122        * Destroys the bean.
  123        * 
  124        * @param <T> bean type info
  125        * @param bean dependent context scoped bean
  126        * @param instance bean instance
  127        */
  128       @SuppressWarnings("unchecked")
  129       private <T> void destroyBean(Bean<T> bean, Object instance)
  130       {
  131           if (bean.getScope().equals(Dependent.class))
  132           {
  133               T inst = (T) instance;
  134   
  135               //TODO Creational Context
  136               bean.destroy(inst,null);
  137           }
  138       }
  139   
  140       /**
  141        * {@inheritDoc}
  142        */    
  143       @Override
  144       public boolean isReadOnly(ELContext arg0, Object arg1, Object arg2) throws NullPointerException, PropertyNotFoundException, ELException
  145       {
  146           return false;
  147       }
  148   
  149       /**
  150        * {@inheritDoc}
  151        */    
  152       @Override
  153       public void setValue(ELContext arg0, Object arg1, Object arg2, Object arg3) throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException
  154       {
  155   
  156       }
  157   
  158   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.el » [javadoc | source]