+

Search Tips   |   Advanced Search

Object values and the Blueprint Container

The Blueprint Container specification defines XML elements that describe different types of object values and we can use in manager definitions.

For example, we can use XML value elements in a bean manager to specify argument or property values, or in a service manager to specify the values of service properties. The XML value elements are converted into value objects and injected into the manager components. We can use the following XML value elements:

ref

The ref element defines a reference to a top-level manager. The component-id attribute specifies an ID of a top-level manager. The injected value will be the object that the referenced manager returns.

The following partial Java class and Blueprint XML example code shows an example of the ref value element. The accountOne bean instance is injected into the managedAccount property of the accountManagerTwo bean.

public class AccountManager {
   ...
   public void setManagedAccount(Account account) {
      ...   
   }
}
<bean id="accountOne" class="org.apache.aries.simple.Account">
   <argument value="1"/>
   <property name="description" value="#1 account"/>
</bean>

<bean id="accountManagerTwo" class="org.apache.aries.AccountManager">
   <property name="managedAccount">
       <ref component-id="accountOne"/>
   </property>
</bean>

idref

The idref element defines an ID of a top-level manager. The injected value is the component-id, as specified by the component-id attribute. The idref element is used to ensure that a manager with the specified ID actually exists before the manager is activated.

value

The value element represents an object to create from the string content of the element. Optionally, use the type attribute to specify a type to convert the string content to. If we do not specify the type attribute, the string content is converted to the type that it is injected into.

null

The null element represents Java null.

list

The list element is a collection and represents a java.util.List object. Any XML value element that is described in this section can be a sub-element of this collection. Optionally, we can set the value-type attribute to specify a default type for the collection sub-elements.

set

The set element is a collection and represents a java.util.Set object. Any XML value element that is described in this section can be a sub-element of this collection. Optionally, we can set the value-type attribute to specify a default type for the collection sub-elements.

array

The array element is a collection and represents an Object[] array. Any XML value element that is described in this section can be a sub-element of this collection. Optionally, we can set the value-type attribute to specify a default type for the collection sub-elements.

The following Blueprint XML example code shows how we can combine XML value elements to create a list. The created list will contain the following items:

  • The string 123
  • A java.math.BigInteger object with a value of 456
  • A null
  • A java.util.Set object with two values that are of type java.lang.Integer

<list>
   <value>123</value>
   <value type="java.math.BigInteger">456</value>
   <null/>
   <set value-type="java.lang.Integer">
      <value>1</value>
      <value>2</value>
   </set>      
</list>

props

The props element represents a java.util.Properties object where the keys and values are of String type. The prop sub-elements represent the individual properties. To specify the property key, we use a key attribute, and to specify the property value, we use a value attribute or specify the content of the element.

The following Blueprint XML example code shows an example of the props value element.

<props>
   <prop key="yes">good</prop>
   <prop key="no" value="bad"/>
</props>

map

The map element represents a java.util.Map object where the keys and the values can be arbitrary objects. The entry sub-elements represent the individual properties.

To specify the key, we use a key or key-ref attribute, or an inline declaration in a key sub-element. We can specify an inline key using any XML value element that is described in this section, except the null element. In the Blueprint Container specification, map elements cannot have null keys.

To specify the value, we use a value or value-ref attribute, or an inline declaration. We can specify an inline value using any XML value element that is described in this section. However, the inline key can be specified as any of the XML value elements except the null element.

The key-ref and value-ref attributes specify an ID of a top-level manager and are used to obtain an object from the specified manager as the property key or value. The map element can specify key-type and value-type attributes to define a default type for keys and values.

The following Blueprint XML example code shows an example of the map value element and how the entries of a map object can be constructed in several ways. The created map object will contain the following entries:

  • A myKey1 String key that is mapped to myValue String.
  • A key that is an object that the account bean manager returns and that is mapped to myValue String.
  • A key that is a java.lang.Integer object with a value of 123 and that is mapped to myValue String.
  • A myKey2 String key is mapped to a value that is an object that the account bean manager returns.
  • A myKey3 String key is mapped to a value that is a java.lang.Long object with a value of 345.
  • A key that is a java.net.URI object with a value of urn:ibm and that is mapped to a value that is a java.net.URL object with a value of http://ibm.com value.

<map>
   <entry key="myKey1" value="myValue"/>

   <entry key-ref="account" value="myValue"/>
   <entry value="myValue">
      <key>
         <value type="java.lang.Integer">123</value>
      <key/>
   </entry>

   <entry key="myKey2" value-ref="account">
   <entry key="myKey3">           
      <value type="java.lang.Long">345</value>          
   </entry>

   <entry> 
      <key>
         <value type="java.net.URI">urn:ibm</value>
      <key/>
      <value type="java.net.URL">http://ibm.com</value>
   </entry>
</map>            

Each manager can also be specified as a value using an inline declaration. The following Blueprint XML example code shows an inline bean manager.

<bean id="accountManagerThree" class="org.apache.aries.AccountManager">
   <property name="managedAccount">
      <bean class="org.apache.aries.simple.Account">
         <argument value="10"/>
         <property name="description" value="Inline Account"/>
      </bean>
   </property>
</bean>     


Related:

  • Blueprint bundles
  • Blueprint XML
  • Beans and the Blueprint Container
  • Services and the Blueprint Container
  • References and the Blueprint Container
  • Scopes and the Blueprint Container
  • Object life cycles and the Blueprint Container
  • Resource references and the Blueprint Container
  • Dynamism and the Blueprint Container
  • Type converters and the Blueprint Container
  • JNDI lookup for blueprint components
  • Developing an OSGi application
  • OSGi Service Platform Release 4 Version 4.2 Enterprise Specification
  • Building OSGi applications with the Blueprint Container specification




    File name: was314.html

    prettyPrint();