[CVS nano] start of moves to picoextras

Paul Hammant <paul-yCVjj/[email protected]> Mon, 17 Nov 2003 04:03:23 -0600
Newsgroups gmane.comp.java.nanocontainer.cvs
Message-ID <[email protected]>
Commit in nano on MAIN

nanocontainer/src/java/org/nanocontainer/JavaScriptCompositionNanoContainer.java +2 -2 1.1 -> 1.2

/JythonCompositionNanoContainer.java +3 -3 1.1 -> 1.2

/NanoContainer.java +2 -2 1.10 -> 1.11

/XmlCompositionNanoContainer.java +3 -3 1.1 -> 1.2

nanocontainer/src/test/org/nanocontainer/BespokeNanoRhinoScriptable.java +1 -1 1.3 -> 1.4

/BespokeXmlFrontEnd.java +2 -2 1.5 -> 1.6

/BogusNanoRhinoScriptable.java +1 -1 1.2 -> 1.3

/JavaScriptCompositionNanoContainerTestCase.java +4 -4 1.1 -> 1.2

/JythonCompositionNanoContainerTestCase.java +3 -3 1.1 -> !

1.2

/XmlCompositionNanoContainerTestCase.java +15 -15 1.1 -> 1.2

picoidea/src/java/META-INF/plugin.xml +1 -1 1.1 -> 1.2

xdocs/introduction.html +4 -4 1.6 -> 1.7

ant/src/java/org/picoextras/ant/AbstractPicoContainerTaskTestCase.java +22 added 1.1

/Component.java +116 added 1.1

/PicoContainerTask.java +105 added 1.1

ant/src/test/org/picoextras/ant/OneConstructorArrayList.java +11 added 1.1

/Pang.java +9 added 1.1

/Ping.java +24 added 1.1

/Pong.java +11 added 1.1

/Pung.java +17 added 1.1

/SimplePicoContainerTaskTestCase.java +72 added 1.1

bsh/src/java/org/picoextras/bsh/BeanShellComponentAdapter.java +113 added 1.1

/BeanShellComponentAdapterFactory.java +34 added 1.1

/BeanShellScriptInitializationException.java +31 added 1.1

bsh/src/test/org/picoextras/bsh/BeanShellComponentAdapterFactoryTestCase.java +43 added 1.1

/ScriptableDemoBean.bsh +3 added 1.1

/ScriptableDemoBean.java +30 added 1.1

ant/src/java/org/nanocontainer/ant/AbstractPicoContainerTaskTestCase.java -22 1.1 removed

/Component.java -116 1.2 removed

/PicoContainerTask.java -105 1.3 removed

ant/src/test/org/nanocontainer/ant/OneConstructorArrayList.java -11 1.1 removed

/Pang.java -9 1.1 removed

/Ping.java -24 1.1 removed

/Pong.java -9 1.1 removed

/Pung.java -15 1.1 removed

/SimplePicoContainerTaskTestCase.java -72 1.1 removed

bsh/src/java/org/nanocontainer/bsh/BeanShellComponentAdapter.java -113 1.4 removed

/BeanShellComponentAdapterFactory.java -34 1.1 removed

/BeanShellScriptInitializationException.java -31 1.1 removed

bsh/src/test/org/nanocontainer/bsh/BeanShellComponentAdapterFactoryTestCase.java -42 1.2 removed

/ScriptableDemoBean.bsh -3 1.1 removed

/ScriptableDemoBean.java -30 1.2 removed

groovypico/src/java/org/picocontainer/groovy/PicoBuilder.java -133 1.3 removed

/PicoBuilderException.java -29 1.1 removed

groovypico/src/test/org/picocontainer/groovy/ExampleTest.groovy -117 1.2 removed

/Xxx.java -45 1.1 removed

nanning/src/java/org/nanocontainer/nanning/NanningComponentAdapter.java -55 1.1 removed

/NanningComponentAdapterFactory.java -120 1.2 removed

/NanningNanoContainer.java -41 1.5 removed

/package.html -8 1.1 removed

nanning/src/test/org/nanocontainer/nanning/NanningComponentFactoryTestCase.java -100 1.3 removed

/NanningNanoContainerTestCase.java -178 1.4 removed

servlet/src/java/org/nanocontainer/servlet/ApplicationScopeObjectReference.java -39 1.1 removed

/KeyConstants.java -20 1.2 removed

/RequestScopeObjectReference.java -39 1.1 removed

/ServletContainerListener.java -91 1.2 removed

/ServletRequestContainerLauncher.java -59 1.1 removed

/SessionScopeObjectReference.java -39 1.1 removed

testmodel/src/java/org/nanocontainer/testmodel/DefaultWebServerConfig.java -23 1.1 removed

/FlintstonesImpl.java -20 1.2 removed

/FredImpl.java -20 1.2 removed

/MockComponent.java -28 1.1 removed

/MockComponentImpl.java -50 1.1 removed

/ResourceBundleWebServerConfig.java -43 1.1 removed

/ThingThatTakesParamsInConstructor.java -15 1.1 removed

/WebServer.java -14 1.1 removed

/WebServerConfig.java -25 1.1 removed

/WebServerConfigBean.java -34 1.2 removed

/WebServerConfigComp.java -29 1.1 removed

/WebServerConfigStub.java -26 1.1 removed

/WebServerImpl.java -23 1.1 removed

/Wilma.java -15 1.2 removed

/WilmaImpl.java -27 1.2 removed

type3msg/src/java/org/nanocontainer/type3msg/MulticastingPicoException.java -16 1.1.1.1 removed

/MulticastingProxy.java -48 1.3 removed

/RoundRobinMulticastingProxy.java -27 1.1.1.1 removed

/Type3MsgPicoContainer.java -35 1.2 removed

type3msg/src/java/org/nanocontainer/type3msg/sample/Controller.java -29 1.1 removed

/Database.java -14 1.1 removed

/PretendDatabase.java -22 1.2 removed

/UnitOfWork.java -20 1.1 removed

/Worker.java -12 1.1 removed

/WorkerDoer.java -29 1.2 removed

/WorkerLogger.java -20 1.1 removed

type3msg/src/test/org/nanocontainer/type3msg/Kissable.java -5 1.1.1.1 removed

/TestBoy.java -20 1.1.1.1 removed

/TestGirl.java -20 1.1.1.1 removed

/Type3MsgPicoContainerTest.java -124 1.2 removed

webwork2/src/java/org/nanocontainer/webwork2/PicoActionInvocation.java -60 1.1 removed

/PicoActionProxyFactory.java -32 1.1 removed

/PicoServletDispatcher.java -43 1.1 removed

/WebWork2ContainerListener.java -24 1.1 removed

webwork/src/java/org/nanocontainer/webwork/PicoActionFactory.java -78 1.2 removed

/PicoServletDispatcher.java -42 1.2 removed

/WebWorkActionFactory.java -44 1.1 removed

xml/src/java/org/nanocontainer/xml/BeanXmlPseudoComponentFactory.java -70 1.2 removed

/DefaultXmlFrontEnd.java -195 1.9 removed

/EmptyXmlCompositionException.java -19 1.1 removed

/ParameterXmlFrontEnd.java -222 1.2 removed

/XStreamXmlPseudoComponentFactory.java -27 1.1 removed

/XmlFrontEnd.java -36 1.4 removed

/XmlFrontEndException.java -37 1.2 removed

/XmlPseudoComponentFactory.java -18 1.1 removed

xml/src/test/org/nanocontainer/xml/BeanXmlPseudoComponentFactoryTestCase.java -46 1.1 removed

/DefaultXmlFrontEndTestCase.java -155 1.7 removed

/ParameterXmlFrontEndTestCase.java -120 1.1 removed

/TestPseudoComp.java -30 1.2 removed

/XStreamXmlPseudoComponentFactoryTestCase.java -46 1.1 removed

+682 -3967

15 added + 81 removed + 12 modified, total 108 files

start of moves to picoextras

----------

nano /nanocontainer /src /java /org /nanocontainer

JavaScriptCompositionNanoContainer.java 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- JavaScriptCompositionNanoContainer.java 8 Nov 2003 12:13:37 -0000 1.1
+++ JavaScriptCompositionNanoContainer.java 17 Nov 2003 10:03:16 -0000 1.2
@@ -8,8 +8,8 @@

*****************************************************************************/
package org.nanocontainer;

-import org.nanocontainer.rhino.DefaultNanoRhinoScriptable;
-import org.nanocontainer.rhino.NanoRhinoManager;

+import org.picoextras.rhino.DefaultNanoRhinoScriptable;
+import org.picoextras.rhino.NanoRhinoManager;

import org.picocontainer.PicoCompositionException;

import java.io.IOException;

----------

nano /nanocontainer /src /java /org /nanocontainer

JythonCompositionNanoContainer.java 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- JythonCompositionNanoContainer.java 16 Nov 2003 16:19:10 -0000 1.1
+++ JythonCompositionNanoContainer.java 17 Nov 2003 10:03:16 -0000 1.2
@@ -8,8 +8,8 @@

*****************************************************************************/
package org.nanocontainer;

-import org.nanocontainer.reflection.DefaultReflectionFrontEnd;
-import org.nanocontainer.reflection.ReflectionFrontEnd;

+import org.picoextras.reflection.DefaultReflectionFrontEnd;
+import org.picoextras.reflection.ReflectionFrontEnd;

import org.picocontainer.PicoCompositionException;
import org.python.util.PythonInterpreter;

@@ -32,7 +32,7 @@

throws PicoCompositionException, ClassNotFoundException, IOException {
super(monitor);
interpreter = new PythonInterpreter();

- interpreter.exec("from org.nanocontainer.reflection import DefaultReflectionFrontEnd");

+ interpreter.exec("from org.picoextras.reflection import DefaultReflectionFrontEnd");

reflectionRootContainer = new DefaultReflectionFrontEnd();
compose(script);
}

----------

nano /nanocontainer /src /java /org /nanocontainer

NanoContainer.java 1.10 -> 1.11

diff -u -r1.10 -r1.11
--- NanoContainer.java 8 Nov 2003 12:13:37 -0000 1.10
+++ NanoContainer.java 17 Nov 2003 10:03:16 -0000 1.11
@@ -8,7 +8,7 @@

*****************************************************************************/
package org.nanocontainer;

-import org.nanocontainer.xml.EmptyXmlCompositionException;

+import org.picoextras.xml.EmptyXmlCompositionException;

import org.picocontainer.PicoContainer;
import org.picocontainer.PicoCompositionException;
import org.picocontainer.extras.DefaultLifecyclePicoAdapter;

@@ -22,7 +22,7 @@

* @author Mauro Talevi
* @author Ward Cunningham
* @author Paul Hammant

- * @version $Revision: 1.10 $

+ * @version $Revision: 1.11 $

