Home » geronimo-2.2-source-release » org.apache.geronimo.myfaces » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    *  http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   
   21   package org.apache.geronimo.myfaces;
   22   
   23   import java.lang.reflect.InvocationTargetException;
   24   import java.util.Map;
   25   
   26   import javax.naming.NamingException;
   27   import javax.naming.Context;
   28   
   29   import org.apache.myfaces.config.annotation.LifecycleProvider;
   30   import org.apache.geronimo.j2ee.annotation.Holder;
   31   import org.apache.geronimo.j2ee.annotation.LifecycleMethod;
   32   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   33   import org.apache.geronimo.gbean.GBeanLifecycle;
   34   import org.apache.geronimo.gbean.GBeanInfo;
   35   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   36   import org.apache.geronimo.kernel.Kernel;
   37   import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
   38   
   39   /**
   40    * @version $Rev: 698441 $ $Date: 2008-09-24 00:10:08 -0700 (Wed, 24 Sep 2008) $
   41    */
   42   public class LifecycleProviderGBean implements LifecycleProvider, GBeanLifecycle {
   43       
   44       private final Holder holder;
   45       private final Context context;
   46       private final ApplicationIndexedLifecycleProviderFactory factory;
   47       private final ClassLoader classLoader;
   48   
   49   
   50       public LifecycleProviderGBean(Holder holder, Map componentContext, LifecycleProviderFactorySource factory, Kernel kernel, ClassLoader classLoader) throws NamingException {
   51           this.holder = holder;
   52   //        GeronimoUserTransaction userTransaction = new GeronimoUserTransaction(transactionManager);
   53           context = EnterpriseNamingContext.createEnterpriseNamingContext(componentContext, null, kernel, classLoader);
   54           this.factory = factory.getLifecycleProviderFactory();
   55           this.classLoader = classLoader;
   56       }
   57   
   58       public Object newInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException, InvocationTargetException {
   59           if (className == null) {
   60               throw new InstantiationException("no class name provided");
   61           }
   62           return holder.newInstance(className, classLoader, context);
   63       }
   64   
   65       public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException {
   66           Class clazz = o.getClass();
   67           if (holder != null) {
   68               Map<String, LifecycleMethod> preDestroy = holder.getPreDestroy();
   69               if (preDestroy != null) {
   70                   Holder.apply(o, clazz, preDestroy);
   71               }
   72           }
   73       }
   74   
   75       public void doStart() {
   76           factory.registerLifecycleProvider(classLoader, this);
   77       }
   78   
   79       public void doStop() {
   80           factory.unregisterLifecycleProvider(classLoader);
   81       }
   82   
   83       public void doFail() {
   84           doStop();
   85       }
   86   
   87       public static final GBeanInfo GBEAN_INFO;
   88   
   89       static {
   90           GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(LifecycleProviderGBean.class, GBeanInfoBuilder.DEFAULT_J2EE_TYPE);
   91           infoBuilder.addAttribute("holder", Holder.class, true);
   92           infoBuilder.addAttribute("componentContext", Map.class, true);
   93   
   94           infoBuilder.addReference("LifecycleProviderFactory", LifecycleProviderFactorySource.class);
   95   //        infoBuilder.addReference("TransactionManager", TransactionManager.class);
   96           infoBuilder.addAttribute("kernel", Kernel.class, false);
   97           infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
   98   
   99           infoBuilder.setConstructor(new String[] {"holder", "componentContext", "LifecycleProviderFactory", "kernel", "classLoader"});
  100   
  101           GBEAN_INFO = infoBuilder.getBeanInfo();
  102       }
  103   
  104       public static GBeanInfo getGBeanInfo() {
  105           return GBEAN_INFO;
  106       }
  107   }

Home » geronimo-2.2-source-release » org.apache.geronimo.myfaces » [javadoc | source]