archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r630818 - in /maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring: PlexusComponentFactoryBean.java PlexusInSpringTestCase.java
Date Mon, 25 Feb 2008 11:55:06 GMT
Author: nicolas
Date: Mon Feb 25 03:54:45 2008
New Revision: 630818

URL: http://svn.apache.org/viewvc?rev=630818&view=rev
Log:
fix : cache instance in beanFactory when instanciation-strategy = singleton

Modified:
    maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
    maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java

Modified: maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java?rev=630818&r1=630817&r2=630818&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
(original)
+++ maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
Mon Feb 25 03:54:45 2008
@@ -27,6 +27,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.codehaus.plexus.PlexusConstants;
 import org.codehaus.plexus.logging.LogEnabled;
 import org.codehaus.plexus.logging.LoggerManager;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
@@ -34,6 +35,7 @@
 import org.springframework.beans.BeansException;
 import org.springframework.beans.SimpleTypeConverter;
 import org.springframework.beans.TypeConverter;
+import org.springframework.beans.factory.BeanCreationException;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.BeanFactoryAware;
 import org.springframework.beans.factory.BeanInitializationException;
@@ -58,6 +60,9 @@
 public class PlexusComponentFactoryBean
     implements FactoryBean, BeanFactoryAware, DisposableBean
 {
+
+    private static final char HINT = '#';
+
     private Class role;
 
     private Class implementation;
@@ -94,6 +99,16 @@
     public Object getObject()
         throws Exception
     {
+        if ( "poolable".equals( instanciationStrategy ) )
+        {
+            throw new BeanCreationException( "Plexus poolable instanciation-strategy is not
supported" );
+        }
+
+        if ( "singleton".equals( instanciationStrategy ) && !instances.isEmpty()
)
+        {
+            return instances.get( 0 );
+        }
+
         final Object component = implementation.newInstance();
         synchronized ( instances )
         {
@@ -114,7 +129,7 @@
                         {
                             // component ask plexus for a Map of all available components
for the role
                             Map map = new HashMap();
-                            String mask = beanName + '#';
+                            String mask = beanName + HINT;
                             String[] beans = beanFactory.getBeanDefinitionNames();
                             for ( int i = 0; i < beans.length; i++ )
                             {
@@ -126,14 +141,14 @@
                             }
                             if ( beanFactory.containsBean( beanName ) )
                             {
-                                map.put( "default", beanFactory.getBean( beanName ) );
+                                map.put( PlexusConstants.PLEXUS_DEFAULT_HINT, beanFactory.getBean(
beanName ) );
                             }
                             dependency = map;
                         }
                         else if ( Collection.class.isAssignableFrom( field.getType() ) )
                         {
                             List list = new LinkedList();
-                            String mask = beanName + '#';
+                            String mask = beanName + HINT;
                             String[] beans = beanFactory.getBeanDefinitionNames();
                             for ( int i = 0; i < beans.length; i++ )
                             {
@@ -151,7 +166,7 @@
                         }
                         else
                         {
-                            dependency = beanFactory.getBean( beanName );
+                             dependency = beanFactory.getBean( beanName );
                         }
                     }
                     if ( dependency != null )
@@ -247,6 +262,10 @@
      */
     public void setInstanciationStrategy( String instanciationStrategy )
     {
+        if (instanciationStrategy.length() == 0)
+        {
+            instanciationStrategy = "singleton";
+        }
         this.instanciationStrategy = instanciationStrategy;
     }
 

Modified: maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java?rev=630818&r1=630817&r2=630818&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
(original)
+++ maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
Mon Feb 25 03:54:45 2008
@@ -45,7 +45,8 @@
     {
         basedir = getBasedir();
         applicationContext =
-            new PlexusClassPathXmlApplicationContext( new String[] { "classpath*:META-INF/plexus/components.xml",
+            new PlexusClassPathXmlApplicationContext( new String[] {
+                "classpath*:META-INF/plexus/components.xml",
                 "classpath*:META-INF/plexus/components-fragment.xml",
                 "classpath*:" + getPlexusConfigLocation(),
                 "classpath*:" + getSpringConfigLocation()} );
@@ -153,5 +154,10 @@
                                       String path )
     {
         return getTestFile( basedir, path ).getAbsolutePath();
+    }
+
+    protected ConfigurableApplicationContext getApplicationContext()
+    {
+        return applicationContext;
     }
 }



Mime
View raw message