[picocontainer-scm] [5555] java/2.x/trunk/pico/distribution/src/site/content/regex.html: more words on regex

paul-yCVjj/[email protected]
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <[email protected]>
Revision 5555
Author paul
Date 2009-11-01 12:48:40 -0600 (Sun, 01 Nov 2009)

Log Message

more words on regex

Modified Paths

- java/2.x/trunk/pico/distribution/src/site/content/regex.html

Diff

Modified: java/2.x/trunk/pico/distribution/src/site/content/regex.html (5554 => 5555)

--- java/2.x/trunk/pico/distribution/src/site/content/regex.html 2009-11-01 18:48:25 UTC (rev 5554)
+++ java/2.x/trunk/pico/distribution/src/site/content/regex.html 2009-11-01 18:48:40 UTC (rev 5555)
@@ -24,5 +24,37 @@
assertEquals("[Braeburn, Granny Smith]", apples.toString());
</pre>
</div>
+<p>The above example is fed the regular expression in the getComponent(..) invocation, which may be in practical. Here is one where the parameter names of the injectee are used for correlation purposes </p>
+<div class="source">
+<pre>
+public static class NeedsApples {
+ private List&lt;String> apples;
+ public NeedsApples(List&lt;String> apples) { // correlate param name to regex below
+ this.apples = apples;
+ }
+}
+
+public static class NeedsPlums {
+ private List&lt;String> plums;
+ public NeedsPlums(List&lt;String> plums) { // correlate param name to regex below
+ this.plums = plums;
+ }
+}
+
+....
+
+MutablePicoContainer pico = new DefaultPicoContainer(
+ new ComposingMonitor(new RegexComposer("apple[1-9]", "apples"), new RegexComposer("plum*", "plums")));
+pico.addComponent("apple1", "Braeburn")
+ .addComponent("apple2", "Granny Smith")
+ .addComponent("plumV", "Victoria");
+pico.as(USE_NAMES).addComponent(NeedsApples.class)
+ .as(USE_NAMES).addComponent(NeedsPlums.class);
+
+assertEquals("[Braeburn, Granny Smith]", pico.getComponent(NeedsApples.class).apples.toString());
+
+assertEquals("[Victoria]", pico.getComponent(NeedsPlums.class).plums.toString());
+</pre>
+</div>
</body>
</html>
\ No newline at end of file

----------

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.