james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1143788 - in /james/server/trunk/lifecycle-spring: ./ src/main/java/org/apache/james/container/spring/lifecycle/osgi/ src/main/resources/META-INF/spring/extender/
Date Thu, 07 Jul 2011 12:16:59 GMT
Author: norman
Date: Thu Jul  7 12:16:59 2011
New Revision: 1143788

URL: http://svn.apache.org/viewvc?rev=1143788&view=rev
Log:
Add BeanPostProcessors which handles @Resource and @PersistenceUnit annotation. See JAMES-835

Added:
    james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
    james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
    james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
Modified:
    james/server/trunk/lifecycle-spring/pom.xml
    james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OsgiLifecycleBeanFactoryPostProcessor.java
    james/server/trunk/lifecycle-spring/src/main/resources/META-INF/spring/extender/lifecycle-extender.xml

Modified: james/server/trunk/lifecycle-spring/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/lifecycle-spring/pom.xml?rev=1143788&r1=1143787&r2=1143788&view=diff
==============================================================================
--- james/server/trunk/lifecycle-spring/pom.xml (original)
+++ james/server/trunk/lifecycle-spring/pom.xml Thu Jul  7 12:16:59 2011
@@ -125,5 +125,9 @@
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-annotation_1.1_spec</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-jpa_2.0_spec</artifactId>
+    </dependency>
   </dependencies>
 </project>

Added: james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java?rev=1143788&view=auto
==============================================================================
--- james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
(added)
+++ james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
Thu Jul  7 12:16:59 2011
@@ -0,0 +1,326 @@
+/****************************************************************
+ * 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.james.container.spring.lifecycle.osgi;
+
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.FatalBeanException;
+import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.PropertyValues;
+import org.springframework.beans.factory.BeanClassLoaderAware;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.osgi.context.BundleContextAware;
+import org.springframework.osgi.service.importer.support.Cardinality;
+import org.springframework.osgi.service.importer.support.OsgiServiceCollectionProxyFactoryBean;
+import org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean;
+import org.springframework.util.ReflectionUtils;
+
+/**
+ * Abstract base class for {@link BeanPostProcessor} implementations which need to wire stuff
via annotations and need to be functional via OSGI.
+ * 
+ * Many of this code is borrowed from the spring-dm's class <code>org.springframework.osgi.extensions.annotation.ServiceReferenceInjectionBeanPostProcessor.</code>
+ *  * 
+ * 
+ *
+ * @param <A>
+ */
+public abstract class AbstractOSGIAnnotationBeanPostProcessor<A extends Annotation>
extends InstantiationAwareBeanPostProcessorAdapter implements BundleContextAware, BeanClassLoaderAware,
BeanFactoryAware{
+
+    public final static long DEFAULT_TIMEOUT = 60 * 1000* 5;
+    private BundleContext bundleContext;
+
+    private static Logger logger = LoggerFactory.getLogger(AbstractOSGIAnnotationBeanPostProcessor.class);
+
+    protected BeanFactory beanFactory;
+
+    private ClassLoader classLoader;
+
+    private boolean lookupBeanFactory = true;
+
+    private long timeout = DEFAULT_TIMEOUT;
+
+
+    /**
+     * Set the timeout in milliseconds. The default is 5 minutes
+     * 
+     * @param timeout
+     */
+    public void setTimeout(long timeout) {
+        this.timeout = timeout;
+    }
+    public void setLookupBeanFactory(boolean lookupBeanFactory) {
+        this.lookupBeanFactory = lookupBeanFactory;
+    }
+    
+    private abstract static class ImporterCallAdapter {
+
+        @SuppressWarnings("rawtypes")
+        static void setInterfaces(Object importer, Class[] classes) {
+            if (importer instanceof OsgiServiceProxyFactoryBean)
+                ((OsgiServiceProxyFactoryBean) importer).setInterfaces(classes);
+            else
+                ((OsgiServiceCollectionProxyFactoryBean) importer).setInterfaces(classes);
+        }
+
+        static void setBundleContext(Object importer, BundleContext context) {
+            ((BundleContextAware) importer).setBundleContext(context);
+        }
+
+        static void setBeanClassLoader(Object importer, ClassLoader cl) {
+            ((BeanClassLoaderAware) importer).setBeanClassLoader(cl);
+        }
+
+        static void setCardinality(Object importer, Cardinality cardinality) {
+            if (importer instanceof OsgiServiceProxyFactoryBean)
+                ((OsgiServiceProxyFactoryBean) importer).setCardinality(cardinality);
+            else
+                ((OsgiServiceCollectionProxyFactoryBean) importer).setCardinality(cardinality);
+        }
+
+
+        static void afterPropertiesSet(Object importer) throws Exception {
+            ((InitializingBean) importer).afterPropertiesSet();
+        }
+
+        static void setFilter(Object importer, String filter) throws Exception {
+            if (importer instanceof OsgiServiceProxyFactoryBean)
+                ((OsgiServiceProxyFactoryBean) importer).setFilter(filter);
+            else
+                ((OsgiServiceCollectionProxyFactoryBean) importer).setFilter(filter);
+        }
+
+
+        @SuppressWarnings("unused")
+        static void setServiceBean(Object importer, String name) {
+            if (importer instanceof OsgiServiceProxyFactoryBean)
+                ((OsgiServiceProxyFactoryBean) importer).setServiceBeanName(name);
+            else
+                ((OsgiServiceCollectionProxyFactoryBean) importer).setServiceBeanName(name);
+        }
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader)
+     */
+    public void setBeanClassLoader(ClassLoader classLoader) {
+        this.classLoader = classLoader;
+    }
+
+    /**
+     * process FactoryBean created objects, since these will not have had
+     * services injected.
+     * 
+     * @param bean
+     * @param beanName
+     */
+    @Override
+    public Object postProcessAfterInitialization(final Object bean, final String beanName)
throws BeansException {
+        if (logger.isDebugEnabled())
+            logger.debug("processing [" + bean.getClass().getName() + ", " + beanName + "]");
+        // Catch FactoryBean created instances.
+        if (!(bean instanceof FactoryBean) && beanFactory.containsBean(BeanFactory.FACTORY_BEAN_PREFIX
+ beanName)) {
+            injectServices(bean, beanName);
+        }
+        return bean;
+    }
+
+    /* private version of the injector can use */
+    private void injectServices(final Object bean, final String beanName) {
+        ReflectionUtils.doWithMethods(bean.getClass(), new ReflectionUtils.MethodCallback()
{
+
+            public void doWith(Method method) {
+                A s = AnnotationUtils.getAnnotation(method, getAnnotation());
+                if (s != null && method.getParameterTypes().length == 1) {
+                    try {
+                        if (logger.isDebugEnabled())
+                            logger.debug("Processing annotation [" + s + "] for [" + bean.getClass().getName()
+ "."
+                                    + method.getName() + "()] on bean [" + beanName + "]");
+                        method.invoke(bean, getServiceImporter(s, method, beanName).getObject());
+                    }
+                    catch (Exception e) {
+                        throw new IllegalArgumentException("Error processing annotation "
+s , e);
+                    }
+                }
+            }
+        });
+    }
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[]
pds, Object bean,
+            String beanName) throws BeansException {
+
+        MutablePropertyValues newprops = new MutablePropertyValues(pvs);
+        for (PropertyDescriptor pd : pds) {
+            A s = hasAnnotatedProperty(pd);
+            if (s != null && !pvs.contains(pd.getName())) {
+                try {
+                    if (logger.isDebugEnabled())
+                        logger.debug("Processing annotation [" + s + "] for [" + beanName
+ "." + pd.getName() + "]");
+                    FactoryBean importer = getServiceImporter(s, pd.getWriteMethod(), beanName);
+                    // BPPs are created in stageOne(), even though they are run in stageTwo().
This check means that
+                    // the call to getObject() will not fail with ServiceUnavailable. This
is safe to do because
+                    // ServiceReferenceDependencyBeanFactoryPostProcessor will ensure that
mandatory services are
+                    // satisfied before stageTwo() is run.
+                    if (bean instanceof BeanPostProcessor) {
+                        ImporterCallAdapter.setCardinality(importer, Cardinality.C_0__1);
+                    }
+                    newprops.addPropertyValue(pd.getName(), importer.getObject());
+                }
+                catch (Exception e) {
+                    throw new FatalBeanException("Could not create service reference", e);
+                }
+            }
+        }
+        return newprops;
+    }
+
+    @SuppressWarnings("rawtypes")
+    private FactoryBean getServiceImporter(final A s, final Method writeMethod, String beanName)
throws Exception {
+        // Invocations will block here, so although the ApplicationContext is
+        // created nothing will
+        // proceed until all the dependencies are satisfied.
+        Class<?>[] params = writeMethod.getParameterTypes();
+        if (params.length != 1) {
+            throw new IllegalArgumentException("Setter for [" + beanName + "] must have only
one argument");
+        }
+
+        if (lookupBeanFactory) {
+            if (logger.isDebugEnabled())
+                logger.debug("Lookup the bean via the BeanFactory");
+            
+            final Class<?> clazz = writeMethod.getParameterTypes()[0];
+            Object bean;
+            try {
+                bean = getBeanFromFactory(s, clazz);
+            } catch (NoSuchBeanDefinitionException e) {
+                // We was not able to find the bean in the factory so fallback to the osgi
registry
+                bean = null;
+            }
+            
+            if (bean != null) {
+                final Object fBean = bean;
+                
+                // Create a new FactoryBean which just return the found beab
+                return new FactoryBean() {
+
+                    @Override
+                    public Object getObject() throws Exception {
+                        return fBean;
+                    }
+
+                    @Override
+                    public Class getObjectType() {
+                        return fBean.getClass();
+                    }
+
+                    @Override
+                    public boolean isSingleton() {
+                        return true;
+                    }
+                };
+            }
+        }
+        // The bean was not found in the BeanFactory. Its time to lookup it via the OSGI-Registry
+        return getResourceProperty(new OsgiServiceProxyFactoryBean(), getFilter(s), writeMethod,
beanName);
+    }
+
+    
+
+    @SuppressWarnings("rawtypes")
+    private FactoryBean getResourceProperty(OsgiServiceProxyFactoryBean pfb,  String filter,
Method writeMethod, String beanName) throws Exception {
+        pfb.setTimeout(timeout);
+        
+        // check if the we have a name for the requested bean. If so we set the filter for
it
+        if (filter != null) {
+            ImporterCallAdapter.setFilter(pfb, filter );
+        }
+        ImporterCallAdapter.setInterfaces(pfb, writeMethod.getParameterTypes());
+        
+        ImporterCallAdapter.setBundleContext(pfb, bundleContext);
+        ImporterCallAdapter.setBeanClassLoader(pfb, classLoader);
+        ImporterCallAdapter.afterPropertiesSet(pfb);
+        return pfb;
+    }
+
+
+    private A hasAnnotatedProperty(PropertyDescriptor propertyDescriptor) {
+        Method setter = propertyDescriptor.getWriteMethod();
+        return setter != null ? AnnotationUtils.getAnnotation(setter, getAnnotation()) :
null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.springframework.osgi.context.BundleContextAware#setBundleContext(org.osgi.framework.BundleContext)
+     */
+    public void setBundleContext(BundleContext context) {
+        this.bundleContext = context;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+     */
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
+        this.beanFactory = beanFactory;
+    }
+    
+
+    /**
+     * Return the class of the {@link Annotation}
+     * 
+     * @return clazz
+     */
+    protected abstract Class<A> getAnnotation();
+    
+    /**
+     * Return the filter which should get used to lookup the service in the osgi registry.
+     * If no special filter should be used, just return null
+     * 
+     * @param annotation
+     * @return filter
+     */
+    protected abstract String getFilter(A annotation);
+    
+    /**
+     * Return the Bean lookup-ed from the {@link BeanFactory}. If non can be found just return
null
+     * 
+     * @param a
+     * @param clazz
+     * @return bean
+     */
+    protected abstract Object getBeanFromFactory(A a, Class<?> clazz);
+    
+}
+

Added: james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java?rev=1143788&view=auto
==============================================================================
--- james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
(added)
+++ james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
Thu Jul  7 12:16:59 2011
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.james.container.spring.lifecycle.osgi;
+
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+
+
+/**
+ * Inject the {@link EntityManagerFactory} if an method is marked with the {@link PersistenceUnit}
annotation
+ * 
+ *
+ */
+public class OSGIPersistenceUnitAnnotationBeanPostProcessor extends AbstractOSGIAnnotationBeanPostProcessor<PersistenceUnit>{
+
+
+    @Override
+    protected Class<PersistenceUnit> getAnnotation() {
+        return PersistenceUnit.class;
+    }
+
+    @Override
+    protected String getFilter(PersistenceUnit a) {
+        return null;
+    }
+
+    @Override
+    protected Object getBeanFromFactory(PersistenceUnit a, Class<?> clazz) {
+        return beanFactory.getBean(clazz);
+    }
+
+}

Added: james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java?rev=1143788&view=auto
==============================================================================
--- james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
(added)
+++ james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
Thu Jul  7 12:16:59 2011
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.james.container.spring.lifecycle.osgi;
+
+import javax.annotation.Resource;
+
+import org.springframework.osgi.service.exporter.OsgiServicePropertiesResolver;
+
+public class OSGIResourceAnnotationBeanPostProcessor extends AbstractOSGIAnnotationBeanPostProcessor<Resource>{
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.container.spring.lifecycle.osgi.AbstractOSGIAnnotationBeanPostProcessor#getAnnotation()
+     */
+    protected Class<Resource> getAnnotation() {
+        return Resource.class;
+    }
+
+    @Override
+    protected String getFilter(Resource a) {
+        return  "(" +OsgiServicePropertiesResolver.BEAN_NAME_PROPERTY_KEY + "=" + a.name()
+")";
+    }
+    @Override
+    protected Object getBeanFromFactory(Resource a, Class<?> clazz) {
+        return beanFactory.getBean(a.name(), clazz);
+    }
+    
+}

Modified: james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OsgiLifecycleBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OsgiLifecycleBeanFactoryPostProcessor.java?rev=1143788&r1=1143787&r2=1143788&view=diff
==============================================================================
--- james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OsgiLifecycleBeanFactoryPostProcessor.java
(original)
+++ james/server/trunk/lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OsgiLifecycleBeanFactoryPostProcessor.java
Thu Jul  7 12:16:59 2011
@@ -18,45 +18,72 @@
  ****************************************************************/
 package org.apache.james.container.spring.lifecycle.osgi;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
 import org.apache.james.container.spring.lifecycle.ConfigurableBeanPostProcessor;
+import org.apache.james.container.spring.lifecycle.ConfigurationProvider;
 import org.apache.james.container.spring.lifecycle.LogEnabledBeanPostProcessor;
+import org.apache.james.container.spring.lifecycle.LogProvider;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.InvalidSyntaxException;
 import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
 import org.springframework.osgi.extender.OsgiBeanFactoryPostProcessor;
 
 
 public class OsgiLifecycleBeanFactoryPostProcessor implements OsgiBeanFactoryPostProcessor
{
 
-    private ConfigurableBeanPostProcessor configurationProcessor;
-    private LogEnabledBeanPostProcessor loggingProcessor;
-    private CommonAnnotationBeanPostProcessor annotationProcessor;
 
-    public void setConfigurationProcessor(ConfigurableBeanPostProcessor configurationProcessor)
{
-        this.configurationProcessor = configurationProcessor;
-    }
+    private ConfigurationProvider confProvider;
+    private LogProvider logProvider;
 
-    public void setLoggingProcessor(LogEnabledBeanPostProcessor loggingProcessor) {
-        this.loggingProcessor = loggingProcessor;
+    public void setConfigurationProvider(ConfigurationProvider confProvider) {
+        this.confProvider = confProvider;
     }
 
-    public void setAnnotationProcessor(CommonAnnotationBeanPostProcessor annotationProcessor)
{
-        this.annotationProcessor = annotationProcessor;
+    public void setLogProvider(LogProvider logProvider) {
+        this.logProvider = logProvider;
     }
 
+
     @Override
     public void postProcessBeanFactory(BundleContext context, ConfigurableListableBeanFactory
factory) throws BeansException, InvalidSyntaxException, BundleException {
         // We need to set the beanfactory by hand. This MAY be a bug in spring-dm but I'm
not sure yet
+        LogEnabledBeanPostProcessor loggingProcessor = new LogEnabledBeanPostProcessor();
         loggingProcessor.setBeanFactory(factory);
+        loggingProcessor.setLogProvider(logProvider);
+        loggingProcessor.setOrder(0);
         factory.addBeanPostProcessor(loggingProcessor);
+        
+        OSGIResourceAnnotationBeanPostProcessor resourceProcessor = new OSGIResourceAnnotationBeanPostProcessor();
+        resourceProcessor.setBeanClassLoader(factory.getBeanClassLoader());
+        resourceProcessor.setBeanFactory(factory);
+        resourceProcessor.setBundleContext(context);
+        resourceProcessor.setTimeout(60 * 1000);
+        factory.addBeanPostProcessor(resourceProcessor);
+        
+        OSGIPersistenceUnitAnnotationBeanPostProcessor persistenceProcessor = new OSGIPersistenceUnitAnnotationBeanPostProcessor();
+        persistenceProcessor.setBeanClassLoader(factory.getBeanClassLoader());
+        persistenceProcessor.setBeanFactory(factory);
+        persistenceProcessor.setBundleContext(context);
+        persistenceProcessor.setTimeout(60 * 1000);
+        factory.addBeanPostProcessor(persistenceProcessor);
+        
+        ConfigurableBeanPostProcessor configurationProcessor = new ConfigurableBeanPostProcessor();
         configurationProcessor.setBeanFactory(factory);
+        configurationProcessor.setConfigurationProvider(confProvider);
+        configurationProcessor.setOrder(2);
         factory.addBeanPostProcessor(configurationProcessor);
-        annotationProcessor.setBeanFactory(factory);
+        
+        InitDestroyAnnotationBeanPostProcessor annotationProcessor = new InitDestroyAnnotationBeanPostProcessor();
+        annotationProcessor.setInitAnnotationType(PostConstruct.class);
+        annotationProcessor.setDestroyAnnotationType(PreDestroy.class);
         factory.addBeanPostProcessor(annotationProcessor);
 
+
     }
 
 }

Modified: james/server/trunk/lifecycle-spring/src/main/resources/META-INF/spring/extender/lifecycle-extender.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/lifecycle-spring/src/main/resources/META-INF/spring/extender/lifecycle-extender.xml?rev=1143788&r1=1143787&r2=1143788&view=diff
==============================================================================
--- james/server/trunk/lifecycle-spring/src/main/resources/META-INF/spring/extender/lifecycle-extender.xml
(original)
+++ james/server/trunk/lifecycle-spring/src/main/resources/META-INF/spring/extender/lifecycle-extender.xml
Thu Jul  7 12:16:59 2011
@@ -23,35 +23,14 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 
     <!-- 
-    ===========================================================================
-       Annotation - Bean Post-Processors
-    ===========================================================================
-    -->
-          
-    <!-- 
-      Enable Java Annotations processing.
-     -->
-    <bean id="annotationProcessor" class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
-        <property name="order" value="3" />
-    </bean>
-
-    <!-- 
       Spring "Bean-Post-Processor" for LogEnabled interface.
      -->
-    <bean id="loggingProcessor" class="org.apache.james.container.spring.lifecycle.LogEnabledBeanPostProcessor">
-        <property name="logProvider" ref="logprovider" />
-        <property name="order" value="0" />
-    </bean>
     <bean id="logprovider" class="org.apache.james.container.spring.lifecycle.LogProviderImpl">
     </bean>
 
     <!-- 
       Spring "Bean-Post-Processor" for Configurable interface.
      -->
-    <bean id="configurationProcessor" class="org.apache.james.container.spring.lifecycle.ConfigurableBeanPostProcessor">
-        <property name="configurationProvider" ref="configurationprovider" />
-        <property name="order" value="1" />
-    </bean>
     <bean id="configurationprovider" class="org.apache.james.container.spring.lifecycle.osgi.OSGIConfigurationProvider">
     <!--  
         <property name="configurationMappings">
@@ -65,9 +44,8 @@
     </bean>
     
     <bean class="org.apache.james.container.spring.lifecycle.osgi.OsgiLifecycleBeanFactoryPostProcessor">
-        <property name="loggingProcessor" ref="loggingProcessor" />
-        <property name="configurationProcessor" ref="configurationProcessor" />
-        <property name="annotationProcessor" ref="annotationProcessor" />
+        <property name="logProvider" ref="logprovider" />
+        <property name="configurationProvider" ref="configurationprovider" />
     </bean>
   
 </beans>



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message