6.4. InitParams configuration object

InitParams are the configuration object that is essentially a map of key-value pairs, where key is always a String, and value can be any type that can be described using the kernel configuration.xml file.

Service components that form GateIn 3.5 infrastructure use the InitParams object to configure themselves. A component can have one instance of InitParams injected at most. If the service component's constructor takes InitParams as any of the parameters, it will automatically be injected at the component instantiation time. The xml configuration for a service component that expects the InitParams object must include the <init-params> element (even if the empty one).

To learn about how the kernel xml configuration syntax looks for creating InitParams instances, see the following example.

Example: InitParams - properties-param


<component>
     <key>org.exoplatform.services.naming.InitialContextInitializer</key>
     <type>org.exoplatform.services.naming.InitialContextInitializer</type>
     <init-params>
        <properties-param>
           <name>default-properties</name>
           <description>Default initial context properties</description>
           <property name="java.naming.factory.initial"
                    value="org.exoplatform.services.naming.SimpleContextFactory" />
        </properties-param>
     </init-params>
  </component>

The InitParams object description begins with the <init-params> element. It can have zero or more children elements, each of which is one of <value-param>, <values-param>, <properties-param>, or <object-param>. Each of these child elements takes a <name> that serves as a map entry key, and an optional <description>. It also takes a type-specific value specification.

For <properties-param>, the value specification is in the form of one or more <property> elements, each of which specifies two strings - a property name, and a property value. Each <properties-params> defines one java.util.Properties instance. Also, see Example: HibernateService using variables for an example.

Example: InitParams - value-param


<component>
     <key>org.exoplatform.services.transaction.TransactionService</key>
     <type>org.exoplatform.services.transaction.impl.jotm.TransactionServiceJotmImpl</type>
     <init-params>
        <value-param>
           <name>timeout</name>
           <value>5</value>
        </value-param>
     </init-params>
</component>

For <value-param>, the value specification is in the form of <value> element, which defines one String instance.

Example: InitParams - values-param


<component>
    <key>org.exoplatform.services.resources.ResourceBundleService</key>
    <type>org.exoplatform.services.resources.impl.SimpleResourceBundleService</type>
      <init-params>
        <values-param>
          <name>classpath.resources</name>
          <description>The resources  that start with the following package name should be load from file system</description>
          <value>locale.portlet</value>
        </values-param>

        <values-param>
          <name>init.resources</name>
          <description>Store the following resources into the db for  the first launch </description>
          <value>locale.test.resources.test</value>
        </values-param>

        <values-param>
          <name>portal.resource.names</name>
          <description>The properties files of  the portal ,  those file will be merged
            into one ResourceBundle properties </description>
          <value>local.portal.portal</value>
          <value>local.portal.custom</value>
        </values-param>
      </init-params>
</component>

For <values-param>, the value specification is in the form of one or more <value> elements, each of which represents one String instance, where all the String values are then collected into a java.util.List instance.

Example: InitParams - object-param


<component>
     <key>org.exoplatform.services.cache.CacheService</key>
     <jmx-name>cache:type=CacheService</jmx-name>
     <type>org.exoplatform.services.cache.impl.CacheServiceImpl</type>
     <init-params>
        <object-param>
           <name>cache.config.default</name>
           <description>The default cache configuration</description>
           <object type="org.exoplatform.services.cache.ExoCacheConfig">
              <field name="name">
                 <string>default</string>
              </field>
              <field name="maxSize">
                 <int>300</int>
              </field>
              <field name="liveTime">
                 <long>300</long>
              </field>
              <field name="distributed">
                 <boolean>false</boolean>
              </field>
              <field name="implementation">
                 <string>org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache</string>
              </field>
           </object>
        </object-param>
     </init-params>
</component>

For <object-param>, the value specification comes in a form of the <object> element, which is used for the POJO style object specification (you specify an implementation class - <type>, and property values - <field>).

Also see Example: Portal container declaration for an example of specifying a field of the Collection type.

The InitParams structure - the names and types of entries is specific for each service, as it is the code inside service components' class that decides what entry names to look up and what types it expects to find.

See also

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus