import java.util.List;\r
import java.util.Map;\r
\r
+import org.codehaus.plexus.PlexusConstants;\r
import org.codehaus.plexus.logging.LogEnabled;\r
import org.codehaus.plexus.logging.LoggerManager;\r
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;\r
import org.springframework.beans.BeansException;\r
import org.springframework.beans.SimpleTypeConverter;\r
import org.springframework.beans.TypeConverter;\r
+import org.springframework.beans.factory.BeanCreationException;\r
import org.springframework.beans.factory.BeanFactory;\r
import org.springframework.beans.factory.BeanFactoryAware;\r
import org.springframework.beans.factory.BeanInitializationException;\r
public class PlexusComponentFactoryBean\r
implements FactoryBean, BeanFactoryAware, DisposableBean\r
{\r
+\r
+ private static final char HINT = '#';\r
+\r
private Class role;\r
\r
private Class implementation;\r
public Object getObject()\r
throws Exception\r
{\r
+ if ( "poolable".equals( instanciationStrategy ) )\r
+ {\r
+ throw new BeanCreationException( "Plexus poolable instanciation-strategy is not supported" );\r
+ }\r
+\r
+ if ( "singleton".equals( instanciationStrategy ) && !instances.isEmpty() )\r
+ {\r
+ return instances.get( 0 );\r
+ }\r
+\r
final Object component = implementation.newInstance();\r
synchronized ( instances )\r
{\r
{\r
// component ask plexus for a Map of all available components for the role\r
Map map = new HashMap();\r
- String mask = beanName + '#';\r
+ String mask = beanName + HINT;\r
String[] beans = beanFactory.getBeanDefinitionNames();\r
for ( int i = 0; i < beans.length; i++ )\r
{\r
}\r
if ( beanFactory.containsBean( beanName ) )\r
{\r
- map.put( "default", beanFactory.getBean( beanName ) );\r
+ map.put( PlexusConstants.PLEXUS_DEFAULT_HINT, beanFactory.getBean( beanName ) );\r
}\r
dependency = map;\r
}\r
else if ( Collection.class.isAssignableFrom( field.getType() ) )\r
{\r
List list = new LinkedList();\r
- String mask = beanName + '#';\r
+ String mask = beanName + HINT;\r
String[] beans = beanFactory.getBeanDefinitionNames();\r
for ( int i = 0; i < beans.length; i++ )\r
{\r
}\r
else\r
{\r
- dependency = beanFactory.getBean( beanName );\r
+ dependency = beanFactory.getBean( beanName );\r
}\r
}\r
if ( dependency != null )\r
*/\r
public void setInstanciationStrategy( String instanciationStrategy )\r
{\r
+ if (instanciationStrategy.length() == 0)\r
+ {\r
+ instanciationStrategy = "singleton";\r
+ }\r
this.instanciationStrategy = instanciationStrategy;\r
}\r
\r
{
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()} );
{
return getTestFile( basedir, path ).getAbsolutePath();
}
+
+ protected ConfigurableApplicationContext getApplicationContext()
+ {
+ return applicationContext;
+ }
}