[jboss-cvs] JBossAS SVN: r90082 - projects/microcontainer/mcdocs/trunk/userguide/src/main/docbook.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 11 07:10:53 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-06-11 07:10:53 -0400 (Thu, 11 Jun 2009)
New Revision: 90082

Modified:
   projects/microcontainer/mcdocs/trunk/userguide/src/main/docbook/User_Guide.xml
Log:
Fix up the examples so that they match the actual annotations used. Add some more information about the different enum types used in the annotations.

Modified: projects/microcontainer/mcdocs/trunk/userguide/src/main/docbook/User_Guide.xml
===================================================================
--- projects/microcontainer/mcdocs/trunk/userguide/src/main/docbook/User_Guide.xml	2009-06-11 07:48:32 UTC (rev 90081)
+++ projects/microcontainer/mcdocs/trunk/userguide/src/main/docbook/User_Guide.xml	2009-06-11 11:10:53 UTC (rev 90082)
@@ -1190,11 +1190,13 @@
         <itemizedlist>
           <listitem>
             <para>Default constructor</para>
-            <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;/&gt;</programlisting>
+            <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot;
+      class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;/&gt;</programlisting>
           </listitem>
           <listitem>
-            <para>Contructor with parameters</para>
-            <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
+            <para>Constructor with parameters</para>
+            <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; 
+      class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
     &lt;constructor&gt;
         &lt;property name=&quot;ABoolean&quot;&gt;true&lt;/property&gt;
         &lt;property name=&quot;ACharacter&quot;&gt;x&lt;/property&gt;
@@ -1204,14 +1206,16 @@
           </listitem>
           <listitem>
             <para>Static factory method</para>
-            <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
+            <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; 
+      class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
     &lt;constructor factoryClass=&quot;org.jboss.test.javabean.support.SimpleBeanFactory&quot;
                  factoryMethod=&quot;newInstance&quot;/&gt;
 &lt;/javabean&gt;</programlisting>
           </listitem>
           <listitem>
             <para>Static factory method with parameters</para>
-            <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
+            <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; 
+      class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
     &lt;constructor factoryClass=&quot;org.jboss.test.javabean.support.SimpleBeanFactory&quot;
                  factoryMethod=&quot;newInstance&quot;&gt;
         &lt;property name=&quot;AString&quot;&gt;StringValue&lt;/property&gt;
@@ -1224,7 +1228,8 @@
           <para>JavaBean declarations do not include a <code>name</code> attribute which means that you cannot inject references into other JavaBeans or lookup a reference to a JavaBean instance from a client at runtime.</para>
         </note>
         <para>Once a JavaBean has been constructed then simple injection of property values is possible using the &lt;property&gt; element: </para>
-        <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
+        <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; 
+      class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
     &lt;property name=&quot;ADouble&quot;&gt;3.14e12&lt;/property&gt;
     &lt;property name=&quot;ADate&quot;&gt;Jan 01 00:00:00 CET 2001&lt;/property&gt;
     &lt;property name=&quot;ABigDecimal&quot;&gt;12e4&lt;/property&gt;
@@ -1232,14 +1237,16 @@
     &lt;property name=&quot;abyte&quot;&gt;12&lt;/property&gt; 
 &lt;/javabean&gt;</programlisting>
         <para>As with properties defined using the bean-deployer XML schema the string values are converted into objects of the correct type using JavaBean <ulink url="http://java.sun.com/j2se/1.5.0/docs/api/java/beans/PropertyEditor.html">PropertyEditors</ulink>. For cases where the type is ambiguous, e.g. when defining numbers, you can specify the required type by including a <code>class</code> attribute: </para>
-        <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
+        <programlisting role="XML">&lt;javabean xmlns=&quot;urn:jboss:javabean:2.0&quot; 
+      class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
     &lt;property name=&quot;ANumber&quot; class=&quot;java.lang.Long&quot;&gt;12345&lt;/property&gt; 
 &lt;/javabean&gt;</programlisting>
         <important>
           <para>Beans created using the bean-deployer XML schema  can include JavaBeans  created using the javabean XML schema instead of string values. This provides a simple way to inject objects composed of multiple values into a bean property without having to write a complicated property editor:</para>
           <programlisting role="XML">&lt;bean name=&quot;example&quot; class=&quot;org.jboss.acme.Example&quot;&gt;
     &lt;property name=&quot;myProperty&quot;&gt;
