The Command service

The Command service is based on Apache's commons-chain and allows to encapsulate methods to execute as a Command objects

A Command framework Application can create own Catalog of Commands, configuring org.exoplatform.services.command.impl.CommonsXMLConfigurationPlugin as following:

<component>
    <key>org.exoplatform.services.command.impl.CommandService</key>
    <type>org.exoplatform.services.command.impl.CommandService</type>
    <component-plugins>    
      <component-plugin> 
          <name>config.catalog</name>
          <set-method>addPlugin</set-method>
          <type>org.exoplatform.services.command.impl.CommonsXMLConfigurationPlugin</type>
          <init-params>
            <value-param>
              <name>config-file</name>
              <value>conf/test-commands.xml</value>
            </value-param>
          </init-params>    
      </component-plugin>
    </component-plugins>      
  </component>

Where test-commands.xml is commons-chain standard chain definition xml like:

<catalog>
  <command   name="addNode"
        className="org.exoplatform.frameworks.jcr.command.core.AddNodeCommand"/>
  <command   name="save"
        className="org.exoplatform.frameworks.jcr.command.core.SaveCommand"/>
  <command   name="setProperty"
        className="org.exoplatform.frameworks.jcr.command.core.SetPropertyCommand"/>
</catalog>

CommandService's CommonsXMLConfigurationPlugin uses Apache commons-chain's CatalogFactory instance of which is a singleton for the relevant ClassLoader. For applications that use a thread context class loader (such as web applications running inside a servet container), static getInstance() method will return a separate instance for each application, even if this class is loaded from a shared parent class loader.

Multiple Configuration and Multiple Catalogs:

There is one default Catalog (exposed as element catalog without "name" attribute, as in example above) and it is possible to configure named Catalogs (like catalog name="my-name"). Each Catalog's configuration can be added in different CommonsXMLConfigurationPlugin entries.

For instance, you can have a plugin configuration like:

........
          <type>org.exoplatform.services.command.impl.CommonsXMLConfigurationPlugin</type>
          <init-params>
            <value-param>
              <name>config-file</name>
              <value>conf/test-commands1.xml</value>
            </value-param>
          </init-params>    
        ........

with

<catalog>
  <command   name="save"
        className="org.exoplatform.frameworks.jcr.command.core.SaveCommand"/>
</catalog>

inside conf/test-commands1.xml file and

........
          <type>org.exoplatform.services.command.impl.CommonsXMLConfigurationPlugin</type>
          <init-params>
            <value-param>
              <name>config-file</name>
              <value>conf/test-commands2.xml</value>
            </value-param>
          </init-params>    
     ........

with

<catalog>
  <command   name="addNode"
        className="org.exoplatform.frameworks.jcr.command.core.AddNodeCommand"/>
</catalog>

inside conf/test-commands2.xml file and at the end you will have both save and addNode commands accessible in the default catalog (the same is valid for named catalogs of course)


Creator: Administrator on 2007/05/22 15:46
Copyright (c) 2000-2009. Allright reserved - eXo platform SAS
1.6.13286