You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/03/13 23:40:50 UTC
svn commit: r517917 - in /myfaces/core/branches/jsf12/impl/src:
main/java/org/apache/myfaces/ main/java/org/apache/myfaces/config/
main/java/org/apache/myfaces/config/annotation/
main/java/org/apache/myfaces/webapp/ main/resources/META-INF/services/ te...
Author: bommel
Date: Tue Mar 13 15:40:48 2007
New Revision: 517917
URL: http://svn.apache.org/viewvc?view=rev&rev=517917
Log:
(MYFACES-1246)
(MYFACES-1559)
thanks david for the proposal
disable TomcatAnnotationLifecycleProvider until it's real tested
Added:
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationLifecycleProvider.java
- copied, changed from r517832, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DefaultLifecycleProviderFactory.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DiscoverableLifecycleProvider.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProvider.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProviderFactory.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoAnnotationLifecyleProvider.java
- copied, changed from r517832, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NopAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationLifecycleProvider.java
- copied, changed from r517832, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java
- copied, changed from r517832, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationLifecycleProvider.java
- copied, changed from r517844, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestDiscoverableLifecycleProvider.java
myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestLifecycleProvider.java
- copied, changed from r517832, myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.config.annotation.LifecycleProvider
- copied, changed from r517832, myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.AnnotationProcessor
Removed:
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/AnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/DiscoverableAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotationProcessorFactory.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DefaultAnnotationProcessorFactory.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NopAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/resources/META-INF/services/org.apache.myfaces.AnnotationProcessor
myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestDiscoverableAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.AnnotationProcessor
Modified:
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/AbstractMyFacesListener.java
myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotationProcessorTestCase.java
myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/OwnAnnotationProcessorTestCase.java
Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java?view=diff&rev=517917&r1=517916&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java Tue Mar 13 15:40:48 2007
@@ -38,7 +38,8 @@
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.config.annotation.AnnotationProcessorFactory;
+import org.apache.myfaces.config.annotation.LifecycleProviderFactory;
+import org.apache.myfaces.config.annotation.LifecycleProvider;
import org.apache.myfaces.config.element.ListEntries;
import org.apache.myfaces.config.element.ListEntry;
import org.apache.myfaces.config.element.ManagedBean;
@@ -46,7 +47,6 @@
import org.apache.myfaces.config.element.MapEntries;
import org.apache.myfaces.config.element.MapEntry;
import org.apache.myfaces.shared_impl.util.ClassUtils;
-import org.apache.myfaces.AnnotationProcessor;
/**
@@ -76,16 +76,9 @@
return null;*/
try
{
- AnnotationProcessor annotationProcessor =
- AnnotationProcessorFactory.getAnnotatonProcessorFactory().getAnnotatonProcessor(facesContext.getExternalContext());
- final Object bean = annotationProcessor.newInstance(beanConfiguration.getManagedBeanClassName());
-
- annotationProcessor.processAnnotations(bean);
-
- if (!beanConfiguration.getManagedBeanScope().equals(ManagedBeanBuilder.NONE))
- {
- annotationProcessor.postConstruct(bean);
- }
+ LifecycleProvider lifecycleProvider =
+ LifecycleProviderFactory.getLifecycleProviderFactory().getLifecycleProvider(facesContext.getExternalContext());
+ final Object bean = lifecycleProvider.newInstance(beanConfiguration.getManagedBeanClassName());
switch (beanConfiguration.getInitMode())
{
Copied: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationLifecycleProvider.java (from r517832, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationProcessor.java)
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationLifecycleProvider.java?view=diff&rev=517917&p1=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationProcessor.java&r1=517832&p2=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationLifecycleProvider.java&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationProcessor.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AllAnnotationLifecycleProvider.java Tue Mar 13 15:40:48 2007
@@ -30,10 +30,10 @@
import java.lang.reflect.Field;
// TODO @EJBs
-public class AllAnnotationProcessor extends ResourceAnnotationProcessor
+public class AllAnnotationLifecycleProvider extends ResourceAnnotationLifecycleProvider
{
- public AllAnnotationProcessor(Context context)
+ public AllAnnotationLifecycleProvider(Context context)
{
super(context);
}
Added: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DefaultLifecycleProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DefaultLifecycleProviderFactory.java?view=auto&rev=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DefaultLifecycleProviderFactory.java (added)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DefaultLifecycleProviderFactory.java Tue Mar 13 15:40:48 2007
@@ -0,0 +1,214 @@
+package org.apache.myfaces.config.annotation;
+
+/*
+ * 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.
+ */
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.discovery.resource.ClassLoaders;
+import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
+import org.apache.commons.discovery.ResourceNameIterator;
+import org.apache.myfaces.shared_impl.util.ClassUtils;
+
+import javax.faces.context.ExternalContext;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Constructor;
+
+/*
+ * Date: Mar 12, 2007
+ * Time: 9:53:40 PM
+ */
+public class DefaultLifecycleProviderFactory extends LifecycleProviderFactory {
+ private static Log log = LogFactory.getLog(DefaultLifecycleProviderFactory.class);
+ private static LifecycleProvider LIFECYCLE_PROVIDER_INSTANCE;
+ public static final String LIFECYCLE_PROVIDER = LifecycleProvider.class.getName();
+
+
+ public DefaultLifecycleProviderFactory()
+ {
+ }
+
+ public LifecycleProvider getLifecycleProvider(ExternalContext externalContext)
+ {
+ if (LIFECYCLE_PROVIDER_INSTANCE == null)
+ {
+ if (externalContext == null)
+ {
+ log.info("No ExternalContext using fallback LifecycleProvider.");
+ resolveFallbackLifecycleProvider();
+ }
+ else
+ {
+ if (!resolveLifecycleProviderFromExternalContext(externalContext))
+ {
+ if (!resolveLifecycleProviderFromService(externalContext))
+ {
+ resolveFallbackLifecycleProvider();
+ }
+ }
+ }
+ log.info("Using LifecycleProvider "+ LIFECYCLE_PROVIDER_INSTANCE.getClass().getName());
+ }
+ return LIFECYCLE_PROVIDER_INSTANCE;
+ }
+
+ public void release() {
+ LIFECYCLE_PROVIDER_INSTANCE = null;
+ }
+
+
+
+ private boolean resolveLifecycleProviderFromExternalContext(ExternalContext externalContext)
+ {
+ try
+ {
+ String lifecycleProvider = externalContext.getInitParameter(LIFECYCLE_PROVIDER);
+ if (lifecycleProvider != null)
+ {
+
+ Object obj = createClass(lifecycleProvider, externalContext);
+
+ if (obj instanceof LifecycleProvider) {
+ LIFECYCLE_PROVIDER_INSTANCE = (LifecycleProvider) obj;
+ return true;
+ }
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.error("", e);
+ }
+ catch (InstantiationException e)
+ {
+ log.error("", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.error("", e);
+ }
+ catch (InvocationTargetException e)
+ {
+ log.error("", e);
+ }
+ return false;
+ }
+
+
+ private boolean resolveLifecycleProviderFromService(ExternalContext externalContext) {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoaders loaders = new ClassLoaders();
+ loaders.put(classLoader);
+ DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
+ ResourceNameIterator iter = dsn.findResourceNames(LIFECYCLE_PROVIDER);
+ while (iter.hasNext()) {
+ String className = iter.nextResourceName();
+ try
+ {
+ Object obj = createClass(className, externalContext);
+ if (DiscoverableLifecycleProvider.class.isAssignableFrom(obj.getClass())) {
+ DiscoverableLifecycleProvider discoverableLifecycleProvider =
+ (DiscoverableLifecycleProvider) obj;
+ if (discoverableLifecycleProvider.isAvailable()) {
+ LIFECYCLE_PROVIDER_INSTANCE = discoverableLifecycleProvider;
+ return true;
+ }
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ // ignore
+ }
+ catch (NoClassDefFoundError e)
+ {
+ // ignore
+ }
+ catch (InstantiationException e)
+ {
+ log.error("", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.error("", e);
+ }
+ catch (InvocationTargetException e)
+ {
+ log.error("", e);
+ }
+ }
+ return false;
+ }
+
+ private Object createClass(String className, ExternalContext externalContext)
+ throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
+ {
+ Class clazz = ClassUtils.classForName(className);
+
+ Object obj;
+ try
+ {
+ Constructor constructor = clazz.getConstructor(ExternalContext.class);
+ obj = constructor.newInstance(externalContext);
+ }
+ catch (NoSuchMethodException e)
+ {
+ obj = clazz.newInstance();
+ }
+ return obj;
+ }
+
+
+ private void resolveFallbackLifecycleProvider()
+ {
+ try
+ {
+ ClassUtils.classForName("javax.annotation.PreDestroy");
+ }
+ catch (ClassNotFoundException e)
+ {
+ // no annotation available don't process annotations
+ LIFECYCLE_PROVIDER_INSTANCE = new NoAnnotationLifecyleProvider();
+ return;
+ }
+ Context context;
+ try
+ {
+ context = new InitialContext();
+ try
+ {
+ ClassUtils.classForName("javax.ejb.EJB");
+ // Asume full JEE 5 container
+ LIFECYCLE_PROVIDER_INSTANCE = new AllAnnotationLifecycleProvider(context);
+ }
+ catch (ClassNotFoundException e)
+ {
+ // something else
+ LIFECYCLE_PROVIDER_INSTANCE = new ResourceAnnotationLifecycleProvider(context);
+ }
+ }
+ catch (NamingException e)
+ {
+ // no initial context available no injection
+ LIFECYCLE_PROVIDER_INSTANCE = new NoInjectionAnnotationLifecycleProvider();
+ log.error("No InitialContext found. Using NoInjectionAnnotationProcessor.", e);
+
+ }
+ }
+}
Added: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DiscoverableLifecycleProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DiscoverableLifecycleProvider.java?view=auto&rev=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DiscoverableLifecycleProvider.java (added)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/DiscoverableLifecycleProvider.java Tue Mar 13 15:40:48 2007
@@ -0,0 +1,12 @@
+package org.apache.myfaces.config.annotation;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Mar 13, 2007
+ * Time: 10:09:38 PM
+ */
+public interface DiscoverableLifecycleProvider extends LifecycleProvider
+{
+ public boolean isAvailable();
+}
Added: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProvider.java?view=auto&rev=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProvider.java (added)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProvider.java Tue Mar 13 15:40:48 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.myfaces.config.annotation;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.naming.NamingException;
+
+/**
+ * Proposed interface to annotation service. An implementation of this class needs to know the appropriate classloader,
+ * dependencies to be injected, and lifecycle methods to be called.
+ *
+ * @version $Rev:$ $Date:$
+ */
+public interface LifecycleProvider {
+
+ /**
+ * Create an object of the class with the supplied name, inject dependencies as appropriate,
+ * and call a postContruct method as appropriate.
+ *
+ * @param className name of the class of the desired object
+ * @return a fully constructed, dependency-injected, and initialized object.
+ */
+ Object newInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException, InvocationTargetException;
+
+ /**
+ * Take whatever steps are needed to shut down the object, including calling a preDestroy method.
+ *
+ * @param o object to shut down.
+ */
+ void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException;
+}
Added: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProviderFactory.java?view=auto&rev=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProviderFactory.java (added)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/LifecycleProviderFactory.java Tue Mar 13 15:40:48 2007
@@ -0,0 +1,49 @@
+package org.apache.myfaces.config.annotation;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.discovery.tools.DiscoverSingleton;
+
+
+import javax.faces.context.ExternalContext;
+
+
+public abstract class LifecycleProviderFactory {
+ protected static final String FACTORY_DEFAULT = DefaultLifecycleProviderFactory.class.getName();
+
+ private static volatile LifecycleProviderFactory INSTANCE;
+
+ public static LifecycleProviderFactory getLifecycleProviderFactory()
+ {
+ LifecycleProviderFactory instance = INSTANCE;
+ if (instance != null) {
+ return instance;
+ }
+ return (LifecycleProviderFactory) DiscoverSingleton.find(LifecycleProviderFactory.class, FACTORY_DEFAULT);
+ }
+
+
+ public static void setLifecycleProviderFactory(LifecycleProviderFactory instance) {
+ INSTANCE = instance;
+ }
+
+ public abstract LifecycleProvider getLifecycleProvider(ExternalContext externalContext);
+
+ public abstract void release();
+
+}
Copied: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoAnnotationLifecyleProvider.java (from r517832, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NopAnnotationProcessor.java)
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoAnnotationLifecyleProvider.java?view=diff&rev=517917&p1=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NopAnnotationProcessor.java&r1=517832&p2=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoAnnotationLifecyleProvider.java&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NopAnnotationProcessor.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoAnnotationLifecyleProvider.java Tue Mar 13 15:40:48 2007
@@ -17,37 +17,23 @@
* limitations under the License.
*/
-import org.apache.myfaces.AnnotationProcessor;
import org.apache.myfaces.shared_impl.util.ClassUtils;
-import javax.naming.NamingException;
import java.lang.reflect.InvocationTargetException;
-public class NopAnnotationProcessor implements AnnotationProcessor
+public class NoAnnotationLifecyleProvider implements LifecycleProvider
{
- public Object newInstance(String className) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
- {
- Class clazz = ClassUtils.classForName(className);
- return clazz.newInstance();
- }
-
- public void postConstruct(Object instance)
- throws IllegalAccessException, InvocationTargetException
+ public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException
{
}
- public void preDestroy(Object instance)
- throws IllegalAccessException, InvocationTargetException
+ public Object newInstance(String className) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
{
-
+ Class clazz = ClassUtils.classForName(className);
+ return clazz.newInstance();
}
- public void processAnnotations(Object instance)
- throws IllegalAccessException, InvocationTargetException, NamingException
- {
-
- }
}
Copied: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationLifecycleProvider.java (from r517832, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java)
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationLifecycleProvider.java?view=diff&rev=517917&p1=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java&r1=517832&p2=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationLifecycleProvider.java&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationLifecycleProvider.java Tue Mar 13 15:40:48 2007
@@ -17,7 +17,6 @@
* limitations under the License.
*/
-import org.apache.myfaces.AnnotationProcessor;
import org.apache.myfaces.shared_impl.util.ClassUtils;
import javax.annotation.PostConstruct;
@@ -33,20 +32,23 @@
*/
-public class NoInjectionAnnotationProcessor implements AnnotationProcessor {
+public class NoInjectionAnnotationLifecycleProvider implements LifecycleProvider {
public Object newInstance(String className)
- throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
+ throws InstantiationException, IllegalAccessException, NamingException, InvocationTargetException, ClassNotFoundException
{
Class clazz = ClassUtils.classForName(className);
- return clazz.newInstance();
+ Object object = clazz.newInstance();
+ processAnnotations(object);
+ postConstruct(object);
+ return object;
}
/**
* Call postConstruct method on the specified instance.
*/
- public void postConstruct(Object instance)
+ private void postConstruct(Object instance)
throws IllegalAccessException, InvocationTargetException
{
@@ -80,10 +82,7 @@
}
- /**
- * Call preDestroy method on the specified instance.
- */
- public void preDestroy(Object instance)
+ public void destroyInstance(Object instance)
throws IllegalAccessException, InvocationTargetException
{
@@ -117,16 +116,6 @@
}
-
- /**
- * Inject resources in specified instance.
- */
- public void processAnnotations(Object instance)
- throws IllegalAccessException, InvocationTargetException, NamingException
- {
-
- }
-
private void invokeAnnotatedMethod(Method method, Object instance)
throws IllegalAccessException, InvocationTargetException
{
@@ -139,6 +128,15 @@
method.invoke(instance);
method.setAccessible(accessibility);
}
+ }
+
+ /**
+ * Inject resources in specified instance.
+ */
+ protected void processAnnotations(Object instance)
+ throws IllegalAccessException, InvocationTargetException, NamingException
+ {
+
}
}
Copied: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java (from r517832, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java)
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java?view=diff&rev=517917&p1=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java&r1=517832&p2=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationLifecycleProvider.java Tue Mar 13 15:40:48 2007
@@ -25,13 +25,13 @@
import java.lang.reflect.Field;
// TODO @Resources
-public class ResourceAnnotationProcessor extends NoInjectionAnnotationProcessor
+public class ResourceAnnotationLifecycleProvider extends NoInjectionAnnotationLifecycleProvider
{
protected Context context;
private static final String JAVA_COMP_ENV = "java:comp/env/";
- public ResourceAnnotationProcessor(Context context)
+ public ResourceAnnotationLifecycleProvider(Context context)
{
this.context = context;
}
@@ -40,7 +40,7 @@
/**
* Inject resources in specified instance.
*/
- public void processAnnotations(Object instance)
+ protected void processAnnotations(Object instance)
throws IllegalAccessException, InvocationTargetException, NamingException
{
Copied: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationLifecycleProvider.java (from r517844, myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationProcessor.java)
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationLifecycleProvider.java?view=diff&rev=517917&p1=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationProcessor.java&r1=517844&p2=myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationLifecycleProvider.java&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationProcessor.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/TomcatAnnotationLifecycleProvider.java Tue Mar 13 15:40:48 2007
@@ -18,28 +18,42 @@
*/
-import org.apache.myfaces.DiscoverableAnnotationProcessor;
import org.apache.myfaces.shared_impl.util.ClassUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import javax.naming.NamingException;
import javax.faces.context.ExternalContext;
import javax.servlet.ServletContext;
import java.lang.reflect.InvocationTargetException;
-public class TomcatAnnotationProcessor implements DiscoverableAnnotationProcessor
+public class TomcatAnnotationLifecycleProvider implements DiscoverableLifecycleProvider
{
+ private static Log log = LogFactory.getLog(TomcatAnnotationLifecycleProvider.class);
+
private ExternalContext externalContext;
private org.apache.AnnotationProcessor annotationProcessor;
- public TomcatAnnotationProcessor(ExternalContext externalContext)
+ public TomcatAnnotationLifecycleProvider(ExternalContext externalContext)
{
this.externalContext = externalContext;
}
public Object newInstance(String className)
- throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {
+ throws InstantiationException, IllegalAccessException, InvocationTargetException, NamingException, ClassNotFoundException {
Class clazz = ClassUtils.classForName(className);
- return clazz.newInstance();
+ log.error("Creating instance of " + className);
+ Object object = clazz.newInstance();
+ annotationProcessor.processAnnotations(object);
+ annotationProcessor.postConstruct(object);
+ return object;
+ }
+
+
+ public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException
+ {
+ log.error("Destroy instance of " + o.getClass().getName());
+ annotationProcessor.preDestroy(o);
}
public boolean isAvailable()
@@ -55,19 +69,10 @@
return false;
}
- public void postConstruct(Object instance) throws IllegalAccessException, InvocationTargetException
- {
- annotationProcessor.postConstruct(instance);
- }
- public void preDestroy(Object instance) throws IllegalAccessException, InvocationTargetException
- {
- annotationProcessor.preDestroy(instance);
- }
- public void processAnnotations(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException
- {
- annotationProcessor.processAnnotations(instance);
- }
+
+
+
}
Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/AbstractMyFacesListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/AbstractMyFacesListener.java?view=diff&rev=517917&r1=517916&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/AbstractMyFacesListener.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/AbstractMyFacesListener.java Tue Mar 13 15:40:48 2007
@@ -21,7 +21,7 @@
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.http.HttpSessionBindingEvent;
-import org.apache.myfaces.config.annotation.AnnotationProcessorFactory;
+import org.apache.myfaces.config.annotation.LifecycleProviderFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -57,7 +57,7 @@
try
{
- AnnotationProcessorFactory.getAnnotatonProcessorFactory().getAnnotatonProcessor(null).preDestroy(value);
+ LifecycleProviderFactory.getLifecycleProviderFactory().getLifecycleProvider(null).destroyInstance(value);
} catch (IllegalAccessException e)
{
log.error("", e);
Modified: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotationProcessorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotationProcessorTestCase.java?view=diff&rev=517917&r1=517916&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotationProcessorTestCase.java (original)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotationProcessorTestCase.java Tue Mar 13 15:40:48 2007
@@ -18,14 +18,14 @@
*/
import org.apache.shale.test.base.AbstractJsfTestCase;
-import org.apache.myfaces.AnnotationProcessor;
+import javax.naming.NamingException;
import java.lang.reflect.InvocationTargetException;
public class AnnotationProcessorTestCase extends AbstractJsfTestCase
{
- protected AnnotationProcessor processor;
+ protected LifecycleProvider lifecycleProvider;
protected AnnotatedManagedBean managedBean;
@@ -36,21 +36,22 @@
public void setUp() throws Exception {
super.setUp();
- processor = AnnotationProcessorFactory.getAnnotatonProcessorFactory().getAnnotatonProcessor(externalContext);
+ lifecycleProvider = new AllAnnotationLifecycleProvider(null);
managedBean = new AnnotatedManagedBean();
}
- public void testPostConstruct() throws IllegalAccessException, InvocationTargetException
+ public void testPostConstruct() throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException
{
- processor.postConstruct(managedBean);
+ AnnotatedManagedBean managedBean = (AnnotatedManagedBean) lifecycleProvider.newInstance(AnnotatedManagedBean.class.getName());
assertTrue(managedBean.isPostConstructCalled());
assertFalse(managedBean.isPreDestroyCalled());
}
- public void testPreDestroy() throws IllegalAccessException, InvocationTargetException
+ public void testPreDestroy() throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException
{
- processor.preDestroy(managedBean);
- assertFalse(managedBean.isPostConstructCalled());
+ AnnotatedManagedBean managedBean = (AnnotatedManagedBean) lifecycleProvider.newInstance(AnnotatedManagedBean.class.getName());
+ lifecycleProvider.destroyInstance(managedBean);
+ assertTrue(managedBean.isPostConstructCalled());
assertTrue(managedBean.isPreDestroyCalled());
}
@@ -58,7 +59,7 @@
{
try
{
- processor.postConstruct(new AnnotatedManagedBean(true));
+ lifecycleProvider.destroyInstance(new AnnotatedManagedBean(true));
} catch (InvocationTargetException e) {
return;
}
Modified: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/OwnAnnotationProcessorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/OwnAnnotationProcessorTestCase.java?view=diff&rev=517917&r1=517916&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/OwnAnnotationProcessorTestCase.java (original)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/OwnAnnotationProcessorTestCase.java Tue Mar 13 15:40:48 2007
@@ -18,14 +18,13 @@
*/
import org.apache.shale.test.base.AbstractJsfTestCase;
-import org.apache.myfaces.AnnotationProcessor;
public class OwnAnnotationProcessorTestCase extends AbstractJsfTestCase
{
- protected AnnotationProcessor processor;
+ protected LifecycleProvider lifecycleProvider;
protected AnnotatedManagedBean managedBean;
- private static final String TEST_ANNOTATION_PROCESSOR = "org.apache.myfaces.config.annotation.TestAnnotationProcessor";
+ private static final String TEST_LIFECYCLE_PROVIDER = "org.apache.myfaces.config.annotation.TestLifecycleProvider";
public OwnAnnotationProcessorTestCase(String string)
@@ -35,15 +34,15 @@
public void setUp() throws Exception {
super.setUp();
- AnnotationProcessorFactory.getAnnotatonProcessorFactory().release();
- servletContext.addInitParameter(DefaultAnnotationProcessorFactory.ANNOTATION_PROCESSOR_PROVIDER, TEST_ANNOTATION_PROCESSOR);
- processor = AnnotationProcessorFactory.getAnnotatonProcessorFactory().getAnnotatonProcessor(externalContext);
+ LifecycleProviderFactory.getLifecycleProviderFactory().release();
+ servletContext.addInitParameter(DefaultLifecycleProviderFactory.LIFECYCLE_PROVIDER, TEST_LIFECYCLE_PROVIDER);
+ lifecycleProvider = LifecycleProviderFactory.getLifecycleProviderFactory().getLifecycleProvider(externalContext);
managedBean = new AnnotatedManagedBean();
}
public void testOwnProcessor()
{
- assertEquals(TEST_ANNOTATION_PROCESSOR, processor.getClass().getName());
+ assertEquals(TEST_LIFECYCLE_PROVIDER, lifecycleProvider.getClass().getName());
}
}
Added: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestDiscoverableLifecycleProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestDiscoverableLifecycleProvider.java?view=auto&rev=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestDiscoverableLifecycleProvider.java (added)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestDiscoverableLifecycleProvider.java Tue Mar 13 15:40:48 2007
@@ -0,0 +1,45 @@
+package org.apache.myfaces.config.annotation;
+
+/*
+ * 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.
+ */
+
+
+import javax.naming.NamingException;
+import java.lang.reflect.InvocationTargetException;
+
+
+
+public class TestDiscoverableLifecycleProvider implements DiscoverableLifecycleProvider
+{
+ private LifecycleProvider processor = new NoInjectionAnnotationLifecycleProvider();
+
+ public boolean isAvailable()
+ {
+ return true;
+ }
+
+ public Object newInstance(String className) throws InstantiationException, IllegalAccessException, NamingException, InvocationTargetException, ClassNotFoundException
+ {
+ return processor.newInstance(className);
+ }
+
+
+ public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException
+ {
+ processor.destroyInstance(o);
+ }
+}
Copied: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestLifecycleProvider.java (from r517832, myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestAnnotationProcessor.java)
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestLifecycleProvider.java?view=diff&rev=517917&p1=myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestAnnotationProcessor.java&r1=517832&p2=myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestLifecycleProvider.java&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestAnnotationProcessor.java (original)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/TestLifecycleProvider.java Tue Mar 13 15:40:48 2007
@@ -17,34 +17,25 @@
* limitations under the License.
*/
-import org.apache.myfaces.AnnotationProcessor;
import javax.naming.NamingException;
import java.lang.reflect.InvocationTargetException;
-public class TestAnnotationProcessor implements AnnotationProcessor
+public class TestLifecycleProvider implements LifecycleProvider
{
- private AnnotationProcessor processor = new NoInjectionAnnotationProcessor();
+ private LifecycleProvider processor = new NoInjectionAnnotationLifecycleProvider();
- public Object newInstance(String className) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
+ public Object newInstance(String className) throws InstantiationException, NamingException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
{
return processor.newInstance(className);
}
- public void postConstruct(Object instance) throws IllegalAccessException, InvocationTargetException
- {
- processor.postConstruct(instance);
- }
- public void preDestroy(Object instance) throws IllegalAccessException, InvocationTargetException
+ public void destroyInstance(Object instance) throws IllegalAccessException, InvocationTargetException
{
- processor.preDestroy(instance);
+ processor.destroyInstance(instance);
}
- public void processAnnotations(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException
- {
- processor.processAnnotations(instance);
- }
}
Copied: myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.config.annotation.LifecycleProvider (from r517832, myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.AnnotationProcessor)
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.config.annotation.LifecycleProvider?view=diff&rev=517917&p1=myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.AnnotationProcessor&r1=517832&p2=myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.config.annotation.LifecycleProvider&r2=517917
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.AnnotationProcessor (original)
+++ myfaces/core/branches/jsf12/impl/src/test/resources/META-INF/services/org.apache.myfaces.config.annotation.LifecycleProvider Tue Mar 13 15:40:48 2007
@@ -1 +1 @@
-org.apache.myfaces.config.annotation.TestDiscoverableAnnotationProcessor
\ No newline at end of file
+org.apache.myfaces.config.annotation.TestDiscoverableLifecycleProvider
\ No newline at end of file