*/
public abstract class NanoContainer {

----------

nano /nanocontainer /src /java /org /nanocontainer

XmlCompositionNanoContainer.java 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- XmlCompositionNanoContainer.java 8 Nov 2003 12:13:37 -0000 1.1
+++ XmlCompositionNanoContainer.java 17 Nov 2003 10:03:16 -0000 1.2
@@ -8,8 +8,8 @@

*****************************************************************************/
package org.nanocontainer;

-import org.nanocontainer.xml.DefaultXmlFrontEnd;
-import org.nanocontainer.xml.XmlFrontEnd;

+import org.picoextras.xml.DefaultXmlFrontEnd;
+import org.picoextras.xml.XmlFrontEnd;

import org.picocontainer.PicoCompositionException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

@@ -27,7 +27,7 @@

* @author Aslak Helles&oslash;y
* @author Paul Hammant
* @author Ward Cunningham

- * @version $Revision: 1.1 $

+ * @version $Revision: 1.2 $

*/
public class XmlCompositionNanoContainer extends NanoContainer {

----------

nano /nanocontainer /src /test /org /nanocontainer

BespokeNanoRhinoScriptable.java 1.3 -> 1.4

diff -u -r1.3 -r1.4
--- BespokeNanoRhinoScriptable.java 4 Nov 2003 22:09:49 -0000 1.3
+++ BespokeNanoRhinoScriptable.java 17 Nov 2003 10:03:16 -0000 1.4
@@ -12,7 +12,7 @@

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;

-import org.nanocontainer.rhino.DefaultNanoRhinoScriptable;

+import org.picoextras.rhino.DefaultNanoRhinoScriptable;

public class BespokeNanoRhinoScriptable extends DefaultNanoRhinoScriptable {

----------

nano /nanocontainer /src /test /org /nanocontainer

BespokeXmlFrontEnd.java 1.5 -> 1.6

diff -u -r1.5 -r1.6
--- BespokeXmlFrontEnd.java 8 Nov 2003 12:13:37 -0000 1.5
+++ BespokeXmlFrontEnd.java 17 Nov 2003 10:03:16 -0000 1.6
@@ -8,8 +8,8 @@

*****************************************************************************/
package org.nanocontainer;

-import org.nanocontainer.xml.DefaultXmlFrontEnd;
-import org.nanocontainer.xml.XmlFrontEnd;

+import org.picoextras.xml.DefaultXmlFrontEnd;
+import org.picoextras.xml.XmlFrontEnd;

import org.picocontainer.MutablePicoContainer;
import org.picocontainer.PicoCompositionException;
import org.picocontainer.PicoContainer;

----------

nano /nanocontainer /src /test /org /nanocontainer

BogusNanoRhinoScriptable.java 1.2 -> 1.3

diff -u -r1.2 -r1.3
--- BogusNanoRhinoScriptable.java 4 Nov 2003 22:09:49 -0000 1.2
+++ BogusNanoRhinoScriptable.java 17 Nov 2003 10:03:16 -0000 1.3
@@ -13,7 +13,7 @@

import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

-import org.nanocontainer.rhino.DefaultNanoRhinoScriptable;

+import org.picoextras.rhino.DefaultNanoRhinoScriptable;

public class BogusNanoRhinoScriptable extends ScriptableObject {

----------

nano /nanocontainer /src /test /org /nanocontainer

JavaScriptCompositionNanoContainerTestCase.java 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- JavaScriptCompositionNanoContainerTestCase.java 8 Nov 2003 12:13:37 -0000 1.1
+++ JavaScriptCompositionNanoContainerTestCase.java 17 Nov 2003 10:03:16 -0000 1.2
@@ -11,7 +11,7 @@

import junit.framework.ComparisonFailure;
import junit.framework.TestCase;
import org.mozilla.javascript.EcmaError;

-import org.nanocontainer.testmodel.WebServerConfig;

+import org.picoextras.testmodel.WebServerConfig;

import org.picocontainer.PicoCompositionException;
import org.picocontainer.defaults.NoSatisfiableConstructorsException;

@@ -23,7 +23,7 @@

* @author Aslak Helles&oslash;y
* @author Paul Hammant
* @author Ward Cunningham

- * @version $Revision: 1.1 $

+ * @version $Revision: 1.2 $

*/
public class JavaScriptCompositionNanoContainerTestCase extends TestCase {

@@ -146,11 +146,11 @@

NanoContainer nano = new JavaScriptCompositionNanoContainer(new StringReader("" +
"var parentContainer = new NanoRhinoScriptable();\n" +
"with (parentContainer) {\n" +

- " var pc = new Packages.org.nanocontainer.testmodel.WebServerConfigBean();\n" +

+ " var pc = new Packages.org.picoextras.testmodel.WebServerConfigBean();\n" +

" pc.setHost('foobar.com');\n" +
" pc.setPort(4321);\n" +
" addComponentInstance(pc);\n" +

- " addComponentWithClassKey('org.nanocontainer.testmodel.WebServer','" + XmlCompositionNanoContainerTestCase.OverriddenWebServerImpl.class.getName() + "');\n" +

+ " addComponentWithClassKey('org.picoextras.testmodel.WebServer','" + XmlCompositionNanoContainerTestCase.OverriddenWebServerImpl.class.getName() + "');\n" +

"}\n" +
"nano.setNanoRhinoScriptable(parentContainer)\n"
), new MockMonitor());

----------

nano /nanocontainer /src /test /org /nanocontainer

JythonCompositionNanoContainerTestCase.java 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- JythonCompositionNanoContainerTestCase.java 16 Nov 2003 16:19:10 -0000 1.1
+++ JythonCompositionNanoContainerTestCase.java 17 Nov 2003 10:03:16 -0000 1.2
@@ -10,7 +10,7 @@

import junit.framework.ComparisonFailure;
import junit.framework.TestCase;

-import org.nanocontainer.testmodel.WebServerConfig;

+import org.picoextras.testmodel.WebServerConfig;

import org.picocontainer.PicoCompositionException;
import org.picocontainer.defaults.NoSatisfiableConstructorsException;

@@ -23,7 +23,7 @@

* @author Paul Hammant
* @author Ward Cunningham
* @author Mike Royle

- * @version $Revision: 1.1 $

+ * @version $Revision: 1.2 $

*/
public class JythonCompositionNanoContainerTestCase extends TestCase {

@@ -101,7 +101,7 @@

"wsc.setHost('foobar.com')\n" +
"wsc.setPort(4321)\n" +
"rootContainer.getPicoContainer().registerComponentInstance(wsc)\n" +

- "rootContainer.registerComponentWithClassKey('org.nanocontainer.testmodel.WebServer','" + XmlCompositionNanoContainerTestCase.OverriddenWebServerImpl.class.getName() + "')\n"

+ "rootContainer.registerComponentWithClassKey('org.picoextras.testmodel.WebServer','" + XmlCompositionNanoContainerTestCase.OverriddenWebServerImpl.class.getName() + "')\n"

), new MockMonitor());

assertEquals("WebServerConfigBean and WebServerImpl expected", 2, nano.getRootContainer().getComponentInstances().size());

----------

nano /nanocontainer /src /test /org /nanocontainer

XmlCompositionNanoContainerTestCase.java 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- XmlCompositionNanoContainerTestCase.java 8 Nov 2003 12:13:37 -0000 1.1
+++ XmlCompositionNanoContainerTestCase.java 17 Nov 2003 10:03:16 -0000 1.2
@@ -10,9 +10,9 @@

import junit.framework.Assert;
import junit.framework.TestCase;

-import org.nanocontainer.testmodel.DefaultWebServerConfig;
-import org.nanocontainer.testmodel.WebServerConfig;
-import org.nanocontainer.testmodel.WebServerImpl;

+import org.picoextras.testmodel.DefaultWebServerConfig;
+import org.picoextras.testmodel.WebServerConfig;
+import org.picoextras.testmodel.WebServerImpl;

import org.picocontainer.PicoCompositionException;
import org.picocontainer.defaults.AmbiguousComponentResolutionException;
import org.picocontainer.defaults.DefaultComponentAdapterFactory;

@@ -30,7 +30,7 @@

* @author Aslak Helles&oslash;y
* @author Paul Hammant
* @author Ward Cunningham

- * @version $Revision: 1.1 $

+ * @version $Revision: 1.2 $

*/
public class XmlCompositionNanoContainerTestCase extends TestCase {

@@ -100,7 +100,7 @@

NanoContainer nano = null;
nano = new XmlCompositionNanoContainer(new StringReader("" +
"<container componentadaptor='" + OverriddenComponentAdapterFactory.class.getName() + "'>" +

- " <component typekey='org.nanocontainer.testmodel.WebServerConfig' impl='org.nanocontainer.testmodel.DefaultWebServerConfig'/>" +

+ " <component typekey='org.picoextras.testmodel.WebServerConfig' impl='org.picoextras.testmodel.DefaultWebServerConfig'/>" +

"</container>"), new MockMonitor());

Object wsc = nano.getRootContainer().getComponentInstance(WebServerConfig.class);

@@ -122,14 +122,14 @@

NanoContainer nano = null;
nano = new XmlCompositionNanoContainer(new StringReader("" +
"<container>" +

- " <pseudocomponent factory='org.nanocontainer.xml.XStreamXmlPseudoComponentFactory'>" +
- " <org.nanocontainer.testmodel.WebServerConfigStub>" +

+ " <pseudocomponent factory='org.picoextras.xml.XStreamXmlPseudoComponentFactory'>" +
+ " <org.picoextras.testmodel.WebServerConfigStub>" +

" <host>foobar.com</host> " +
" <port>4321</port> " +

- " </org.nanocontainer.testmodel.WebServerConfigStub>" +

+ " </org.picoextras.testmodel.WebServerConfigStub>" +

" </pseudocomponent>" +

- " <component typekey='org.nanocontainer.testmodel.WebServer' " +
- " impl='org.nanocontainer.testmodel.WebServerImpl'/>" +

+ " <component typekey='org.picoextras.testmodel.WebServer' " +
+ " impl='org.picoextras.testmodel.WebServerImpl'/>" +

"</container>"), new MockMonitor());

assertEquals("WebServerConfigBean and WebServerImpl expected", 2, nano.getRootContainer().getComponentInstances().size());

@@ -143,14 +143,14 @@

NanoContainer nano = null;
nano = new XmlCompositionNanoContainer(new StringReader("" +
"<container>" +

- " <pseudocomponent factory='org.nanocontainer.xml.BeanXmlPseudoComponentFactory'>" +
- " <org.nanocontainer.testmodel.WebServerConfigBean>" +

+ " <pseudocomponent factory='org.picoextras.xml.BeanXmlPseudoComponentFactory'>" +
+ " <org.picoextras.testmodel.WebServerConfigBean>" +

" <host>foobar.com</host> " +
" <port>4321</port> " +

- " </org.nanocontainer.testmodel.WebServerConfigBean>" +

+ " </org.picoextras.testmodel.WebServerConfigBean>" +

" </pseudocomponent>" +

- " <component typekey='org.nanocontainer.testmodel.WebServer' " +
- " impl='org.nanocontainer.testmodel.WebServerImpl'/>" +

+ " <component typekey='org.picoextras.testmodel.WebServer' " +
+ " impl='org.picoextras.testmodel.WebServerImpl'/>" +

"</container>"), new MockMonitor());

assertEquals("WebServerConfigBean and WebServerImpl expected", 2, nano.getRootContainer().getComponentInstances().size());

----------

nano /picoidea /src /java /META-INF

plugin.xml 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- plugin.xml 16 Sep 2003 23:08:33 -0000 1.1
+++ plugin.xml 17 Nov 2003 10:03:16 -0000 1.2
@@ -7,7 +7,7 @@

<application-components>
<component>

- <implementation-class>org.picocontainer.idea.PicoPlugin</implementation-class>

+ <implementation-class>org.picoextras.idea.PicoPlugin</implementation-class>

</component>
</application-components>
</idea-plugin>

----------

nano /xdocs

introduction.html 1.6 -> 1.7

diff -u -r1.6 -r1.7
--- introduction.html 10 Sep 2003 14:21:57 -0000 1.6
+++ introduction.html 17 Nov 2003 10:03:16 -0000 1.7
@@ -22,8 +22,8 @@

<li>StringRegistrationNanoContainerImpl.Default - no args</li>
</ul>
<pre>&nbsp;&nbsp;&nbsp; StringRegistrationNanoContainer nc = new StringRegistrationNanoContainerImpl.Default();</pre>

-<pre>&nbsp;&nbsp;&nbsp; nc.registerComponent("org.org.nanocontainer.testmodel.DefaultWebServerConfig");</pre>
-<pre>&nbsp;&nbsp;&nbsp; nc.registerComponent("org.org.nanocontainer.testmodel.WebServer", "org.org.nanocontainer.testmodel.WebServerImpl");</pre>

+<pre>&nbsp;&nbsp;&nbsp; nc.registerComponent("org.org.picoextras.testmodel.DefaultWebServerConfig");</pre>
+<pre>&nbsp;&nbsp;&nbsp; nc.registerComponent("org.org.picoextras.testmodel.WebServer", "org.org.picoextras.testmodel.WebServerImpl");</pre>

<pre>&nbsp;&nbsp;&nbsp; nc.start();</pre>
<h2>InputSourceRegistrationNanoContainer </h2>
This container takes a single InputSource (from the SAX API) .&nbsp;

@@ -48,8 +48,8 @@

<pre>&nbsp;&nbsp;&nbsp; InputSourceRegistrationNanoContainer nc = new DomRegistrationNanoContainer.Default();</pre>
<pre>&nbsp;&nbsp;&nbsp; nc.registerComponents(new InputSource(new StringReader(</pre>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&lt;components&gt;" +</pre>

-<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;component class=\"org.org.nanocontainer.testmodel.DefaultWebServerConfig\"/&gt;" +</pre>
-<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;component type=\"org.org.nanocontainer.testmodel.WebServer\" class=\"org.org.nanocontainer.testmodel.WebServerImpl\"/&gt;" +</pre>

+<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;component class=\"org.org.picoextras.testmodel.DefaultWebServerConfig\"/&gt;" +</pre>
+<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;component type=\"org.org.picoextras.testmodel.WebServer\" class=\"org.org.picoextras.testmodel.WebServerImpl\"/&gt;" +</pre>

<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&lt;/components&gt;")));</pre>
<pre>&nbsp;&nbsp;&nbsp; nc.start();</pre>
<h2>AggregatingNanoContainer<br>

----------

nano /ant /src /java /org /picoextras /ant

AbstractPicoContainerTaskTestCase.java added at 1.1

diff -N AbstractPicoContainerTaskTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AbstractPicoContainerTaskTestCase.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,22 @@

+package org.picoextras.ant;
+
+import junit.framework.TestCase;
+import org.apache.tools.ant.Project;
+
+/**
+ *
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractPicoContainerTaskTestCase extends TestCase {
+ protected PicoContainerTask task;
+
+ public void setUp() {
+ Project project = new Project();
+ task = createPicoContainerTask();
+ task.setProject(project);
+ task.setTaskName(task.getClass().getName());
+ }
+
+ protected abstract PicoContainerTask createPicoContainerTask();
+}

----------

nano /ant /src /java /org /picoextras /ant

Component.java added at 1.1

diff -N Component.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Component.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,116 @@

+package org.picoextras.ant;
+
+import org.apache.tools.ant.DynamicConfigurator;
+import org.apache.tools.ant.BuildException;
+import org.picocontainer.defaults.ConstantParameter;
+import org.picocontainer.Parameter;
+import org.picocontainer.defaults.ComponentParameter;
+import org.picoextras.reflection.StringToObjectConverter;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.ListIterator;
+
+/**
+ *
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class Component implements DynamicConfigurator {
+ private String className;
+ private Map properties = new HashMap();
+ private List parameters = new ArrayList();
+ private String key;
+
+ public void setClassname(String className) {
+ this.className = className;
+ }
+
+ public String getClassname() {
+ return className;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getKey() {
+ return key != null ? key : getClassname();
+ }
+
+ public void setDynamicAttribute(String name, String value) throws BuildException {
+ properties.put(name, value);
+ }
+
+ public Object createDynamicElement(String string) throws BuildException {
+ throw new BuildException("No sub elements of " + string + " is allowed");
+ }
+
+// public void setPropertiesOn(BeanPropertyComponentAdapterFactory.Adapter adapter) throws BeanPropertyComponentAdapterFactory.NoSuchPropertyException {
+// for (Iterator i = properties.keySet().iterator(); i.hasNext();) {
+// String name = (String) i.next();
+// String value = (String) properties.get(name);
+// adapter.setPropertyValue(name, value);
+// }
+// }
+
+ public ConstantParam createConstant() {
+ ConstantParam constant = new ConstantParam();
+ parameters.add(constant);
+ return constant;
+ }
+
+ public Parameter[] getParameters() {
+ if (parameters.size() == 0) {
+ return null;
+ }
+
+ Parameter[] result = new Parameter[parameters.size()];
+ for (ListIterator iterator = parameters.listIterator(); iterator.hasNext();) {
+ AbstractParam constant = (AbstractParam) iterator.next();
+ result[iterator.previousIndex()] = constant.createParameter();
+ }
+
+ return result;
+ }
+
+ public ComponentParam createComponent() {
+ ComponentParam param = new ComponentParam();
+ parameters.add(param);
+ return param;
+ }
+
+ public Map getProperties() {
+ return properties;
+ }
+
+ public static abstract class AbstractParam {
+ protected Class type = String.class;
+
+ public abstract Parameter createParameter();
+
+ public void setType(Class type) {
+ this.type = type;
+ }
+ }
+
+ public static class ComponentParam extends AbstractParam {
+ public Parameter createParameter() {
+ return new ComponentParameter(type);
+ }
+ }
+
+ public static class ConstantParam extends AbstractParam {
+ private String value;
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public Parameter createParameter() {
+ return new ConstantParameter(new StringToObjectConverter().convertTo(type, value));
+ }
+ }
+}

----------

nano /ant /src /java /org /picoextras /ant

PicoContainerTask.java added at 1.1

diff -N PicoContainerTask.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ PicoContainerTask.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,105 @@

+package org.picoextras.ant;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.picocontainer.extras.InvokingComponentAdapterFactory;
+import org.picocontainer.extras.BeanPropertyComponentAdapterFactory;
+import org.picocontainer.defaults.*;
+import org.picocontainer.Parameter;
+import org.picocontainer.MutablePicoContainer;
+
+import java.util.*;
+
+/**
+ * An Ant task that makes the use of PicoContainer possible from Ant.
+ * When the task is executed, it will invoke <code>execute()</code>
+ * on all components that have a public no-arg, non-static execute method.
+ * The components's execute() method (if it exists) will be invoked
+ * in the order of instantiation.
+ *
+ * &lt;taskdef name="pico" classname="org.picoextras.ant.PicoContainerTask"/&gt;
+ *
+ * &lt;pico&gt;
+ * &lt;component classname="foo.Bar" someprop="somevalue"/&gt;
+ * &lt;component classname="ping.Pong"/&gt;
+ * &lt;/pico&gt;
+ *
+ * Also note that bean/ant style properties can be set too. The above
+ * usage will call <code>setSomeprop("somevalue")</code> on the
+ * <code>foo.Bar</code> instance.
+ *
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class PicoContainerTask extends Task {
+ private final List components = new ArrayList();
+
+ private final BeanPropertyComponentAdapterFactory propertyFactory;
+ private final MutablePicoContainer pico;
+
+ public PicoContainerTask() {
+ DefaultComponentAdapterFactory defaultFactory = new DefaultComponentAdapterFactory();
+ propertyFactory = new BeanPropertyComponentAdapterFactory(defaultFactory);
+ InvokingComponentAdapterFactory invokingFactory = new InvokingComponentAdapterFactory(
+ propertyFactory,
+ "execute",
+ null,
+ null
+ );
+ pico = new DefaultPicoContainer(invokingFactory);
+ }
+
+ public void addComponent(Component component) {
+ components.add(component);
+ }
+
+ public void execute() {
+ registerComponentsSpecifiedInAnt();
+ try {
+ getPicoContainer().getComponentInstances();
+ } catch (PicoInvocationTargetInitializationException e) {
+ throw new BuildException(e.getCause());
+ } catch (Exception e) {
+ throw new BuildException(e);
+ }
+ }
+
+ private void registerComponentsSpecifiedInAnt() {
+
+ for (Iterator iterator = components.iterator(); iterator.hasNext();) {
+ Component component = (Component) iterator.next();
+
+ // set the properties on the adapter factory
+ // they will be set upon instantiation
+ Object key = component.getKey();
+ Map properties = component.getProperties();
+ propertyFactory.setProperties(key, properties);
+
+ Parameter[] parameters = component.getParameters();
+
+ try {
+ Class aClass = getClassLoader().loadClass(component.getClassname());
+ MutablePicoContainer picoContainer = (MutablePicoContainer) getPicoContainer();
+ if (parameters != null) {
+ picoContainer.registerComponentImplementation(component.getKey(), aClass, parameters);
+ } else {
+ picoContainer.registerComponentImplementation(component.getKey(), aClass);
+ }
+ } catch (Exception e) {
+ throw new BuildException(e);
+ }
+ }
+ }
+
+ private ClassLoader getClassLoader() {
+ ClassLoader classLoader = getClass().getClassLoader();
+ if (classLoader == null) {
+ classLoader = getClass().getClassLoader();
+ }
+ return classLoader;
+ }
+
+ public MutablePicoContainer getPicoContainer() {
+ return pico;
+ }
+}

----------

nano /ant /src /test /org /picoextras /ant

OneConstructorArrayList.java added at 1.1

diff -N OneConstructorArrayList.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ OneConstructorArrayList.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,11 @@

+package org.picoextras.ant;
+
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class OneConstructorArrayList extends ArrayList {
+}

----------

nano /ant /src /test /org /picoextras /ant

Pang.java added at 1.1

diff -N Pang.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Pang.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,9 @@

+package org.picoextras.ant;
+
+/**
+ *
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class Pang {
+}

----------

nano /ant /src /test /org /picoextras /ant

Ping.java added at 1.1

diff -N Ping.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Ping.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,24 @@

+package org.picoextras.ant;
+
+import junit.framework.Assert;
+
+/**
+ *
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class Ping {
+ private String prop;
+ boolean wasExecuted = false;
+
+ public void setSomeprop(String prop) {
+ this.prop = prop;
+ }
+
+ public void execute() {
+ Assert.assertEquals("The property should be set", "HELLO", prop);
+ wasExecuted = true;
+ // This is only so we can see the output when run from Ant
+ System.out.println("Ping executing :-)");
+ }
+}

----------

nano /ant /src /test /org /picoextras /ant

Pong.java added at 1.1

diff -N Pong.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Pong.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,11 @@

+package org.picoextras.ant;
+
+import org.picoextras.ant.Ping;
+
+/**
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class Pong {
+ public Pong(Ping foo) {}
+}

----------

nano /ant /src /test /org /picoextras /ant

Pung.java added at 1.1

diff -N Pung.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Pung.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,17 @@

+package org.picoextras.ant;
+
+import org.picoextras.ant.Pang;
+
+/**
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class Pung {
+ public String text;
+ public Pang pang;
+
+ public Pung(Pang pang, String text){
+ this.pang = pang;
+ this.text = text;
+ }
+}

----------

nano /ant /src /test /org /picoextras /ant

SimplePicoContainerTaskTestCase.java added at 1.1

diff -N SimplePicoContainerTaskTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SimplePicoContainerTaskTestCase.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,72 @@

+package org.picoextras.ant;
+
+import org.picocontainer.MutablePicoContainer;
+import org.picocontainer.PicoContainer;
+import org.picocontainer.PicoException;
+import org.picocontainer.defaults.DefaultPicoContainer;
+import org.picocontainer.extras.InvokingComponentAdapterFactory;
+
+/**
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class SimplePicoContainerTaskTestCase extends AbstractPicoContainerTaskTestCase {
+
+ public void testPicoContainerTaskWithPropertyButWithoutParameters() throws PicoException {
+ Component pongComp = new Component();
+ pongComp.setClassname(Pong.class.getName());
+ task.addComponent(pongComp);
+
+ Component pingComp = new Component();
+ pingComp.setClassname(Ping.class.getName());
+ pingComp.setDynamicAttribute("someprop", "HELLO");
+ task.addComponent(pingComp);
+
+ task.execute();
+
+ PicoContainer pico = task.getPicoContainer();
+
+ Ping ping = (Ping) pico.getComponentInstance(Ping.class);
+ assertNotNull(ping);
+ assertTrue(ping.wasExecuted);
+ }
+
+ public void testPicoContainerTaskWithParameters() throws PicoException {
+ Component pangComp = new Component();
+ pangComp.setClassname(Pang.class.getName());
+ task.addComponent(pangComp);
+
+ Component pungComp = new Component();
+ pungComp.setClassname(Pung.class.getName());
+
+ // one component param
+ Component.ComponentParam componentParam = pungComp.createComponent();
+ componentParam.setType(Pang.class);
+
+ // and one constant param
+ Component.ConstantParam constantParam = pungComp.createConstant();
+ constantParam.setValue("bajs");
+
+ task.addComponent(pungComp);
+ task.execute();
+
+ // Now see if the task did the job properly
+ PicoContainer pico = task.getPicoContainer();
+
+ Pung pung = (Pung) pico.getComponentInstance(Pung.class);
+ assertNotNull(pung);
+ assertEquals("bajs", pung.text);
+
+ Pang pang = (Pang) pico.getComponentInstance(Pang.class);
+ assertNotNull(pang);
+ assertSame(pung.pang, pang);
+ }
+
+ protected PicoContainerTask createPicoContainerTask() {
+ return new PicoContainerTask() {
+ protected MutablePicoContainer createPicoContainer(InvokingComponentAdapterFactory invokingFactory) {
+ return new DefaultPicoContainer(invokingFactory);
+ }
+ };
+ }
+}

----------

nano /bsh /src /java /org /picoextras /bsh

BeanShellComponentAdapter.java added at 1.1

diff -N BeanShellComponentAdapter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BeanShellComponentAdapter.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,113 @@

+/*****************************************************************************
+ * Copyright (C) NanoContainer 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 Leo Simons *
+ *****************************************************************************/
+package org.picoextras.bsh;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import org.picocontainer.Parameter;
+import org.picocontainer.ComponentAdapter;
+import org.picocontainer.PicoContainer;
+import org.picocontainer.MutablePicoContainer;
+import org.picocontainer.PicoInitializationException;
+import org.picocontainer.PicoIntrospectionException;
+import org.picocontainer.PicoContainer;
+import org.picocontainer.defaults.NoSatisfiableConstructorsException;
+
+import bsh.Interpreter;
+import bsh.EvalError;
+
+/**
+ * This adapter relies on <a href="http://beanshell.org/">Bsh</a> for instantiation
+ * (and possibly also initialisation) of component instances.
+ * <p>
+ * When {@link #getComponentInstance} is called (by PicoContainer),
+ * the adapter instance will look for a script with the same name as the component implementation
+ * class (but with the .bsh extension). This script must reside in the same folder as the class.
+ * (It's ok to have them both in a jar).
+ * <p>
+ * The bsh script's only contract is that it will have to instantiate a bsh variable called
+ * "instance".
+ * <p>
+ * The script will have access to the following variables:
+ * <ul>
+ * <li>adapter - the adapter calling the script</li>
+ * <li>picoContainer - the MutablePicoContainer calling the adapter</li>
+ * <li>componentKey - the component key</li>
+ * <li>componentImplementation - the component implementation</li>
+ * <li>parameters - the ComponentParameters (as a List)</li>
+ * </ul>
+ *
+ * @author <a href="mail at leosimons dot com">Leo Simons</a>
+ * @author Aslak Hellesoy
+ * @version $Id: BeanShellComponentAdapter.java,v 1.1 2003/11/17 10:03:17 paul Exp $
+ */
+public class BeanShellComponentAdapter implements ComponentAdapter {
+ private final Object componentKey;
+ private final Class componentImplementation;
+ private final Parameter[] parameters;
+
+ private Object instance = null;
+
+ public BeanShellComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters) {
+ this.componentKey = componentKey;
+ this.componentImplementation = componentImplementation;
+ this.parameters = parameters;
+ }
+
+ public Object getComponentKey() {
+ return componentKey;
+ }
+
+ public Class getComponentImplementation() {
+ return componentImplementation;
+ }
+
+ public Object getComponentInstance(MutablePicoContainer picoContainer)
+ throws PicoInitializationException, PicoIntrospectionException {
+
+ if (instance == null) {
+ try {
+ Interpreter i = new Interpreter();
+ i.set("adapter", this);
+ i.set("picoContainer", picoContainer);
+ i.set("componentKey", componentKey);
+ i.set("componentImplementation", componentImplementation);
+ i.set("parameters", parameters != null ? Arrays.asList(parameters) : Collections.EMPTY_LIST);
+ i.eval("import " + componentImplementation.getName() + ";");
+
+ String scriptPath = "/" + componentImplementation.getName().replace('.', '/') + ".bsh";
+ URL scriptURL = componentImplementation.getResource(scriptPath);
+ if(scriptURL == null) {
+ throw new BeanShellScriptInitializationException("Couldn't load script at path " + scriptPath);
+ }
+ Reader sourceReader = new InputStreamReader(scriptURL.openStream());
+ i.eval(sourceReader, i.getNameSpace(), scriptURL.toExternalForm());
+
+ instance = i.get("instance");
+ if(i == null) {
+ throw new BeanShellScriptInitializationException("The 'instance' variable was not instantiated");
+ }
+ } catch (EvalError e) {
+ throw new BeanShellScriptInitializationException(e);
+ } catch (IOException e) {
+ throw new BeanShellScriptInitializationException(e);
+ }
+ }
+ return instance;
+ }
+
+ public void verify(PicoContainer picoContainer) throws NoSatisfiableConstructorsException {
+ }
+}

----------

nano /bsh /src /java /org /picoextras /bsh

BeanShellComponentAdapterFactory.java added at 1.1

diff -N BeanShellComponentAdapterFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BeanShellComponentAdapterFactory.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,34 @@

+/*****************************************************************************
+ * Copyright (C) NanoContainer 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 Leo Simons *
+ *****************************************************************************/
+package org.picoextras.bsh;
+
+import org.picocontainer.defaults.ComponentAdapterFactory;
+import org.picocontainer.defaults.AssignabilityRegistrationException;
+import org.picocontainer.defaults.NotConcreteRegistrationException;
+import org.picocontainer.ComponentAdapter;
+import org.picocontainer.Parameter;
+import org.picocontainer.PicoIntrospectionException;
+
+/**
+ * This factory creates component adapters that relies on Bsh.
+ *
+ * @see BeanShellComponentAdapter
+ * @author <a href="mail at leosimons dot com">Leo Simons</a>
+ * @version $Id: BeanShellComponentAdapterFactory.java,v 1.1 2003/11/17 10:03:17 paul Exp $
+ */
+public class BeanShellComponentAdapterFactory
+ implements ComponentAdapterFactory {
+ public ComponentAdapter createComponentAdapter(Object componentKey,
+ Class componentImplementation,
+ Parameter[] parameters) throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
+ return new BeanShellComponentAdapter(componentKey, componentImplementation, parameters);
+ }
+
+}

----------

nano /bsh /src /java /org /picoextras /bsh

BeanShellScriptInitializationException.java added at 1.1

diff -N BeanShellScriptInitializationException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BeanShellScriptInitializationException.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,31 @@

+/*****************************************************************************
+ * Copyright (C) NanoContainer 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 Leo Simons *
+ *****************************************************************************/
+package org.picoextras.bsh;
+
+import org.picocontainer.PicoInitializationException;
+
+/**
+ *
+ *
+ * @author <a href="mail at leosimons dot com">Leo Simons</a>
+ * @version $Id: BeanShellScriptInitializationException.java,v 1.1 2003/11/17 10:03:17 paul Exp $
+ */
+public class BeanShellScriptInitializationException
+ extends PicoInitializationException {
+
+ BeanShellScriptInitializationException(String message) {
+ super(message);
+ }
+
+ BeanShellScriptInitializationException(Throwable cause) {
+ this("BeanShellScriptInitializationException: " + cause.getClass().getName() + " "
+ + cause.getMessage());
+ }
+}

----------

nano /bsh /src /test /org /picoextras /bsh

BeanShellComponentAdapterFactoryTestCase.java added at 1.1

diff -N BeanShellComponentAdapterFactoryTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BeanShellComponentAdapterFactoryTestCase.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,43 @@

+/*****************************************************************************
+ * Copyright (C) NanoContainer 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 Leo Simons *
+ *****************************************************************************/
+package org.picoextras.bsh;
+
+import junit.framework.TestCase;
+
+import org.picocontainer.ComponentAdapter;
+import org.picocontainer.MutablePicoContainer;
+import org.picocontainer.defaults.DefaultPicoContainer;
+import org.picoextras.bsh.BeanShellComponentAdapterFactory;
+
+import java.util.ArrayList;
+
+/**
+ * <a href="http://www.junit.org/">JUnit</a>
+ * {@link junit.framework.TestCase testcase} for
+ * BeanShellComponentAdapter.
+ *
+ * @author <a href="mail at leosimons dot com">Leo Simons</a>
+ * @version $Id: BeanShellComponentAdapterFactoryTestCase.java,v 1.1 2003/11/17 10:03:17 paul Exp $
+ */
+public class BeanShellComponentAdapterFactoryTestCase extends TestCase {
+ public void testGetComponentInstance() {
+ MutablePicoContainer pico = new DefaultPicoContainer();
+ pico.registerComponentImplementation("whatever", ArrayList.class);
+
+ ComponentAdapter adapter = new BeanShellComponentAdapterFactory().createComponentAdapter(
+ "thekey", ScriptableDemoBean.class, null);
+
+ ScriptableDemoBean bean = (ScriptableDemoBean) adapter.getComponentInstance(pico);
+
+ assertEquals("Bsh demo script should have set the key", "thekey", bean.key);
+
+ assertTrue(bean.whatever instanceof ArrayList);
+ }
+}

----------

nano /bsh /src /test /org /picoextras /bsh

ScriptableDemoBean.bsh added at 1.1

diff -N ScriptableDemoBean.bsh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ScriptableDemoBean.bsh 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,3 @@

+instance = new ScriptableDemoBean();
+instance.rememberMyKey(componentKey);
+instance.setWhatever(picoContainer.getComponentInstance("whatever"));

\ No newline at end of file

----------

nano /bsh /src /test /org /picoextras /bsh

ScriptableDemoBean.java added at 1.1

diff -N ScriptableDemoBean.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ScriptableDemoBean.java 17 Nov 2003 10:03:17 -0000 1.1
@@ -0,0 +1,30 @@

+/*****************************************************************************
+ * Copyright (C) NanoContainer 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 Leo Simons *
+ *****************************************************************************/
+package org.picoextras.bsh;
+
+/**
+ *
+ *
+ * @author <a href="mail at leosimons dot com">Leo Simons</a>
+ * @author Aslak Hellesoy
+ * @version $Id: ScriptableDemoBean.java,v 1.1 2003/11/17 10:03:17 paul Exp $
+ */
+public class ScriptableDemoBean {
+ public Object key;
+ public Object whatever;
+
+ public void rememberMyKey(Object key) {
+ this.key = key;
+ }
+
+ public void setWhatever(Object whatever) {
+ this.whatever = whatever;
+ }
+}

----------

nano /ant /src /java /org /nanocontainer /ant

AbstractPicoContainerTaskTestCase.java removed after 1.1

diff -N AbstractPicoContainerTaskTestCase.java
--- AbstractPicoContainerTaskTestCase.java 10 Sep 2003 15:22:32 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,22 +0,0 @@

-package org.nanocontainer.ant;
-
-import junit.framework.TestCase;
-import org.apache.tools.ant.Project;
-
-/**
- *
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.1 $
- */
-public abstract class AbstractPicoContainerTaskTestCase extends TestCase {
- protected PicoContainerTask task;
-
- public void setUp() {
- Project project = new Project();
- task = createPicoContainerTask();
- task.setProject(project);
- task.setTaskName(task.getClass().getName());
- }
-
- protected abstract PicoContainerTask createPicoContainerTask();
-}

----------

nano /ant /src /java /org /nanocontainer /ant

Component.java removed after 1.2

diff -N Component.java
--- Component.java 16 Sep 2003 23:11:31 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,116 +0,0 @@

-package org.nanocontainer.ant;
-
-import org.apache.tools.ant.DynamicConfigurator;
-import org.apache.tools.ant.BuildException;
-import org.picocontainer.defaults.ConstantParameter;
-import org.picocontainer.Parameter;
-import org.picocontainer.defaults.ComponentParameter;
-import org.nanocontainer.reflection.StringToObjectConverter;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.ListIterator;
-
-/**
- *
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.2 $
- */
-public class Component implements DynamicConfigurator {
- private String className;
- private Map properties = new HashMap();
- private List parameters = new ArrayList();
- private String key;
-
- public void setClassname(String className) {
- this.className = className;
- }
-
- public String getClassname() {
- return className;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getKey() {
- return key != null ? key : getClassname();
- }
-
- public void setDynamicAttribute(String name, String value) throws BuildException {
- properties.put(name, value);
- }
-
- public Object createDynamicElement(String string) throws BuildException {
- throw new BuildException("No sub elements of " + string + " is allowed");
- }
-
-// public void setPropertiesOn(BeanPropertyComponentAdapterFactory.Adapter adapter) throws BeanPropertyComponentAdapterFactory.NoSuchPropertyException {
-// for (Iterator i = properties.keySet().iterator(); i.hasNext();) {
-// String name = (String) i.next();
-// String value = (String) properties.get(name);
-// adapter.setPropertyValue(name, value);
-// }
-// }
-
- public ConstantParam createConstant() {
- ConstantParam constant = new ConstantParam();
- parameters.add(constant);
- return constant;
- }
-
- public Parameter[] getParameters() {
- if (parameters.size() == 0) {
- return null;
- }
-
- Parameter[] result = new Parameter[parameters.size()];
- for (ListIterator iterator = parameters.listIterator(); iterator.hasNext();) {
- AbstractParam constant = (AbstractParam) iterator.next();
- result[iterator.previousIndex()] = constant.createParameter();
- }
-
- return result;
- }
-
- public ComponentParam createComponent() {
- ComponentParam param = new ComponentParam();
- parameters.add(param);
- return param;
- }
-
- public Map getProperties() {
- return properties;
- }
-
- public static abstract class AbstractParam {
- protected Class type = String.class;
-
- public abstract Parameter createParameter();
-
- public void setType(Class type) {
- this.type = type;
- }
- }
-
- public static class ComponentParam extends AbstractParam {
- public Parameter createParameter() {
- return new ComponentParameter(type);
- }
- }
-
- public static class ConstantParam extends AbstractParam {
- private String value;
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public Parameter createParameter() {
- return new ConstantParameter(new StringToObjectConverter().convertTo(type, value));
- }
- }
-}

----------

nano /ant /src /java /org /nanocontainer /ant

PicoContainerTask.java removed after 1.3

diff -N PicoContainerTask.java
--- PicoContainerTask.java 20 Sep 2003 12:34:52 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,105 +0,0 @@

-package org.nanocontainer.ant;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import org.picocontainer.extras.InvokingComponentAdapterFactory;
-import org.picocontainer.extras.BeanPropertyComponentAdapterFactory;
-import org.picocontainer.defaults.*;
-import org.picocontainer.Parameter;
-import org.picocontainer.MutablePicoContainer;
-
-import java.util.*;
-
-/**
- * An Ant task that makes the use of PicoContainer possible from Ant.
- * When the task is executed, it will invoke <code>execute()</code>
- * on all components that have a public no-arg, non-static execute method.
- * The components's execute() method (if it exists) will be invoked
- * in the order of instantiation.
- *
- * &lt;taskdef name="pico" classname="org.nanocontainer.ant.PicoContainerTask"/&gt;
- *
- * &lt;pico&gt;
- * &lt;component classname="foo.Bar" someprop="somevalue"/&gt;
- * &lt;component classname="ping.Pong"/&gt;
- * &lt;/pico&gt;
- *
- * Also note that bean/ant style properties can be set too. The above
- * usage will call <code>setSomeprop("somevalue")</code> on the
- * <code>foo.Bar</code> instance.
- *
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.3 $
- */
-public class PicoContainerTask extends Task {
- private final List components = new ArrayList();
-
- private final BeanPropertyComponentAdapterFactory propertyFactory;
- private final MutablePicoContainer pico;
-
- public PicoContainerTask() {
- DefaultComponentAdapterFactory defaultFactory = new DefaultComponentAdapterFactory();
- propertyFactory = new BeanPropertyComponentAdapterFactory(defaultFactory);
- InvokingComponentAdapterFactory invokingFactory = new InvokingComponentAdapterFactory(
- propertyFactory,
- "execute",
- null,
- null
- );
- pico = new DefaultPicoContainer(invokingFactory);
- }
-
- public void addComponent(Component component) {
- components.add(component);
- }
-
- public void execute() {
- registerComponentsSpecifiedInAnt();
- try {
- getPicoContainer().getComponentInstances();
- } catch (PicoInvocationTargetInitializationException e) {
- throw new BuildException(e.getCause());
- } catch (Exception e) {
- throw new BuildException(e);
- }
- }
-
- private void registerComponentsSpecifiedInAnt() {
-
- for (Iterator iterator = components.iterator(); iterator.hasNext();) {
- Component component = (Component) iterator.next();
-
- // set the properties on the adapter factory
- // they will be set upon instantiation
- Object key = component.getKey();
- Map properties = component.getProperties();
- propertyFactory.setProperties(key, properties);
-
- Parameter[] parameters = component.getParameters();
-
- try {
- Class aClass = getClassLoader().loadClass(component.getClassname());
- MutablePicoContainer picoContainer = (MutablePicoContainer) getPicoContainer();
- if (parameters != null) {
- picoContainer.registerComponentImplementation(component.getKey(), aClass, parameters);
- } else {
- picoContainer.registerComponentImplementation(component.getKey(), aClass);
- }
- } catch (Exception e) {
- throw new BuildException(e);
- }
- }
- }
-
- private ClassLoader getClassLoader() {
- ClassLoader classLoader = getClass().getClassLoader();
- if (classLoader == null) {
- classLoader = getClass().getClassLoader();
- }
- return classLoader;
- }
-
- public MutablePicoContainer getPicoContainer() {
- return pico;
- }
-}

----------

nano /ant /src /test /org /nanocontainer /ant

OneConstructorArrayList.java removed after 1.1

diff -N OneConstructorArrayList.java
--- OneConstructorArrayList.java 10 Sep 2003 15:22:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,11 +0,0 @@

-package org.nanocontainer.ant;
-
-import java.util.ArrayList;
-
-/**
- *
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.1 $
- */
-public class OneConstructorArrayList extends ArrayList {
-}

----------

nano /ant /src /test /org /nanocontainer /ant

Pang.java removed after 1.1

diff -N Pang.java
--- Pang.java 10 Sep 2003 15:22:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,9 +0,0 @@

-package org.nanocontainer.ant;
-
-/**
- *
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.1 $
- */
-public class Pang {
-}

----------

nano /ant /src /test /org /nanocontainer /ant

Ping.java removed after 1.1

diff -N Ping.java
--- Ping.java 10 Sep 2003 15:22:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,24 +0,0 @@

-package org.nanocontainer.ant;
-
-import junit.framework.Assert;
-
-/**
- *
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.1 $
- */
-public class Ping {
- private String prop;
- boolean wasExecuted = false;
-
- public void setSomeprop(String prop) {
- this.prop = prop;
- }
-
- public void execute() {
- Assert.assertEquals("The property should be set", "HELLO", prop);
- wasExecuted = true;
- // This is only so we can see the output when run from Ant
- System.out.println("Ping executing :-)");
- }
-}

----------

nano /ant /src /test /org /nanocontainer /ant

Pong.java removed after 1.1

diff -N Pong.java
--- Pong.java 10 Sep 2003 15:22:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,9 +0,0 @@

-package org.nanocontainer.ant;
-
-/**
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.1 $
- */
-public class Pong {
- public Pong(Ping foo) {}
-}

----------

nano /ant /src /test /org /nanocontainer /ant

Pung.java removed after 1.1

diff -N Pung.java
--- Pung.java 10 Sep 2003 15:22:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,15 +0,0 @@

-package org.nanocontainer.ant;
-
-/**
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.1 $
- */
-public class Pung {
- public String text;
- public Pang pang;
-
- public Pung(Pang pang, String text){
- this.pang = pang;
- this.text = text;
- }
-}

----------

nano /ant /src /test /org /nanocontainer /ant

SimplePicoContainerTaskTestCase.java removed after 1.1

diff -N SimplePicoContainerTaskTestCase.java
--- SimplePicoContainerTaskTestCase.java 10 Sep 2003 15:22:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,72 +0,0 @@

-package org.nanocontainer.ant;
-
-import org.picocontainer.PicoContainer;
-import org.picocontainer.PicoException;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.defaults.DefaultPicoContainer;
-import org.picocontainer.extras.InvokingComponentAdapterFactory;
-
-/**
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.1 $
- */
-public class SimplePicoContainerTaskTestCase extends AbstractPicoContainerTaskTestCase {
-
- public void testPicoContainerTaskWithPropertyButWithoutParameters() throws PicoException {
- Component pongComp = new Component();
- pongComp.setClassname(Pong.class.getName());
- task.addComponent(pongComp);
-
- Component pingComp = new Component();
- pingComp.setClassname(Ping.class.getName());
- pingComp.setDynamicAttribute("someprop", "HELLO");
- task.addComponent(pingComp);
-
- task.execute();
-
- PicoContainer pico = task.getPicoContainer();
-
- Ping ping = (Ping) pico.getComponentInstance(Ping.class);
- assertNotNull(ping);
- assertTrue(ping.wasExecuted);
- }
-
- public void testPicoContainerTaskWithParameters() throws PicoException {
- Component pangComp = new Component();
- pangComp.setClassname(Pang.class.getName());
- task.addComponent(pangComp);
-
- Component pungComp = new Component();
- pungComp.setClassname(Pung.class.getName());
-
- // one component param
- Component.ComponentParam componentParam = pungComp.createComponent();
- componentParam.setType(Pang.class);
-
- // and one constant param
- Component.ConstantParam constantParam = pungComp.createConstant();
- constantParam.setValue("bajs");
-
- task.addComponent(pungComp);
- task.execute();
-
- // Now see if the task did the job properly
- PicoContainer pico = task.getPicoContainer();
-
- Pung pung = (Pung) pico.getComponentInstance(Pung.class);
- assertNotNull(pung);
- assertEquals("bajs", pung.text);
-
- Pang pang = (Pang) pico.getComponentInstance(Pang.class);
- assertNotNull(pang);
- assertSame(pung.pang, pang);
- }
-
- protected PicoContainerTask createPicoContainerTask() {
- return new PicoContainerTask() {
- protected MutablePicoContainer createPicoContainer(InvokingComponentAdapterFactory invokingFactory) {
- return new DefaultPicoContainer(invokingFactory);
- }
- };
- }
-}

----------

nano /bsh /src /java /org /nanocontainer /bsh

BeanShellComponentAdapter.java removed after 1.4

diff -N BeanShellComponentAdapter.java
--- BeanShellComponentAdapter.java 16 Nov 2003 19:53:30 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,113 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Leo Simons *
- *****************************************************************************/
-package org.nanocontainer.bsh;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.InputStreamReader;
-import java.net.URL;
-
-import org.picocontainer.Parameter;
-import org.picocontainer.ComponentAdapter;
-import org.picocontainer.PicoContainer;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.PicoInitializationException;
-import org.picocontainer.PicoIntrospectionException;
-import org.picocontainer.PicoContainer;
-import org.picocontainer.defaults.NoSatisfiableConstructorsException;
-
-import bsh.Interpreter;
-import bsh.EvalError;
-
-/**
- * This adapter relies on <a href="http://beanshell.org/">Bsh</a> for instantiation
- * (and possibly also initialisation) of component instances.
- * <p>
- * When {@link #getComponentInstance} is called (by PicoContainer),
- * the adapter instance will look for a script with the same name as the component implementation
- * class (but with the .bsh extension). This script must reside in the same folder as the class.
- * (It's ok to have them both in a jar).
- * <p>
- * The bsh script's only contract is that it will have to instantiate a bsh variable called
- * "instance".
- * <p>
- * The script will have access to the following variables:
- * <ul>
- * <li>adapter - the adapter calling the script</li>
- * <li>picoContainer - the MutablePicoContainer calling the adapter</li>
- * <li>componentKey - the component key</li>
- * <li>componentImplementation - the component implementation</li>
- * <li>parameters - the ComponentParameters (as a List)</li>
- * </ul>
- *
- * @author <a href="mail at leosimons dot com">Leo Simons</a>
- * @author Aslak Hellesoy
- * @version $Id: BeanShellComponentAdapter.java,v 1.4 2003/11/16 19:53:30 rinkrank Exp $
- */
-public class BeanShellComponentAdapter implements ComponentAdapter {
- private final Object componentKey;
- private final Class componentImplementation;
- private final Parameter[] parameters;
-
- private Object instance = null;
-
- public BeanShellComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters) {
- this.componentKey = componentKey;
- this.componentImplementation = componentImplementation;
- this.parameters = parameters;
- }
-
- public Object getComponentKey() {
- return componentKey;
- }
-
- public Class getComponentImplementation() {
- return componentImplementation;
- }
-
- public Object getComponentInstance(MutablePicoContainer picoContainer)
- throws PicoInitializationException, PicoIntrospectionException {
-
- if (instance == null) {
- try {
- Interpreter i = new Interpreter();
- i.set("adapter", this);
- i.set("picoContainer", picoContainer);
- i.set("componentKey", componentKey);
- i.set("componentImplementation", componentImplementation);
- i.set("parameters", parameters != null ? Arrays.asList(parameters) : Collections.EMPTY_LIST);
- i.eval("import " + componentImplementation.getName() + ";");
-
- String scriptPath = "/" + componentImplementation.getName().replace('.', '/') + ".bsh";
- URL scriptURL = componentImplementation.getResource(scriptPath);
- if(scriptURL == null) {
- throw new BeanShellScriptInitializationException("Couldn't load script at path " + scriptPath);
- }
- Reader sourceReader = new InputStreamReader(scriptURL.openStream());
- i.eval(sourceReader, i.getNameSpace(), scriptURL.toExternalForm());
-
- instance = i.get("instance");
- if(i == null) {
- throw new BeanShellScriptInitializationException("The 'instance' variable was not instantiated");
- }
- } catch (EvalError e) {
- throw new BeanShellScriptInitializationException(e);
- } catch (IOException e) {
- throw new BeanShellScriptInitializationException(e);
- }
- }
- return instance;
- }
-
- public void verify(PicoContainer picoContainer) throws NoSatisfiableConstructorsException {
- }
-}

----------

nano /bsh /src /java /org /nanocontainer /bsh

BeanShellComponentAdapterFactory.java removed after 1.1

diff -N BeanShellComponentAdapterFactory.java
--- BeanShellComponentAdapterFactory.java 18 Sep 2003 18:28:24 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,34 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Leo Simons *
- *****************************************************************************/
-package org.nanocontainer.bsh;
-
-import org.picocontainer.defaults.ComponentAdapterFactory;
-import org.picocontainer.defaults.AssignabilityRegistrationException;
-import org.picocontainer.defaults.NotConcreteRegistrationException;
-import org.picocontainer.ComponentAdapter;
-import org.picocontainer.Parameter;
-import org.picocontainer.PicoIntrospectionException;
-
-/**
- * This factory creates component adapters that relies on Bsh.
- *
- * @see BeanShellComponentAdapter
- * @author <a href="mail at leosimons dot com">Leo Simons</a>
- * @version $Id: BeanShellComponentAdapterFactory.java,v 1.1 2003/09/18 18:28:24 rinkrank Exp $
- */
-public class BeanShellComponentAdapterFactory
- implements ComponentAdapterFactory {
- public ComponentAdapter createComponentAdapter(Object componentKey,
- Class componentImplementation,
- Parameter[] parameters) throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
- return new BeanShellComponentAdapter(componentKey, componentImplementation, parameters);
- }
-
-}

----------

nano /bsh /src /java /org /nanocontainer /bsh

BeanShellScriptInitializationException.java removed after 1.1

diff -N BeanShellScriptInitializationException.java
--- BeanShellScriptInitializationException.java 18 Sep 2003 18:28:24 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,31 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Leo Simons *
- *****************************************************************************/
-package org.nanocontainer.bsh;
-
-import org.picocontainer.PicoInitializationException;
-
-/**
- *
- *
- * @author <a href="mail at leosimons dot com">Leo Simons</a>
- * @version $Id: BeanShellScriptInitializationException.java,v 1.1 2003/09/18 18:28:24 rinkrank Exp $
- */
-public class BeanShellScriptInitializationException
- extends PicoInitializationException {
-
- BeanShellScriptInitializationException(String message) {
- super(message);
- }
-
- BeanShellScriptInitializationException(Throwable cause) {
- this("BeanShellScriptInitializationException: " + cause.getClass().getName() + " "
- + cause.getMessage());
- }
-}

----------

nano /bsh /src /test /org /nanocontainer /bsh

BeanShellComponentAdapterFactoryTestCase.java removed after 1.2

diff -N BeanShellComponentAdapterFactoryTestCase.java
--- BeanShellComponentAdapterFactoryTestCase.java 18 Sep 2003 18:34:16 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,42 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Leo Simons *
- *****************************************************************************/
-package org.nanocontainer.bsh;
-
-import junit.framework.TestCase;
-
-import org.picocontainer.ComponentAdapter;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.defaults.DefaultPicoContainer;
-
-import java.util.ArrayList;
-
-/**
- * <a href="http://www.junit.org/">JUnit</a>
- * {@link junit.framework.TestCase testcase} for
- * BeanShellComponentAdapter.
- *
- * @author <a href="mail at leosimons dot com">Leo Simons</a>
- * @version $Id: BeanShellComponentAdapterFactoryTestCase.java,v 1.2 2003/09/18 18:34:16 rinkrank Exp $
- */
-public class BeanShellComponentAdapterFactoryTestCase extends TestCase {
- public void testGetComponentInstance() {
- MutablePicoContainer pico = new DefaultPicoContainer();
- pico.registerComponentImplementation("whatever", ArrayList.class);
-
- ComponentAdapter adapter = new BeanShellComponentAdapterFactory().createComponentAdapter(
- "thekey", ScriptableDemoBean.class, null);
-
- ScriptableDemoBean bean = (ScriptableDemoBean) adapter.getComponentInstance(pico);
-
- assertEquals("Bsh demo script should have set the key", "thekey", bean.key);
-
- assertTrue(bean.whatever instanceof ArrayList);
- }
-}

----------

nano /bsh /src /test /org /nanocontainer /bsh

ScriptableDemoBean.bsh removed after 1.1

diff -N ScriptableDemoBean.bsh
--- ScriptableDemoBean.bsh 18 Sep 2003 18:28:25 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,3 +0,0 @@

-instance = new ScriptableDemoBean();
-instance.rememberMyKey(componentKey);
-instance.setWhatever(picoContainer.getComponentInstance("whatever"));

\ No newline at end of file

----------

nano /bsh /src /test /org /nanocontainer /bsh

ScriptableDemoBean.java removed after 1.2

diff -N ScriptableDemoBean.java
--- ScriptableDemoBean.java 18 Sep 2003 18:34:16 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,30 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Leo Simons *
- *****************************************************************************/
-package org.nanocontainer.bsh;
-
-/**
- *
- *
- * @author <a href="mail at leosimons dot com">Leo Simons</a>
- * @author Aslak Hellesoy
- * @version $Id: ScriptableDemoBean.java,v 1.2 2003/09/18 18:34:16 rinkrank Exp $
- */
-public class ScriptableDemoBean {
- public Object key;
- public Object whatever;
-
- public void rememberMyKey(Object key) {
- this.key = key;
- }
-
- public void setWhatever(Object whatever) {
- this.whatever = whatever;
- }
-}

----------

nano /groovypico /src /java /org /picocontainer /groovy

PicoBuilder.java removed after 1.3

diff -N PicoBuilder.java
--- PicoBuilder.java 16 Nov 2003 19:53:30 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,133 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 James Strachan *
- *****************************************************************************/
-
-package org.picocontainer.groovy;
-
-import groovy.util.BuilderSupport;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.codehaus.groovy.runtime.InvokerHelper;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.defaults.ComponentAdapterFactory;
-import org.picocontainer.defaults.DefaultPicoContainer;
-
-/**
- * Builds trees of Pico containers and Pico components using GroovyMarkup
- *
- * @author <a href="mailto:[email protected]">James Strachan</a>
- * @version $Revision: 1.3 $
- */
-public class PicoBuilder extends BuilderSupport {
-
- public PicoBuilder() {
- }
-
- protected void setParent(Object parent, Object child) {
- if (parent instanceof MutablePicoContainer) {
- MutablePicoContainer parentContainer = (MutablePicoContainer) parent;
- if (child instanceof MutablePicoContainer) {
- MutablePicoContainer childContainer = (MutablePicoContainer) child;
- parentContainer.addChild(childContainer);
- }
- }
- }
-
- protected void nodeCompleted(Object parent, Object node) {
- }
-
- protected Object createNode(Object name) {
- return createNode(name, Collections.EMPTY_MAP);
- }
-
- protected Object createNode(Object name, Object value) {
- if (value instanceof Class) {
- Map attributes = new HashMap();
- attributes.put("componentClass", value);
- return createNode(name, attributes);
- }
- return createNode(name);
- }
-
- protected Object createNode(Object name, Map attributes) {
- if (name.equals("container")) {
- return createContainer(attributes);
- }
- else {
- Object parent = getCurrent();
- if (parent instanceof MutablePicoContainer) {
- MutablePicoContainer pico = (MutablePicoContainer) parent;
-
- //System.out.println("Creating node: " + name + " with " + attributes);
-
- if (name.equals("component")) {
- Class type = (Class) attributes.remove("componentClass");
- if (type != null) {
- Object key = attributes.remove("key");
- if (key != null) {
- pico.registerComponentImplementation(key, type);
- }
- else {
- pico.registerComponentImplementation(type);
- }
- return name;
- }
- else {
- throw new PicoBuilderException("Must specify a componentClass attribute for a component");
- }
- }
- else if (name.equals("bean")) {
- // lets create a bean
- Object answer = createBean(attributes);
- pico.registerComponentInstance(answer);
- return answer;
- }
- }
- else {
- throw new PicoBuilderException("method: " + name + " must be a child of a container element");
- }
- }
- throw new PicoBuilderException("uknown method: " + name);
- }
-
- protected Object createContainer(Map attributes) {
- ComponentAdapterFactory adapterFactory = (ComponentAdapterFactory) attributes.remove("adapterFactory");
- if (adapterFactory != null) {
- return new DefaultPicoContainer(adapterFactory);
- }
- else {
- return new DefaultPicoContainer();
- }
- }
-
- protected Object createBean(Map attributes) {
- Class type = (Class) attributes.remove("beanClass");
- if (type == null) {
- throw new PicoBuilderException("bean must have a beanClass attribute");
- }
- try {
- Object bean = type.newInstance();
- // now lets set the properties on the bean
- for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
- Map.Entry entry = (Map.Entry) iter.next();
- String name = entry.getKey().toString();
- Object value = entry.getValue();
- InvokerHelper.setProperty(bean, name, value);
- }
- return bean;
- }
- catch (Exception e) {
- throw new PicoBuilderException("Failed to create bean of type: " + type + ". Reason: " + e, e);
- }
- }
-}

----------

nano /groovypico /src /java /org /picocontainer /groovy

PicoBuilderException.java removed after 1.1

diff -N PicoBuilderException.java
--- PicoBuilderException.java 27 Oct 2003 19:39:13 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,29 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 James Strachan *
- *****************************************************************************/
-
-package org.picocontainer.groovy;
-
-/**
- * Exception thrown due to invalid GroovyMarkup when creating pico containers
- * and components
- *
- * @author <a href="mailto:[email protected]">James Strachan</a>
- * @version $Revision: 1.1 $
- */
-public class PicoBuilderException extends RuntimeException {
-
- public PicoBuilderException(String message) {
- super(message);
- }
-
- public PicoBuilderException(String message, Exception e) {
- super(message, e);
- }
-}

----------

nano /groovypico /src /test /org /picocontainer /groovy

ExampleTest.groovy removed after 1.2

diff -N ExampleTest.groovy
--- ExampleTest.groovy 28 Oct 2003 10:04:20 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,117 +0,0 @@

-package org.picocontainer.groovy
-
-import org.picocontainer.defaults.NoSatisfiableConstructorsException
-import org.picocontainer.extras.ImplementationHidingComponentAdapterFactory
-import org.picocontainer.extras.DefaultLifecyclePicoAdapter
-
-import org.nanocontainer.testmodel.DefaultWebServerConfig
-import org.nanocontainer.testmodel.WebServer
-import org.nanocontainer.testmodel.WebServerConfig
-import org.nanocontainer.testmodel.WebServerConfigBean
-import org.nanocontainer.testmodel.WebServerImpl
-
-class ExampleTest extends GroovyTestCase {
-
- void testInstantiateBasicCopmonent() {
- builder = new PicoBuilder()
- nano = builder.container {
- component(Xxx$A)
- }
-
- startAndStop(nano)
-
- assertEquals("Should match the expression", "<A!A", Xxx.componentRecorder)
- }
-
- void testInstantiateWithChildContainer() {
-
- // A and C have no no dependancies. B Depends on A.
-
- builder = new PicoBuilder()
- nano = builder.container {
- component(Xxx$A)
- container() {
- component(Xxx$B)
- }
- component(Xxx$C)
- }
-
- startAndStop(nano)
-
- assertEquals("Should match the expression", "<A!A<A<C!C!A", Xxx.componentRecorder)
- //assertEquals("Should match the expression", "<A<C<BB>C>A>!B!C!A", Xxx.componentRecorder)
- //assertEquals("Should match the expression", "*A*B+A_started+B_started+B_stopped+A_stopped+B_disposed+A_disposed", MockMonitor.monitorRecorder)
-
- }
-
- void testInstantiateWithImpossibleComponentDependanciesConsideringTheHierarchy() {
-
- // A and C have no no dependancies. B Depends on A.
-
- try {
- builder = new PicoBuilder()
- nano = builder.container {
- component(Xxx$B)
- container() {
- component(Xxx$A)
- }
- component(Xxx$C)
- }
-
- startAndStop(nano)
-
- fail("Should not have been able to instansiate component tree due to visibility/parent reasons.")
- }
- catch (NoSatisfiableConstructorsException e) {
- }
- }
-
- void testInstantiateWithBespokeComponentAdaptor() {
-
- builder = new PicoBuilder()
- nano = builder.container(adapterFactory:new ImplementationHidingComponentAdapterFactory()) {
- component(key:WebServerConfig, componentClass:DefaultWebServerConfig)
- component(key:WebServer, componentClass:WebServerImpl)
- }
-
- startAndStop(nano)
-
-/** @todo instanceof not yet supported
- Object ws = nano.getRootContainer().getComponentInstance(WebServer)
-
- assertTrue(ws instanceof WebServer)
- assertFalse(ws instanceof WebServerImpl)
-
- ws = nano.getRootContainer().getComponentInstances().get(1)
-
- assertTrue(ws instanceof WebServer)
-
- //TODO - should be assertFalse( ), we're implementation hiding here !
- assertTrue(ws instanceof WebServerImpl)
-*/
- }
-
- void testInstantiateWithInlineConfiguration() {
-
- builder = new PicoBuilder()
- nano = builder.container {
- bean(beanClass:WebServerConfigBean, host:'foobar.com', port:4321)
- component(key:WebServer, componentClass:WebServerImpl)
- }
-
- startAndStop(nano)
-
-
- assertEquals("WebServerConfigBean and WebServerImpl expected", 2, nano.getComponentInstances().size())
-
- wsc = nano.getComponentInstance(WebServerConfig)
- assertEquals("foobar.com", wsc.getHost())
- assertEquals(4321, wsc.getPort())
- }
-
- protected void startAndStop(pico) {
- adapter = new DefaultLifecyclePicoAdapter(pico)
- adapter.start()
- adapter.dispose()
- }
-}

\ No newline at end of file

----------

nano /groovypico /src /test /org /picocontainer /groovy

Xxx.java removed after 1.1

diff -N Xxx.java
--- Xxx.java 27 Oct 2003 19:39:13 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,45 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.picocontainer.groovy;
-
-import org.picocontainer.lifecycle.Lifecycle;
-import junit.framework.Assert;
-
-/**
- * An abstract component and three dependancies used for testing.
- */
-public abstract class Xxx implements Lifecycle {
-
- public static String componentRecorder = "";
-
- public void start() {
- componentRecorder += "<" + code();
- }
-
- public void stop() {
- componentRecorder += code() + ">";
- }
-
- public void dispose() {
- componentRecorder += "!" + code();
- }
-
- private String code() {
- String name = getClass().getName();
- return name.substring(name.indexOf('$')+1,name.length());
- }
-
- public static class A extends Xxx {}
- public static class B extends Xxx {
- public B(A a) {
- Assert.assertNotNull(a);
- }
- }
- public static class C extends Xxx {}
-}

----------

nano /nanning /src /java /org /nanocontainer /nanning

NanningComponentAdapter.java removed after 1.1

diff -N NanningComponentAdapter.java
--- NanningComponentAdapter.java 10 Sep 2003 15:22:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,55 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Jon Tirsen *
- *****************************************************************************/
-
-package org.nanocontainer.nanning;
-
-import org.codehaus.nanning.AspectInstance;
-import org.codehaus.nanning.Mixin;
-import org.codehaus.nanning.config.AspectSystem;
-import org.picocontainer.extras.DecoratingComponentAdapter;
-import org.picocontainer.ComponentAdapter;
-import org.picocontainer.defaults.AssignabilityRegistrationException;
-import org.picocontainer.defaults.NotConcreteRegistrationException;
-import org.picocontainer.PicoInitializationException;
-import org.picocontainer.PicoIntrospectionException;
-import org.picocontainer.MutablePicoContainer;
-
-/**
- * @author Jon Tirsen (tirsen-yCVjj/[email protected])
- * @author Aslak Hellesoy
- * @version $Revision: 1.1 $
- */
-public class NanningComponentAdapter extends DecoratingComponentAdapter {
-
- private final AspectSystem aspectSystem;
-
- public NanningComponentAdapter(AspectSystem aspectSystem, ComponentAdapter decoratedComponentAdapter) {
- super(decoratedComponentAdapter);
- this.aspectSystem = aspectSystem;
- }
-
- public Object getComponentInstance(MutablePicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
- Object component = super.getComponentInstance(picoContainer);
- // TODO Nanning will at the moment only aspectify stuff when it has one and only one interface
- if (component.getClass().getInterfaces().length == 1) {
- Class intf = component.getClass().getInterfaces()[0];
- // the trick: set up first mixin manually with the component as target
- AspectInstance aspectInstance = new AspectInstance(intf);
- Mixin mixin = new Mixin(intf, component);
- aspectInstance.addMixin(mixin);
-
- // let the aspects do its work
- aspectSystem.initialize(aspectInstance);
- component = aspectInstance.getProxy();
- }
-
- return component;
- }
-}

----------

nano /nanning /src /java /org /nanocontainer /nanning

NanningComponentAdapterFactory.java removed after 1.2

diff -N NanningComponentAdapterFactory.java
--- NanningComponentAdapterFactory.java 10 Sep 2003 16:32:31 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,120 +0,0 @@

-package org.nanocontainer.nanning;
-
-import org.codehaus.nanning.config.AspectSystem;
-import org.codehaus.nanning.config.Aspect;
-import org.codehaus.nanning.AspectInstance;
-import org.codehaus.nanning.Mixin;
-import org.picocontainer.extras.DecoratingComponentAdapterFactory;
-import org.picocontainer.extras.DecoratingComponentAdapter;
-import org.picocontainer.defaults.*;
-import org.picocontainer.*;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Collections;
-import java.util.ArrayList;
-
-/**
- * @author Jon Tirsen
- * @version $Revision: 1.2 $
- */
-public class NanningComponentAdapterFactory extends DecoratingComponentAdapterFactory implements Serializable {
- private AspectSystem aspectSystem;
-
- public NanningComponentAdapterFactory(AspectSystem aspectSystem,
- ComponentAdapterFactory delegate) {
- super(delegate);
- this.aspectSystem = aspectSystem;
- }
-
- public NanningComponentAdapterFactory() {
- this(new AspectSystem(), new DefaultComponentAdapterFactory());
- }
-
- public ComponentAdapter createComponentAdapter(Object componentKey,
- Class componentImplementation,
- Parameter[] parameters)
- throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
- ComponentAdapter componentAdapter = super.createComponentAdapter(componentKey, componentImplementation, parameters);
-
- if (Aspect.class.isAssignableFrom(componentImplementation)) {
- componentAdapter = new AspectAdapter(componentAdapter, aspectSystem);
-
- } else if (canBeWeaved(componentImplementation)) {
- Class componentInterface = getComponentInterface(componentImplementation);
- componentAdapter = new WeavingAdapter(componentAdapter, aspectSystem, componentInterface);
- }
-
- return componentAdapter;
- }
-
- private Class getComponentInterface(Class componentImplementation) {
- return (Class) getAllInterfaces(componentImplementation).get(0);
- }
-
- List getAllInterfaces(Class componentImplementation) {
- if (componentImplementation == null) {
- return Collections.EMPTY_LIST;
- }
- List result = new ArrayList(Arrays.asList(componentImplementation.getInterfaces()));
- result.addAll(getAllInterfaces(componentImplementation.getSuperclass()));
- return result;
- }
-
- private boolean canBeWeaved(Class componentImplementation) {
- return getAllInterfaces(componentImplementation).size() == 1;
- }
-
- public static class WeavingAdapter extends DecoratingComponentAdapter {
-
- private final AspectSystem aspectSystem;
- private Class componentInterface;
-
- public WeavingAdapter(ComponentAdapter delegate, AspectSystem aspectSystem, Class componentInterface) {
- super(delegate);
- this.aspectSystem = aspectSystem;
- this.componentInterface = componentInterface;
- }
-
- public Object getComponentInstance(MutablePicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
- Object component = super.getComponentInstance(picoContainer);
- // TODO Nanning will at the moment only aspectify stuff when it has one and only one interface
-
- // the trick: set up first mixin manually with the component as target
- AspectInstance aspectInstance = new AspectInstance(componentInterface);
- Mixin mixin = new Mixin(componentInterface, component);
- aspectInstance.addMixin(mixin);
-
- // let the aspects do its work
- getAspectSystem().initialize(aspectInstance);
- component = aspectInstance.getProxy();
-
- return component;
- }
-
- private AspectSystem getAspectSystem() {
- return aspectSystem;
- }
- }
-
- public static class AspectAdapter extends DecoratingComponentAdapter {
- private AspectSystem aspectSystem;
-
- public AspectAdapter(ComponentAdapter delegate, AspectSystem aspectSystem) {
- super(delegate);
- this.aspectSystem = aspectSystem;
- }
-
- public Object getComponentInstance(MutablePicoContainer picoContainer)
- throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
- Aspect aspect = (Aspect) super.getComponentInstance(picoContainer);
- getAspectSystem().addAspect(aspect);
- return aspect;
- }
-
- private AspectSystem getAspectSystem() {
- return aspectSystem;
- }
- }
-}

----------

nano /nanning /src /java /org /nanocontainer /nanning

NanningNanoContainer.java removed after 1.5

diff -N NanningNanoContainer.java
--- NanningNanoContainer.java 17 Sep 2003 23:57:27 -0000 1.5
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,41 +0,0 @@

-/*****************************************************************************
- * 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 Jon Tirsen *
- *****************************************************************************/
-
-package org.nanocontainer.nanning;
-
-import org.codehaus.nanning.config.AspectSystem;
-import org.picocontainer.defaults.DefaultComponentAdapterFactory;
-import org.picocontainer.defaults.ComponentAdapterFactory;
-import org.picocontainer.defaults.DefaultPicoContainer;
-
-/**
- * @author Jon Tirsen (tirsen-yCVjj/[email protected])
- * @author Aslak Hellesoy
- * @version $Revision: 1.5 $
- * @deprecated Use a {@link DefaultPicoContainer} with a {@link NanningComponentAdapterFactory}
- * instead. This favours chaining of component adapters.
- */
-public class NanningNanoContainer extends DefaultPicoContainer {
- public NanningNanoContainer(AspectSystem aspectSystem, ComponentAdapterFactory componentAdapterFactory) {
- super(new NanningComponentAdapterFactory(aspectSystem, componentAdapterFactory));
- }
-
- public NanningNanoContainer(AspectSystem aspectSystem) {
- this(aspectSystem, new DefaultComponentAdapterFactory());
- }
-
- public NanningNanoContainer(ComponentAdapterFactory componentAdapterFactory) {
- this(new AspectSystem(), componentAdapterFactory);
- }
-
- public NanningNanoContainer() {
- this(new AspectSystem(), new DefaultComponentAdapterFactory());
- }
-}

----------

nano /nanning /src /java /org /nanocontainer /nanning

package.html removed after 1.1

diff -N package.html
--- package.html 10 Sep 2003 15:22:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,8 +0,0 @@

-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
-</head>
-<body>
-Foo
-</body>
-</html>

----------

nano /nanning /src /test /org /nanocontainer /nanning

NanningComponentFactoryTestCase.java removed after 1.3

diff -N NanningComponentFactoryTestCase.java
--- NanningComponentFactoryTestCase.java 17 Sep 2003 23:57:27 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,100 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Jon Tirs?n *
- *****************************************************************************/
-
-package org.nanocontainer.nanning;
-
-import junit.framework.TestCase;
-import org.codehaus.nanning.Aspects;
-import org.codehaus.nanning.Invocation;
-import org.codehaus.nanning.MethodInterceptor;
-import org.codehaus.nanning.config.AspectSystem;
-import org.codehaus.nanning.config.InterceptorAspect;
-import org.picocontainer.*;
-import org.picocontainer.defaults.*;
-
-/**
- * @author Jon Tirsen
- * @version $Revision: 1.3 $
- */
-public class NanningComponentFactoryTestCase extends TestCase {
-
- public interface Wilma {
- void hello();
- }
-
- public static class WilmaImpl implements Wilma {
- public void hello() {
- }
- }
-
- public static class FredImpl {
- public FredImpl(Wilma wilma) {
- assertNotNull("Wilma cannot be passed in as null", wilma);
- wilma.hello();
- }
- }
-
- private StringBuffer log = new StringBuffer();
-
- public void testComponentsWithOneInterfaceAreAspected() throws PicoInitializationException, AssignabilityRegistrationException, NotConcreteRegistrationException, PicoIntrospectionException {
- NanningComponentAdapter componentFactory =
- new NanningComponentAdapter(new AspectSystem(), new DefaultComponentAdapter(Wilma.class, WilmaImpl.class));
- Object component = componentFactory.getComponentInstance(new DefaultPicoContainer());
- assertTrue(Aspects.isAspectObject(component));
- assertEquals(Wilma.class, Aspects.getAspectInstance(component).getClassIdentifier());
- }
-
- public void testComponentsWithoutInterfaceNotAspected() throws PicoInitializationException, PicoRegistrationException {
- NanningComponentAdapter componentFactory = new NanningComponentAdapter(new AspectSystem(),
- new DefaultComponentAdapter(FredImpl.class, FredImpl.class));
- DefaultPicoContainer registry = new DefaultPicoContainer();
- registry.registerComponent(new InstanceComponentAdapter(Wilma.class, new WilmaImpl()));
- Object component = componentFactory.getComponentInstance(registry);
- assertFalse(Aspects.isAspectObject(component));
- }
-
-
- /**
- * Acceptance test (ie a teeny bit functional, but you'll get over it).
- */
- public void testSimpleLogOfMethodCall()
- throws PicoException, PicoInitializationException {
-
- AspectSystem aspectSystem = new AspectSystem();
- aspectSystem.addAspect(new InterceptorAspect(new MethodInterceptor() {
- public Object invoke(Invocation invocation) throws Throwable {
- log.append(invocation.getMethod().getName() + " ");
- return invocation.invokeNext();
- }
- }));
-
- MutablePicoContainer nanningEnabledPicoContainer = new DefaultPicoContainer(
- new NanningComponentAdapterFactory(aspectSystem, new DefaultComponentAdapterFactory()));
- nanningEnabledPicoContainer.registerComponentImplementation(Wilma.class, WilmaImpl.class);
- nanningEnabledPicoContainer.registerComponentImplementation(FredImpl.class);
-
- assertEquals("", log.toString());
-
- nanningEnabledPicoContainer.getComponentInstances();
-
- // fred says hello to wilma, even the interceptor knows
- assertEquals("hello ", log.toString());
-
- Wilma wilma = (Wilma) nanningEnabledPicoContainer.getComponentInstance(Wilma.class);
-
- assertNotNull(wilma);
-
- wilma.hello();
-
- // another entry in the log
- assertEquals("hello hello ", log.toString());
-
- }
-}

----------

nano /nanning /src /test /org /nanocontainer /nanning

NanningNanoContainerTestCase.java removed after 1.4

diff -N NanningNanoContainerTestCase.java
--- NanningNanoContainerTestCase.java 19 Sep 2003 22:59:46 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,178 +0,0 @@

-package org.nanocontainer.nanning;
-
-import junit.framework.TestCase;
-import org.codehaus.nanning.*;
-import org.codehaus.nanning.config.Aspect;
-import org.codehaus.nanning.config.P;
-import org.codehaus.nanning.config.Pointcut;
-import org.picocontainer.*;
-import org.picocontainer.defaults.AssignabilityRegistrationException;
-import org.picocontainer.defaults.NotConcreteRegistrationException;
-import org.picocontainer.defaults.DefaultPicoContainer;
-
-/**
- * Contains both unit-tests for the NanninNanoContainer and acceptance-tests outlining an example
- * of how to use it.
- * @author Jon Tirsen (tirsen-yCVjj/[email protected])
- * @version $Revision: 1.4 $
- */
-public class NanningNanoContainerTestCase extends TestCase {
-
- private MutablePicoContainer container;
-
- /**
- * RecordingAware2 very simplified interface to a TransactionManager.
- */
- public static interface TransactionManager {
- Transaction startTransaction();
- }
-
- public static interface Transaction {
- void commit();
-
- void rollback();
- }
-
- /**
- * RecordingAware2 very simplified "declarative" transaction-aspect.
- */
- public static class TransactionAspect implements Aspect {
- Pointcut transactionPointcut = P.all();
- TransactionManager transactionManager;
-
- public TransactionAspect(TransactionManager transactionManager) {
- this.transactionManager = transactionManager;
- }
-
- public void introduce(AspectInstance instance) {
- // nothing to introduce
- }
-
- public void advise(AspectInstance instance) {
- transactionPointcut.advise(instance, new MethodInterceptor() {
- public Object invoke(Invocation invocation) throws Throwable {
- Transaction transaction = transactionManager.startTransaction();
- try {
- Object o = invocation.invokeNext();
- transaction.commit();
- return o;
- } catch (Exception e) {
- transaction.rollback();
- throw e;
- }
- }
- });
- }
- }
-
- public static interface Component {
- void doSomethingRequiringATransaction() throws Exception;
- }
-
- public static class SucceedingComponent implements Component {
- public void doSomethingRequiringATransaction() {
- // success!!
- }
- }
-
- public static class FailingComponent implements Component {
- public void doSomethingRequiringATransaction() throws Exception {
- throw new Exception();
- }
- }
-
- public static class LoggingTransactionManager implements TransactionManager {
- public StringBuffer transactionLog = new StringBuffer();
-
- public Transaction startTransaction() {
- transactionLog.append("instantiateComponents ");
-
- return new Transaction() {
- public void commit() {
- transactionLog.append("commit ");
- }
-
- public void rollback() {
- transactionLog.append("rollback ");
- }
- };
- }
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- container = new DefaultPicoContainer(new NanningComponentAdapterFactory());
- }
-
- public void testServiceIsInstantiated() throws PicoRegistrationException, PicoInitializationException {
- container.registerComponentImplementation(TransactionManager.class, LoggingTransactionManager.class);
- container.getComponentInstances();
-
- assertTrue(container.hasComponent(TransactionManager.class));
- assertNotNull(container.getComponentInstance(TransactionManager.class));
- }
-
- public void testAspectDependingOnServiceIsInstantiated() throws PicoRegistrationException, PicoInitializationException {
- container.registerComponentImplementation(TransactionManager.class, LoggingTransactionManager.class);
- container.registerComponentImplementation(TransactionAspect.class);
- container.getComponentInstances();
-
- TransactionAspect transactionAspect = (TransactionAspect) container.getComponentInstance(TransactionAspect.class);
- assertNotNull(transactionAspect);
- assertNotNull(transactionAspect.transactionManager);
- }
-
- public void testAspectifiedComponentIsInstantiatedWithProperAspects()
- throws PicoRegistrationException, PicoInitializationException {
- container.registerComponentImplementation(TransactionManager.class, LoggingTransactionManager.class);
- container.registerComponentImplementation(TransactionAspect.class);
- container.registerComponentImplementation(Component.class, SucceedingComponent.class);
- container.getComponentInstances();
-
- Component component = (Component) container.getComponentInstance(Component.class);
- assertNotNull(component);
- assertTrue(Aspects.isAspectObject(component));
- assertEquals(1, Aspects.getAspectInstance(component).getAllInterceptors().size());
- }
-
- /**
- * The 'acceptance-test' for the example.
- */
- public void testTransactionAspectStartsAndCommitsTransaction() throws PicoRegistrationException, PicoInstantiationException, Exception {
- container.registerComponentImplementation(TransactionManager.class, LoggingTransactionManager.class);
- container.registerComponentImplementation(TransactionAspect.class, TransactionAspect.class);
- container.registerComponentImplementation(Component.class, SucceedingComponent.class);
- container.getComponentInstances();
-
- Component component = (Component) container.getComponentInstance(Component.class);
- assertNotNull(component);
- component.doSomethingRequiringATransaction();
-
- LoggingTransactionManager transactionManager = getTransactionManagerTarget();
- assertEquals("instantiateComponents commit ", transactionManager.transactionLog.toString());
- }
-
- public void testTransactionAspectStartsAndRollsBackTransaction() throws PicoRegistrationException, PicoInstantiationException, Exception {
- container.registerComponentImplementation(TransactionManager.class, LoggingTransactionManager.class);
- container.registerComponentImplementation(TransactionAspect.class);
- container.registerComponentImplementation(Component.class, FailingComponent.class);
- container.getComponentInstances();
-
- Component component = (Component) container.getComponentInstance(Component.class);
- try {
- component.doSomethingRequiringATransaction();
- fail();
- } catch (Exception shouldHappen) {
- }
-
- LoggingTransactionManager transactionManager = getTransactionManagerTarget();
- assertEquals("instantiateComponents rollback ", transactionManager.transactionLog.toString());
- }
-
- private LoggingTransactionManager getTransactionManagerTarget() throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
- AspectInstance aspectInstance = Aspects.getAspectInstance(container.getComponentInstance(TransactionManager.class));
- Mixin mixin = aspectInstance.getMixinForInterface(TransactionManager.class);
- return (LoggingTransactionManager) mixin.getTarget();
- }
-
-}

----------

nano /servlet /src /java /org /nanocontainer /servlet

ApplicationScopeObjectReference.java removed after 1.1

diff -N ApplicationScopeObjectReference.java
--- ApplicationScopeObjectReference.java 29 Oct 2003 17:22:30 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,39 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.servlet;
-
-import org.nanocontainer.integrationkit.ObjectReference;
-
-import javax.servlet.ServletContext;
-
-/**
- * References an object that lives as an attribute of the
- * ServletContext (application scope)
- *
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public class ApplicationScopeObjectReference implements ObjectReference {
-
- private ServletContext context;
- private String key;
-
- public ApplicationScopeObjectReference(ServletContext context, String key) {
- this.context = context;
- this.key = key;
- }
-
- public void set(Object item) {
- context.setAttribute(key, item);
- }
-
- public Object get() {
- return context.getAttribute(key);
- }
-
-}

----------

nano /servlet /src /java /org /nanocontainer /servlet

KeyConstants.java removed after 1.2

diff -N KeyConstants.java
--- KeyConstants.java 31 Oct 2003 17:38:15 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,20 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.servlet;
-
-/**
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public interface KeyConstants {
- String APPLICATION_CONTAINER = "picocontainer.application";
- String SESSION_CONTAINER = "picocontainer.session";
- String REQUEST_CONTAINER = "picocontainer.request";
- String ASSEMBLER = "picocontainer.assembler";
- String BUILDER = "picocontainer.builder";
-}

----------

nano /servlet /src /java /org /nanocontainer /servlet

RequestScopeObjectReference.java removed after 1.1

diff -N RequestScopeObjectReference.java
--- RequestScopeObjectReference.java 29 Oct 2003 17:22:30 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,39 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.servlet;
-
-import org.nanocontainer.integrationkit.ObjectReference;
-
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * References an object that lives as an attribute of the
- * ServletRequest.
- *
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public class RequestScopeObjectReference implements ObjectReference {
-
- private HttpServletRequest request;
- private String key;
-
- public RequestScopeObjectReference(HttpServletRequest request, String key) {
- this.request = request;
- this.key = key;
- }
-
- public void set(Object item) {
- request.setAttribute(key, item);
- }
-
- public Object get() {
- return request.getAttribute(key);
- }
-
-}

----------

nano /servlet /src /java /org /nanocontainer /servlet

ServletContainerListener.java removed after 1.2

diff -N ServletContainerListener.java
--- ServletContainerListener.java 31 Oct 2003 17:38:15 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,91 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.servlet;
-
-import org.nanocontainer.integrationkit.ContainerAssembler;
-import org.nanocontainer.integrationkit.ContainerBuilder;
-import org.nanocontainer.integrationkit.DefaultLifecycleContainerBuilder;
-import org.nanocontainer.integrationkit.ObjectReference;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionEvent;
-import javax.servlet.http.HttpSessionListener;
-
-/**
- * Servlet listener class that hooks into the underlying servlet
- * container and instantiates, assembles, starts, stores and
- * disposes the appropriate pico containers when
- * applications/sessions start/stop.
- *
- * To use, add this as a listener-class to web.xml.
- *
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public class ServletContainerListener implements ServletContextListener, HttpSessionListener, KeyConstants {
-
- private ContainerBuilder containerBuilder;
-
- public void contextInitialized(ServletContextEvent event) {
-
- ServletContext context = event.getServletContext();
- ContainerAssembler assembler = loadAssembler(context);
-
- ObjectReference containerRef = new ApplicationScopeObjectReference(context, APPLICATION_CONTAINER);
- ObjectReference builderRef = new ApplicationScopeObjectReference(context, BUILDER);
-
- containerBuilder = new DefaultLifecycleContainerBuilder();
- builderRef.set(containerBuilder);
-
- containerBuilder.buildContainer(containerRef, null, assembler, "application");
- }
-
- public void contextDestroyed(ServletContextEvent event) {
- ServletContext context = event.getServletContext();
- ObjectReference containerRef = new ApplicationScopeObjectReference(context, APPLICATION_CONTAINER);
-
- containerBuilder.killContainer(containerRef);
- }
-
- public void sessionCreated(HttpSessionEvent event) {
- HttpSession session = event.getSession();
- ServletContext context = session.getServletContext();
- ContainerAssembler assembler = getAssembler(context);
- ObjectReference containerRef = new SessionScopeObjectReference(session, SESSION_CONTAINER);
- ObjectReference parentContainerRef = new ApplicationScopeObjectReference(context, APPLICATION_CONTAINER);
-
- containerBuilder.buildContainer(containerRef, parentContainerRef, assembler, "session");
- }
-
- public void sessionDestroyed(HttpSessionEvent event) {
- HttpSession session = event.getSession();
- ObjectReference containerRef = new SessionScopeObjectReference(session, SESSION_CONTAINER);
-
- containerBuilder.killContainer(containerRef);
- }
-
- private ContainerAssembler loadAssembler(ServletContext context) {
- try {
- ObjectReference assemblerRef = new ApplicationScopeObjectReference(context, ASSEMBLER);
- String className = context.getInitParameter("assembler");
- ContainerAssembler result = (ContainerAssembler) Class.forName(className).newInstance();
- assemblerRef.set(result);
- return result;
- } catch (Exception e) {
- throw new RuntimeException(e); // todo: what should be thrown?
- }
- }
-
- private ContainerAssembler getAssembler(ServletContext context) {
- ObjectReference assemblerRef = new ApplicationScopeObjectReference(context, ASSEMBLER);
- return (ContainerAssembler) assemblerRef.get();
- }
-}

----------

nano /servlet /src /java /org /nanocontainer /servlet

ServletRequestContainerLauncher.java removed after 1.1

diff -N ServletRequestContainerLauncher.java
--- ServletRequestContainerLauncher.java 4 Nov 2003 18:15:27 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,59 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.servlet;
-
-import org.nanocontainer.integrationkit.ContainerAssembler;
-import org.nanocontainer.integrationkit.ContainerBuilder;
-import org.nanocontainer.integrationkit.ObjectReference;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-/**
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public class ServletRequestContainerLauncher {
-
- private ContainerBuilder containerBuilder;
- private ContainerAssembler assembler;
- private ObjectReference containerRef;
- private HttpServletRequest request;
-
- public ServletRequestContainerLauncher(ServletContext context, HttpServletRequest request) {
-
- ObjectReference builderRef = new ApplicationScopeObjectReference(context, KeyConstants.BUILDER);
- ObjectReference assemblerRef = new ApplicationScopeObjectReference(context, KeyConstants.ASSEMBLER);
-
- assembler = (ContainerAssembler) assemblerRef.get();
- containerRef = new RequestScopeObjectReference(request, KeyConstants.REQUEST_CONTAINER);
- containerBuilder = (ContainerBuilder) builderRef.get();
- this.request = request;
-
- }
-
- public void startContainer() throws ServletException {
-
- HttpSession session = request.getSession(true);
-
- ObjectReference parentContainerRef = new SessionScopeObjectReference(session, KeyConstants.SESSION_CONTAINER);
-
- if (assembler == null || containerBuilder == null) {
- throw new ServletException("org.nanocontainer.servlet.ServletContainerListener not deployed");
- }
-
- containerBuilder.buildContainer(containerRef, parentContainerRef, assembler, "request");
-
- }
-
- public void killContainer() {
- containerBuilder.killContainer(containerRef);
- }
-}

----------

nano /servlet /src /java /org /nanocontainer /servlet

SessionScopeObjectReference.java removed after 1.1

diff -N SessionScopeObjectReference.java
--- SessionScopeObjectReference.java 29 Oct 2003 17:22:30 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,39 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.servlet;
-
-import org.nanocontainer.integrationkit.ObjectReference;
-
-import javax.servlet.http.HttpSession;
-
-/**
- * References an object that lives as an attribute of the
- * HttpSession.
- *
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public class SessionScopeObjectReference implements ObjectReference {
-
- private HttpSession session;
- private String key;
-
- public SessionScopeObjectReference(HttpSession session, String key) {
- this.session = session;
- this.key = key;
- }
-
- public void set(Object item) {
- session.setAttribute(key, item);
- }
-
- public Object get() {
- return session.getAttribute(key);
- }
-
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

DefaultWebServerConfig.java removed after 1.1

diff -N DefaultWebServerConfig.java
--- DefaultWebServerConfig.java 10 Sep 2003 15:22:34 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,23 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.testmodel;
-
-public class DefaultWebServerConfig implements WebServerConfig {
-
- public String getHost() {
- return "*";
- }
-
- public int getPort() {
- return 80;
- }
-
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

FlintstonesImpl.java removed after 1.2

diff -N FlintstonesImpl.java
--- FlintstonesImpl.java 10 Sep 2003 16:35:13 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,20 +0,0 @@

-/*****************************************************************************
- * 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.nanocontainer.testmodel;
-
-import junit.framework.Assert;
-
-public class FlintstonesImpl {
- public FlintstonesImpl(Wilma wilma, FredImpl fred) {
- Assert.assertNotNull("Wilma cannot be passed in as null", wilma);
- Assert.assertNotNull("FredImpl cannot be passed in as null", fred);
- }
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

FredImpl.java removed after 1.2

diff -N FredImpl.java
--- FredImpl.java 10 Sep 2003 16:35:13 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,20 +0,0 @@

-/*****************************************************************************
- * 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.nanocontainer.testmodel;
-
-import junit.framework.Assert;
-
-public class FredImpl {
- public FredImpl(Wilma wilma) {
- Assert.assertNotNull("Wilma cannot be passed in as null", wilma);
- wilma.hello();
- }
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

MockComponent.java removed after 1.1

diff -N MockComponent.java
--- MockComponent.java 10 Sep 2003 15:22:34 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,28 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Mike Hogan *
- *****************************************************************************/
-
-
-package org.nanocontainer.testmodel;
-
-public interface MockComponent {
- int getPort();
-
- void setPort(int port);
-
- String getServer();
-
- void setServer(String server);
-
- void addRegister(Integer i);
-
- int getNumRegisters();
-
- boolean hasRegister(int i);
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

MockComponentImpl.java removed after 1.1

diff -N MockComponentImpl.java
--- MockComponentImpl.java 10 Sep 2003 15:22:34 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,50 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Mike Hogan *
- *****************************************************************************/
-
-package org.nanocontainer.testmodel;
-
-import org.nanocontainer.testmodel.MockComponent;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-public class MockComponentImpl implements MockComponent {
- private int port = 0;
- private String server = null;
- private Collection registers = new ArrayList();
-
- public int getPort() {
- return port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- public String getServer() {
- return server;
- }
-
- public void setServer(String server) {
- this.server = server;
- }
-
- public void addRegister(Integer i) {
- registers.add(i);
- }
-
- public int getNumRegisters() {
- return registers.size();
- }
-
- public boolean hasRegister(int i) {
- return registers.contains(new Integer(i));
- }
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

ResourceBundleWebServerConfig.java removed after 1.1

diff -N ResourceBundleWebServerConfig.java
--- ResourceBundleWebServerConfig.java 10 Sep 2003 15:22:34 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,43 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.testmodel;
-
-import java.util.ResourceBundle;
-import java.util.PropertyResourceBundle;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.File;
-
-public class ResourceBundleWebServerConfig implements WebServerConfig {
-
- String host = "localhost";
- int port = 8080;
-
- public ResourceBundleWebServerConfig() throws IOException {
-
- File file = new File(System.getProperty("basedir"), "ResourceBundleWebServerConfig.properties");
- // how do you get this working in intellij, maven and eclipse ?
- if (file.exists()) {
- ResourceBundle bundle = new PropertyResourceBundle(new FileInputStream(file));
- host = bundle.getString("host");
- port = Integer.parseInt(bundle.getString("port"));
- }
- }
-
- public String getHost() {
- return host;
- }
-
- public int getPort() {
- return port;
- }
-
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

ThingThatTakesParamsInConstructor.java removed after 1.1

diff -N ThingThatTakesParamsInConstructor.java
--- ThingThatTakesParamsInConstructor.java 10 Sep 2003 15:22:34 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,15 +0,0 @@

-package org.nanocontainer.testmodel;
-
-public class ThingThatTakesParamsInConstructor {
- private String value;
- private Integer intValue;
-
- public ThingThatTakesParamsInConstructor(String value, Integer intValue) {
- this.value = value;
- this.intValue = intValue;
- }
-
- public String getValue() {
- return value + intValue;
- }
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

WebServer.java removed after 1.1

diff -N WebServer.java
--- WebServer.java 10 Sep 2003 15:22:34 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,14 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.testmodel;
-
-public interface WebServer {
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

WebServerConfig.java removed after 1.1

diff -N WebServerConfig.java
--- WebServerConfig.java 10 Sep 2003 15:22:34 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,25 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.testmodel;
-
-/**
- * For a two parameter confiuration, you might prefer to use
- * addParameterForComponent on OldRegistrationPicoContainer. This example
- * that uses a separate configuration object would be better
- * for cases where there were say fifty configurable things
- * about a particilar component.
- */
-public interface WebServerConfig {
-
- String getHost();
-
- int getPort();
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

WebServerConfigBean.java removed after 1.2

diff -N WebServerConfigBean.java
--- WebServerConfigBean.java 23 Oct 2003 13:24:59 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,34 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.testmodel;
-
-public class WebServerConfigBean implements WebServerConfig {
-
- private int port;
- private String host;
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- public String getHost() {
- return host;
- }
-
- public int getPort() {
- return port;
- }
-
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

WebServerConfigComp.java removed after 1.1

diff -N WebServerConfigComp.java
--- WebServerConfigComp.java 26 Oct 2003 14:12:32 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,29 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.testmodel;
-
-public class WebServerConfigComp implements WebServerConfig {
-
- private String host;
- private int port;
-
- public WebServerConfigComp(String host, int port) {
- this.host = host;
- this.port = port;
- }
-
- public String getHost() {
- return host;
- }
-
- public int getPort() {
- return port;
- }
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

WebServerConfigStub.java removed after 1.1

diff -N WebServerConfigStub.java
--- WebServerConfigStub.java 23 Oct 2003 13:24:59 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,26 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.testmodel;
-
-public class WebServerConfigStub implements WebServerConfig {
-
- private int port;
- private String host;
-
- public String getHost() {
- return host;
- }
-
- public int getPort() {
- return port;
- }
-
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

WebServerImpl.java removed after 1.1

diff -N WebServerImpl.java
--- WebServerImpl.java 10 Sep 2003 15:22:34 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,23 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.testmodel;
-
-import junit.framework.Assert;
-import org.nanocontainer.testmodel.WebServer;
-import org.nanocontainer.testmodel.WebServerConfig;
-
-public class WebServerImpl implements WebServer {
-
- public WebServerImpl(WebServerConfig wsc) {
- Assert.assertTrue("No port number specified", wsc.getPort() > 0);
- Assert.assertNotNull("No host name specified", wsc.getHost());
- }
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

Wilma.java removed after 1.2

diff -N Wilma.java
--- Wilma.java 10 Sep 2003 16:35:13 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,15 +0,0 @@

-/*****************************************************************************
- * 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.nanocontainer.testmodel;
-
-public interface Wilma {
- void hello();
-}

----------

nano /testmodel /src /java /org /nanocontainer /testmodel

WilmaImpl.java removed after 1.2

diff -N WilmaImpl.java
--- WilmaImpl.java 10 Sep 2003 16:35:13 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,27 +0,0 @@

-/*****************************************************************************
- * 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.nanocontainer.testmodel;
-
-import org.nanocontainer.testmodel.Wilma;
-
-
-public class WilmaImpl implements Wilma {
-
- private boolean helloCalled;
-
- public boolean helloCalled() {
- return helloCalled;
- }
-
- public void hello() {
- helloCalled = true;
- }
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg

MulticastingPicoException.java removed after 1.1.1.1

diff -N MulticastingPicoException.java
--- MulticastingPicoException.java 10 Sep 2003 22:11:39 -0000 1.1.1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@

-package org.nanocontainer.type3msg;
-
-import org.picocontainer.PicoException;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 8:58:44 PM
- * To change this template use Options | File Templates.
- */
-public class MulticastingPicoException extends PicoException {
- public MulticastingPicoException(String string) {
- super(string);
- }
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg

MulticastingProxy.java removed after 1.3

diff -N MulticastingProxy.java
--- MulticastingProxy.java 10 Sep 2003 23:21:31 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,48 +0,0 @@

-package org.nanocontainer.type3msg;
-
-import org.picocontainer.PicoException;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.*;
-
-public class MulticastingProxy implements InvocationHandler {
-
- private Class theInterface;
- private List items;
-
- public MulticastingProxy(Class theInterface) {
- this.theInterface = theInterface;
- items = new ArrayList();
- }
-
- public void add(Object item) throws PicoException {
- if ( !theInterface.isAssignableFrom(item.getClass())) {
- throw new MulticastingPicoException(
- "The item " + item.getClass().getName() + " is not an instance of " + theInterface.getName());
- }
- items.add(item);
- }
-
- public Object getProxy() {
- return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {theInterface}, this);
- }
-
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- Iterator iterator = items.iterator();
- while (iterator.hasNext()) {
- Object item = iterator.next();
- method.invoke(item, args);
- }
- return null;
- }
-
- protected Object getItem(int index) {
- return items.get(index);
- }
-
- protected int getItemCount() {
- return items.size();
- }
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg

RoundRobinMulticastingProxy.java removed after 1.1.1.1

diff -N RoundRobinMulticastingProxy.java
--- RoundRobinMulticastingProxy.java 10 Sep 2003 22:11:39 -0000 1.1.1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,27 +0,0 @@

-package org.nanocontainer.type3msg;
-
-import java.lang.reflect.Method;
-import java.util.Iterator;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 9:03:36 PM
- * To change this template use Options | File Templates.
- */
-public class RoundRobinMulticastingProxy extends MulticastingProxy {
-
- int next = 0;
-
- public RoundRobinMulticastingProxy(Class theInterface) {
- super(theInterface);
- }
-
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- Object item = getItem(next % getItemCount());
- next++;
- return method.invoke(item, args);
- }
-
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg

Type3MsgPicoContainer.java removed after 1.2

diff -N Type3MsgPicoContainer.java
--- Type3MsgPicoContainer.java 10 Sep 2003 23:16:09 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,35 +0,0 @@

-package org.nanocontainer.type3msg;
-
-import org.picocontainer.defaults.DefaultPicoContainer;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- */
-public class Type3MsgPicoContainer extends DefaultPicoContainer {
- private Map impls = new HashMap();
-
- public void registerMulticasted(Class theInterface, Object theImpl) {
- MulticastingProxy proxy = (MulticastingProxy) impls.get(theInterface);
- if (proxy==null) {
- proxy = new MulticastingProxy(theInterface);
- impls.put(theInterface, proxy);
- registerComponentInstance(theInterface, proxy.getProxy());
- }
- proxy.add(theImpl);
- }
-
- public void registerRoundRobin(Class theInterface, Object theImpl) {
- RoundRobinMulticastingProxy proxy = (RoundRobinMulticastingProxy) impls.get(theInterface);
- if (proxy==null) {
- proxy = new RoundRobinMulticastingProxy(theInterface);
- impls.put(theInterface, proxy);
- registerComponentInstance(theInterface, proxy.getProxy());
- }
- proxy.add(theImpl);
- }
-
-
- //proxy = new MulticastingProxy(theInterface, theCreationStratgy, theDelegationStrategy)
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg /sample

Controller.java removed after 1.1

diff -N Controller.java
--- Controller.java 10 Sep 2003 22:32:56 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,29 +0,0 @@

-package org.nanocontainer.type3msg.sample;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 10:18:15 PM
- * To change this template use Options | File Templates.
- */
-public class Controller {
-
- Worker worker;
- private Database database;
-
- public Controller(Worker worker, Database database) {
- this.worker = worker;
- this.database = database;
- }
-
- public void fireOffAUnitOfWork(String name)
- {
- UnitOfWork task = new UnitOfWork(name);
- worker.work(task);
- }
-
- public void storeObject(String anObject) {
- database.storeObject(anObject);
- }
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg /sample

Database.java removed after 1.1

diff -N Database.java
--- Database.java 10 Sep 2003 22:32:56 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,14 +0,0 @@

-package org.nanocontainer.type3msg.sample;
-
-import java.util.List;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 10:30:13 PM
- * To change this template use Options | File Templates.
- */
-public interface Database {
- public void storeObject(String anObject);
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg /sample

PretendDatabase.java removed after 1.2

diff -N PretendDatabase.java
--- PretendDatabase.java 10 Sep 2003 22:36:39 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,22 +0,0 @@

-package org.nanocontainer.type3msg.sample;
-
-import java.util.List;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 10:31:29 PM
- * To change this template use Options | File Templates.
- */
-public class PretendDatabase implements Database {
- private List objects;
-
- public PretendDatabase(List objects) {
- this.objects = objects;
- }
-
- public void storeObject(String anObject) {
- objects.add(anObject);
- }
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg /sample

UnitOfWork.java removed after 1.1

diff -N UnitOfWork.java
--- UnitOfWork.java 10 Sep 2003 22:32:56 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,20 +0,0 @@

-package org.nanocontainer.type3msg.sample;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 10:13:18 PM
- * To change this template use Options | File Templates.
- */
-public class UnitOfWork {
- String name;
-
- public UnitOfWork(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg /sample

Worker.java removed after 1.1

diff -N Worker.java
--- Worker.java 10 Sep 2003 22:32:56 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,12 +0,0 @@

-package org.nanocontainer.type3msg.sample;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 10:12:45 PM
- * To change this template use Options | File Templates.
- */
-public interface Worker {
- public void work(UnitOfWork task);
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg /sample

WorkerDoer.java removed after 1.2

diff -N WorkerDoer.java
--- WorkerDoer.java 10 Sep 2003 23:16:09 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,29 +0,0 @@

-package org.nanocontainer.type3msg.sample;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 10:15:14 PM
- * To change this template use Options | File Templates.
- */
-public class WorkerDoer implements Worker{
- private List doneTasks;
-
- public WorkerDoer() {
- this.doneTasks = new ArrayList();
- }
-
- public void work(UnitOfWork task) {
- doneTasks.add(task.getName());
- System.out.println("Doing task " + task.getName());
- }
-
- public Collection getDoneTasks() {
- return doneTasks;
- }
-}

----------

nano /type3msg /src /java /org /nanocontainer /type3msg /sample

WorkerLogger.java removed after 1.1

diff -N WorkerLogger.java
--- WorkerLogger.java 10 Sep 2003 22:32:56 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,20 +0,0 @@

-package org.nanocontainer.type3msg.sample;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 10:15:03 PM
- * To change this template use Options | File Templates.
- */
-public class WorkerLogger implements Worker {
- private String logged;
-
- public void work(UnitOfWork task) {
- logged = task.getName();
- }
-
- public String getLogged() {
- return logged;
- }
-}

----------

nano /type3msg /src /test /org /nanocontainer /type3msg

Kissable.java removed after 1.1.1.1

diff -N Kissable.java
--- Kissable.java 10 Sep 2003 22:11:39 -0000 1.1.1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,5 +0,0 @@

-package org.nanocontainer.type3msg;
-
-public interface Kissable {
- void kiss();
-}

----------

nano /type3msg /src /test /org /nanocontainer /type3msg

TestBoy.java removed after 1.1.1.1

diff -N TestBoy.java
--- TestBoy.java 10 Sep 2003 22:11:39 -0000 1.1.1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,20 +0,0 @@

-package org.nanocontainer.type3msg;
-
-/**
- * Created by IntelliJ IDEA.
- * User: skizz
- * Date: Sep 10, 2003
- * Time: 9:52:20 PM
- * To change this template use Options | File Templates.
- */
-public class TestBoy {
- private Kissable kissable;
-
- public TestBoy(Kissable kissable) {
- this.kissable = kissable;
- }
-
- public void doKiss() {
- kissable.kiss();
- }
-}

----------

nano /type3msg /src /test /org /nanocontainer /type3msg

TestGirl.java removed after 1.1.1.1

diff -N TestGirl.java
--- TestGirl.java 10 Sep 2003 22:11:39 -0000 1.1.1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,20 +0,0 @@

-package org.nanocontainer.type3msg;
-
-public class TestGirl implements Kissable {
- private boolean kissed = false;
-
- public TestGirl(int id) {
- }
-
- public boolean wasKissed() {
- return kissed;
- }
-
- public void kiss() {
- kissed = true;
- }
-
- public void wipeFace() {
- kissed = false;
- }
-}

----------

nano /type3msg /src /test /org /nanocontainer /type3msg

Type3MsgPicoContainerTest.java removed after 1.2

diff -N Type3MsgPicoContainerTest.java
--- Type3MsgPicoContainerTest.java 10 Sep 2003 23:16:09 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,124 +0,0 @@

-package org.nanocontainer.type3msg;
-
-import junit.framework.TestCase;
-import org.nanocontainer.type3msg.sample.*;
-import org.picocontainer.PicoContainer;
-import org.picocontainer.defaults.DefaultPicoContainer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Chris Stevenson, Stacy Curl
- */
-public class Type3MsgPicoContainerTest extends TestCase {
- private TestGirl testGirl1;
- private TestGirl testGirl2;
- private TestGirl testGirl3;
-
- protected void setUp() throws Exception {
- testGirl1 = new TestGirl(1);
- testGirl2 = new TestGirl(2);
- testGirl3 = new TestGirl(3);
- }
-
- public void testCannotAddAComponentWithWrongInterface()
- {
- MulticastingProxy multicastingProxy = new MulticastingProxy(Kissable.class);
- try {
- multicastingProxy.add("foo");
- fail("Should throw an Exception");
- }
- catch(MulticastingPicoException e) {
- //expected
- }
- }
-
- public void testMulticastingProxySendsKissToAllComponents()
- {
- MulticastingProxy multicastingProxy = new MulticastingProxy(Kissable.class);
-
- multicastingProxy.add(testGirl1);
- multicastingProxy.add(testGirl2);
- multicastingProxy.add(testGirl3);
-
- Kissable kissable = (Kissable) multicastingProxy.getProxy();
-
- kissable.kiss();
-
- assertTrue(testGirl1.wasKissed());
- assertTrue(testGirl2.wasKissed());
- assertTrue(testGirl3.wasKissed());
-
- }
-
- public void testRoundRobinProxySendsKissToOneOfTheComponents()
- {
- RoundRobinMulticastingProxy multicastingProxy = new RoundRobinMulticastingProxy(Kissable.class);
-
- multicastingProxy.add(testGirl1);
- multicastingProxy.add(testGirl2);
-
- Kissable kissable = (Kissable) multicastingProxy.getProxy();
-
- kissable.kiss();
- assertTrue(testGirl1.wasKissed());
- assertFalse(testGirl2.wasKissed());
-
- testGirl1.wipeFace();
- testGirl2.wipeFace();
-
- kissable.kiss();
- assertFalse(testGirl1.wasKissed());
- assertTrue(testGirl2.wasKissed());
- }
-
- public void testPicoContainerWithKnowledgeOfCasting()
- {
- Type3MsgPicoContainer c = new Type3MsgPicoContainer();
-
- c.registerComponentImplementation(TestBoy.class);
-
- c.registerMulticasted(Kissable.class, testGirl1);
- c.registerMulticasted(Kissable.class, testGirl2);
-
- TestBoy testBoy = (TestBoy) c.getComponentInstance(TestBoy.class);
- testBoy.doKiss();
-
- assertTrue(testGirl1.wasKissed());
- assertTrue(testGirl2.wasKissed());
-
- }
-
- public void testWhyWouldYouUseMulticasting()
- {
- Type3MsgPicoContainer c = new Type3MsgPicoContainer();
-
- c.registerComponentImplementation(Controller.class);
-// c.registerRoundRobinMulticaster(Database.class, db2);
-
- //smelly - how do we do this
- //c.registerMulticasted(Worker.class, new RoundRobin(UnitOfWorkDoer.class, UnitOfWorkDoer.class));
- WorkerLogger workerLogger = new WorkerLogger();
- WorkerDoer workerDoer = new WorkerDoer();
-
- c.registerMulticasted(Worker.class, workerLogger);
- c.registerMulticasted(Worker.class, workerDoer);
-
- List objects = new ArrayList();
-
- c.registerRoundRobin(Database.class, new PretendDatabase(objects));
- c.registerRoundRobin(Database.class, new PretendDatabase(objects));
-
- Controller controller = (Controller) c.getComponentInstance(Controller.class);
-
- controller.fireOffAUnitOfWork("foo");
-
- assertEquals("foo", workerLogger.getLogged());
- assertTrue(workerDoer.getDoneTasks().contains("foo"));
-
- controller.storeObject("bar");
- assertTrue(objects.contains("bar"));
- }
-
-}

----------

nano /webwork2 /src /java /org /nanocontainer /webwork2

PicoActionInvocation.java removed after 1.1

diff -N PicoActionInvocation.java
--- PicoActionInvocation.java 4 Nov 2003 18:17:35 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,60 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.webwork2;
-
-import com.opensymphony.xwork.Action;
-import com.opensymphony.xwork.ActionProxy;
-import com.opensymphony.xwork.DefaultActionInvocation;
-import com.opensymphony.webwork.WebWorkStatics;
-import org.nanocontainer.integrationkit.ObjectReference;
-import org.nanocontainer.servlet.KeyConstants;
-import org.nanocontainer.servlet.RequestScopeObjectReference;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.defaults.DefaultPicoContainer;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.Map;
-
-/**
- * @author Chris Sturm
- */
-public class PicoActionInvocation extends DefaultActionInvocation implements KeyConstants {
-
- public PicoActionInvocation(ActionProxy proxy) throws Exception {
- super(proxy);
- }
-
- public PicoActionInvocation(ActionProxy proxy, Map extraContext) throws Exception {
- super(proxy, extraContext);
- }
-
- public PicoActionInvocation(ActionProxy proxy, Map extraContext, boolean pushAction) throws Exception {
- super(proxy, extraContext, pushAction);
- }
-
- protected void createAction() {
- // load action
- try {
- MutablePicoContainer container = new DefaultPicoContainer();
- container.addParent(getParentContainer());
-
- Class actionClass = proxy.getConfig().getClazz();
- container.registerComponentImplementation(actionClass);
- action = (Action) container.getComponentInstance(actionClass);
- } catch (Exception e) {
- throw new IllegalArgumentException("Unknown action name: " + e.getMessage());
- }
- }
-
- private MutablePicoContainer getParentContainer() {
- HttpServletRequest request = (HttpServletRequest) getStack().getContext().get(WebWorkStatics.HTTP_REQUEST);
- ObjectReference ref = new RequestScopeObjectReference(request, REQUEST_CONTAINER);
- return (MutablePicoContainer) ref.get();
- }
-}

----------

nano /webwork2 /src /java /org /nanocontainer /webwork2

PicoActionProxyFactory.java removed after 1.1

diff -N PicoActionProxyFactory.java
--- PicoActionProxyFactory.java 4 Nov 2003 18:17:35 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,32 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.webwork2;
-
-import com.opensymphony.xwork.ActionInvocation;
-import com.opensymphony.xwork.ActionProxy;
-import com.opensymphony.xwork.DefaultActionProxyFactory;
-
-import java.util.Map;
-
-/**
- * @author Chris Sturm
- */
-public class PicoActionProxyFactory extends DefaultActionProxyFactory {
- public ActionInvocation createActionInvocation(ActionProxy actionProxy) throws Exception {
- return new PicoActionInvocation(actionProxy);
- }
-
- public ActionInvocation createActionInvocation(ActionProxy actionProxy, Map extraContext) throws Exception {
- return new PicoActionInvocation(actionProxy, extraContext);
- }
-
- public ActionInvocation createActionInvocation(ActionProxy actionProxy, Map extraContext, boolean pushAction) throws Exception {
- return new PicoActionInvocation(actionProxy, extraContext, pushAction);
- }
-}

----------

nano /webwork2 /src /java /org /nanocontainer /webwork2

PicoServletDispatcher.java removed after 1.1

diff -N PicoServletDispatcher.java
--- PicoServletDispatcher.java 4 Nov 2003 18:17:35 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,43 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.webwork2;
-
-import org.nanocontainer.servlet.KeyConstants;
-import org.nanocontainer.servlet.ServletRequestContainerLauncher;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import com.opensymphony.webwork.dispatcher.ServletDispatcher;
-
-/**
- * Extension to the standard WebWork2 ServletDispatcher that instantiates a new container in the request
- * scope for each request and disposes of it correctly at the end of the request.
- *
- * To use, replace the WebWork ServletDispatcher in web.xml with this.
- *
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public class PicoServletDispatcher extends ServletDispatcher implements KeyConstants {
-
-
- public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {
- ServletRequestContainerLauncher containerLauncher = new ServletRequestContainerLauncher(getServletContext(), request);
- try {
- containerLauncher.startContainer();
- // process the servlet using webwork2
- super.service(request, response);
- } finally {
- containerLauncher.killContainer();
- }
-
- }
-
-}

----------

nano /webwork2 /src /java /org /nanocontainer /webwork2

WebWork2ContainerListener.java removed after 1.1

diff -N WebWork2ContainerListener.java
--- WebWork2ContainerListener.java 4 Nov 2003 18:17:35 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,24 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.webwork2;
-
-import com.opensymphony.xwork.ActionProxyFactory;
-import org.nanocontainer.servlet.ServletContainerListener;
-
-import javax.servlet.ServletContextEvent;
-
-/**
- * @author Chris Sturm
- */
-public class WebWork2ContainerListener extends ServletContainerListener {
- public void contextInitialized(ServletContextEvent event) {
- ActionProxyFactory.setFactory(new PicoActionProxyFactory());
- super.contextInitialized(event);
- }
-}

----------

nano /webwork /src /java /org /nanocontainer /webwork

PicoActionFactory.java removed after 1.2

diff -N PicoActionFactory.java
--- PicoActionFactory.java 3 Nov 2003 09:30:10 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,78 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.webwork;
-
-import org.nanocontainer.integrationkit.ObjectReference;
-import org.nanocontainer.servlet.KeyConstants;
-import org.nanocontainer.servlet.RequestScopeObjectReference;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.defaults.DefaultPicoContainer;
-import webwork.action.Action;
-import webwork.action.ServletActionContext;
-import webwork.action.factory.ActionFactory;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Replacement for the standard WebWork JavaActionFactory that resolves all of the
- * dependencies an Action may have in the constructor.
- *
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public class PicoActionFactory extends ActionFactory implements KeyConstants {
-
- private Map classCache = new HashMap();
-
- public Action getActionImpl(String className) throws Exception {
- Class actionClass = loadClass(className);
- if (actionClass == null) {
- return null;
- } else {
- Action action = null;
- try {
- action = instantiateAction(actionClass);
- } catch (Exception e) {
- // todo: what? webwork seems to swallow these exceptions - I think.
- e.printStackTrace();
- }
- return action;
- }
- }
-
- protected Class loadClass(String className) {
- if (classCache.containsKey(className)) {
- return (Class) classCache.get(className);
- } else {
- try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class result = classLoader.loadClass(className);
- classCache.put(className, result);
- return result;
- } catch (ClassNotFoundException e) {
- return null;
- }
- }
- }
-
- protected Action instantiateAction(Class actionClass) {
- MutablePicoContainer container = new DefaultPicoContainer();
- container.addParent(getParentContainer());
- container.registerComponentImplementation(actionClass);
- return (Action) container.getComponentInstance(actionClass);
- }
-
- private MutablePicoContainer getParentContainer() {
- HttpServletRequest request = ServletActionContext.getRequest();
- ObjectReference ref = new RequestScopeObjectReference(request, REQUEST_CONTAINER);
- return (MutablePicoContainer) ref.get();
- }
-
-}

----------

nano /webwork /src /java /org /nanocontainer /webwork

PicoServletDispatcher.java removed after 1.2

diff -N PicoServletDispatcher.java
--- PicoServletDispatcher.java 4 Nov 2003 18:16:08 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,42 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.webwork;
-
-import org.nanocontainer.servlet.KeyConstants;
-import org.nanocontainer.servlet.ServletRequestContainerLauncher;
-import webwork.dispatcher.ServletDispatcher;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Extension to the standard WebWork DispatcherServlet that instantiates a new container in the request
- * scope for each request and disposes of it correctly at the end of the request.
- *
- * To use, replace the WebWork ServletDispatcher in web.xml with this.
- *
- * @author <a href="mailto:[email protected]">Joe Walnes</a>
- */
-public class PicoServletDispatcher extends ServletDispatcher implements KeyConstants {
-
-
- public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {
- ServletRequestContainerLauncher containerLauncher = new ServletRequestContainerLauncher(getServletContext(), request);
- try {
- containerLauncher.startContainer();
- // process the servlet using webwork
- super.service(request, response);
- } finally {
- containerLauncher.killContainer();
- }
-
- }
-
-}

----------

nano /webwork /src /java /org /nanocontainer /webwork

WebWorkActionFactory.java removed after 1.1

diff -N WebWorkActionFactory.java
--- WebWorkActionFactory.java 3 Nov 2003 09:24:12 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,44 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.webwork;
-
-import webwork.action.Action;
-import webwork.action.factory.*;
-
-/**
- * Custom webwork action lifecycle that ensures actions are treated as pico components.
- *
- * <p>To use, add to webwork.properties:
- * <pre>
- * webwork.action.factory=org.nanocontainer.webwork.WebWorkActionFactory
- * </pre></p>
- */
-public class WebWorkActionFactory extends ActionFactory {
-
- private ActionFactory factory;
-
- public WebWorkActionFactory() {
- // replace standard JavaActionFactory with PicoActionFactory
- factory = new PicoActionFactory();
- // the rest are the standard webwork ActionFactoryProxies
- factory = new PrefixActionFactoryProxy(factory);
- factory = new CommandActionFactoryProxy(factory);
- factory = new AliasingActionFactoryProxy(factory);
- factory = new CommandActionFactoryProxy(factory);
- factory = new ContextActionFactoryProxy(factory);
- factory = new PrepareActionFactoryProxy(factory);
- factory = new ParametersActionFactoryProxy(factory);
- factory = new ChainingActionFactoryProxy(factory);
- }
-
- public Action getActionImpl(String actionName) throws Exception {
- return factory.getActionImpl(actionName);
- }
-
-}

----------

nano /xml /src /java /org /nanocontainer /xml

BeanXmlPseudoComponentFactory.java removed after 1.2

diff -N BeanXmlPseudoComponentFactory.java
--- BeanXmlPseudoComponentFactory.java 4 Nov 2003 07:00:03 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,70 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.xml;
-
-import org.nanocontainer.reflection.DefaultReflectionFrontEnd;
-import org.nanocontainer.reflection.ReflectionFrontEnd;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * @author Paul Hammant
- * @author Marcos Tarruella
- */
-public class BeanXmlPseudoComponentFactory implements XmlPseudoComponentFactory {
-
- public Object makeInstance(Element elem) throws SAXException, ClassNotFoundException {
- String className = elem.getNodeName();
- ReflectionFrontEnd rfe = new DefaultReflectionFrontEnd();
- rfe.registerComponentImplementation(className);
- Object o = rfe.getPicoContainer().getComponentInstances().get(0);
-
- NodeList nl = elem.getChildNodes();
- for (int i=0; i < nl.getLength(); i++) {
- Node n = nl.item(i);
- if (n instanceof Element) {
- Element e = (Element) n;
- setBeanProperty(o, e.getNodeName(), e.getChildNodes().item(0).getNodeValue());
- }
- }
- return o;
- }
-
- private void setBeanProperty(Object o, String nodeName, String nodeValue) {
- String methodName = "set" + nodeName.substring(0,1).toUpperCase() + nodeName.substring(1);
- Method[] methods = o.getClass().getMethods();
- for (int i=0; i < methods.length; i++) {
- Method method = methods[i];
- if (method.getName().equals(methodName)) {
- Class paramType = method.getParameterTypes()[0];
- try {
- if (paramType == String.class) {
- method.invoke(o, new Object[] {nodeValue});
- return;
- } else if (paramType == Integer.TYPE) {
- method.invoke(o, new Object[] { new Integer(nodeValue)});
- return;
- }
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- }
- }
- throw new UnsupportedOperationException("Whoa - bad type!!");
- }
-}

----------

nano /xml /src /java /org /nanocontainer /xml

DefaultXmlFrontEnd.java removed after 1.9

diff -N DefaultXmlFrontEnd.java
--- DefaultXmlFrontEnd.java 8 Nov 2003 12:13:37 -0000 1.9
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,195 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.xml;
-
-import org.nanocontainer.reflection.ReflectionFrontEnd;
-import org.nanocontainer.reflection.DefaultReflectionFrontEnd;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.PicoContainer;
-import org.picocontainer.PicoCompositionException;
-import org.picocontainer.defaults.DefaultPicoContainer;
-import org.picocontainer.defaults.ComponentAdapterFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-
-/**
- * This class builds up a hierarchy of PicoContainers from an XML configuration file.
- *
- * @author Paul Hammant
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.9 $
- */
-public class DefaultXmlFrontEnd implements XmlFrontEnd {
-
- public PicoContainer createPicoContainer(Element rootElement) throws IOException, SAXException, ClassNotFoundException, PicoCompositionException {
- MutablePicoContainer mutablePicoContainer = getMutablePicoContainerFromContainerAttribute(rootElement);
- return createPicoContainer(rootElement, mutablePicoContainer);
- }
-
- public PicoContainer createPicoContainer(Element rootElement, MutablePicoContainer mutablePicoContainer)
- throws IOException, SAXException, ClassNotFoundException, PicoCompositionException {
-
- ReflectionFrontEnd rootReflectionFrontEnd = new DefaultReflectionFrontEnd(mutablePicoContainer);
- registerComponentsAndChildContainers(rootReflectionFrontEnd, rootElement);
-
- return rootReflectionFrontEnd.getPicoContainer();
- }
-
- private void registerComponentsAndChildContainers(ReflectionFrontEnd reflectionFrontEnd, Element containerElement) throws ClassNotFoundException, IOException, PicoCompositionException {
-
- NodeList children = containerElement.getChildNodes();
- // register classpath first, regardless of order in the document.
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- short type = child.getNodeType();
- if (type == Document.ELEMENT_NODE) {
- String name = child.getNodeName();
- if (name.equals("classpath")) {
- registerClasspath(reflectionFrontEnd, (Element) child);
- }
- }
- }
- int componentCount = 0;
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- short type = child.getNodeType();
- if (type == Document.ELEMENT_NODE) {
- String name = child.getNodeName();
- if (name.equals("pseudocomponent")) {
- registerPseudoComponent(reflectionFrontEnd, (Element) child);
- componentCount++;
- } if (name.equals("component")) {
- registerComponent(reflectionFrontEnd, (Element) child);
- componentCount++;
- } else if (name.equals("container")) {
-
- MutablePicoContainer mutablePicoContainer = getMutablePicoContainerFromContainerAttribute(child);
-
- ReflectionFrontEnd childFrontEnd = new DefaultReflectionFrontEnd(reflectionFrontEnd, mutablePicoContainer);
- registerComponentsAndChildContainers(childFrontEnd, (Element) child);
- }
- }
- }
- if (componentCount == 0) {
- throw new EmptyXmlCompositionException();
- }
- }
-
- private MutablePicoContainer getMutablePicoContainerFromContainerAttribute(Node child) throws ClassNotFoundException {
- String picoContainerClassName = ((Element) child).getAttribute("container");
- String componentAdaptorClassName = ((Element) child).getAttribute("componentadaptor");
-
- ReflectionFrontEnd tempContainer = new DefaultReflectionFrontEnd();
-
- if (componentAdaptorClassName != null && !componentAdaptorClassName.equals("")) {
- tempContainer.registerComponent(ComponentAdapterFactory.class, componentAdaptorClassName);
- }
- if (picoContainerClassName == null || picoContainerClassName.equals("")) {
- tempContainer.registerComponent(PicoContainer.class, DefaultPicoContainer.class.getName());
- } else {
- tempContainer.registerComponentImplementation(picoContainerClassName);
- }
- return (MutablePicoContainer) tempContainer.getPicoContainer().getComponentInstance(PicoContainer.class);
- }
-
- private void registerClasspath(ReflectionFrontEnd reflectionFrontEnd, Element classpathElement) throws IOException {
- NodeList children = classpathElement.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- short type = child.getNodeType();
- if (type == Document.ELEMENT_NODE) {
- String name = child.getNodeName();
- if (name.equals("element")) {
- String fileName = ((Element) child).getAttribute("file");
- String urlSpec = ((Element) child).getAttribute("url");
- URL url = null;
- if (urlSpec != null && !"".equals(urlSpec)) {
- url = new URL(urlSpec);
- } else {
- File file = new File(fileName);
- if (!file.exists()) {
- throw new IOException(file.getAbsolutePath() + " doesn't exist");
- }
- url = file.toURL();
- }
- reflectionFrontEnd.addClassLoaderURL(url);
- }
- }
- }
- }
-
- private void registerComponent(ReflectionFrontEnd pico, Element componentElement) throws ClassNotFoundException {
- String className = componentElement.getAttribute("impl");
- String stringKey = componentElement.getAttribute("stringkey");
- String typeKey = componentElement.getAttribute("typekey");
-
- ArrayList hints = new ArrayList();
- NodeList children = componentElement.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- if (child.getNodeName() == "hint") {
- hints.add(((Element) child).getAttribute("stringkey"));
- }
- }
-
-
- //TODO we need to have config elements parsing here, and register with params action...
- if (stringKey == null || stringKey.equals("")) {
- stringKey = className;
- }
- if (typeKey == null || typeKey.equals("")) {
- pico.registerComponent(stringKey, className);
- } else {
- pico.registerComponentWithClassKey(typeKey,className);
- }
- }
-
- private void registerPseudoComponent(ReflectionFrontEnd pico, Element componentElement) throws ClassNotFoundException, PicoCompositionException {
- String factoryClass = componentElement.getAttribute("factory");
-
- if (factoryClass == null || factoryClass.equals("")) {
- throw new java.lang.IllegalArgumentException("factory attribute should be specified for pseudocomponent element");
- // unless we provide a default.
- }
-
- ReflectionFrontEnd tempContainer = new DefaultReflectionFrontEnd();
- tempContainer.registerComponentWithClassKey(XmlPseudoComponentFactory.class.getName(), factoryClass);
- XmlPseudoComponentFactory factory = (XmlPseudoComponentFactory) tempContainer.getPicoContainer().getComponentInstances().get(0);
-
- NodeList nl = componentElement.getChildNodes();
- Element childElement = null;
- for (int i = 0; i < nl.getLength(); i++) {
- if (nl.item(i) instanceof Element) {
- childElement = (Element) nl.item(i);
- break;
- }
- }
-
- try {
- Object pseudoComp = factory.makeInstance(childElement);
- pico.getPicoContainer().registerComponentInstance(pseudoComp);
- } catch (final SAXException e) {
- throw new PicoCompositionException() {
- public String getMessage() {
- return "SAXException during creation of PseudoComponent :" + e.getMessage();
- }
- };
- }
- }
-}

----------

nano /xml /src /java /org /nanocontainer /xml

EmptyXmlCompositionException.java removed after 1.1

diff -N EmptyXmlCompositionException.java
--- EmptyXmlCompositionException.java 8 Nov 2003 12:13:37 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,19 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.xml;
-
-public class EmptyXmlCompositionException extends XmlFrontEndException {
- public EmptyXmlCompositionException() {
- }
-
- public String getMessage() {
- return "No components in the XML composition";
- }
-}

----------

nano /xml /src /java /org /nanocontainer /xml

ParameterXmlFrontEnd.java removed after 1.2

diff -N ParameterXmlFrontEnd.java
--- ParameterXmlFrontEnd.java 8 Nov 2003 12:13:37 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,222 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Jeppe Cramon *
- *****************************************************************************/
-
-package org.nanocontainer.xml;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.nanocontainer.reflection.ReflectionFrontEnd;
-import org.nanocontainer.reflection.DefaultReflectionFrontEnd;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.PicoContainer;
-import org.picocontainer.PicoCompositionException;
-import org.picocontainer.defaults.DefaultPicoContainer;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-/**
- * Handles XML configuration files which includes specification of container implementation (default is DefaultPicoContainer) + plus constant
- * parameters (including primitive types) for components.
- * Requirement for Containers is that they have a default constructor which initializes it with the necessary
- * requirements.<br>
- * <br>
- * Sample XML document:
- * <pre>
- * &lt;container classname="org.nanocontainer.jmx.NanoMXContainer"&gt;
- * &lt;component key="testClass" classname="org.test.TestClass"&gt;
- * &lt;parameter classname="java.lang.String"&gt;Test&lt;/parameter&gt;
- * &lt;parameter classname="int"&gt;23&lt;/parameter&gt;
- * &lt;/component&gt;
- * &lt;container&gt;
- * &lt;component classname="org.test.TestClass2"/&gt;
- * &lt;component key="class23" classname="org.test.TestClass3"/&gt;
- * &lt;/container&gt;
- * &lt;/container&gt;
- * </pre>
- * @author Jeppe Cramon
- */
-public class ParameterXmlFrontEnd implements XmlFrontEnd {
- private int componentCount = 0;
-
- /**
- *
- */
- public ParameterXmlFrontEnd() {
- super();
- }
-
- /* (non-Javadoc)
- * @see org.nanocontainer.xml.XmlFrontEnd#createPicoContainer(org.w3c.dom.Element)
- */
- public PicoContainer createPicoContainer(Element rootElement)
- throws
- IOException,
- SAXException,
- ClassNotFoundException,
- XmlFrontEndException {
- componentCount = 0;
- PicoContainer container = registerContainer(null, rootElement);
- if (componentCount == 0) {
- throw new EmptyXmlCompositionException();
- }
- return container;
- }
-
- public PicoContainer createPicoContainer(Element rootElement, MutablePicoContainer mutablePicoContainer) throws IOException, SAXException, ClassNotFoundException, PicoCompositionException {
- // ignore mutablePicoContainer param for now.
- return createPicoContainer(rootElement);
- }
-
- /**
- * Accepts elements:<br>
- * &lt;container classname=""/&gt; where classname is optional. If left out the type of container is the DefaultPicoContainer
- * @param element
- * @return
- */
- private PicoContainer registerContainer(ReflectionFrontEnd parent, Element element) throws XmlFrontEndException {
- if (!element.getNodeName().equals("container")) {
- throw new XmlFrontEndException("Excepted 'container' element, but found '" + element.getNodeName() + "'");
- }
- // Check which type of container to register
- String containerClass = DefaultPicoContainer.class.getName();
- if (element.getAttribute("classname") != null && element.getAttribute("classname").length() != 0) {
- containerClass = element.getAttribute("classname");
- }
-
- try {
- MutablePicoContainer container = (MutablePicoContainer) Class.forName(containerClass).newInstance();
- ReflectionFrontEnd frontEnd = new DefaultReflectionFrontEnd(container);
- if (parent != null) {
- MutablePicoContainer parentContainer = (MutablePicoContainer)parent.getPicoContainer();
- container.addParent(parentContainer);
- }
- // Loop through components and child containers
- NodeList elemList = element.getChildNodes();
- for (int index = 0; index < elemList.getLength(); index++) {
- if(elemList.item(index).getNodeType() == Document.ELEMENT_NODE) {
- registerComponentsAndChildContainers(frontEnd, (Element)elemList.item(index));
- }
- }
- return container;
- } catch (InstantiationException e) {
- throw MakeXmlFrontEndException(containerClass, e);
- } catch (IllegalAccessException e) {
- throw MakeXmlFrontEndException(containerClass, e);
- } catch (ClassNotFoundException e) {
- throw MakeXmlFrontEndException(containerClass, e);
- }
- }
-
- private XmlFrontEndException MakeXmlFrontEndException(final String containerClass, final Exception e) {
- return new XmlFrontEndException("Failed to create an instance of container '" + containerClass + "', due to " + e.getMessage(), e);
- }
-
- /**
- * @param frontEnd
- * @param element
- */
- private void registerComponentsAndChildContainers(ReflectionFrontEnd frontEnd, Element element) throws ClassNotFoundException, XmlFrontEndException {
- if (element.getNodeName().equals("container")) {
- registerContainer(frontEnd, element);
- } else if (element.getNodeName().equals("component")) {
- registerComponent(frontEnd, element);
- } else {
- throw new XmlFrontEndException("Unknown element type: '" + element.getNodeName() + "'");
- }
- }
-
- /**
- * Accepts elements of the following type:<br>
- * &lt;component key="" classname=""/&gt; where key is optional. If key is left out the key value default to the classname<br>
- * It also accepts parameter childelements :<br>
- * &lt;parameter classname=""&gt;[Value]&lt;/parameter&gt;<br>
- * Full classname for type is needed, but shorthands for most primitives and wrapper classes exists.
- *
- * @param pico
- * @param element
- */
- private void registerComponent(ReflectionFrontEnd pico, Element element) throws ClassNotFoundException, XmlFrontEndException {
- String className = element.getAttribute("classname");
- String key = element.getAttribute("key");
- if(key == null || key.equals("")) {
- key = className;
- }
- // Check for initialization parameters
- if (element.getChildNodes().getLength() == 0) {
- pico.registerComponent(key, className);
- } else {
- List parameterTypes = new ArrayList();
- List parameterValues = new ArrayList();
- NodeList elemList = element.getChildNodes();
- int parameterIndex = 0;
- for (int index = 0; index < elemList.getLength(); index++) {
- if(elemList.item(index).getNodeType() == Document.ELEMENT_NODE) {
- Element paramElement = (Element) elemList.item(index);
- if (paramElement.getNodeName().equals("parameter")) {
- parameterTypes.add(handleShortHands(paramElement.getAttribute("classname")));
- if (paramElement.hasChildNodes() && paramElement.getChildNodes().item(0).getNodeType() == Document.TEXT_NODE) {
- parameterValues.add(paramElement.getChildNodes().item(0).getNodeValue());
- } else {
- throw new XmlFrontEndException("No value specified for parameter " + (String)parameterTypes.get(parameterIndex) + " at order " + parameterIndex + 1);
- }
- parameterIndex++;
- } else {
- throw new XmlFrontEndException("Unkown component parameter element '" + paramElement.getNodeName() + "'");
- }
- }
- }
- pico.registerComponent(key, className, (String[])parameterTypes.toArray(new String[parameterTypes.size()]), (String[])parameterValues.toArray(new String[parameterValues.size()]));
- }
- componentCount++;
- }
-
- /**
- * Handles shorthands for most of the simple type wrappers (translates from a shorthand for to the full
- * form, e.g. from "int" to "java.lang.Integer" og "Short" to "java.lang.Short"
- * @param name Shorthand
- * @return The translated shorthand or the parameter value in case no shorthand was found
- */
- private String handleShortHands(String name) {
- if (name.equals("String")) {
- return "java.lang.String";
- } else if (name.equals("")) {
- return "java.lang.String";
- } else if (name.equals("Integer")) {
- return "java.lang.Integer";
- } else if (name.equals("Float")) {
- return "java.lang.Float";
- } else if (name.equals("Double")) {
- return "java.lang.Double";
- } else if (name.equals("Boolean")) {
- return "java.lang.Boolean";
- } else if (name.equals("Short")) {
- return "java.lang.Short";
- } else if (name.equals("int")) {
- return "java.lang.Integer";
- } else if (name.equals("long")) {
- return "java.lang.Long";
- } else if (name.equals("float")) {
- return "java.lang.Float";
- } else if (name.equals("double")) {
- return "java.lang.Double";
- } else if (name.equals("boolean")) {
- return "java.lang.Boolean";
- } else if (name.equals("short")) {
- return "java.lang.Short";
- } else {
- return name;
- }
- }
-
-}

----------

nano /xml /src /java /org /nanocontainer /xml

XStreamXmlPseudoComponentFactory.java removed after 1.1

diff -N XStreamXmlPseudoComponentFactory.java
--- XStreamXmlPseudoComponentFactory.java 23 Oct 2003 09:03:54 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,27 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.xml;
-
-import org.nanocontainer.xml.XmlPseudoComponentFactory;
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-import com.thoughtworks.xstream.xml.dom.DomXMLReader;
-import com.thoughtworks.xstream.XStream;
-
-/**
- * @author Paul Hammant
- * @author Marcos Tarruella
- */
-public class XStreamXmlPseudoComponentFactory implements XmlPseudoComponentFactory {
- public Object makeInstance(Element elem) throws SAXException, ClassNotFoundException {
- XStream xs = new XStream();
- Object result = xs.fromXML(new DomXMLReader(elem));
- return result;
- }
-}

----------

nano /xml /src /java /org /nanocontainer /xml

XmlFrontEnd.java removed after 1.4

diff -N XmlFrontEnd.java
--- XmlFrontEnd.java 8 Nov 2003 12:13:37 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,36 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.xml;
-
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.PicoCompositionException;
-import org.picocontainer.PicoContainer;
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-
-import java.io.IOException;
-
-/**
- * This interface builds up a hierarchy of PicoContainers from an XML configuration file.
- *
- * @author Paul Hammant
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.4 $
- */
-
-public interface XmlFrontEnd {
-
- public PicoContainer createPicoContainer(Element rootElement, MutablePicoContainer mutablePicoContainer)
- throws IOException, SAXException, ClassNotFoundException, PicoCompositionException;
-
- public PicoContainer createPicoContainer(Element rootElement)
- throws IOException, SAXException, ClassNotFoundException, PicoCompositionException;
-}

----------

nano /xml /src /java /org /nanocontainer /xml

XmlFrontEndException.java removed after 1.2

diff -N XmlFrontEndException.java
--- XmlFrontEndException.java 8 Nov 2003 12:13:37 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,37 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.xml;
-
-import org.picocontainer.PicoCompositionException;
-
-/**
- * @author Jeppe Cramon
- */
-public class XmlFrontEndException extends PicoCompositionException {
-
- public XmlFrontEndException() {
- }
-
- /**
- * @param cause
- */
- public XmlFrontEndException(Throwable cause) {
- super(cause);
- }
-
- public XmlFrontEndException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public XmlFrontEndException(String message) {
- super(message);
- }
-
-}

----------

nano /xml /src /java /org /nanocontainer /xml

XmlPseudoComponentFactory.java removed after 1.1

diff -N XmlPseudoComponentFactory.java
--- XmlPseudoComponentFactory.java 22 Oct 2003 13:30:20 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,18 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.xml;
-
-import org.xml.sax.SAXException;
-import org.w3c.dom.Element;
-
-public interface XmlPseudoComponentFactory {
- Object makeInstance(Element elem) throws SAXException, ClassNotFoundException;
-}

----------

nano /xml /src /test /org /nanocontainer /xml

BeanXmlPseudoComponentFactoryTestCase.java removed after 1.1

diff -N BeanXmlPseudoComponentFactoryTestCase.java
--- BeanXmlPseudoComponentFactoryTestCase.java 23 Oct 2003 09:03:54 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,46 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.xml;
-
-import junit.framework.TestCase;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
-import java.io.StringReader;
-
-/**
- * @author Paul Hammant
- * @author Marcos Tarruella
- */
-public class BeanXmlPseudoComponentFactoryTestCase extends TestCase {
-
- public void testDeserialization() throws ParserConfigurationException, IOException, SAXException, ClassNotFoundException {
- BeanXmlPseudoComponentFactory xsf = new BeanXmlPseudoComponentFactory();
-
- StringReader sr = new StringReader("" +
- "<org.nanocontainer.xml.TestPseudoComp>" +
- "<foo>10</foo>" +
- "<bar>hello</bar>" +
- "</org.nanocontainer.xml.TestPseudoComp>"
- );
- InputSource is = new InputSource(sr);
- DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document doc = db.parse(is);
-
- Object o = xsf.makeInstance(doc.getDocumentElement());
- TestPseudoComp tsc = (TestPseudoComp) o;
- assertEquals("hello",tsc.getBar());
- assertEquals(10,tsc.getFoo());
- }
-}

----------

nano /xml /src /test /org /nanocontainer /xml

DefaultXmlFrontEndTestCase.java removed after 1.7

diff -N DefaultXmlFrontEndTestCase.java
--- DefaultXmlFrontEndTestCase.java 8 Nov 2003 12:13:37 -0000 1.7
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,155 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Aslak Hellesoy and Paul Hammant *
- *****************************************************************************/
-
-package org.nanocontainer.xml;
-
-import junit.framework.TestCase;
-import org.nanocontainer.testmodel.DefaultWebServerConfig;
-import org.nanocontainer.testmodel.WebServer;
-import org.picocontainer.PicoCompositionException;
-import org.picocontainer.PicoContainer;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringReader;
-
-/**
- * @author Aslak Helles&oslash;y
- * @version $Revision: 1.7 $
- */
-public class DefaultXmlFrontEndTestCase extends TestCase {
-
- private Element getRootElement(InputSource is) throws ParserConfigurationException, IOException, SAXException {
- return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is).getDocumentElement();
- }
-
- public void testCreateSimpleContainer() throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException, PicoCompositionException {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <component impl='org.nanocontainer.testmodel.DefaultWebServerConfig'/>" +
- " <component typekey='org.nanocontainer.testmodel.WebServer' impl='org.nanocontainer.testmodel.WebServerImpl'/>" +
- "</container>"));
-
- XmlFrontEnd inputSourceContainerFactory = new DefaultXmlFrontEnd();
- PicoContainer picoContainer = inputSourceContainerFactory.createPicoContainer(getRootElement(inputSource));
- assertNotNull(picoContainer.getComponentInstance(DefaultWebServerConfig.class));
- }
-
- public void testPicoInPico() throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException, PicoCompositionException {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <component impl='org.nanocontainer.testmodel.DefaultWebServerConfig'/>" +
- " <container>" +
- " <component typekey='org.nanocontainer.testmodel.WebServer' impl='org.nanocontainer.testmodel.WebServerImpl'/>" +
- " </container>" +
- "</container>"));
-
- XmlFrontEnd inputSourceFrontEnd = new DefaultXmlFrontEnd();
- PicoContainer rootContainer = inputSourceFrontEnd.createPicoContainer(getRootElement(inputSource));
- assertNotNull(rootContainer.getComponentInstance(DefaultWebServerConfig.class));
-
- PicoContainer childContainer = (PicoContainer) rootContainer.getChildContainers().iterator().next();
- assertNotNull(childContainer.getComponentInstance(WebServer.class));
- }
-
- public void testClassLoaderHierarchy() throws ParserConfigurationException, ClassNotFoundException, SAXException, IOException, PicoCompositionException {
-
- String testcompJarFileName = System.getProperty("testcomp.jar");
- // Paul's path to TestComp. PLEASE do not take out.
- //testcompJarFileName = "D:/DEV/nano/reflection/src/test-comp/TestComp.jar";
-
- assertNotNull("The testcomp.jar system property should point to nano/reflection/src/test-comp/TestComp.jar", testcompJarFileName);
- File testCompJar = new File(testcompJarFileName);
- File testCompJar2 = new File(testCompJar.getParentFile(), "TestComp2.jar");
- assertTrue(testCompJar.isFile());
- assertTrue(testCompJar2.isFile());
-
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <classpath>" +
- " <element file='" + testCompJar.getCanonicalPath() + "'/>" +
- " </classpath>" +
- " <component stringkey='foo' impl='TestComp'/>" +
- " <container>" +
- " <classpath>" +
- " <element file='" + testCompJar2.getCanonicalPath() + "'/>" +
- " </classpath>" +
- " <component stringkey='bar' impl='TestComp2'/>" +
- " </container>" +
- "</container>"));
-
- XmlFrontEnd inputSourceFrontEnd = new DefaultXmlFrontEnd();
- PicoContainer rootContainer = inputSourceFrontEnd.createPicoContainer(getRootElement(inputSource));
-
- Object fooTestComp = rootContainer.getComponentInstance("foo");
- assertNotNull("Container should have a 'foo' component", fooTestComp);
-
- PicoContainer childContainer = (PicoContainer) rootContainer.getChildContainers().iterator().next();
- Object barTestComp = childContainer.getComponentInstance("bar");
- assertNotNull("Container should have a 'bar' component", barTestComp);
-
- assertEquals("foo classloader should be parent of bar",fooTestComp.getClass().getClassLoader(),
- barTestComp.getClass().getClassLoader().getParent());
-
- }
-
- public void testInstantiateXmlWithMissingComponent() throws Exception, SAXException, ParserConfigurationException, IOException {
-
- try {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <component impl='Foo'/>" +
- "</container>"));
- PicoContainer rootContainer = new DefaultXmlFrontEnd().createPicoContainer(getRootElement(inputSource));
- fail("Should have thrown a ClassNotFoundException");
- } catch (ClassNotFoundException cnfe) {
- }
-
- }
-
- public void testInstantiateEmptyXml() throws Exception, SAXException, ParserConfigurationException, IOException {
-
- try {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- "</container>"));
- PicoContainer rootContainer = new DefaultXmlFrontEnd().createPicoContainer(getRootElement(inputSource));
- fail("Should have thrown a EmptyXmlCompositionException");
- } catch (EmptyXmlCompositionException cnfe) {
- }
- }
-
- public void testPseudoComponentCreation() throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException, PicoCompositionException {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <pseudocomponent factory='org.nanocontainer.xml.DefaultXmlFrontEndTestCase$TestFactory'>" +
- " <config-or-whatever/>"+
- " </pseudocomponent>" +
- "</container>"));
-
- XmlFrontEnd inputSourceContainerFactory = new DefaultXmlFrontEnd();
- PicoContainer picoContainer = inputSourceContainerFactory.createPicoContainer(getRootElement(inputSource));
- assertNotNull(picoContainer.getComponentInstances().get(0));
- assertTrue(picoContainer.getComponentInstances().get(0) instanceof String);
- assertEquals("Hello", picoContainer.getComponentInstances().get(0).toString());
-
- }
- public static class TestFactory implements XmlPseudoComponentFactory {
- public Object makeInstance(Element elem) throws SAXException, ClassNotFoundException {
- return "Hello";
- }
- }
-
-}

----------

nano /xml /src /test /org /nanocontainer /xml

ParameterXmlFrontEndTestCase.java removed after 1.1

diff -N ParameterXmlFrontEndTestCase.java
--- ParameterXmlFrontEndTestCase.java 26 Oct 2003 14:12:32 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,120 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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 Jeppe Cramon *
- *****************************************************************************/
-
-package org.nanocontainer.xml;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import junit.framework.TestCase;
-
-import org.nanocontainer.testmodel.DefaultWebServerConfig;
-import org.nanocontainer.testmodel.WebServerConfigComp;
-import org.picocontainer.PicoContainer;
-import org.picocontainer.defaults.DefaultPicoContainer;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- * @author Jeppe Cramon
- * @author Paul Hammant
- */
-public class ParameterXmlFrontEndTestCase extends TestCase {
-
- private Element getRootElement(InputSource is) throws ParserConfigurationException, IOException, SAXException {
- return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is).getDocumentElement();
- }
-
- public void testSingleDefaultContainer() throws XmlFrontEndException, IOException, SAXException, ClassNotFoundException, ParserConfigurationException {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <component classname='org.nanocontainer.testmodel.DefaultWebServerConfig'/>" +
- " <component key='org.nanocontainer.testmodel.WebServer' classname='org.nanocontainer.testmodel.WebServerImpl'/>" +
- "</container>"));
- ParameterXmlFrontEnd inputSourceContainerFactory = new ParameterXmlFrontEnd();
- PicoContainer picoContainer = inputSourceContainerFactory.createPicoContainer(getRootElement(inputSource));
- assertNotNull(picoContainer.getComponentInstance(DefaultWebServerConfig.class));
- }
-
- public void testContainerOverride() throws XmlFrontEndException, IOException, SAXException, ClassNotFoundException, ParserConfigurationException {
- OverriddenPicoContainer.used = false;
- InputSource inputSource = new InputSource(new StringReader(
- "<container classname='"+OverriddenPicoContainer.class.getName()+"'>" +
- " <component classname='org.nanocontainer.testmodel.DefaultWebServerConfig'/>" +
- " <component key='org.nanocontainer.testmodel.WebServer' classname='org.nanocontainer.testmodel.WebServerImpl'/>" +
- "</container>"));
- ParameterXmlFrontEnd inputSourceContainerFactory = new ParameterXmlFrontEnd();
- PicoContainer picoContainer = inputSourceContainerFactory.createPicoContainer(getRootElement(inputSource));
- assertNotNull(picoContainer.getComponentInstance(DefaultWebServerConfig.class));
- assertTrue("OverriddenPicoContainer should have been used", OverriddenPicoContainer.used);
- }
-
- public void testPicoInPico() throws XmlFrontEndException, IOException, SAXException, ClassNotFoundException, ParserConfigurationException {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <component classname='org.nanocontainer.testmodel.DefaultWebServerConfig'/>" +
- " <container>" +
- " <component key='org.nanocontainer.testmodel.WebServer' classname='org.nanocontainer.testmodel.WebServerImpl'/>" +
- " </container>" +
- "</container>"));
-
- ParameterXmlFrontEnd inputSourceContainerFactory = new ParameterXmlFrontEnd();
- PicoContainer rootContainer = inputSourceContainerFactory.createPicoContainer(getRootElement(inputSource));
- assertNotNull(rootContainer.getComponentInstance(DefaultWebServerConfig.class));
-
- PicoContainer childContainer = (PicoContainer) rootContainer.getChildContainers().iterator().next();
- assertNotNull(childContainer.getComponentInstance("org.nanocontainer.testmodel.WebServer"));
- }
-
- public void testInstantiationOfComponentsWithParams() throws XmlFrontEndException, IOException, SAXException, ClassNotFoundException, ParserConfigurationException {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <component classname='org.nanocontainer.testmodel.WebServerConfigComp'>" +
- " <parameter classname='String'>localhost</parameter>" +
- " <parameter classname='int'>8080</parameter>" +
- " </component>" +
- " <component key='org.nanocontainer.testmodel.WebServer' classname='org.nanocontainer.testmodel.WebServerImpl'/>" +
- "</container>"));
- ParameterXmlFrontEnd inputSourceContainerFactory = new ParameterXmlFrontEnd();
- PicoContainer picoContainer = inputSourceContainerFactory.createPicoContainer(getRootElement(inputSource));
- assertNotNull(picoContainer.getComponentInstance(WebServerConfigComp.class));
- WebServerConfigComp config = (WebServerConfigComp) picoContainer.getComponentInstance(WebServerConfigComp.class);
- assertEquals("localhost", config.getHost());
- assertEquals(8080, config.getPort());
- }
-
- public void testInstantiationOfComponentsWithDefaultParamHandling() throws XmlFrontEndException, IOException, SAXException, ClassNotFoundException, ParserConfigurationException {
- InputSource inputSource = new InputSource(new StringReader(
- "<container>" +
- " <component classname='org.nanocontainer.testmodel.WebServerConfigComp'>" +
- " <parameter>localhost</parameter>" +
- " <parameter classname='int'>8080</parameter>" +
- " </component>" +
- " <component key='org.nanocontainer.testmodel.WebServer' classname='org.nanocontainer.testmodel.WebServerImpl'/>" +
- "</container>"));
- ParameterXmlFrontEnd inputSourceContainerFactory = new ParameterXmlFrontEnd();
- PicoContainer picoContainer = inputSourceContainerFactory.createPicoContainer(getRootElement(inputSource));
- assertNotNull(picoContainer.getComponentInstance(WebServerConfigComp.class));
- WebServerConfigComp config = (WebServerConfigComp) picoContainer.getComponentInstance(WebServerConfigComp.class);
- assertEquals("localhost", config.getHost());
- assertEquals(8080, config.getPort());
- }
-
- public static class OverriddenPicoContainer extends DefaultPicoContainer {
- public static boolean used;
- public OverriddenPicoContainer() {
- used = true;
- }
- }
-}

