incubator-composer-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject svn commit: r618174 [2/5] - in /incubator/composer/trunk: ./ composer-site/ composer-site/src/ composer-site/src/assembly/ composer-site/src/config/ composer-site/src/resources/ composer-site/src/resources/images/ composer-site/src/resources/style/ com...
Date Mon, 04 Feb 2008 06:33:26 GMT
Added: incubator/composer/trunk/composer-site/src/site/content/builder.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/builder.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/builder.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/builder.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,70 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+<title>Building Containers</title>
+</head>
+<body>
+<p>Rather than new up a Apache Composer instance with the right ComponentFactory, LifecycleStategy and ComponentMonitor, your can use  ContainerBuilder for conveniece. Refer to Martin's <a
+  href="http://www.martinfowler.com/bliki/FluentInterface.html">'Fluent
+Interface'</a> article, for some of the motivation behing this class.</p>
+<p>Some simple examples :</p>
+    <div class="source"><pre>
+pico = new ContainerBuilder().build();
+pico.addComponent(Apple.class);
+</pre></div>
+    <div class="source"><pre>pico = new ContainerBuilder().withCaching().build();
+pico.addComponent(Apple.class);</pre></div>
+    <div class="source"><pre>
+pico = new ContainerBuilder().withCaching().build();
+pico.addComponent(Apple.class);
+</pre></div>
+    <div class="source"><pre>pico = new ContainerBuilder().withHiddenImplementations().build();
+pico.addComponent(Apple.class);</pre></div>
+
+<p>More varations for behaviors :</p>
+<div class="source"><pre>
+pico = new ContainerBuilder().withLifecycle().withConsoleMonitor().build();
+pico.addComponent(Apple.class);
+</pre></div>
+    <div class="source"><pre>pico = new ContainerBuilder().withMonitor(ConsoleComponentMonitor.class).build();
+pico.addComponent(Apple.class);</pre></div>
+    <div class="source"><pre>
+import static org.picocontainer.injectors.Injectors.SDI;
+import static org.picocontainer.behaviors.Behaviors.caching;
+import static org.picocontainer.behaviors.Behaviors.implementationHiding;
+import static org.picocontainer.behaviors.Behaviors.synchronizing;
+...  
+pico = new ContainerBuilder(SDI()).withBehaviors(caching(), implementationHiding(), synchronizing()).build();
+pico.addComponent(Apple.class);
+</pre></div>
+<p>Setting a parent container :</p>
+    <div class="source"><pre>child = new ContainerBuilder(parentContainer).build();
+child.addComponent(Apple.class);</pre></div>
+
+<p>Specifying an injection type:</p>
+    <div class="source"><pre>
+pico = new ContainerBuilder().withAnnotationInjection().build();
+pico.addComponent(Apple.class);
+</pre></div>
+<p>Specifying an injection type a different way:</p>
+    <div class="source"><pre>
+import static org.picocontainer.injectors.Injectors.SDI;
+...
+pico = new ContainerBuilder(SDI()).build();
+pico.addComponent(Apple.class);</pre></div>
+<p>A custom container component used by a custom  ComponentBehavior (though could be used by ComponentMonitor or LifecycleStrategy as easily): </p>
+
+    <div class="source">
+      <pre>
+pico = new ContainerBuilder()
+    .withCustomContainerComponent(new MyQuantumPhysicsConnector())
+    .withComponentFactory(MyQuantumPhysicsConnectionNeedingComponentBehavior.class).build();
+pico.addComponent(Apple.class);</pre></div>
+	<p>A custom container implementation (DefaultApache Composer is the default):</p> 
+    <div class="source">
+      <pre>MyCustomApache Composer pico = (MyCustomApache Composer) new ContainerBuilder().implementedBy(MyCustomApache Composer.class).build();
+pico.addComponent(Apple.class);</pre>
+</div>
+</body>
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/class-naming.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/class-naming.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/class-naming.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/class-naming.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,23 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+<title>Class Naming</title>
+</head>
+<body>
+<p>Apache Composer's class naming changed substantially between 1.0 and 2.0. There are two major influences for this:</p>
+<ol>
+  <li>Dan North's &quot;Behavior Driven Design&quot; agenda and his interest in Neuro Linguistic Programming (NLP)</li>
+  <li>Steve Yegge's technical fable : <a href="http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html">Execution in the Kingdom of Nouns</a></li>
+</ol>
+<p>The take away from both is that we don't have to have long classnames like <em>CachingComponentAdapterFactory</em> and <em>ImplementationHidingComponentAdapterFactory</em>, we can in fact have shorter names, that read better in their intended use:</p>
+<pre>  new DefaultApache Composer(new Caching());</pre>
+<p>Similarly,  method names can play a part in simplicity and meaning for real situations where they are used.</p>
+<pre>  new DefaultApache Composer(new Caching().wrap(new ImplementationHiding()));
+</pre>
+<p>Caching, the class, implements an abstraction called BehaviorFactory as do many others. All BehaviorFactory implementations make implementations of Behavior like 'Cached'. Similarly 'ConstructionInjection' (and similar) make implementations of Injector like 'ConstructorInjector' (and similar). Both BehaviorFactory and InjectionFactory are extensions of ComponentFactory.</p>
+<p></p>
+<p>&nbsp;</p>
+<p>&nbsp;</p>
+</body>
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/comparisons.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/comparisons.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/comparisons.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/comparisons.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html 
+     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Container Comparisons</title>
+</head>
+<body>
+    <div>
+      <div>
+        <h2>Overview</h2>
+        <p>This document aims to compare Apache Composer to other IoC containers, both lightweight and not.</p>
+        <p>There are a number of published API specifications since Java was initially released that proport to be container/component designs. We discuss then here, suggesting there are goals that some have met, and some not. This may help you make better design choices for your own components.</p>
+      </div>
+      <div>
+        <h2>IoC Containers</h2>
+        <div>
+          <h3>Spring Framework</h3>
+          <p>The <a href="http://www.springframework.org/">Spring Framework</a> is a J2EE framework. As such, <a href="injection.html" title="Dependency Injection">Dependency Injection</a> and <a href="lifecycle.html" title="lifecycle">Lifecycle</a> is only one of its concerns. Apache Composer, on the other hand, is concerned only with <a href="injection.html" title="Dependency Injection">Dependency Injection</a>, configuration and <a href="lifecycle.html" title="lifecycle">Lifecycle</a>.</p>
+        </div>
+        <div>
+          <h3>Apache Avalon and its containers</h3>
+          <p>(Avalon ceased development in 2005)</p>
+          <p>Apache hosted a project that had been running for many years called Avalon. It had many components that fit that its design and many containers is writtern in Java. Avalon components were characterised by implementation of many optional interfaces. Avalon components were distributed with meta-information in XML in the jar file. More XML is required to assemble components together for the same of a application. Avalon Phoenix, Excalibur Component Manager (ECM), Avalon Fortress and Avalon Merlin were the pertinent containers.</p>
+          <p>The Avalon Framework required implementing components to implement a number of interfaces. By the end of the the project, this had proven historically to be a bit of a turn-off for component writers.  Those interfaces were :-</p>
+          <table>
+            <tbody>
+              <tr>
+                <th> Avalon Interface </th>
+                <th> Apache Composer equivalent </th>
+              </tr>
+              <tr>
+                <td> LogEnabled </td>
+                <td> Logging agnostic </td>
+              </tr>
+              <tr>
+                <td> Contextualizable </td>
+                <td> n/a </td>
+              </tr>
+              <tr>
+                <td> Serviceable (was Composable) </td>
+                <td>arguments are injected</td>
+              </tr>
+              <tr>
+                <td> Configurable </td>
+                <td>arguments are injected</td>
+              </tr>
+              <tr>
+                <td> Parameterizable </td>
+                <td> n/a </td>
+              </tr>
+              <tr>
+                <td> Initializable </td>
+                <td> Constructor is the equivalent lifecycle concept </td>
+              </tr>
+              <tr>
+                <td> Startable </td>
+                <td> Startable </td>
+              </tr>
+              <tr>
+                <td> Suspendable </td>
+                <td> n/a </td>
+              </tr>
+              <tr>
+                <td> Recontextualizable </td>
+                <td> n/a </td>
+              </tr>
+              <tr>
+                <td> Recomposable </td>
+                <td> n/a </td>
+              </tr>
+              <tr>
+                <td> Reconfigurable </td>
+                <td> n/a </td>
+              </tr>
+              <tr>
+                <td> Reparameterizable </td>
+                <td> n/a </td>
+              </tr>
+              <tr>
+                <td> Disposable </td>
+                <td> Disposable </td>
+              </tr>
+            </tbody>
+          </table>
+          <p>Avalon is a Contextualized Lookup IoC design. </p>
+          <div>
+    <h2>Example</h2>
+
+    <div class="source">
+        <div>
+            <pre>import org.apache.avalon.framework.ServiceManager;
+import org.apache.avalon.framework.Serviceable;
+import org.apache.avalon.framework.ServiceException;
+
+public class Shop implements Serviceable, Initializable {
+    StockManager stockManager;
+    String shopZipCode;
+    public void service(ServiceManager sm) throws ServiceException {
+        stockManager = (StockManager) sm.lookup(&quot;StockManager&quot;);
+    }
+    public void initialize() {
+        // all service()ing has been done.
+    }
+}</pre>
+        </div>
+    </div>
+    <p>A component has to have service (component) declarations in an external file. The  <a href="http://loom.codehaus.org/">Loom</a>  container (forked from
+       <a href="http://www.axint.net/apache/avalon/phoenix/v4.0.2/">Phoenix</a>) has .xinfo files for each component to meet such needs. All Avalon container have some mechanism for storing
+       configuration and assembly externally to the class. Cross referenced against the xinfo files, Loom's assembly.xml
+       defines the implementations to be used for component types. Thus all Avalon components must be
+       interface/implementation separated. Another Avalon using server technology is <a href="http://www.keelframework.org/">Keel</a>. </p>
+    <p>It has to be said that all post-Avalon projects are not as active as they could be.</p>
+    <div>
+      <h3>Using <em>Contextualized Dependency Lookup</em> Components
+          Without a Container.</h3>
+
+<p>The downside of the this design is that components can only be used without the container with great
+           difficulty. If at all. Thus a proper container is needed at all times, and you have to choose one for
+           different purposes. If you do manage to instantiate components without a container, you might miss one of the
+           essential service dependencies. The component-using class will continue to compile, but at run time it will
+           be apparent that there are missing dependencies. Because of the these complexities, unit testing with frameworks like <a href="http://www.junit.org/index.htm">JUnit</a>  is very difficult for of Avalon components. </p>
+    </div>
+</div>
+        </div>
+      </div>
+      <div>
+        <h2>Sun specified nearly-IoC Containers &amp; Component designs</h2>
+        <p>Sun have specified several container/component designs over the years.</p>
+        <div>
+          <h3>Enterprise Java Beans</h3>
+          <p>Clearly Entity and Session beans run inside a container. The API is well defined, and to varying degrees of success one can deploy EJB appllications to WebLogic, WebSphere, Orion and JBoss etc. For assembly and configuration, there is high use of element-normal XML . There are some mandated parent objects and interfaces for various to extend and/or implement. Resolution is done by the components themselves via JNDI more often than not.</p>
+          <p>Apache Composer Components are simpler in they they do not force an extensive XML markup, nor require the implementing of certaing interfaces or extening base classes. Quite importantly the relationship between factory (home), implementation (bean) and interface (remote) parts is much more real in Apache Composer-style components. EJB 2.0 components are nearly impossible to unit-test without much effort.</p>
+          <p>With the advent of EJB 3.0 (which the our team directly influenced), things became easier for EJB developers. Annotations were used to mark fields, and methods for injection. Strangely constructors were not eligible for injection. It was reported back to the our team that it was felt that the J2EE container makers would not find it easy making multi-argument constructor injection a reality.</p>
+        </div>
+        <div>
+          <h3>Servlets</h3>
+          <p>Not so obvious - Servlets are contained by a servlet container. They are generally bundled with (or replaced by) value added propositions like JSP, but it is still a container/component design. High use of XML for assembly and configuration. Servlets have no concept of parent container or the conatainer above that (sometimes EJB) and its provision of components, which is very unfortunate. Servlets have a number of interfaces to honor, none of which is too malignent. Servlets typically deal with external (or parent) components via RMI or JNDI. In more recent releases of EJB, local interfaces rather than RMI may be the mechanism for connection the parent components. WebLogic have always provided an optimizing mechanism for this interoperation</p>
+          <p>As with EJB, Apache Composer Components are far simpler. This is probably because they offer no web experience, without an extension. Servlets again are not that unit-testable.</p>
+        </div>
+        <div>
+          <h3></a>Applets</h3>
+          <p>Applets, though presently not so often used, are a good example of Container/Component separations. There is very little XML in use by Applets. Configuration is typically delivered in applet tags in HTML. Applets are granted some access to the parent container, the brower, and its DOM model for pages and other applets. There very little standardisation for Browser as a container.</p>
+          <p>As with EJB, Apache Composer Components are far simpler. Applets are unit-testable but with a little effort. Complex DOM interoperation is impossible under unit testing.</p>
+        </div>
+        <div>
+          <h3>Mainable (Not actually a container)</h3>
+          <div class="source">
+            <div>
+              <pre>public static void main(String[] args) {}</pre>
+            </div>
+          </div>
+          
+
+          <p>Familiar? Hopefully not <img class="emoticon" src="http://docs.codehaus.org/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0" />Static plays no part in a good IoC container/component design. This includes static launching of Java Webstart (JNLP) applications. If you have to keep mainable functionaility separate your components away from the main() class so they may be instntiated separately. In .NET you'll have to make sure that the application assembly is a small bootstrap to a component one.</p>
+        </div>
+        <div>
+          <h3>JNDI (Java API)</h3>
+          <p>A huge map of clunkily access components via a very non-IoC mechanism. It has to be strapped with much XML to prevent inappropriate access. This is not IoC because the component reaches out for external component dependancies whenever it feels like. This last fact clouds Serlvets and EJB use.</p>
+        </div>
+        <div>
+          <h3>AWT, Swing, SWT (Java graphic toolkits)</h3>
+          <p>Nice container/component designs. In the case of Swing, perhaps a little difficult for coders to easily assemble applications.</p>
+        </div>
+        <div>
+          <h3>Eclipse (Java graphical application platform)</h3>
+          <p>The <a href="http://eclipse.org">Eclipse</a> platform is very compelling. It supports the notion of a pluggable application concept. Each component statically accesses other components via a factory (which at least Paul does not like), though it is clear that some complex classloader magic is going on. The underpinning set of graphical components, SWT , are a simple and elegant design.</p>
+        </div>
+      </div>
+    </div>
+
+</body>
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/component-configuration.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/component-configuration.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/component-configuration.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/component-configuration.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,100 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>Component Configuration</title>
+</head>
+<body>
+<div>
+<h2>Choices</h2>
+<p>In true IoC style,  configuration for a component is pushed into it. </p>
+<p>With Apache Composer,  there are a few ways to do this:</p>
+<ul>
+  <li>Design a class to hold the configuration and have getters on it to allow depending components to access configuration.</li>
+  <li>Manually set the configuration for components as you add them to a container</li>
+  <li>Leverage the fact that Apache Composer can pick up on named components </li>
+</ul>
+<h3>Configuration Object</h3>
+<div class="source">
+    <pre>public interface BigFatComponentConfig {
+  String getSpellingWebServiceURL();
+  String getTimeout();
+}
+public class BigFatComponent {
+  URL spellWebService;
+  String timeout;
+  public BigFatComponent(BigFatComponentConfig config) {
+    this.spellWebService = new URL(config.getSpellingWebServiceURL());
+    this.timeout = config.getTimeout();
+  }  
+  // other methods
+}
+...
+pico.addComponent(BigFatComponent.class)
+pico.addComponent(new BigFatComponentConfigBean(&quot;http://foo.com/foo.wsdl&quot;, 120))</pre>
+  </div>
+  <h3>Setting config as part of addComponent(..) </h3>
+  <div class="source">
+      <pre>public class BigFatComponent {
+  URL spellWebService;
+  int timeout;
+  public BigFatComponent(String spellingWebServiceURL, int timeout) {
+    this.spellWebService = new URL(spellingWebServiceURL);
+    this.timeout = timeout;
+  }  
+  // other methods
+}
+
+
+...
+pico.addComponent(BigFatComponent.class, new ConstantParameter(&quot;http://foo.com/foo.wsdl&quot;), new ConstantParameter(120));</pre>
+    </div>
+  <h3>Configuration using parameter names </h3>
+  <p>Consider this component ...</p>
+  <div class="source">
+    <pre>public class BigFatComponent {
+  URL spellWebService;
+  int timeout;
+  public BigFatComponent(String spellingWebServiceURL, int timeout) throws MalformedURLExeption {
+    this.spellWebService = new URL(spellingWebServiceURL);
+    this.timeout = timeout;
+  }  
+  public String toString() {
+    return &quot;URL=&quot; + spellWebService + &quot;, timeout=&quot; + timeout;  
+  }
+
+  // other methods
+}
+
+</pre>
+  </div>
+  <p>And this composition ...</p>
+<div class="source">
+        <pre>
+pico.addConfig(&quot;spellingWebServiceURL&quot;, &quot;http://foo.com/spelling.wsdl&quot;); // matches constructor parameter name
+pico.addConfig(&quot;somethingOtherURL&quot;, &quot;http://bar.com/other.wsdl&quot;);
+pico.addConfig(&quot;timeout&quot;, 120); // matches constructor parameter name
+pico.addConfig(&quot;timeout2&quot;, 456);
+pico.as(Characteristics.USE_NAMES).addComponent(BigFatComponent.class);
+
+BigFatComponent bfc = pico.getComponent(BigFatComponent.class);
+System.out.println(&quot;bfc: &quot; + bfc.toString());
+// Prints .. &quot;bfg: URL=http://foo.com/spelling.wsdl, timeout=120&quot;</pre>
+  </div>
+  <p>This feature of Apache Composer relies on the a non-JDK mechanism of <strong>accessing parameter names for methods and constructors</strong>. In this case named parameters spellingWebServiceURL and timeout.</p>
+  <p>There are two ways for this to work: </p>
+  <ul>
+    <li>relying on the fact that  your component classes have debug info compiled into them. </li>
+    <li>post-processing component classes with <a href="http://paranamer.codehaus.org/">Paranamer</a> before placing them in their jar </li>
+  </ul>
+  <p>If the parameter name information cannot be accessed at runtime by Apache Composer, then Apache Composer will be unable to differentiate between potential injectable classes of the same type and throws an exception that suggests that there is an ambiguity.</p>
+  <p>This is <strong>not</strong> a global variable facility. Its scoped with the container in question and its child containers.</p>
+</div>
+<h2>Taking configuration from the elsewhere</h2>
+<p>Configuration can also be bound to components with :</p>
+<blockquote>
+  <p><a href="CommandLineArgumentsApache Composer.html">CommandLineArgumentsApache Composer</a></p>
+  <p><a href="PropertiesApache Composer.html">PropertiesApache Composer</a></p>
+  <p><a href="SystemPropertiesApache Composer.html">SystemPropertiesApache Composer</a></p>
+</blockquote>
+</body>
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/constructor-injection.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/constructor-injection.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/constructor-injection.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/constructor-injection.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,70 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+    <title>Constructor Injection</title></head>
+
+
+<body>
+<h2>Overview</h2>
+
+<p>Constructor Injection is a <a href="injection.html" title="Dependency Injection">Dependency Injection</a> variant
+   where an object gets all its dependencies via the constructor.
+</p>
+
+<p>The most important benefits of Constructor Injection are:</p>
+<ul>
+    <li>It makes a strong dependency contract</li>
+    <li>It makes testing easy, since dependencies can be passed in as <a href="mock-objects.html" title="Mock Objects">Mock Objects</a></li>
+    <li>It's very succinct in terms of lines of code</li>
+    <li>Classes that rely on Constructor Injection are generally <a href="patterns.html" title="Good Citizen">Good
+                                                                                                              Citizen</a>s
+    </li>
+    <li>A dependency may be made immutable by making the dependency reference <em>final</em></li>
+</ul>
+<p><img class="emoticon" src="http://docs.codehaus.org/images/icons/emoticons/information.gif" alt="" align="middle" border="0" height="16" width="16" /> Martin Fowler explains <a href="http://www.martinfowler.com/articles/injection.html#ConstructorInjectionWithPicocontainer">Constructor
+                                                                                                     Injection</a>
+                                                          in more detail.<br />
+    <br />
+    <img class="emoticon" src="http://docs.codehaus.org/images/icons/emoticons/information.gif" alt="" align="middle" border="0" height="16" width="16" /> Apache Composer also supports <a href="setter-injection.html" title="Setter Injection">Setter Injection</a>.</p>
+
+<h2>Origin</h2>
+
+<p><a href="http://www.twelve71.com/rachel/">Rachel Davies</a>, while reviewing Joe's forthcoming book,
+left a Fermat-like margin note when looking at a coe sample that used
+Setter Injection: "Why not use constructors ?". Brilliant and simple.
+&nbsp;Using constructors per se, is an ordinary OO feature, but having
+a container that works out what to inject where amongst a list of
+constructor arguments is something that is useful too.
+</p>
+
+<h2>Example</h2>
+
+<div class="source">
+            <pre>public class Shop {<br />    private final StockManager stockManager;<br />    private final String shopZipCode;<br />    public Shop(StockManager stockManager, String shopZipCode) {<br />        this.stockManager = stockManager;<br />        this.shopZipCode = shopZipCode;<br />    }<br /> }</pre>
+</div>
+<p>Note, for this there is no need to declare needs in any other way. No interfaces, no doclet tags, no external
+   XML. Just your simple component(s) and Apache Composer. No need for post assembly/config initialization either. If
+   it is constructed (not withstanding some asserts on nulls) it has its needs satisfied. Components need not be
+   interface/implementation separated. This is the coder's choice.</p>
+
+<h3><a name="ConstructorInjection-UsingConstructorInjectorComponentsWithoutaContainer." id="ConstructorInjection-UsingConstructorInjectorComponentsWithoutaContainer."></a>Using Constructor
+                                                                                          Injector Components
+                                                                                          Without a Container.
+</h3>
+
+<p>The component can be used directly, without any container. The missing dependency scenario is not an issue
+   since it is impossible to instantiate an object without all dependencies being satisfied.</p>
+
+<div class="source">
+    <div>
+        <pre>Shop shop = new Shop(myStockManager);</pre>
+    </div>
+</div>
+<h2>Container support
+</h2>
+
+<p>Apache Composer was the first lightweight container to support and popularize this for of dependency injection.
+   Spring Framework has been retrofitted with constructor injection capability, but its primary focus is still
+   setter injection. Even the once heavyweight technologies like Avalon and OSGi moved towards&nbsp;constructor
+   injection.</p>
+</body></html>
\ No newline at end of file

Added: incubator/composer/trunk/composer-site/src/site/content/disambiguation.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/disambiguation.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/disambiguation.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/disambiguation.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Disambiguation</title>
+
+</head>
+
+
+<body>
+<h2>Overview</h2>
+You may have a component that has a dependency on something that the
+container could ordinarily satisfy more than one. &nbsp;By default,
+when Apache Composer is presented with such a situation, it will throw an
+exception suggesting the depency resolution is ambiguous.
+<h2>Disambiguation using parameter names<span style="text-decoration: underline;"></span></h2>
+With Apache Composer 2.0 we are able to leverage the parameter names of
+constructors and methods in order to remove the ambiguity on
+dependancies.<br />
+<div class="source">
+<pre>public class Store {<br /> public Store(StockManager workingDayStockManager, StockManager afterHoursStockManager) {<br /> // etc<br /> }<br />}</pre>
+</div>
+If Store is added to the container appropriately, then its parameter
+names <span style="font-family: monospace;">'</span>workingHoursStockManager'
+and 'afterHoursStockManager
+' can be used in conjunction with similarly named components inject the
+right dependency in the right way:<br />
+<div class="source">
+<pre>pico.as(Characteristics.USE_NAMES).addComponent(Store.class);&nbsp;<br /></pre>
+</div>
+
+Access to parameter names was dropped from JDK 6.0 and it is uncertain
+whether it will be added as a feature in another release, so
+Apache Composer relies on another open source library called <a href="http://paranamer.codehaus.org">Paranamer</a>,
+without requiring a dependency on its Jar. &nbsp;In other words,
+Apache Composer has the same classes from Paranamer in its jar.<br />
+<br />
+See <a href="CommandLineArgumentsApache Composer.html">CommandLineArgumentsApache Composer</a>,
+<a href="PropertiesApache Composer.html">PropertiesApache Composer</a>
+and <a href="SystemPropertiesApache Composer.html">SystemPropertiesApache Composer</a>
+for implementations of Apache Composer that set up components for
+subsequent parameter name binding.<br />
+<br />
+Page <a href="component-configuration.html">component-configuration</a>
+also shows parameter names being used for binding as does <a href="injection.html">injection.</a><br />
+<br />
+Usage of parameter names is available for all types of
+Dependency-Injection where parameter names are present.<br />
+<span style="text-decoration: underline;"></span>
+<h3>Disambiguation using Binding Annotations
+</h3>
+<p>This worls the same as Guice. &nbsp;Namely you make an
+annotation that extends our 'Bind' annotation and mark it in your&nbsp;constructor or method's signature like so.</p>
+<div class="source">
+<div>
+<pre>@Retention(RetentionPolicy.RUNTIME)<br />@Target({ElementType.FIELD, ElementType.PARAMETER})<br />@Bind<br />public static @interface WorkingDayStockManager {}<br /><br />@Retention(RetentionPolicy.RUNTIME)<br />@Target({ElementType.FIELD, ElementType.PARAMETER})<br />@Bind<br />public static @interface AfterHoursStockManager {}<br /><br />public class Store {<br /> public Store(@WorkingDayStockManager StockManager workingDayStockManager, <br /> @AfterHoursStockManager StockManager afterHoursStockManager) {<br /> // etc<br /> }<br />}</pre>
+</div>
+</div>
+Making Apache Composer leverage binding annotations if present is
+automatic.<br /><br />Biniding
+annotations specified for constructor parameters (as shown above),
+method injection parameters as well as field injection.<br />
+</body></html>
\ No newline at end of file

Added: incubator/composer/trunk/composer-site/src/site/content/downloads.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/downloads.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/downloads.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/downloads.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html><head>
+<title>Downloads</title></head>
+
+<body>
+<h2>Released Jars (1.3 and 2.0) </h2>
+<p>Core  : <a href="http://repository.codehaus.org/org/picocontainer/picocontainer/">http://repository.codehaus.org/org/picocontainer/picocontainer/</a></p>
+<p>Gems  : <a href="http://repository.codehaus.org/org/picocontainer/picocontainer-gems/">http://repository.codehaus.org/org/picocontainer/picocontainer-gems/</a></p>
+<h2>Snapshot Jars (2.1) </h2>
+<p>Core : <a href="http://snapshots.repository.codehaus.org/org/picocontainer/picocontainer/">http://snapshots.repository.codehaus.org/org/picocontainer/picocontainer/</a></p>
+<p>Gems : <a href="http://snapshots.repository.codehaus.org/org/picocontainer/picocontainer-gems/">http://snapshots.repository.codehaus.org/org/picocontainer/picocontainer-gems/</a></p>
+<hr />
+<p>Currently, the Core jar is ~190K, and the Gems jar is ~89K. </p>
+
+</body></html>
\ No newline at end of file

Added: incubator/composer/trunk/composer-site/src/site/content/faq.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/faq.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/faq.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/faq.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,234 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>FAQ</title>
+</head>
+<body>
+<h3 class="headerstyle">
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">Why Apache Composer 2.0?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p>First EJB 3.0 then Google Guice seemed to copy the ideas from Apache Composer, adding some more value. EJB 3.0 ommitted the essential Constructor Injection, and Guice went far to far down a annotations road. Soon after Guice, even the Spring Framework team decided to do things the direct way with 'JavaConfig'.</p>
+  <p>So Apache Composer 1.x was refactored (not rewritten) into Apache Composer 2.0. All the unit tests were kept, and excerise took hundreds of commits, but the team is pleased with the result.</p>
+</div>
+<h3 class="headerstyle">
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">Can my component use multiple constructors?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p>Yes.</p>
+  <p>You can code multiple constructors for a component:</p>
+  <div class="source">
+    <div>
+      <pre>class MyComp {
+
+  private ThreadPool theThreadPool;
+  
+  public MyComp(ThreadPool threadpool) {
+    theThreadPool = threadpool;
+  }
+
+  public MyComp() {
+    theThreadPool = new DefaultThreadPool();
+  }
+
+  // other methods.
+
+
+}</pre>
+    </div>
+  </div>
+</div>
+<h3 class="headerstyle">
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">How does Apache Composer decide what constructor to use?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p>Apache Composer will instantiate a given component using the &quot;greediest&quot; satisfiable constructor. By greedy, we mean the constructor that takes the most parameters. By satisfiable, we mean constructors where all arguments can be satisfied by other registered components.</p>
+  <p>If you register a component with no satisfiable constructors, or two or more ambiguous &quot;largest&quot; constructors, a RuntimeException will be thrown when you ask for the component instance.</p>
+  <p>We recommend for most components, you use only one constructor, although this is by no means a requirement.</p>
+</div>
+<h3 class="headerstyle">
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">How does Apache Composer compare to EJB containers?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p>Oh blimey, it is rather different. EJB has loads of things you must extend, implement, provide and throw. It is also not an IoC design. It is close in that components are managed by a container, but the cumbersome and static nature of the JNDI lookups ensure that it is not actually IoC. Apache Composer is not a superset of EJB though, as it provides no remoting capability (but NanoContainer will). At least the Apache Composer compatible components hosted in this project do not.</p>
+</div>
+<h3 class="headerstyle" >
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">How does Apache Composer decide what constructor to use?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p>Apache Composer will instantiate a given component using the &quot;greediest&quot; satisfiable constructor. By greedy, we mean the constructor that takes the most parameters. By satisfiable, we mean constructors where all arguments can be satisfied by other registered components.</p>
+  <p>If you register a component with no satisfiable constructors, or two or more ambiguous &quot;largest&quot; constructors, a RuntimeException will be thrown when you ask for the component instance.</p>
+  <p>We recommend, for the sake of predictablility, that Apache Composer compatible components use only one constructor, although this is by no means a requirement.</p>
+</div>
+<h3 class="headerstyle" >
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">How to use primitive types in constructors?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p>Apache Composer will look for the greediest constructor of your component. But if your component's constructor depends on primitive types you may set the values explicitly.</p>
+  <div class="source">
+    <div>
+      <pre>public interface ThreadPool {
+	void setSize(int);
+}
+
+public class MyComp {
+	private ThreadPool threadPool;
+	public MyComp(ThreadPool pool, int size) {
+		threadPool = pool;
+		threadPool.setSize(size);
+	}
+}</pre>
+    </div>
+  </div>
+  <p>In this case you can set the parameters at registration time:</p>
+  <div class="source">
+    <div>
+      <pre>DefaultApache Composer pico = new DefaultApache Composer();
+pico.addComponent(ThreadPool.class, DefaultThreadPool.class);
+pico.addComponent(MyComp.class, MyComp.class, new Parameters[] {
+	new ComponentParameter(),
+	new ConstantParameter(new Integer(5));
+})
+MyComp myComp = (MyComp)pico.getInstance(MyComp.class);</pre>
+    </div>
+  </div>
+  <p>Use ConstantParameter to set constant values and the ComponentParameter to let Apache Composer resolve the dependency.</p>
+</div>
+<h3 class="headerstyle" >
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">When should I use Apache Composer?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p><br />
+    We recommend using Apache Composer when your application consists of many different classes (components) that are related to each other. Instantiating and lacing/connecting a lot of objects can be difficult task.</p>
+</div>
+<h3 class="headerstyle" >
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">Why Another IoC Framework?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+<p>After a long period of watching Inversion of Control frameworks,
+and for some of us avoiding them because of their cumbersome nature, we
+got together to write what we believe is the simplest possible IoC
+design. One, perhaps, that considers the so-designed component as more
+important that the container.</p>
+<p>When we set out to do this in 2003, there was nothing equivalent
+to Apache Composer (xContainer originally). XWork, that underpinned
+WebWork2 was a general/embeddable Setter Dependency Injection framework,
+but not well known. The Spring Framework started in the same timescale,
+and we were talking to its authors before Martin Fowlers Dependency
+Injection article. Later we discovered that HiveMind (now at Apache)
+also was in the same space.</p>
+</div>
+<h3 class="headerstyle" >
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">Why Constructor Injection?</td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p><a href="constructor-injection.html" title="Constructor Injection">Constructor Injection</a> is hard to swallow for people who have been living with Interface Lookup or <a href="setter-injection.html" title="Setter Injection">Setter Injection</a> for long. We think it's like TDD. Once you get the grasp of it, you don't go back. Here are some benefits with this type of IoC:</p>
+  <ul>
+    <li>Constructor Injection makes a stronger dependency contract</li>
+    <li>It's more succinct in terms of lines of code</li>
+    <li>It's more succinct in terms dependency-statement-mechanism i.e. no XML, attributes, enabler interfaces etc</li>
+    <li>A component is characterized by InterfaceImplSeparation with the interface being the service offered to other comps, and the impl declaring whatever goddarned need it likes and that need being wholly up to the implementor of the component and nothing to do with the service contract.</li>
+    <li>No indeterminate state. Not all the post instantiation setters may be called. Consider the non-container case for comp usage, if v1.2 of that comp introduces a new dependancy, with <a href="constructor-injection.html" title="Constructor Injection">Constructor Injection</a> the compiler will tell me.</li>
+  </ul>
+</div>
+<h3 class="headerstyle" >
+  <table style="width: 100%; padding-right: 2mm">
+    <tr>
+      <td align="left" valign="middle">Will we support Guice's @Inject annotation transparently? </td>
+    </tr>
+  </table>
+</h3>
+<div>
+  <p>We could compile Apache Composer against Guice.jar and leverage the @Inject method with a new InjectionFactory (and probably will). The problem is that there is no easy way to use an annotation without having its class in the classpath. There's no easy 'transparent' solution for this. </p>
+  <p>Things  fail silently if the jar is missing, unless the annotation is used - then it fails noisily. Meaning, the mere declaration of an annotation on a component is not enough to cause a ClassNotFoundException on load, if its not used:</p>
+  <div class="source"><pre>@Retention(RetentionPolicy.RUNTIME)
+@Target(value={ElementType.METHOD})
+public static @interface Bar {
+}
+</pre></div>
+<div class="source"><pre>
+import com.google.inject.Inject;
+public class Foo {
+
+    @Inject
+    @Bar
+    public void setFoo(String str) {
+        System.out.println("0>" + str);
+    }
+
+    public static void main(String[] args) throws NoSuchMethodException {
+
+        Foo foo = new Foo();
+        foo.setFoo("hello");
+
+        Method m = Foo.class.getMethod("setFoo", String.class);
+
+        Annotation[] anns =  m.getDeclaredAnnotations();
+        System.out.println("1> " + anns.length);
+        for (int i = 0; i < anns.length; i++) {
+            Annotation ann = anns[i];
+            System.out.println("2> " + ann.toString());
+        }
+
+        Annotation ann =  m.getAnnotation(Inject.class);
+        System.out.println("3> " + ann);
+    }
+}
+</pre></div>
+<p>Leaving Guice out of the classpath, and trying to launch Foo...</p>
+<div class="source">
+  <pre>commandline: java -cp classes Foo
+0>hellos
+1> 1
+2> @Foo$Bar()
+Exception in thread "main" java.lang.NoClassDefFoundError: org/picocontainer/annotations/Inject
+        at Foo.main(Foo.java:32)</pre>
+</div>
+  <p>The class loads, but the @Inject annotation is not present in the set of declared annotations, but another in the classpath is.  Lastly when accessed explicitly, there is an exception thrown.  Contrast to, the same run with Guice in the classpath:</p>
+<div class="source"><pre>0>hello
+1> 2
+2> @org.picocontainer.annotations.Inject()
+2> @Foo$Bar()
+3> @org.picocontainer.annotations.Inject()
+</pre></div>
+
+</div>
+</body>
+
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/fluent-style.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/fluent-style.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/fluent-style.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/fluent-style.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,42 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+<title>Fluent Stype</title>
+</head>
+<body>
+<p>Apache Composer allows for a very fluent style of use. Refer to Martin's <a
+  href="http://www.martinfowler.com/bliki/FluentInterface.html">'Fluent
+Interface'</a> article.</p>
+<p>A simple example :</p>
+    <div class="source">
+      <pre>
+pico = new DefaultApache Composer();
+pico.addComponent(Apple.class).addComponent(Orange.class).addComponent(Pear.class)
+    .addComponent(Banana.class)
+    .addComponent(Grape.class, Grenache.class);</pre>
+</div>
+<p>One with per component properties:</p>
+<div class="source"><pre>
+pico = new DefaultApache Composer();
+pico.addComponent(Apple.class)
+    .as(CACHE).addComponent(Orange.class)
+    .as(CACHE, HIDE_IMPLEMENTATION).addComponent(Pear.class)
+    .as(SYNCHRONIZE, CACHE).addComponent(Banana.class)
+    .addComponent(Grape.class, Grenache.class);</pre>
+</div>
+<p>One with properties that are persistently set, half way through.</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer();
+pico.addComponent(&quot;Coxs&quot;, CoxsApple.class)
+    .addComponent(&quot;Golden&quot;, GoldenDeliciousApple.class)
+    .addComponent(new ValenciaOrange())
+    .change(SYNCHRONIZE, CACHE, HIDE_IMPLEMENTATION)
+    .addComponent(Pear.class)
+    .addComponent(Banana.class)
+    .addComponent(Grape.class, Grenache.class);</pre>
+</div>
+
+<p>&nbsp;</p>
+</body>
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/goals.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/goals.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/goals.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/goals.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+<title>Our Goals</title>
+</head>
+<body>
+<p>Apache Composer's core was designed with some goals in mind:</p>
+<ul>
+  <li>No mandatory dependencies.</li>
+  <li>No logging built in (we have a Monitor interface and implementations for Commons-Logging and Log4J etc)</li>
+  <li>No meta-data requirement.</li>
+  <li>Small jar size.</li>
+  <li>Embeddable by design (no main method entry point)</li>
+</ul>
+<p>If someone has a need for Apache Composer that we did not originally envision, or a feature that could be imlemented, we will try to accomodate it. The principle of Lowest Common Denominator (LCD) allows us for Apache Composer itself, to keep things small, while allowing extensions to deliver the larger visions. Thus, meta-data, dependancies, mainable are all OK for related extensions of Apache Composer.</p>
+<p>&nbsp;</p>
+<p>&nbsp;</p>
+<p>&nbsp;</p>
+<p>&nbsp;</p>
+<p>&nbsp; </p>
+</body>
+
+
+
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/help/ambiguous-injectable-help.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/help/ambiguous-injectable-help.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/help/ambiguous-injectable-help.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/help/ambiguous-injectable-help.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,48 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+    <title>Ambiguous Injectable</title></head>
+<body>
+<p>Apache Composer tries to determine what to inject into the constructor of each component as it instantiates (or setters/fields for other injection types). Sometimes there can be two or more classes that could equally satisfy a constructor: </p>
+<div class="source">
+  <pre>pico.add(new Apple(&quot;Braeburn&quot;));
+pico.add(new Apple(&quot;Granny Smith&quot;));
+pico.add(Pie.class); // needs Apple
+Pie pie = pico.getComponent(Pie.class); // throws AmbiguousComponentResolutionException citing there are two Apples.
+</pre>
+</div>
+
+<p>The best advice is don't setup Apache Composer in a way that would allow ambiguities  (just put in one Apple in the case above).</p>
+<p>An alternative strategy would be to use custom parameters (TODO)</p>
+<p>One more strategy would be to use names parameters </p>
+<div class="source">
+  <pre>class Pie {
+  Pie(Apple grannySmith) {
+    // etc 
+
+  }
+
+}
+
+...
+
+
+pico.add(&quot;braeburn&quot;, new Apple(&quot;Braeburn&quot;));
+pico.add(&quot;grannySmith&quot;, new Apple(&quot;Granny Smith&quot;));
+pico.add(Pie.class); // needs Apple, specifically a Granny Smith.
+Pie pie = pico.getComponent(Pie.class); // OK this time.
+</pre>
+</div>
+<p>To use names Parameters, you are going to need Paranamer 1.0 (or above) in the classpath, as well as ASM 3.0 (or above). If you are expecting Apache Composer to work based on parameter names, but its not doing so, it is most likely that you do not have paranamer-1.0.jar in the classpath. See <a href="http://repository.codehaus.org/com/thoughtworks/paranamer/paranamer/">http://repository.codehaus.org/com/thoughtworks/paranamer/paranamer/</a> for versions of paranamer. Also <a href="http://maven.objectweb.org/maven2/asm/asm/">http://maven.objectweb.org/maven2/asm/asm/</a> for the ASM jar.</p>
+<p>You also have to make a decision as to when parameter name data is made. There are two choices for this:</p>
+<ol>
+  <li>At runtime</li>
+  <li>At build time   </li>
+</ol>
+<p>When at runtime, Apache Composer will need to be accompanied by ASM and Paranamer in the classpath. You will also need to compile your Java classes with debug information.</p>
+<p>When at build time, you will need to use and Ant or Maven fragment to post-process the compiled classes for your app to add the paramaeter name data. At runtime, neither Paranamer nor ASM will be needed. See <a href="http://paranamer.codehaus.org/">http://paranamer.codehaus.org/</a> - specifically the quick start section pertinent to Ant and Maven. </p>
+<p>&nbsp; </p>
+<p>&nbsp;</p>
+</body>
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/help/unprocessed-properties-help.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/help/unprocessed-properties-help.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/help/unprocessed-properties-help.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/help/unprocessed-properties-help.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+    <title>Unprocessed Properties</title></head>
+<body>
+<p>Properties are a powerful mechanism to add hints at registration time as to what the behavior of a component should be. It only works though when the right component factories are set for the container. Ones that recognise the property and can process it. For example, DefaultConstructor's default constructor sets up an adaptive ComponentFactory that can handle HIDE_IMPL: </p>
+
+<div class="source">
+  <pre>pico = new DefaultApache Composer();
+pico.as(HIDE_IMPL).addComponent(Apple.class);</pre>
+</div>
+But with a custom ComponentFactory, it may not:
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new MyComponentFactory);
+pico.as(HIDE_IMPL).addComponent(Apple.class); // fails with CompositionException</pre>
+</div>
+The trick is (in this case) to make sure that the right chain of component factories are setup:
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new MyComponentFactory().wrap(new AdaptiveBehaviorFactory()));
+pico.as(HIDE_IMPL).addComponent(Apple.class); // fails with CompositionException</pre>
+</div>
+
+<p>A component may have many properties as it is added to the container.  As each is processed, it is removed from the set.  If there are any left after the component has been added the behavior or action that the property suggests has not been setup.  Thus a CompositionException being thrown warning of unprocessed properties only happens one or more properties are left - whether they are Apache Composer's own properties or custom ones</p>
+</body>
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/index.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/index.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/index.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/index.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,52 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+<title>Overview</title>
+</head>
+
+<body>
+
+<h2>What is Apache Composer?</h2>
+
+<p>Apache Composer is a  highly embeddable full service Inversion of Control (IoC) container
+for components honour the Dependency Injection pattern.</p>
+<p>You could use it as a lightweight alternative to Sun's J2EE patterns for web applications or general solutions. </p>
+<p>What is Dependency Injection? Martin Fowler has a good <a href="http://www.martinfowler.com/articles/injection.html">article</a> from 2003, but here is another view: It is a good design pattern that, for large enterprise applications, facilitates: </p>
+<ul>
+  <li>easy best practice  unit testing vs little and difficult unit testing. </li>
+  <li>component reuse vs  rewriting through ignorance or need </li>
+  <li>centralized configuration vs components reading their own config (scattered) </li>
+  <li>clean &amp; declarative architecture vs nest of singletons that nobody can make sense of </li>
+  <li>maintainability vs developers having difficulties fixing bugs </li>
+  <li>adaptability vs developers not knowing where to start to add features</li>
+</ul>
+<p>Dependency Injection is
+  quite often, but not exclusively, used by Agile practicioners. It
+  counters the situation where the enterprise application:</p>
+<ul>
+  <li>has grown to be thousands of classes, with dozens if not
+  hundreds of Singletons</li>
+  <li>draws similarities to Spaghetti, Hairballs or <a href="http://www.laputan.org/mud/">Balls of Mud</a></li>
+  <li>has made development staff looking after it miserable</li>
+  <li>suffers repeated allegations of being unable to be developed without complete rewrite </li>
+</ul>
+<p>Despite it being very compact in size (the core is ~128K and it
+has no mandatory dependencies outside the JDK), Apache Composer supports different dependency injection types (Constructor, Setter, Annotated Field and Method) and offers multiple lifecycle and monitoring strategies.</p>
+<p>Apache Composer has originally been implemented in Java but is also
+available for other platforms and languages. These are detailed <a href="http://docs.codehaus.org/display/PICO/Ports">here</a>.</p>
+<div class="section">
+<h3>Getting Started</h3>
+<p>Take a look at the <a href="introduction.html">introduction</a>. </p>
+</div>
+<div class="section">
+<h3>Related projects</h3>
+<p><a href="http://www.nanocontainer.org">NanoContainer</a> builds on top of Apache Composer the support for
+several scripting meta-languages (XML, Groovy, Bsh, Jython and Rhyno),
+AOP, Web frameworks (Struts and WebWork), Persistence (Hibernate) SOAP,
+JMX, and much more.</p>
+</div>
+</body>
+
+
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/injection.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/injection.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/injection.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/injection.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,132 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html><head>
+<title>Dependency Injection</title></head>
+
+
+<body>
+<p>See Martin Fowlers's <a href="http://www.martinfowler.com/articles/injection.html">Inversion of Control Containers and the Dependency Injection</a>  article from 2003 for a thorough description. Surely everyone has read this by now? </p>
+<h2> Injection Types </h2>
+<h3>Constructor Dependency Injection (CDI) </h3>
+<p>This is where a component has a constructor, with arguments that are its dependencies:</p>
+<div class="source">
+  <pre>public class Apple {<br />  private final Orange orange;<br />  private final Pear pear;<br />  private final Banana banana;<br /><br />  public Apple(Orange orange, Pear pear, Banana banana) {<br />    this.orange = orange;<br />    this.pear = pear;<br />    this.banana = banana;<br />  }<br /><br />  // methods<br />}</pre></div>
+<p>
+The Apache Composer team recomends CDI over other types. There is no need
+to mark up the constructor with an annotation. Having more than one
+constructor is OK too, as Apache Composer will try to use the one with
+the most arguments and fall back to ones with fewer if it cannot
+satisfy the longer ones.</p>
+<p>The  component factory for this is <strong>ConstructorInjection</strong>. It only handles constructor injection types of components.  Factory <strong>AdaptiveInjection</strong>
+defaults to constructor injection, after checking first to see it the
+component in question is a Annotated Method or Field type (see below). </p>
+<h3>Setter Dependency Injection (SDI) </h3>
+<p>This is where a component has an empty constructor with dependencies provided by setters after instantiation:</p>
+<div class="source">
+  <pre>public class Apple {<br />  private Orange orange;<br />  private Pear pear;<br />  private Banana banana;<br /><br />  public setOrange(Orange orange) {<br />    this.orange = orange;<br />  }<br />  public setPear(Pear pear) {<br />    this.pear = pear;<br />  }<br />  public setBanana(Banana banana) {<br />    this.banana = banana;<br />  }<br />  // other methods<br />}<br /></pre>
+</div>
+  <p>Setter methods (those prefixed with 'set') may not be your
+preferred choice. You can force a different prefix to be choosable in
+Apache Composer, such as 'init' or 'inject'.</p>
+  <p>The  component factory for this is <strong>SetterInjection</strong>. It only handles setter injection types of components.</p>
+<p>Factory <strong>AdaptiveInjection</strong> can also handle setter injection types, though it requires that the component was registered with the <a href="properties.html">property</a> 'SDI' in order to activate the Setter Injection functionality. <strong>AdaptiveInjection</strong> will also fall through to constructor injection if there is no SDI property. </p>
+<p>If you want to use an prefix other than 'set', then specify your preferred prexix in the non-default constructor for <strong>SetterInjection</strong>.</p>
+<h3>Annotated Field Dependency Injection </h3>
+<p>This is where a component has an empty constructor with dependencies
+indicated by a field annotation and provided automatically by the
+container after instantiation.</p>
+<div class="source">
+  <pre>public class Apple {<br />  @Inject<br />  private Orange orange;<br />  @Inject<br />  private Pear pear;<br />  @Inject<br />  private Banana banana;<br /><br />  // methods<br />}</pre>
+</div>
+<p>
+Yes thats's right, there's no constructor needed. It means that for a
+Unit Test, you cannot simply 'new' the class, which is a downside.</p>
+<p>The  component factory for this is a class<strong> AnnotatedFieldInjection</strong>. It only handles field-annotation injection types of components.</p>
+<p>Additionally component factory <strong>AdaptiveInjection</strong>
+can also handle field annotation types, if the @Inject annotation from
+Apache Composer's codebase is used as the marker for injection. <strong>AdaptiveInjection</strong> will also fall through to constructor injection if there is no recognised @Inject annotation.</p>
+<p>If you want to use an @Inject annotation from another codebase, then
+specify the preferred annotation class in the constructor for <strong>AnnotatedFieldInjection</strong>.</p>
+<h3>Annotated Method Dependency Injection </h3>
+<p>This is where a component has an empty constructor and gets its
+dependencies injected into annotated methods after instantiation:</p>
+<div class="source">
+  <pre>public class Apple {<br />  private Orange orange;<br />  private Pear pear;<br />  private Banana banana;<br /><br />  @Inject<br />  public injectOrange(Orange orange) {<br />    this.orange = orange;<br />  }<br />  @Inject<br />  public setPear(Pear pear) {<br />    this.pear = pear;<br />  }<br />  @Inject<br />  public provideBanana(Banana banana) {<br />    this.banana = banana;<br />  }<br />  // other methods<br />}</pre>
+</div>
+<p>The method (whatever its name) needs an @Inject annotation.  That's from our codebase (org.picocontainer.Inject).</p>
+<p>The  component factory for this is <strong>AnnotatedMethodInjection</strong>. It only handles method-annotation injection types of components.</p>
+<p>Additionally component factory <strong>AdaptiveInjection</strong>
+can also handle method-annotation injection types, if the @Inject
+annotation from Apache Composer's codebase is used as the marker for
+injection. AdaptiveInjection will also fall through to constructor
+injection if there is no recognised annotation.</p>
+<p>If you want to use an @Inject annotation from another codebase, then
+specify the preferred annotation class in the constructor for <strong>AnnotatedMethodInjection</strong>.</p>
+<h3> Method Dependency Injection </h3>
+<p>This is where a component has an empty constructor and gets all its
+dependencies injected into single method after instantiation:</p>
+<div class="source">
+  <pre>public class Apple {<br />  private Orange orange;<br />  private Pear pear;<br />  private Banana banana;<br />  public inject(Orange orange, Pear pear, Banana banana) {<br />    this.orange = orange;<br />    this.pear = pear;<br />    this.banana = banana;<br />  }<br />  // other methods<br />}</pre>
+</div>
+<p>The method name needs be 'inject' unless overridden in the InjectionFactory.</p>
+<p>The  component factory for this is <strong>MethodInjection</strong>. It only handles method-injection types of components.</p>
+<p>Additionally component factory <strong>AdaptiveInjection</strong> can also handle method-injection types, but only if the METHOD_INJECTION characteristic is specified.</p>
+
+<h2>Using Apache Composer with Injection Types</h2>
+<p>Explicit Constructor Injection:</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new ConstructorInjection());<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>Constructor Injection, is a default too (via AdaptiveInjection):</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer();<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>Explicit Setter Injection:</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new SetterInjection());<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>Explicit Annotated Field injection:</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new AnnotatedFieldInjection();<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>Explicit Annotated Field injection, with alternate Annotation:</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new AnnotatedFieldInjection(MyInjectAnnotaton.class);<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>Explicit Annotated Method injection:</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new AnnotatedMethodInjection();<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>Explicit Annotated Method injection, with alternate Annotation:</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new AnnotatedMethodInjection(MyInjectAnnotaton.class);<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>Explicit  Method injection, implicit injection method prefix ('inject'):</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new MethodInjection();<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>Explicit  Method injection, explicit injection method prefix:</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer(new MethodInjection("setDependencies");<br />pico.addComponent(Apple.class);<br /></pre>
+</div>
+<p>  Method injection, via a characteristic:</p>
+<div class="source">
+  <pre>pico = new DefaultApache Composer();<br />pico.as(Characteristics.METHOD_INJECTION).addComponent(Apple.class);<br /></pre>
+</div>
+<h2> Leveraging Parameter Names </h2>
+<p>This is where the type alone is not enough to indicate which
+dependency should be put one or more constructor args. The following
+component has a need for two of the same type, with some subtly
+different characteristics.</p>
+<div class="source">
+  <pre>public class AppleProcessor {<br />  private Apple dessertApple;<br />  private Apple cookingApple;<br /><br />  public inject(Apple dessertApple, Apple cookingApple) {<br />    this.dessertApple = dessertApple;<br />    this.cookingApple = cookingApple;<br /><br />  }<br />  // other methods<br />}<br /><br />pico.addComponent("dessertApple", GoldenDeliciousApple.class);<br /><br />pico.addComponent("cookingApple", BramleyApple.class);<br />pico.as(Characteristics.USE_NAMES).addComponent(AppleProcessor.class);</pre>
+</div>
+<p>In this case the constructor to AppleProcessor has carefully named
+parameters - 'dessertApple' and 'cookingApple'. This is picked up on
+for the two named components GoldenDeliciousApple and BramleyApple also
+set up in the container.</p>
+<p>There are two ways for this to work:</p>
+<ul>
+  <li>relying on the fact that  your component classes have debug info compiled into them. </li>
+  <li>post-processing component classes with <a href="http://paranamer.codehaus.org/">Paranamer</a> before placing them in their jar </li>
+</ul>
+</body></html>
\ No newline at end of file

Added: incubator/composer/trunk/composer-site/src/site/content/interception.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/interception.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/interception.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/interception.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,123 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <title>Interception</title>
+
+    <style type="text/css">
+<!--
+.style1 {font-family: "Courier New", Courier, monospace}
+-->
+    </style>
+</head>
+<body>
+<p>This is a rudimentary Aspect Orientated Programing (AOP) capability. With respect to the methods of a component, both
+   before and after invocation, control can be handed to an interceptor. You can intercept a method call:</p>
+<ul>
+    <li> before it is invoked (and optionally veto its invocation, with an alternate return value).</li>
+    <li> after it is invoked (and optionally override the return value).</li>
+</ul>
+<p>There are some limitations:</p>
+<ul>
+    <li>it will only work for interface/impl separated components</li>
+    <li>it needs a class that implements the interface in question
+        <ul>
+            <li>all of the methods need null implementations, even if not intended to be intercepted</li>
+        </ul>
+    </li>
+    <li>will (likely) break if there's deep recursion into Intercepted instances</li>
+    <li>you can't intercept an implementation's static methods</li>
+    <li>it is not possible to modify a method's arguments</li>
+    <li>the constructor's invocation for the component is not interceptable</li>
+    <li>the component's fields are not interceptable</li>
+    <li>only one component invoking the methods on another component will be intercepted.
+      <ul>
+        <li>components and related classes calling their own methods will not be intercepted</li>
+      </ul>
+    </li>
+</ul>
+<div class="source">
+      <pre>public static class BiteReporter implements Apple {
+    private Intercepted.Controller controller;
+
+    public BiteReporter(Intercepted.Controller controller) {
+        this.controller = controller;
+
+    } 
+    public boolean takeBite(int grams) {
+        System.out.println(&quot;Bite of &quot; + grams + &quot; grams of apple '&quot; + controller.instance().getName() + &quot;'&quot;);
+        return false; // ignored, but necessary.
+    }
+}
+...
+pico = new DefaultApache Composer(new Intercepting());
+pico.addComponent(Apple.class, BraeburnApple.class);
+Intercpeted intercepted = pico.getComponentAdapter(Apple.class).findAdapterOfType(Intercpeted.class);
+intercepted.pre(Apple.class, new BiteReporter(intercepted.getController()));
+// see also Intercpeted.post(...) method.
+Apple a1 = pico.getComponent(Apple.class);
+a1.takeBite(100); 
+// prints Bite of 100 grams of apple 'Braeburn' 
+// ... irrespective of what else Braeburn.takeBite(int) does.
+  </pre>
+</div>
+<div class="source">
+    <pre>pico = new DefaultApache Composer();
+pico.as(INTERCEPT).addComponent(Apple.class, BraeburnApple.class);
+// etc</pre>
+</div>
+<div class="source">
+    <pre>pico = new ContainerBuilder.withInterception().build();
+pico.addComponent(Apple.class, BraeburnApple.class);
+// etc</pre>
+</div>
+<div class="source">
+    <pre>pico = new ContainerBuilder.withBehaviors(interception()).build();
+pico.addComponent(Apple.class, BraeburnApple.class);
+// etc</pre>
+</div>
+<p><b>Fine grained participation in interception</b><br/>Assuming you're passing in the Interceptor to the classes you're using for interception of a component, you can
+   participate in the fate of the method call. For a 'pre' invocation, you can veto the calling of the 'real'
+   method. </p>
+
+<div class="source">
+    <pre>    public boolean takeBite(int grams) {
+        if (grams &gt; 50) {
+             controller.veto();
+
+        }
+        return false; // will be passed back to the caller.
+    }
+</pre>
+</div>
+<p>For a 'post' invocation, you can override the return value of the 'real' method. </p>
+
+<div class="source">
+    <pre>    public boolean takeBite(int grams) {        
+
+        if (grams &gt; 50) {
+             controller.override();
+             (Apple) realApple = (Apple) controller.instance();
+             realApple.takeBite(-1 * grams); // undo !
+        }
+        return false; // will be passed back to the caller.
+    }
+</pre>
+</div>
+<p>Also for a 'post' invocation, you can access the return value of the 'real' method. </p>
+
+<div class="source">
+    <pre>    public boolean takeBite(int grams) {        
+
+        boolean rv = (boolean) controller.getOriginalRetVal();
+        if (rv == false) {
+             // do something !
+        }
+        return true; // ignored as no 'override'
+    }
+</pre>
+</div>
+</body>
+
+
+</html>

Added: incubator/composer/trunk/composer-site/src/site/content/introduction.html
URL: http://svn.apache.org/viewvc/incubator/composer/trunk/composer-site/src/site/content/introduction.html?rev=618174&view=auto
==============================================================================
--- incubator/composer/trunk/composer-site/src/site/content/introduction.html (added)
+++ incubator/composer/trunk/composer-site/src/site/content/introduction.html Sun Feb  3 22:33:20 2008
@@ -0,0 +1,364 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+    <title>Introduction</title>
+</head>
+<body>
+
+<p>Authors: Aslak Hellesoy, Jon Tirsen</p>
+
+<h2>Basics</h2>
+
+<p>This is a quick introduction to Apache Composer's most important features. Read through it to get an idea of what
+   Apache Composer is and isn't. </p>
+
+<p>Apache Composer's most important feature is its ability to instantiate arbitrary objects. This is done through its API,
+   which is similar to a hash table. You can put java.lang.Class objects in and get object instances back.</p>
+
+<p>Example:</p>
+
+<div class="source">
+    <div>
+                    <pre>MutableApache Composer pico = new DefaultApache Composer();
+pico.addComponent(ArrayList.class);
+List list = (List) pico.getComponent(ArrayList.class);</pre>
+    </div>
+</div>
+
+<p>(i)<a
+    href="http://www.picocontainer.org/picocontainer/latest/picocontainer/apidocs/org/picocontainer/MutableApache Composer.html">MutableApache Composer
+                                                                                                                               API<sup><img
+    class="rendericon" src="/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt=""
+    border="0" /></sup></a></p>
+
+<p>This code does the same as this:</p>
+
+<div class="source">
+    <div>
+        <pre>List list = new ArrayList();</pre>
+    </div>
+</div>
+
+<p>With a trivial example such as this there is no point in using Apache Composer. This was just to illustrate the basic
+   API. Apache Composer becomes useful with larger number of classes and interfaces having complex dependencies between
+   each other:</p>
+<table>
+    <tbody>
+        <tr>
+            <th> Complex Dependencies</th>
+            <th> Juicer Example</th>
+        </tr>
+        <tr>
+            <td><img src="images/complex-dependencies.png" align="absmiddle" border="0" /></td>
+            <td><img src="images/juicer-peeler-peelable.png" align="absmiddle" border="0" /></td>
+        </tr>
+    </tbody>
+</table>
+        <p>(Green means class, Yellow means interface).<br />
+        Apache Composer identifies dependencies by looking at the
+        constructors of registered classes (<a
+          href="constructor-injection.html"
+          title="Constructor Injection">Constructor Injection</a>).
+        Apache Composer can also be though of as a generic factory that
+        can be configured dynamically. Apache Composer is able to
+        instantiate a complex graph of several interdependent objects.</p>
+
+        <h2>Write some simple classes
+                                                                                             and interfaces with
+                                                                                             dependencies</h2>
+
+<p>The "Juicer Example" diagram above could translate to the following code (we added a concrete Peelable):</p>
+
+<p><img src="images/apple-implements-peelable.png" align="absmiddle" border="0" /></p>
+
+<div class="source">
+    <div>
+                    <pre>public interface Peelable {
+    void peel();
+}</pre>
+    </div>
+</div>
+
+<div class="source">
+    <div>
+                    <pre>public class Apple implements Peelable {
+    public void peel() {
+    }
+}</pre>
+    </div>
+</div>
+
+<div class="source">
+    <div>
+                    <pre>public class Peeler implements Startable {
+    private final Peelable peelable;
+
+    public Peeler(Peelable peelable) {
+        this.peelable = peelable;
+    }
+
+    public void start() {
+        peelable.peel();
+    }
+
+    public void stop() {
+
+    }
+}</pre>
+    </div>
+</div>
+
+<div class="source">
+    <div>
+                    <pre>public class Juicer {
+    private final Peelable peelable;
+    private final Peeler peeler;
+
+    public Juicer(Peelable peelable, Peeler peeler) {
+        this.peelable = peelable;
+        this.peeler = peeler;
+    }
+}</pre>
+    </div>
+</div>
+
+<p>(Note that this code suffers from the antipattern <a href="propagating-dependency-antipattern.html"
+                                                        title="Propagating Dependency">Propagating Dependency</a> but
+                                                                                                                  let's
+                                                                                                                  not
+                                                                                                                  worry
+                                                                                                                  about
+                                                                                                                  that
+                                                                                                                  for
+                                                                                                                  now
+    <img class="emoticon" src="/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt=""
+         border="0" />)</p>
+
+<h2>Assemble components</h2>
+
+<p>You tell Apache Composer what classes to manage by registering them like this (the order of registration has no
+   significance):</p>
+
+<div class="source">
+    <div>
+                    <pre>MutableApache Composer pico = new DefaultApache Composer();
+pico.addComponent(Apple.class);
+pico.addComponent(Juicer.class);
+pico.addComponent(Peeler.class);</pre>
+    </div>
+</div>
+
+<p>(i)<a
+    href="http://www.picocontainer.org/picocontainer/latest/picocontainer/apidocs/org/picocontainer/MutableApache Composer.html">MutableApache Composer
+                                                                                                                               API<sup><img
+    class="rendericon" src="/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt=""
+    border="0" /></sup></a></p>
+
+<h2>Instantiate components</h2>
+
+<p>You can tell Apache Composer to give you an instance of a class like this (provided it has been registered
+   previously):</p>
+
+<div class="source">
+    <div>
+        <pre>Juicer juicer = (Juicer) pico.getComponent(Juicer.class);</pre>
+    </div>
+</div>
+
+<p>This will cause Apache Composer to do something similar to this behind the scenes (except that Apache Composer uses
+   reflection):</p>
+
+<div class="source">
+    <div>
+                    <pre>Peelable peelable = new Apple();
+Peeler peeler = new Peeler(peelable);
+Juicer juicer = new Juicer(peelable, peeler);
+return juicer;</pre>
+    </div>
+</div>
+
+<p><img class="emoticon" src="/images/icons/emoticons/information.gif" height="16" width="16" align="absmiddle" alt=""
+        border="0" /> Note how Apache Composer figures out that Apple is a Peelable, so that it can be passed to Peeler
+                      and Juicer's constructors.</p>
+
+<h2>Container hierarchies</h2>
+
+        <p>Apache Composer provides a powerful alternative to the <a
+          href="singleton-antipattern.html" title="Singleton">Singleton</a>.
+        With container hierarchies you can create singleton-like objects
+        where you have fine grained control over the visibility scope of
+        the instance. (The singleton pattern is static and global - it
+        won't allow more than one instance, and it is visible from
+        anywhere. Not nice when you try to build a large enterprise
+        application from it).</p>
+
+        <p><img src="images/pico-hierarchy.png" align="absmiddle" border="0" /></p>
+
+<p>A container (and its registered components) can get access to components registered in a parent container, but not
+   vice-versa. Consider this example, using the classes from above:</p>
+
+<p><img class="emoticon" src="/images/icons/emoticons/warning.gif" height="16" width="16" align="absmiddle" alt=""
+        border="0" /><br />
+    THIS WON'T WORK&#33; It is for illustration purposes only&#33;<br />
+    <img class="emoticon" src="/images/icons/emoticons/warning.gif" height="16" width="16" align="absmiddle" alt=""
+         border="0" /></p>
+
+<div class="source">
+    <div>
+                    <pre>// Create x hierarchy of containers
+MutableApache Composer x = new DefaultApache Composer();
+MutableApache Composer y = new DefaultApache Composer( x );
+MutableApache Composer z = new DefaultApache Composer( y );
+
+// Assemble components
+x.addComponent(Apple.class);
+y.addComponent(Juicer.class);
+z.addComponent(Peeler.class);
+
+// Instantiate components
+Peeler peeler = (Peeler) z.getComponent(Peeler.class);
+// WON'T WORK! peeler will be null
+peeler = (Peeler) x.getComponent(Peeler.class);
+// WON'T WORK! This will throw an exception
+Juicer juicer = (Juicer) y.getComponent(Juicer.class);</pre>
+    </div>
+</div>
+
+<p>This can be visualised as follows:<br />
+    <img src="images/juicer-in-pico-hierarchy.png" align="absmiddle" border="0" /></p>
+
+<p>Let's analyse what will happen here:</p>
+<ul>
+    <li>Line 12 will work fine. z will be able to resolve the dependencies for Peeler (which is Fruit) from the parent
+        container.
+    </li>
+  <li>Line 14 will return null, as x can't see Peeler.</li>
+    <li>Line 16 will throw an exception, since Juicer's dependency to Peeler can't be satisfied (z can't be seen by
+        y).
+    </li>
+</ul>
+        <p><img class="emoticon"
+          src="/images/icons/emoticons/warning.gif" height="16"
+          width="16" align="absmiddle" alt="" border="0" /> Since this
+        obviously won't work, keep in mind that this was just an
+        exercise to illustrate how container hierarchies work.<br />
+        <img class="emoticon"
+          src="/images/icons/emoticons/information.gif" height="16"
+          width="16" align="absmiddle" alt="" border="0" /> For a more
+        concrete example of the usage of container hierarchies, see <a
+          href="http://www.nanocontainer.org/NanoWar" rel="nofollow">NanoContainer
+        NanoWar<sup><img class="rendericon"
+          src="/images/icons/linkext7.gif" height="7" width="7"
+          align="absmiddle" alt="" border="0" /></sup></a>.</p>
+
+        <h2>Lifecycle</h2>
+
+<p>Apache Composer has support for <a href="lifecycle.html" title="Lifecycle">Lifecycle</a>. If your classes implement <a
+    href="http://www.picocontainer.org/picocontainer/latest/picocontainer/apidocs/org/picocontainer/Startable.html">Startable<sup><img
+    class="rendericon" src="/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt=""
+    border="0" /></sup></a>, you can control the lifecycle of all your objects with a simple method call on the
+                           container. The container will figure out the correct order of invocation of start()/stop()
+                           all the objects managed by the container.</p>
+
+<p>Calling start() on the container will call start() on all container managed objects in the order of their
+   instantiation. This means starting with the ones that have no dependencies, and ending with the ones that have
+   dependencies on others:</p>
+<table>
+    <tbody>
+        <tr>
+            <th> MutableApache Composer.start()</th>
+            <th> MutableApache Composer.stop()</th>
+        </tr>
+        <tr>
+            <td><img src="images/start-container.png" align="absmiddle" border="0" /></td>
+            <td><img src="images/stop-container.png" align="absmiddle" border="0" /></td>
+        </tr>
+    </tbody>
+</table>
+<p>Lifecycle also works for hierarchies of containers. Calling start() on a container with child containers will start
+   all the containers in a breadth-first order, starting with itself. Likewise, calling stop() will call stop() on all
+   containers in the hierarchy in a depth-first order. The pictures below show what happens when start() and stop() are
+   called on a container with children.</p>
+<table>
+    <tbody>
+        <tr>
+            <th> MutableApache Composer.start()</th>
+            <th> MutableApache Composer.stop()</th>
+        </tr>
+        <tr>
+            <td><img src="images/start-hierarchy.png" align="absmiddle" border="0" /></td>
+            <td><img src="images/stop-hierarchy.png" align="absmiddle" border="0" /></td>
+        </tr>
+    </tbody>
+</table>
+<p><img class="emoticon" src="/images/icons/emoticons/warning.gif" height="16" width="16" align="absmiddle" alt=""
+        border="0" /> In order for hierarchy-aware lifecycle to work, child containers must be registered as components
+                      in their parent container. Just creating a container with another one as a parent will <b>not</b>
+                      cause the parent container to know about the child container.</p>
+<h3>Example</h3>
+
+<div class="source">
+    <div>
+                    <pre>MutableApache Composer parent = new DefaultApache Composer(new Caching());
+MutableApache Composer child = new DefaultApache Composer(parent);
+// We must let the parent container know about the child container.
+parent.addComponent(child);
+// This will start the parent, which will start the child.
+parent.start();</pre>
+    </div>
+</div>
+
+<p><strong><img class="emoticon" src="/images/icons/emoticons/warning.gif" height="16" width="16" align="absmiddle" alt="warning"
+        border="0" /> </strong>Lifecycle is really only going to work for Apache Composers that are also caching component instances. Caching was a default in Apache Composer 1.x, but is not for 2.x - be warned!</p>
+<p><img class="emoticon" src="/images/icons/emoticons/warning.gif" height="16" width="16" align="absmiddle" alt=""
+        border="0" /> Calling lifecycle methods on a container that has a parent container will <b>not</b> propagate the
+  lifecycle to the parent container. </p>
+<p>Read more about lifecycle <a href="lifecycle.html" title="Lifecycle">here</a>.</p>
+<div id="bodyColumn">
+    <div id="contentBox">
+        <div class="section">
+
+            <h3>Contrasting Usage Styles </h3>
+
+            <p>With Apache Composer you add components and get instances out in two styles. </p>
+
+            <p>Classic bean style: </p>
+
+            <div class="source">
+  <pre>
+pico = new DefaultApache Composer();
+pico.addComponent(ComponentOneImpl.class) // by type
+pico.addComponent(ComponentTwoImpl.class) // by type
+pico.addComponent(new ComponentThreeImpl()) // by instance
+pico.addComponent(ComponentFourImpl.class) // by type
+
+ComponentFourImpl four = pico.getComponent(ComponentFourImpl.class);
+</pre>
+            </div>
+            <p>Or you can use a <a href="http://www.martinfowler.com/bliki/FluentInterface.html">fluent</a> style if you
+               want:</p>
+
+            <div class="source">
+  <pre>
+ComponentFour four = new DefaultApache Composer()
+    .addComponent(ComponentOne.class)
+    .addComponent(ComponentTwo.class)
+    .addComponent(new ComponentThree())
+    .addComponent(ComponentFour.class)
+    .getComponent(ComponentFour.class);</pre>
+            </div>
+
+        </div>
+    </div>
+</div>
+
+</td>
+</tr>
+</table>
+</td>
+</tr>
+</table>
+
+
+</body>
+</html>



Mime
View raw message