incubator-composer-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject svn commit: r613775 [5/15] - in /incubator/composer: ./ core/ core/src/ core/src/java/ core/src/java/org/ core/src/java/org/apache/ core/src/java/org/apache/composer/ core/src/java/org/apache/composer/core/ core/src/java/org/apache/composer/core/adapte...
Date Mon, 21 Jan 2008 06:41:50 GMT
Added: incubator/composer/core/src/java/org/apache/composer/core/behaviors/ThreadCaching.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/behaviors/ThreadCaching.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/behaviors/ThreadCaching.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/behaviors/ThreadCaching.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (c) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
+ *****************************************************************************/
+
+package org.apache.composer.core.behaviors;
+
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.LifecycleStrategy;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+
+import java.util.Properties;
+
+/** @author Paul Hammant */
+public class ThreadCaching extends AbstractBehaviorFactory {
+
+    public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor componentMonitor,
+                                                          LifecycleStrategy lifecycleStrategy,
+                                                          Properties componentProperties,
+                                                          Object componentKey,
+                                                          Class<T> componentImplementation,
+                                                          Parameter... parameters)
+        throws CompositionException
+    {
+        if (removePropertiesIfPresent(componentProperties, Characteristics.NO_CACHE)) {
+            return super.createComponentAdapter(componentMonitor,
+                                                lifecycleStrategy,
+                                                componentProperties,
+                                                componentKey,
+                                                componentImplementation,
+                                                parameters);
+        }
+        removePropertiesIfPresent(componentProperties, Characteristics.CACHE);
+        return new ThreadCached<T>(super.createComponentAdapter(componentMonitor,
+                                                                lifecycleStrategy,
+                                                                componentProperties,
+                                                                componentKey,
+                                                                componentImplementation,
+                                                                parameters));
+
+    }
+
+    public <T> ComponentAdapter<T> addComponentAdapter(ComponentMonitor componentMonitor,
+                                                       LifecycleStrategy lifecycleStrategy,
+                                                       Properties componentProperties,
+                                                       ComponentAdapter<T> adapter)
+    {
+        if (removePropertiesIfPresent(componentProperties, Characteristics.NO_CACHE)) {
+            return super.addComponentAdapter(componentMonitor, lifecycleStrategy, componentProperties, adapter);
+        }
+        removePropertiesIfPresent(componentProperties, Characteristics.CACHE);
+        return new ThreadCached<T>(super.addComponentAdapter(componentMonitor,
+                                                             lifecycleStrategy,
+                                                             componentProperties,
+                                                             adapter));
+    }
+}
\ No newline at end of file