-        &lt;javabean xmlns=&quot;urn:jboss:javabean:1.0&quot; class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
+        &lt;javabean xmlns=&quot;urn:jboss:javabean:1.0&quot; 
+              class=&quot;org.jboss.test.javabean.support.SimpleBean&quot;&gt;
             &lt;property name=&quot;ADate&quot;&gt;Jan 01 00:00:00 CET 2001&lt;/property&gt;
             &lt;property name=&quot;ABigDecimal&quot;&gt;12e4&lt;/property&gt;
         &lt;/javabean&gt;
@@ -1304,7 +1311,8 @@
         &lt;/property&gt;
     &lt;/bean&gt;
 
-    &lt;bean xmlns=&quot;urn:jboss:spring-beans:2.0&quot; id=&quot;testBean&quot; class=&quot;org.jboss.test.TestBean&quot;&gt;
+    &lt;bean xmlns=&quot;urn:jboss:spring-beans:2.0&quot; id=&quot;testBean&quot; 
+          class=&quot;org.jboss.test.TestBean&quot;&gt;
         &lt;property name=&quot;mylist&quot;&gt;
             &lt;list value-type=&quot;java.lang.String&quot;&gt;
                 &lt;value&gt;onel&lt;/value&gt;
@@ -1519,7 +1527,7 @@
         </itemizedlist>
         <para>You can also specify javabeans as parameters if required using the @JavaBeanValue annotation or &lt;javabean&gt; element. In this particular case the annotation is not very useful as it can only call the default constructor of the javabean class to create an instance. If you want to use a different constructor or inject properties then you should use the XML element instead.</para>
         <programlisting role="JAVA">@Constructor
-public TestConstructorBean(@StringValue(&quot;this is a test constructor&quot;) String testString, @JavaBeanValue(&quot;org.jboss.test.Person&quot;) Person testPerson) {
+public TestConstructorBean(@StringValue(&quot;this is a test constructor&quot;) String testString, @JavaBeanValueorg.jboss.test.Person.class) Person testPerson) {
     ...
 }</programlisting>
         <programlisting role="XML">&lt;bean name=&quot;Test&quot; class=&quot;org.jboss.example.constructor.TestConstructorBean&quot;&gt;
@@ -1572,7 +1580,8 @@
             <para>Static factory method with parameters</para>
             <programlisting role="JAVA">@Factory (factoryClass=&quot;org.jboss.example.MyFactory&quot;,
           factoryMethod=&quot;newInstance&quot;,
-          parameters={@Value(string=@StringValue(&quot;a string&quot;)), at Value(string=@StringValue(&quot;7&quot;))})
+          parameters={@Value(string=@StringValue(&quot;a string&quot;)),
+               @Value(string=@StringValue(&quot;7&quot;))})
 public class SimpleBean {
    ...
 }</programlisting>
@@ -1586,7 +1595,7 @@
           </listitem>
           <listitem>
             <para>Non-static factory method</para>
-            <programlisting role="JAVA">@Factory (factory=@Value(javabean=@JavaBeanValue(&quot;org.jboss.example.MyOtherFactory&quot;)),
+            <programlisting role="JAVA">@Factory (factory=@Value(javabean=@JavaBeanValue(org.jboss.example.MyOtherFactory.class)),
           factoryMethod=&quot;createBean&quot;)
 public class SimpleBean {
     ...
@@ -1601,7 +1610,7 @@
           </listitem>
           <listitem>
             <para>Non-static factory method with parameters</para>
-            <programlisting role="JAVA">@Factory (factory=@Value(javabean=@JavaBeanValue(&quot;org.jboss.example.MyOtherFactory&quot;)),
+            <programlisting role="JAVA">@Factory (factory=@Value(javabean=@JavaBeanValue(org.jboss.example.MyOtherFactory.class)),
           factoryMethod=&quot;createBean&quot;,
           parameters={@Value(string=@StringValue(&quot;a string&quot;)), at Value(string=@StringValue(&quot;7&quot;))})
 public class SimpleBean {
@@ -1727,7 +1736,8 @@
         ...
     }
 }</programlisting>
-        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
+        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; 
+      class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
     &lt;property name=&quot;title&quot;&gt;JBoss Microcontainer&lt;/property&gt;
     &lt;property name=&quot;link&quot;&gt;http://www.jboss.org&lt;/property&gt;
     &lt;property name=&quot;number&quot;&gt;4&lt;/property&gt;
@@ -1738,7 +1748,8 @@
         ...
    }
 }</programlisting>