----------

nano /xml /src /test /org /nanocontainer /xml

TestPseudoComp.java removed after 1.2

diff -N TestPseudoComp.java
--- TestPseudoComp.java 26 Oct 2003 14:12:32 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,30 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.xml;
-
-public class TestPseudoComp {
- private int foo;
- private String bar;
-
- public int getFoo() {
- return foo;
- }
- public String getBar() {
- return bar;
- }
-
- public void setFoo(int foo) {
- this.foo = foo;
- }
-
- public void setBar(String bar) {
- this.bar = bar;
- }
-}

----------

nano /xml /src /test /org /nanocontainer /xml

XStreamXmlPseudoComponentFactoryTestCase.java removed after 1.1

diff -N XStreamXmlPseudoComponentFactoryTestCase.java
--- XStreamXmlPseudoComponentFactoryTestCase.java 23 Oct 2003 09:03:54 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,46 +0,0 @@

-/*****************************************************************************
- * Copyright (C) NanoContainer 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.nanocontainer.xml;
-
-import junit.framework.TestCase;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
-import java.io.StringReader;
-
-/**
- * @author Paul Hammant
- * @author Marcos Tarruella
- */
-public class XStreamXmlPseudoComponentFactoryTestCase extends TestCase {
-
- public void testDeserialization() throws ParserConfigurationException, IOException, SAXException, ClassNotFoundException {
- XStreamXmlPseudoComponentFactory xsf = new XStreamXmlPseudoComponentFactory();
-
- StringReader sr = new StringReader("" +
- "<org.nanocontainer.xml.TestPseudoComp>" +
- "<foo>10</foo>" +
- "<bar>hello</bar>" +
- "</org.nanocontainer.xml.TestPseudoComp>"
- );
- InputSource is = new InputSource(sr);
- DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document doc = db.parse(is);
-
- Object o = xsf.makeInstance(doc.getDocumentElement());
- TestPseudoComp tsc = (TestPseudoComp) o;
- assertEquals("hello",tsc.getBar());
- assertEquals(10,tsc.getFoo());
- }
-}