Added: incubator/composer/core/src/java/org/apache/composer/core/containers/AbstractDelegatingContainer.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/containers/AbstractDelegatingContainer.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/containers/AbstractDelegatingContainer.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/containers/AbstractDelegatingContainer.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,98 @@
+package org.apache.composer.core.containers;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
+import java.lang.annotation.Annotation;
+
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.NameBinding;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.ComposerException;
+import org.apache.composer.core.ContainerVisitor;
+
+/**
+ * abstract base class for immutable delegation to pico
+ * 
+ * @author k.pribluda
+ * 
+ */
+public abstract class AbstractDelegatingContainer implements Container, Serializable{
+
+	private Container delegate;
+
+	public AbstractDelegatingContainer(Container delegate) {
+		if (delegate == null) {
+			throw new NullPointerException(
+					"PicoContainer delegate must not be null");
+		}
+		this.delegate = delegate;
+	}
+
+	public void accept(ContainerVisitor visitor) {
+		delegate.accept(visitor);
+	}
+
+
+	public boolean equals(Object obj) {
+		// required to make it pass on both jdk 1.3 and jdk 1.4. Btw, what about
+		// overriding hashCode()? (AH)
+		return delegate.equals(obj) || this == obj;
+	}
+
+	public <T> T getComponent(Class<T> componentType) {
+		return componentType.cast(getComponent((Object) componentType));
+	}
+
+    public <T> T getComponent(Class<T> componentType, Class<? extends Annotation> binding) {
+        return delegate.getComponent(componentType, binding);
+    }
+
+    public Object getComponent(Object componentKeyOrType) {
+		return delegate.getComponent(componentKeyOrType);
+	}
+
+	public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType,
+			NameBinding componentNameBinding) {
+		return delegate.getComponentAdapter(componentType,
+                                            componentNameBinding);
+	}
+
+    public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, Class<? extends Annotation> binding) {
+        return delegate.getComponentAdapter(componentType, binding);
+    }
+
+    public ComponentAdapter<?> getComponentAdapter(Object componentKey) {
+		return delegate.getComponentAdapter(componentKey);
+	}
+
+	public Collection<ComponentAdapter<?>> getComponentAdapters() {
+		return delegate.getComponentAdapters();
+	}
+
+	public <T> List<ComponentAdapter<T>> getComponentAdapters(
+			Class<T> componentType) {
+		return delegate.getComponentAdapters(componentType);
+	}
+
+    public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType, Class<? extends Annotation> binding) {
+        return delegate.getComponentAdapters(componentType, binding);
+    }    
+
+    public List<Object> getComponents() {
+		return delegate.getComponents();
+	}
+
+	public <T> List<T> getComponents(Class<T> type) throws ComposerException {
+		return delegate.getComponents(type);
+	}
+
+	public Container getDelegate() {
+		return delegate;
+	}
+
+	public Container getParent() {
+		return delegate.getParent();
+	}
+	
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/containers/AbstractDelegatingMutableContainer.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/containers/AbstractDelegatingMutableContainer.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/containers/AbstractDelegatingMutableContainer.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/containers/AbstractDelegatingMutableContainer.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by the committers                                           *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import java.util.Properties;
+
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.Container;
+
+/**
+ * abstract base class for delegating to mutable containers
+ * @author Paul Hammant
+ */
+public abstract class AbstractDelegatingMutableContainer extends AbstractDelegatingContainer implements MutableContainer {
+
+	
+    public AbstractDelegatingMutableContainer(MutableContainer delegate) {
+		super(delegate);
+	}
+
+	public MutableContainer addComponent(Object componentKey,
+                                             Object componentImplementationOrInstance,
+                                             Parameter... parameters) throws CompositionException {
+        return getDelegate().addComponent(componentKey, componentImplementationOrInstance, parameters);
+    }
+
+    public MutableContainer addComponent(Object implOrInstance) throws CompositionException {
+        return getDelegate().addComponent(implOrInstance);
+    }
+
+    public MutableContainer addConfig(String name, Object val) {
+        return getDelegate().addConfig(name, val); 
+    }
+
+    public MutableContainer addAdapter(ComponentAdapter<?> componentAdapter) throws CompositionException {
+        return getDelegate().addAdapter(componentAdapter);
+    }
+
+    public <T> ComponentAdapter<T> removeComponent(Object componentKey) {
+        return getDelegate().removeComponent(componentKey);
+    }
+
+    public <T> ComponentAdapter<T> removeComponentByInstance(T componentInstance) {
+        return getDelegate().removeComponentByInstance(componentInstance);
+    }
+
+    public MutableContainer addChildContainer(Container child) {
+        return getDelegate().addChildContainer(child);
+    }
+
+    public boolean removeChildContainer(Container child) {
+        return getDelegate().removeChildContainer(child);
+    }
+
+	public MutableContainer change(Properties... properties) {
+	    return getDelegate().change(properties);
+	}
+
+	public MutableContainer as(Properties... properties) {
+	    return getDelegate().as(properties);
+	}
+	
+	public void dispose() {
+		getDelegate().dispose();
+	}
+
+	public MutableContainer makeChildContainer() {
+
+		return null;
+	}
+
+	public void start() {
+		getDelegate().start();
+	}
+
+	public void stop() {
+		getDelegate().stop();
+	}
+
+	public MutableContainer getDelegate() {
+		return (MutableContainer) super.getDelegate();
+	}
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/containers/CommandLineArgumentsContainer.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/containers/CommandLineArgumentsContainer.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/containers/CommandLineArgumentsContainer.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/containers/CommandLineArgumentsContainer.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,105 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.Container;
+
+/**
+ * CommandLineArgumentsPicoContainer configured itself from array of strings
+ * which are most likely coming in as command line arguments
+ * 
+ */
+@SuppressWarnings("serial")
+public class CommandLineArgumentsContainer extends AbstractDelegatingContainer {
+    public CommandLineArgumentsContainer(String separator, String[] arguments) {
+    	this(separator,arguments,null);
+    }
+
+    public CommandLineArgumentsContainer(String separator, String[] arguments, Container parent ) {
+    	super(new DefaultContainer(parent));
+        for (String argument : arguments) {
+            processArgument(argument, separator);
+        }
+    }
+    public CommandLineArgumentsContainer(String separator, StringReader argumentsProps) throws IOException {
+        this(separator, argumentsProps, new String[0]);
+    }
+    
+    public CommandLineArgumentsContainer(String separator, StringReader argumentProperties, String[] arguments) throws IOException{
+    	this(separator,argumentProperties,arguments,null);
+    }
+
+    public CommandLineArgumentsContainer(String separator, StringReader argumentProperties, String[] arguments, Container parent)
+        throws IOException {
+    	super(new DefaultContainer(parent));
+    	
+        LineNumberReader lnr = new LineNumberReader(argumentProperties);
+        String line = lnr.readLine();
+        while (line != null) {
+            processArgument(line, separator);
+            line = lnr.readLine();
+        }
+        for (String argument : arguments) {
+            processArgument(argument, separator);
+        }
+    }
+    
+    public CommandLineArgumentsContainer(String[] arguments) {
+        this("=", arguments);
+    }
+
+    public CommandLineArgumentsContainer(String[] arguments, Container parent) {
+    	this("=", arguments,parent);
+    }
+
+    private void addConfig(String key, Object val) {
+        if (getDelegate().getComponent(key) != null) {
+            getDelegate().removeComponent(key);
+        }
+        getDelegate().addConfig(key, val);
+    }
+
+    public <T> T getComponent(Class<T> componentType) {
+        return null;
+    }
+
+    public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType) {
+        return null;
+    }
+
+    public Container getParent() {
+        return new EmptyContainer();
+    }
+
+    private void processArgument(String argument, String separator) {
+        String[] kvs = argument.split(separator);
+        if (kvs.length == 2) {
+            addConfig(kvs[0], kvs[1]);
+        } else if (kvs.length == 1) {
+            addConfig(kvs[0], "true");
+        } else if (kvs.length > 2) {
+            throw new CompositionException(
+                "Argument name'"+separator+"'value pair '" + argument + "' has too many '"+separator+"' characters");
+        }
+    }
+    
+    public MutableContainer getDelegate() {
+    	return (MutableContainer) super.getDelegate();
+    }
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/containers/EmptyContainer.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/containers/EmptyContainer.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/containers/EmptyContainer.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/containers/EmptyContainer.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by Paul Hammant                                             *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.ContainerVisitor;
+import org.apache.composer.core.NameBinding;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.lang.annotation.Annotation;
+
+/**
+ * empty pico container serving as recoil damper in situations where you
+ * do not like to check whether container reference suplpied to you
+ * is null or not
+ *
+ * @author Konstantin Pribluda
+ */
+public class EmptyContainer implements Container, Serializable {
+
+    public Object getComponent(Object componentKeyOrType) {
+        return null;
+    }
+
+    public <T> T getComponent(Class<T> componentType) {
+        return null;
+    }
+
+    public <T> T getComponent(Class<T> componentType, Class<? extends Annotation> binding) {
+        return null;
+    }
+
+    public List getComponents() {
+        return Collections.EMPTY_LIST;
+    }
+
+    public Container getParent() {
+        return null;
+    }
+
+    public ComponentAdapter<?> getComponentAdapter(Object componentKey) {
+        return null;
+    }
+
+    public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, NameBinding componentNameBinding) {
+        return null;
+    }
+
+    public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, Class<? extends Annotation> binding) {
+        return null;
+    }
+
+    public Collection<ComponentAdapter<?>> getComponentAdapters() {
+        return Collections.emptyList();
+    }
+
+    public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType) {
+        return Collections.emptyList();
+    }
+
+    public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType, Class<? extends Annotation> binding) {
+        return Collections.emptyList();
+    }
+
+    /**
+     * we do not have anything to do here. 
+     */
+    public void accept(ContainerVisitor visitor) {
+    }
+
+    public <T> List<T> getComponents(Class<T> componentType) {
+        return Collections.emptyList();
+    }
+
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/containers/ImmutableContainer.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/containers/ImmutableContainer.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/containers/ImmutableContainer.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/containers/ImmutableContainer.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import org.apache.composer.core.Container;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ContainerVisitor;
+import org.apache.composer.core.NameBinding;
+
+import java.util.List;
+import java.util.Collection;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+/**
+* wrap pico container to achieve immutability
+ * Typically its used to mock a parent container.
+ *
+ * @author Konstantin Pribluda
+ */
+public class ImmutableContainer implements Container, Serializable {
+
+    private final Container delegate;
+
+    public ImmutableContainer(Container delegate) {
+        if (delegate == null) {
+            throw new NullPointerException();
+        }
+        this.delegate = delegate;
+    }
+
+    public Object getComponent(Object componentKeyOrType) {
+        return delegate.getComponent(componentKeyOrType);
+    }
+
+    public <T> T getComponent(Class<T> componentType) {
+        return delegate.getComponent(componentType);
+    }
+
+    public <T> T getComponent(Class<T> componentType, Class<? extends Annotation> binding) {
+        return delegate.getComponent(componentType, binding);
+    }
+
+    public List getComponents() {
+        return delegate.getComponents();
+    }
+
+    public Container getParent() {
+        return delegate.getParent();
+    }
+
+    public ComponentAdapter<?> getComponentAdapter(Object componentKey) {
+        return delegate.getComponentAdapter(componentKey);
+    }
+
+    public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, NameBinding componentNameBinding) {
+        return delegate.getComponentAdapter(componentType, componentNameBinding);
+    }
+
+    public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType, Class<? extends Annotation> binding) {
+        return delegate.getComponentAdapter(componentType, binding);
+    }
+
+    public Collection<ComponentAdapter<?>> getComponentAdapters() {
+        return delegate.getComponentAdapters();
+    }
+
+    public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType) {
+        return delegate.getComponentAdapters(componentType);
+    }
+
+    public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType, Class<? extends Annotation> binding) {
+        return delegate.getComponentAdapters(componentType, binding);
+    }
+
+    public <T> List<T> getComponents(Class<T> componentType) {
+        return delegate.getComponents(componentType);
+    }
+
+    public void accept(ContainerVisitor visitor) {
+        delegate.accept(visitor);
+    }
+
+    public boolean equals(Object obj) {
+        return obj == this
+               || (obj != null && obj == delegate)
+               || (obj instanceof ImmutableContainer && ((ImmutableContainer) obj).delegate == delegate)
+            ;
+    }
+
+
+    public int hashCode() {
+        return delegate.hashCode();
+    }
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/containers/PropertiesContainer.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/containers/PropertiesContainer.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/containers/PropertiesContainer.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/containers/PropertiesContainer.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import java.util.Properties;
+
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.Container;
+
+/**
+ * immutable pico container constructed from properties.
+ * intendet to be used with config parameter
+ * 
+ * @author k.pribluda
+ *
+ */
+@SuppressWarnings("serial")
+public class PropertiesContainer extends AbstractDelegatingContainer {
+
+	/**
+	 * create with parent container and populate from properties
+	 * @param properties
+	 * @param parent
+	 */
+	public PropertiesContainer(Properties properties, Container parent) {
+		super(new DefaultContainer(parent));
+		// populate container from properties
+		for(Object key: properties.keySet()) {
+			((MutableContainer)getDelegate()).addComponent(key,properties.get(key));
+		}
+	}
+	
+	/**
+	 * construct without a parent
+	 * @param properties
+	 */
+	public PropertiesContainer(Properties properties) {
+		this(properties,null);
+	}
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/containers/SystemPropertiesContainer.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/containers/SystemPropertiesContainer.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/containers/SystemPropertiesContainer.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/containers/SystemPropertiesContainer.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Copyright (c) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import org.apache.composer.core.Container;
+
+/**
+ * container backed by system properties. 
+ * @author k.pribluda
+ */
+@SuppressWarnings("serial")
+public class SystemPropertiesContainer extends PropertiesContainer {
+
+	public SystemPropertiesContainer() {
+		this(null);
+	}
+	public SystemPropertiesContainer(Container parent) {
+		super(System.getProperties(),parent);
+	}
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/containers/TransientContainer.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/containers/TransientContainer.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/containers/TransientContainer.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/containers/TransientContainer.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.injectors.ConstructorInjection;
+import org.apache.composer.core.behaviors.Caching;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+
+public class TransientContainer extends DefaultContainer {
+
+    public TransientContainer() {
+        super(new Caching().wrap(new ConstructorInjection()), new NullLifecycleStrategy(), null, new NullComponentMonitor());
+    }
+
+    public TransientContainer(Container parent) {
+        super(new Caching().wrap(new ConstructorInjection()), new NullLifecycleStrategy(), parent, new NullComponentMonitor());
+    }
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/injectors/AbstractInjector.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/injectors/AbstractInjector.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/injectors/AbstractInjector.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/injectors/AbstractInjector.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,434 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.LifecycleStrategy;
+import org.apache.composer.core.ObjectReference;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.ContainerVisitor;
+import org.apache.composer.core.adapters.AbstractAdapter;
+import org.apache.composer.core.parameters.ComponentParameter;
+
+/**
+ * This ComponentAdapter will instantiate a new object for each call to
+ * {@link org.apache.composer.core.ComponentAdapter#getComponentInstance(org.apache.composer.core.Container)}.
+ * That means that when used with a PicoContainer, getComponent will
+ * return a new object each time.
+ *
+ * @author Aslak Helles&oslash;y
+ * @author Paul Hammant
+ * @author J&ouml;rg Schaible
+ * @author Mauro Talevi
+ */
+public abstract class AbstractInjector<T> extends AbstractAdapter<T> implements LifecycleStrategy {
+    /** The cycle guard for the verification. */
+    protected transient ThreadLocalCyclicDependencyGuard verifyingGuard;
+    /** The parameters to use for initialization. */
+    protected transient Parameter[] parameters;
+
+    /** The strategy used to control the lifecycle */
+    protected LifecycleStrategy lifecycleStrategy;
+    private final boolean useNames;
+
+    /**
+     * Constructs a new ComponentAdapter for the given key and implementation.
+     * @param componentKey the search key for this implementation
+     * @param componentImplementation the concrete implementation
+     * @param parameters the parameters to use for the initialization
+     * @param monitor the component monitor used by this ComponentAdapter
+     * @param lifecycleStrategy the lifecycle strategy used by this ComponentAdapter
+     * @throws org.apache.composer.core.injectors.AbstractInjector.NotConcreteRegistrationException if the implementation is not a concrete class
+     * @throws NullPointerException if one of the parameters is <code>null</code>
+     */
+    protected AbstractInjector(final Object componentKey, final Class<?> componentImplementation, final Parameter[] parameters,
+                                            final ComponentMonitor monitor, final LifecycleStrategy lifecycleStrategy, final boolean useNames) {
+        super(componentKey, componentImplementation, monitor);
+        this.useNames = useNames;
+        checkConcrete();
+        if (parameters != null) {
+            for (int i = 0; i < parameters.length; i++) {
+                if(parameters[i] == null) {
+                    throw new NullPointerException("Parameter " + i + " is null");
+                }
+            }
+        }
+        this.parameters = parameters;
+        this.lifecycleStrategy = lifecycleStrategy;
+    }
+
+    public boolean useNames() {
+        return useNames;
+    }
+
+    private void checkConcrete() throws NotConcreteRegistrationException {
+        // Assert that the component class is concrete.
+        boolean isAbstract = (getComponentImplementation().getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT;
+        if (getComponentImplementation().isInterface() || isAbstract) {
+            throw new NotConcreteRegistrationException(getComponentImplementation());
+        }
+    }
+
+    /**
+     * Create default parameters for the given types.
+     *
+     * @param parameters the parameter types
+     * @return the array with the default parameters.
+     */
+    protected Parameter[] createDefaultParameters(final Class[] parameters) {
+        Parameter[] componentParameters = new Parameter[parameters.length];
+        for (int i = 0; i < parameters.length; i++) {
+            componentParameters[i] = ComponentParameter.DEFAULT;
+        }
+        return componentParameters;
+    }
+
+    public abstract void verify(Container container) throws CompositionException;
+
+    @Override
+	public void accept(final ContainerVisitor visitor) {
+        super.accept(visitor);
+        if (parameters != null) {
+            for (Parameter parameter : parameters) {
+                parameter.accept(visitor);
+            }
+        }
+    }
+    public void start(final Object component) {
+        lifecycleStrategy.start(component);
+    }
+
+    public void stop(final Object component) {
+        lifecycleStrategy.stop(component);
+    }
+
+    public void dispose(final Object component) {
+        lifecycleStrategy.dispose(component);
+    }
+
+    public boolean hasLifecycle(final Class<?> type) {
+        return lifecycleStrategy.hasLifecycle(type);
+    }
+
+    /**
+     * Instantiate an object with given parameters and respect the accessible flag.
+     *
+     * @param constructor the constructor to use
+     * @param parameters the parameters for the constructor
+     * @return the new object.
+     * @throws InstantiationException
+     * @throws IllegalAccessException
+     * @throws InvocationTargetException
+     */
+    protected T newInstance(final Constructor<T> constructor, final Object[] parameters) throws InstantiationException, IllegalAccessException, InvocationTargetException {
+        return constructor.newInstance(parameters);
+    }
+    /**
+     * inform monitor about component instantiation failure
+     * @param componentMonitor
+     * @param constructor
+     * @param e
+     * @param container
+     * @return
+     */
+    protected T caughtInstantiationException(final ComponentMonitor componentMonitor,
+                                                final Constructor<T> constructor,
+                                                final InstantiationException e, final Container container) {
+        // can't get here because checkConcrete() will catch it earlier, but see PICO-191
+        componentMonitor.instantiationFailed(container, this, constructor, e);
+        throw new CompositionException("Should never get here");
+    }
+
+    /**
+     * inform monitor about access exception.
+     * @param componentMonitor
+     * @param constructor
+     * @param e
+     * @param container
+     * @return
+     */
+    protected T caughtIllegalAccessException(final ComponentMonitor componentMonitor,
+                                                final Constructor<T> constructor,
+                                                final IllegalAccessException e, final Container container) {
+        // can't get here because either filtered or access mode set
+        componentMonitor.instantiationFailed(container, this, constructor, e);
+        throw new CompositionException(e);
+    }
+
+    /**
+     * inform monitor about exception while instantiating component
+     * @param componentMonitor
+     * @param member
+     * @param componentInstance
+     * @param e
+     * @return
+     */
+    protected T caughtInvocationTargetException(final ComponentMonitor componentMonitor,
+                                                   final Member member,
+                                                   final Object componentInstance, final InvocationTargetException e) {
+        componentMonitor.invocationFailed(member, componentInstance, e);
+        if (e.getTargetException() instanceof RuntimeException) {
+            throw (RuntimeException) e.getTargetException();
+        } else if (e.getTargetException() instanceof Error) {
+            throw (Error) e.getTargetException();
+        }
+        throw new CompositionException(e.getTargetException());
+    }
+
+    protected Object caughtIllegalAccessException(final ComponentMonitor componentMonitor,
+                                                final Member member,
+                                                final Object componentInstance, final IllegalAccessException e) {
+        componentMonitor.invocationFailed(member, componentInstance, e);
+        throw new CompositionException(e);
+    }
+
+    protected Class<?> box(final Class<?> parameterType) {
+        if (parameterType.isPrimitive()) {
+            if (parameterType == Integer.TYPE) {
+                return Integer.class;
+            } else if (parameterType == Boolean.TYPE) {
+                return Boolean.class;
+            }
+        }
+        return parameterType;
+    }
+
+    /**
+     * Abstract utility class to detect recursion cycles.
+     * Derive from this class and implement {@link ThreadLocalCyclicDependencyGuard#run}.
+     * The method will be called by  {@link ThreadLocalCyclicDependencyGuard#observe}. Select
+     * an appropriate guard for your scope. Any {@link ObjectReference} can be
+     * used as long as it is initialized with  <code>Boolean.FALSE</code>.
+     *
+     * @author J&ouml;rg Schaible
+     */
+    static abstract class ThreadLocalCyclicDependencyGuard<T> extends ThreadLocal<Boolean> {
+
+        protected Container guardedContainer;
+
+        @Override
+		protected Boolean initialValue() {
+            return Boolean.FALSE;
+        }
+
+        /**
+         * Derive from this class and implement this function with the functionality
+         * to observe for a dependency cycle.
+         *
+         * @return a value, if the functionality result in an expression,
+         *      otherwise just return <code>null</code>
+         */
+        public abstract T run();
+
+        /**
+         * Call the observing function. The provided guard will hold the {@link Boolean} value.
+         * If the guard is already <code>Boolean.TRUE</code> a {@link CyclicDependencyException}
+         * will be  thrown.
+         *
+         * @param stackFrame the current stack frame
+         * @return the result of the <code>run</code> method
+         */
+        public final T observe(final Class<?> stackFrame) {
+            if (Boolean.TRUE.equals(get())) {
+                throw new CyclicDependencyException(stackFrame);
+            }
+            T result = null;
+            try {
+                set(Boolean.TRUE);
+                result = run();
+            } catch (final CyclicDependencyException e) {
+                e.push(stackFrame);
+                throw e;
+            } finally {
+                set(Boolean.FALSE);
+            }
+            return result;
+        }
+
+        public void setGuardedContainer(final Container container) {
+            this.guardedContainer = container;
+        }
+
+    }
+
+    @SuppressWarnings("serial")
+	public static class CyclicDependencyException extends CompositionException {
+        private final List<Class> stack;
+
+        /**
+         * @param element
+         */
+        public CyclicDependencyException(final Class<?> element) {
+            super((Throwable)null);
+            this.stack = new LinkedList<Class>();
+            push(element);
+        }
+
+        /**
+         * @param element
+         */
+        public void push(final Class<?> element) {
+            stack.add(element);
+        }
+
+        public Class[] getDependencies() {
+            return stack.toArray(new Class[stack.size()]);
+        }
+
+        @Override
+		public String getMessage() {
+            return "Cyclic dependency: " + stack.toString();
+        }
+    }
+
+    /**
+     * Exception that is thrown as part of the introspection. Raised if a PicoContainer cannot resolve a
+     * type dependency because the registered {@link org.apache.composer.core.ComponentAdapter}s are not
+     * distinct.
+     *
+     * @author Paul Hammant
+     * @author Aslak Helles&oslash;y
+     * @author Jon Tirs&eacute;n
+     */
+    public static final class AmbiguousComponentResolutionException extends CompositionException {
+        /**
+		 *
+		 */
+		private static final long serialVersionUID = 646859644465924465L;
+		private Class<?> component;
+        private final Class<?> ambiguousDependency;
+        private final Object[] ambiguousComponentKeys;
+
+
+        /**
+         * Construct a new exception with the ambigous class type and the ambiguous component keys.
+         *
+         * @param ambiguousDependency the unresolved dependency type
+         * @param componentKeys the ambiguous keys.
+         */
+        public AmbiguousComponentResolutionException(final Class<?> ambiguousDependency, final Object[] componentKeys) {
+            super("");
+            this.ambiguousDependency = ambiguousDependency;
+            this.ambiguousComponentKeys = new Class[componentKeys.length];
+            System.arraycopy(componentKeys, 0, ambiguousComponentKeys, 0, componentKeys.length);
+        }
+
+        /**
+         * @return Returns a string containing the unresolved class type and the ambiguous keys.
+         */
+        @Override
+		public String getMessage() {
+            StringBuffer msg = new StringBuffer();
+            msg.append(component);
+            msg.append(" needs a '");
+            msg.append(ambiguousDependency.getName());
+            msg.append("' injected, but there are too many choices to inject. These:");
+            msg.append(Arrays.asList(getAmbiguousComponentKeys()));
+            msg.append(", refer http://picocontainer.org/ambiguous-injectable-help.html");
+            return msg.toString();
+        }
+
+        /**
+         * @return Returns the ambiguous component keys as array.
+         */
+        public Object[] getAmbiguousComponentKeys() {
+            return ambiguousComponentKeys;
+        }
+
+        public void setComponent(final Class<?> component) {
+            this.component = component;
+        }
+    }
+
+    /**
+     * Exception thrown when some of the component's dependencies are not satisfiable.
+     *
+     * @author Aslak Helles&oslash;y
+     * @author Mauro Talevi
+     */
+    public static class UnsatisfiableDependenciesException extends CompositionException {
+
+        /**
+		 * Serialization UUID.
+		 */
+		private static final long serialVersionUID = -8652053427387751791L;
+		
+		private final ComponentAdapter<?> instantiatingComponentAdapter;
+        private final Set unsatisfiableDependencies;
+        private final Class<?> unsatisfiedDependencyType;
+        
+        /**
+         * The original container requesting the instantiation of the component.
+         */
+        private final Container leafContainer;
+
+        public UnsatisfiableDependenciesException(final ComponentAdapter<?> instantiatingComponentAdapter,
+                                                  final Class<?> unsatisfiedDependencyType, final Set unsatisfiableDependencies,
+                                                  final Container leafContainer) {
+            super(instantiatingComponentAdapter.getComponentImplementation().getName() + " has unsatisfied dependency: " + unsatisfiedDependencyType
+                    +" among unsatisfiable dependencies: "+unsatisfiableDependencies + " where " + leafContainer
+                    + " was the leaf container being asked for dependencies.");
+            this.instantiatingComponentAdapter = instantiatingComponentAdapter;
+            this.unsatisfiableDependencies = unsatisfiableDependencies;
+            this.unsatisfiedDependencyType = unsatisfiedDependencyType;
+            this.leafContainer = leafContainer;
+        }
+
+        public ComponentAdapter<?> getUnsatisfiableComponentAdapter() {
+            return instantiatingComponentAdapter;
+        }
+
+        public Set getUnsatisfiableDependencies() {
+            return unsatisfiableDependencies;
+        }
+
+        public Class<?> getUnsatisfiedDependencyType() {
+            return unsatisfiedDependencyType;
+        }
+
+        public Container getLeafContainer() {
+            return leafContainer;
+        }
+
+    }
+
+    /**
+     * @author Aslak Hellesoy
+     */
+    public static class NotConcreteRegistrationException extends CompositionException {
+        /**
+		 * Serialization UUID.
+		 */
+		private static final long serialVersionUID = 6310754082738087791L;
+		
+		private final Class<?> componentImplementation;
+
+        public NotConcreteRegistrationException(final Class<?> componentImplementation) {
+            super("Bad Access: '" + componentImplementation.getName() + "' is not instantiable");
+            this.componentImplementation = componentImplementation;
+        }
+
+        public Class<?> getComponentImplementation() {
+            return componentImplementation;
+        }
+    }
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/injectors/AdaptingInjection.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/injectors/AdaptingInjection.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/injectors/AdaptingInjection.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/injectors/AdaptingInjection.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,221 @@
+/*****************************************************************************
+ * Copyright (c) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
+ *****************************************************************************/
+
+package org.apache.composer.core.injectors;
+
+import java.io.Serializable;
+import java.lang.reflect.AccessibleObject;
+import java.util.Properties;
+
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.InjectionFactory;
+import org.apache.composer.core.LifecycleStrategy;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.annotations.Inject;
+import org.apache.composer.core.behaviors.AbstractBehaviorFactory;
+
+/**
+ * Creates injector instances, depending on the injection characteristics of the component class. 
+ * It will attempt to create a component adapter with - in order of priority:
+ * <ol>
+ *  <li>Annotated field injection: if annotation {@link @Inject} is found for field</li>
+ *  <li>Annotated method injection: if annotation {@link @Inject} is found for method</li>
+ *  <li>Setter injection: if {@link Characteristics.SDI} is found</li>
+ *  <li>Method injection: if {@link Characteristics.METHOD_INJECTION} if found</li>
+ *  <li>Constructor injection (the default, must find {@link Characteristics.CDI})</li>
+ * </ol>
+ *
+ * @author Paul Hammant
+ * @author Mauro Talevi
+ * @see AnnotatedFieldInjection
+ * @see AnnotatedMethodInjection
+ * @see SetterInjection
+ * @see MethodInjection
+ * @see ConstructorInjection
+ */
+public class AdaptingInjection implements InjectionFactory, Serializable {
+
+    /**
+	 * Serialization UUID.
+	 */
+	private static final long serialVersionUID = 8660775238892763896L;
+
+	public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor componentMonitor,
+                                                   LifecycleStrategy lifecycleStrategy,
+                                                   Properties componentProperties,
+                                                   Object componentKey,
+                                                   Class<T> componentImplementation,
+                                                   Parameter... parameters) throws CompositionException {
+        ComponentAdapter<T> componentAdapter = null;
+        
+        componentAdapter = fieldAnnotatedInjectionAdapter(componentImplementation,
+                               componentMonitor,
+                               lifecycleStrategy,
+                               componentProperties,
+                               componentKey,
+                               componentAdapter,
+                               parameters);
+
+        if (componentAdapter != null) {
+            return componentAdapter;
+        }
+
+
+        componentAdapter = methodAnnotatedInjectionAdapter(componentImplementation,
+                                                           componentMonitor,
+                                                           lifecycleStrategy,
+                                                           componentProperties,
+                                                           componentKey,
+                                                           componentAdapter,
+                                                           parameters);
+
+        if (componentAdapter != null) {
+            return componentAdapter;
+        }
+
+        componentAdapter = setterInjectionAdapter(componentProperties,
+                                                 componentMonitor,
+                                                 lifecycleStrategy,
+                                                 componentKey,
+                                                 componentImplementation,
+                                                 componentAdapter,
+                                                 parameters);
+
+        if (componentAdapter != null) {
+            return componentAdapter;
+        }
+
+        componentAdapter = methodInjectionAdapter(componentProperties,
+                                                 componentMonitor,
+                                                 lifecycleStrategy,
+                                                 componentKey,
+                                                 componentImplementation,
+                                                 componentAdapter,
+                                                 parameters);
+
+        if (componentAdapter != null) {
+            return componentAdapter;
+        }
+
+
+        return defaultInjectionAdapter(componentProperties,
+                                    componentMonitor,
+                                    lifecycleStrategy,
+                                    componentKey,
+                                    componentImplementation,
+                                    parameters);
+    }
+
+    private <T> ComponentAdapter<T> defaultInjectionAdapter(Properties componentProperties,
+                                                  ComponentMonitor componentMonitor,
+                                                  LifecycleStrategy lifecycleStrategy,
+                                                  Object componentKey,
+                                                  Class<T> componentImplementation, Parameter... parameters) {
+        AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, Characteristics.CDI);
+        return new ConstructorInjection().createComponentAdapter(componentMonitor,
+                                                                        lifecycleStrategy,
+                                                                        componentProperties,
+                                                                        componentKey,
+                                                                        componentImplementation,
+                                                                        parameters);
+    }
+
+    private <T> ComponentAdapter<T> setterInjectionAdapter(Properties componentProperties,
+                                                   ComponentMonitor componentMonitor,
+                                                   LifecycleStrategy lifecycleStrategy,
+                                                   Object componentKey,
+                                                   Class<T> componentImplementation,
+                                                   ComponentAdapter<T> componentAdapter,
+                                                   Parameter... parameters) {
+        if (AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, Characteristics.SDI)) {
+            componentAdapter = new SetterInjection().createComponentAdapter(componentMonitor, lifecycleStrategy,
+                                                                                                    componentProperties,
+                                                                                                    componentKey,
+                                                                                                    componentImplementation,
+                                                                                                    parameters);
+        }
+        return componentAdapter;
+    }
+
+    private <T> ComponentAdapter<T> methodInjectionAdapter(Properties componentProperties,
+                                                   ComponentMonitor componentMonitor,
+                                                   LifecycleStrategy lifecycleStrategy,
+                                                   Object componentKey,
+                                                   Class<T> componentImplementation,
+                                                   ComponentAdapter<T> componentAdapter,
+                                                   Parameter... parameters) {
+        if (AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, Characteristics.METHOD_INJECTION)) {
+            componentAdapter = new MethodInjection().createComponentAdapter(componentMonitor, lifecycleStrategy,
+                                                                                                    componentProperties,
+                                                                                                    componentKey,
+                                                                                                    componentImplementation,
+                                                                                                    parameters);
+        }
+        return componentAdapter;
+    }
+
+
+    private <T> ComponentAdapter<T> methodAnnotatedInjectionAdapter(Class<T> componentImplementation,
+                                                             ComponentMonitor componentMonitor,
+                                                             LifecycleStrategy lifecycleStrategy,
+                                                             Properties componentProperties,
+                                                             Object componentKey,
+                                                             ComponentAdapter<T> componentAdapter,
+                                                             Parameter... parameters) {
+        if (injectionMethodAnnotated(componentImplementation)) {
+            componentAdapter =
+                new AnnotatedMethodInjection().createComponentAdapter(componentMonitor,
+                                                                              lifecycleStrategy,
+                                                                              componentProperties,
+                                                                              componentKey,
+                                                                              componentImplementation,
+                                                                              parameters);
+        }
+        return componentAdapter;
+    }
+
+    private <T> ComponentAdapter<T> fieldAnnotatedInjectionAdapter(Class<T> componentImplementation,
+                                 ComponentMonitor componentMonitor,
+                                 LifecycleStrategy lifecycleStrategy,
+                                 Properties componentProperties,
+                                 Object componentKey, ComponentAdapter<T> componentAdapter, Parameter... parameters) {
+        if (injectionFieldAnnotated(componentImplementation)) {
+             componentAdapter =
+                new AnnotatedFieldInjection().createComponentAdapter(componentMonitor,
+                                                                             lifecycleStrategy,
+                                                                             componentProperties,
+                                                                             componentKey,
+                                                                             componentImplementation,
+                                                                             parameters);
+        }
+        return componentAdapter;
+    }
+
+    private boolean injectionMethodAnnotated(Class<?> componentImplementation) {
+        return injectionAnnotated(componentImplementation.getDeclaredMethods());
+    }
+
+    private boolean injectionFieldAnnotated(Class<?> componentImplementation) {
+        return injectionAnnotated(componentImplementation.getDeclaredFields());
+    }
+    
+    private boolean injectionAnnotated(AccessibleObject[] objects) {
+        for (AccessibleObject object : objects) {
+            if (object.getAnnotation(Inject.class) != null) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedFieldInjection.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedFieldInjection.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedFieldInjection.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedFieldInjection.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.LifecycleStrategy;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.InjectionFactory;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.behaviors.AbstractBehaviorFactory;
+import org.apache.composer.core.annotations.Inject;
+
+import java.util.Properties;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+/**
+ * A {@link org.apache.composer.core.InjectionFactory} for Guice-style annotated fields.
+ * The factory creates {@link AnnotatedFieldInjector}.
+ *
+ * @author Paul Hammant
+ */
+public class AnnotatedFieldInjection implements InjectionFactory, Serializable {
+
+    /**
+	 * Serialization UUID.
+	 */
+	private static final long serialVersionUID = -7470345740391531008L;
+	
+	private final Class<? extends Annotation> injectionAnnotation;
+
+    public AnnotatedFieldInjection(Class<? extends Annotation> injectionAnnotation) {
+        this.injectionAnnotation = injectionAnnotation;
+    }
+
+    public AnnotatedFieldInjection() {
+        this(Inject.class);
+    }
+
+    public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor componentMonitor,
+                                                   LifecycleStrategy lifecycleStrategy,
+                                                   Properties componentProperties,
+                                                   Object componentKey,
+                                                   Class<T> componentImplementation,
+                                                   Parameter... parameters) throws CompositionException {
+        boolean useNames = AbstractBehaviorFactory.removePropertiesIfPresent(componentProperties, Characteristics.USE_NAMES);
+        return new AnnotatedFieldInjector(componentKey, componentImplementation, parameters, componentMonitor, lifecycleStrategy,
+                                          injectionAnnotation, useNames);
+    }
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedFieldInjector.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedFieldInjector.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedFieldInjector.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedFieldInjector.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,108 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.LifecycleStrategy;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.NameBinding;
+import org.apache.composer.core.annotations.Bind;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Injection happens after instantiation, and through fields marked as injection points via an Annotation.
+ * The default annotation of org.apache.composer.core.annotations.@Inject can be overridden.
+ */
+public class AnnotatedFieldInjector extends IterativeInjector {
+
+    /**
+	 * Serialization UUID.
+	 */
+	private static final long serialVersionUID = -1995850745951708186L;
+	
+	private final Class<? extends Annotation> injectionAnnotation;
+
+    public AnnotatedFieldInjector(Object key,
+                                  Class<?> impl,
+                                  Parameter[] parameters,
+                                  ComponentMonitor componentMonitor,
+                                  LifecycleStrategy lifecycleStrategy, 
+                                  Class<? extends Annotation> injectionAnnotation, boolean useNames) {
+
+        super(key, impl, parameters, componentMonitor, lifecycleStrategy, useNames);
+        this.injectionAnnotation = injectionAnnotation;
+    }
+
+    protected void initializeInjectionMembersAndTypeLists() {
+        injectionMembers = new ArrayList<AccessibleObject>();
+        List<Annotation> bindingIds = new ArrayList<Annotation>();
+        final List<Class> typeList = new ArrayList<Class>();
+        final Field[] fields = getFields();
+        for (final Field field : fields) {
+            if (isAnnotatedForInjection(field)) {
+                injectionMembers.add(field);
+                typeList.add(box(field.getType()));
+                bindingIds.add(getBinding(field));
+            }
+        }
+        injectionTypes = typeList.toArray(new Class[0]);
+        bindings = bindingIds.toArray(new Annotation[0]);
+    }
+
+    private Annotation getBinding(Field field) {
+        Annotation[] annotations = field.getAnnotations();
+        for (Annotation annotation : annotations) {
+            if (annotation.annotationType().isAnnotationPresent(Bind.class)) {
+                return annotation;
+            }
+        }
+        return null;
+    }
+
+    protected boolean isAnnotatedForInjection(Field field) {
+        return field.getAnnotation(injectionAnnotation) != null;
+    }
+
+    private Field[] getFields() {
+        return (Field[]) AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                return getComponentImplementation().getDeclaredFields();
+            }
+        });
+    }
+
+
+    protected void injectIntoMember(AccessibleObject member, Object componentInstance, Object toInject)
+        throws IllegalAccessException, InvocationTargetException {
+        Field field = (Field) member;
+        field.setAccessible(true);
+        field.set(componentInstance, toInject);
+    }
+
+    public String getDescriptor() {
+        return "FieldInjector-";
+    }
+
+    protected NameBinding makeParameterNameImpl(final AccessibleObject member) {
+        return new NameBinding() {
+            public String getName() {
+                return ((Field) member).getName();
+            }
+        };
+    }
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedMethodInjection.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedMethodInjection.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedMethodInjection.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedMethodInjection.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * Copyright (c) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
+ *****************************************************************************/
+
+package org.apache.composer.core.injectors;
+
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.LifecycleStrategy;
+import org.apache.composer.core.InjectionFactory;
+import org.apache.composer.core.annotations.Inject;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Properties;
+
+
+/**
+ * A {@link org.apache.composer.core.InjectionFactory} for Guice-style annotated methods.
+ * The factory creates {@link AnnotatedMethodInjector}.
+ *
+ * @author Paul Hammant
+ */
+public class AnnotatedMethodInjection implements InjectionFactory, Serializable {
+
+    /**
+	 * Serialization UUID.
+	 */
+	private static final long serialVersionUID = 6225372552727902003L;
+	
+	private final Class<? extends Annotation> injectionAnnotation;
+    private final boolean useNames;
+
+    public AnnotatedMethodInjection(Class<? extends Annotation> injectionAnnotation, boolean useNames) {
+        this.injectionAnnotation = injectionAnnotation;
+        this.useNames = useNames;
+    }
+
+    public AnnotatedMethodInjection() {
+        this(Inject.class, false);
+    }
+
+    /**
+     * Create a {@link SetterInjector}.
+     * 
+     * @param componentMonitor
+     * @param lifecycleStrategy
+     * @param componentProperties
+     * @param componentKey The component's key
+     * @param componentImplementation The class of the bean.
+     * @param parameters Any parameters for the setters. If null the adapter
+     *            solves the dependencies for all setters internally. Otherwise
+     *            the number parameters must match the number of the setter.
+     * @return Returns a new {@link SetterInjector}.
+     * @throws org.apache.composer.core.CompositionException if dependencies cannot
+     *             be solved or if the implementation is an interface or an
+     *             abstract class.
+     */
+    public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor componentMonitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties,
+                                                   Object componentKey, Class<T> componentImplementation, Parameter... parameters)
+            throws CompositionException {
+        return new AnnotatedMethodInjector(componentKey, componentImplementation, parameters, componentMonitor, lifecycleStrategy, injectionAnnotation, useNames);
+    }
+}
\ No newline at end of file

Added: incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedMethodInjector.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedMethodInjector.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedMethodInjector.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/injectors/AnnotatedMethodInjector.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.LifecycleStrategy;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+public class AnnotatedMethodInjector extends SetterInjector {
+
+    /**
+	 * Serialization UUID.
+	 */
+	private static final long serialVersionUID = -1347829923043944701L;
+	
+	private final Class<? extends Annotation> injectionAnnotation;
+
+    public AnnotatedMethodInjector(Object key,
+                                   Class<?> impl,
+                                   Parameter[] parameters,
+                                   ComponentMonitor monitor,
+                                   LifecycleStrategy lifecycleStrategy, Class<? extends Annotation> injectionAnnotation, boolean useNames) {
+        super(key, impl, parameters, monitor, lifecycleStrategy, "", useNames);
+        this.injectionAnnotation = injectionAnnotation;
+    }
+
+    protected final boolean isInjectorMethod(Method method) {
+        return method.getAnnotation(injectionAnnotation) != null;
+    }
+
+    public String toString() {
+        return "MethodInjection-" + super.toString();
+    }
+
+}

Added: incubator/composer/core/src/java/org/apache/composer/core/injectors/ConstructorInjection.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/java/org/apache/composer/core/injectors/ConstructorInjection.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/java/org/apache/composer/core/injectors/ConstructorInjection.java (added)
+++ incubator/composer/core/src/java/org/apache/composer/core/injectors/ConstructorInjection.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * Copyright (c) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
+ *****************************************************************************/
+
+package org.apache.composer.core.injectors;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.InjectionFactory;
+import org.apache.composer.core.LifecycleStrategy;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.behaviors.AbstractBehaviorFactory;
+
+/**
+ * A {@link org.apache.composer.core.InjectionFactory} for constructors.
+ * The factory creates {@link ConstructorInjector}.
+ * 
+ *  @author Paul Hammant 
+ * @author Jon Tirs&eacute;n
+ */
+public class ConstructorInjection implements InjectionFactory, Serializable {
+
+
+    public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor componentMonitor, LifecycleStrategy lifecycleStrategy, Properties properties, Object componentKey,
+                                                   Class<T> componentImplementation, Parameter... parameters) throws CompositionException {
+        boolean useNames = AbstractBehaviorFactory.removePropertiesIfPresent(properties, Characteristics.USE_NAMES);
+        return new ConstructorInjector(componentKey, componentImplementation, parameters, componentMonitor, lifecycleStrategy, useNames);
+    }
+}



Mime
View raw message