-        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
+        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; 
+      class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
     &lt;property name=&quot;number&quot; class=&quot;java.lang.Long&quot;&gt;4&lt;/property&gt;
 &lt;/bean&gt; </programlisting>
         <para>Sometimes you may want to pass in a value that isn&apos;t of the same type as the property but can be progressed into it. Progression is typically used for converting numbers from one type to another, e.g. Short to Int or Float to Double. JBoss Microcontainer by default will automatically perform progression using a <code>SimpleProgressionConverter</code> implementation.</para>
@@ -1771,18 +1782,21 @@
         <programlisting role="JAVA">public void setTitle(@NullValue String title) {
     ...
 } </programlisting>
-        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
+        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; 
+      class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
     &lt;property name=&quot;title&quot;&gt;&lt;null/&gt;&lt;/property&gt;
 &lt;/bean&gt; </programlisting>
         <para>Similarly if you want to refer to the current object then you  should use the @ThisValue annotation or &lt;this/&gt; element.</para>
         <programlisting role="JAVA">public void setObject(@ThisValue Object target) {
     ...
 } </programlisting>
-        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
+        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; 
+      class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
     &lt;property name=&quot;target&quot;&gt;&lt;this/&gt;&lt;/property&gt;
 &lt;/bean&gt; </programlisting>
         <para>Property values can also be defined using a longer form of XML if you prefer.</para>
-        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
+        <programlisting role="XML">&lt;bean name=&quot;PropertiesBean&quot; 
+      class=&quot;org.jboss.example.microcontainer.properties.PropertiesBean&quot;&gt;
     &lt;property name=&quot;number&quot;&gt;
         &lt;value class=&quot;java.lang.Long&quot;&gt;4&lt;/value&gt;
     &lt;/property&gt;
@@ -1919,7 +1933,7 @@
         &lt;/map&gt;
     &lt;/property&gt;
 &lt;/bean&gt; </programlisting>
-        <para>So far we have defined collections, lists, sets, arrays and maps but all of these have multiple implementations, e.g. java.util.ArrayList, java.util.LinkedList,  so which are we using at runtime? By default JBoss Microcontainer will look for an existing instance using the corresponding getter method for the property. If one is found then it is used. If not then the type of the property is analysed and providing that it represents a class (not an interface) then this is used to create a new instance. Failing that a default instance will be created as follows:</para>
+        <para>So far we have defined collections, lists, sets, arrays and maps but all of these have multiple implementations, e.g. java.util.ArrayList, java.util.LinkedList,  so which are we using at runtime? By default JBoss Microcontainer will look for an existing instance using the corresponding getter method for the property. If one is found then it is used, and any values defined in the annotations or xml deployment descriptor will be added to the exisiting values. If not then the type of the property is analysed and providing that it represents a class (not an interface) then this is used to create a new instance. Failing that a default instance will be created as follows:</para>
         <itemizedlist>
           <listitem>
             <para>Collection - java.util.ArrayList</para>
@@ -1988,8 +2002,8 @@
         <para>If you need to pass any parameters to the method then you can use multiple  @Parameter annotations or nested &lt;parameter&gt; elements. </para>
         <programlisting role="JAVA">@ValueFactory(bean=&quot;SimpleBean&quot;,
               method=&quot;getFullName&quot;,
-              parameters=&quot;{@Parameter(string=@StringValue(&quot;Bob&quot;)),
-                           @Parameter(string=@StringValue(&quot;Smith&quot;))}&quot;)
+              parameters={@Parameter(string=@StringValue(&quot;Bob&quot;)),
+                           @Parameter(string=@StringValue(&quot;Smith&quot;))})
 public void setName(String name) {
     ...
 } </programlisting>
@@ -2004,7 +2018,7 @@
         <para>Alternatively if only one parameter is required then you can use the <code>parameter</code> attribute to create a shorthand version. However this only works for values that can be created from strings.</para>
         <programlisting role="JAVA">@ValueFactory(bean=&quot;SimpleBean&quot;,
               method=&quot;getFullName&quot;,
-              parameter=&quot;@Parameter(string=@StringValue(&quot;Bob&quot;))&quot;)
+              parameter=&quot;Bob&quot;)
 public void setName(String name) {
     ...
 } </programlisting>
@@ -2064,7 +2078,7 @@
         <title>Injecting context information</title>
         <para>You may recall that inside the microcontainer each bean is represented by a context which holds amongst other things the bean&apos;s current state. This context information can be injected into bean properties or constructor/factory-method parameters using the @Inject annotation or &lt;inject&gt; element together with a <code>fromContext</code> attribute.</para>
         <programlisting role="JAVA">@Inject(bean=&quot;otherBean&quot;,
-        fromContext=&quot;beanInfo&quot;)
+        fromContext=FromContext.BEANINFO)
 public void setBeanInfo(BeanInfo beanInfo) {
     ...
 }</programlisting>
@@ -2074,7 +2088,7 @@
     &lt;/property&gt;
 &lt;/bean&gt;</programlisting>
         <para>If you want to inject information about the current bean&apos;s context then you can simply omit the <code>bean</code> attribute.</para>
-        <programlisting role="JAVA">@Inject(fromContext=&quot;beanInfo&quot;)
+        <programlisting role="JAVA">@Inject(fromContext=FromContext.BEANINFO)
 public void setBeanInfo(BeanInfo beanInfo) {
     ...
 }</programlisting>
@@ -2083,7 +2097,8 @@
         &lt;inject fromContext=&quot;beaninfo&quot;/&gt;
     &lt;/property&gt;
 &lt;/bean&gt;</programlisting>
-        <para>The <code>fromContext</code> attribute can take the following values:</para>
+        <para>The <code>fromContext</code> attribute can take the following values from the
+        <code>org.jboss.beans.metadata.api.model.FromContext</code> enum:</para>
         <itemizedlist>
           <listitem>
             <para>name - the name of the bean</para>
@@ -2132,21 +2147,23 @@
     &lt;property name=&quot;threadPool&quot;&gt;&lt;inject/&gt;&lt;/property&gt;
 &lt;/bean&gt; </programlisting>
         <para>By default the microcontainer will search for a bean whose class matches that of the parameter/property. However you can change this behaviour when auto-wiring properties so that the microcontainer searches for a bean whose name matches the property name. This is done using the <code>type</code> attribute of the &lt;inject&gt; element.</para>
-        <programlisting role="JAVA">@Inject(type=&quot;ByName&quot;)
+        <programlisting role="JAVA">@Inject(type=AutowireType.By_NAME)
 public void setThreadPool(ThreadPool pool) {
     ...
 }</programlisting>
         <programlisting role="XML">&lt;bean name=&quot;propInj&quot; class=&quot;com.acme.Example&quot;&gt;
     &lt;property name=&quot;threadPool&quot;&gt;&lt;inject type=&quot;ByName&quot;/&gt;&lt;/property&gt;
 &lt;/bean&gt; </programlisting>
+        <para>The <code>org.jboss.beans.metadata.api.model.AutowireType</code> enum defines the valid values to use. <code>AutowireType.By_CLASS</code> is the default if using annotations, and <code>ByClass</code> the default when using xml.</para>
         <para>If no match is found then by default the deployment will fail but for certain properties it may be acceptable for injection to occur after deployment. In these cases you can specify that a property should be set using a callback mechanism whenever a suitable bean becomes available. This is done using the <code>option</code> attribute.</para>
-        <programlisting role="JAVA">@Inject(type=&quot;ByName&quot;, option=&quot;Callback&quot;)
+        <programlisting role="JAVA">@Inject(type=AutowireType.By_NAME, option=InjectOption.CALLBACK)
 public void setThreadPool(ThreadPool pool) {
     ...
 }</programlisting>
         <programlisting role="XML">&lt;bean name=&quot;propInj&quot; class=&quot;com.acme.Example&quot;&gt;
     &lt;property name=&quot;threadPool&quot;&gt;&lt;inject type=&quot;ByName&quot; option=&quot;Callback&quot;/&gt;&lt;/property&gt;
 &lt;/bean&gt; </programlisting>
+        <para>The <code>org.jboss.beans.metadata.api.model.InjectOption</code> enum defines the valid values to use. <code>InjectOption.STRICT</code> is the default when using annotations, and <code>Strict</code> the default when using xml. Another possible value for <code>option</code> is <code>InjectOption.OPTIONAL</code> when using annotations, and <code>Optional</code> when using xml, if this option is used the dependency is injected if present at injection time, otherwise it is ignored.</para>
         <para>Sometimes you may want to prevent a bean from being injected automatically using auto-wiring. In these situations you can set its <code>autowire-candidate</code> attribute to false so that it&apos;s not included in the search for matching beans. This is not currently possible using annotations as there is no annotation to declare a bean.</para>
         <programlisting role="XML">&lt;bean name=&quot;ignored&quot; class=&quot;com.acme.Example&quot; autowire-candidate=&quot;false&quot; /&gt;</programlisting>
       </section>




More information about the jboss-cvs-commits mailing list