Difference between revisions of "Writing an ofbiz Container"

From Opentaps Wiki
Jump to navigationJump to search
m (Protected "Writing an ofbiz Container": Sysop page [edit=sysop:move=sysop])
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
The ofbiz framework has a container architecture that allows you to set up containers which load up system infrastructure such as the delegator (database access), dispatcher (business logic tier), and web servers like Tomcat.  When ofbiz is started, it will call a container based on the command line input:
+
The ofbiz framework has a container architecture that allows you to set up containers which load up system infrastructure such as the delegator (database access), dispatcher (business logic tier), and web servers like Tomcat.  The standard containers are used to run opentaps from the Tomcat server, run the POS terminal as a desktop application, or install data or write unit tests.  You can also create your own containers for other purposes.  For example, we created a custom container to generate Java classes for all the entities in the entitymodel XML files.
 +
 
 +
To write your own container, you would need to create two configuration files, and a Java container file.  Your container will be called based on the commandline parameters when the office framework is started.  For example,
 +
<pre>
 +
$ ant make-base-entities
 +
</pre>
 +
 
 +
causes the following target in the <tt>build.xml</tt> to be called:
 +
<pre>
 +
<target name="make-base-entities">
 +
        <!-- some other stuff -->
 +
        <java jar="ofbiz.jar" fork="true">
 +
            <jvmarg value="${memory.max.param}"/>
 +
            <arg value="pojoentities"/>
 +
        </java>
 +
    </target>
 +
</pre>
 +
which in turn calls ofbiz with the following commandline parameters:
  
 
<pre>
 
<pre>
Line 5: Line 22:
 
</pre>
 
</pre>
  
means that it will call up the <tt>pojoentities</tt> container.
+
means that it will call up the <tt>pojoentities</tt> container.  When ofbiz starts up, it will look for a file called <tt>pojoentities.properties</tt> in the <tt>org.ofbiz.base.start</tt> package.  This file is in fact located in <tt>framework/base/src/start/org/ofbiz/base/start/pojoentities.properties</tt> and defines the runtime configuration of ofbiz.  For example, it defines where the configuration files are, where the log directory is, and whether the container will shut itself down automatically.  The most important definition is an XML file which configures the container:
 +
<pre>
 +
# --- Location (relative to ofbiz.home) for (normal) container configuration
 +
ofbiz.container.config=framework/base/config/pojoentities-containers.xml
 +
</pre>
 +
 
 +
This file is in <tt>framework/base/config</tt>  and defines the loaders for the container and then the container classes.  In this case, it is <tt>org.opentaps.domain.container.PojoGeneratorContainer</tt>.  The XML file also specifies the parameters for the container, which in this case is the name of the delegator and where the template and output file path for the POJOs are:
 +
<pre>
 +
    <container name="pojo-generator-container" class="org.opentaps.domain.container.PojoGeneratorContainer">
 +
        <property name="delegator-name" value="default"/>
 +
        <property name="template" value="hot-deploy/opentaps-common/templates/BaseEntity.ftl"/>
 +
        <property name="output-path" value="hot-deploy/opentaps-common/src/org/opentaps/domain/base/entities/"/>
 +
    </container>
 +
</pre>
 +
 
 +
Finally, your container must have a standard <tt>init</tt> method, and the <tt>start()</tt> method will call the logic of the container.  You can get the configuration properties of your container like this:
 +
<pre>
 +
  public boolean start() throws ContainerException {
 +
        ContainerConfig.Container cfg = ContainerConfig.getContainer(containerName, configFile);
 +
        ContainerConfig.Container.Property delegatorNameProp = cfg.getProperty("delegator-name");
 +
        ContainerConfig.Container.Property outputPathProp = cfg.getProperty("output-path");
 +
        ContainerConfig.Container.Property templateProp = cfg.getProperty("template");
 +
  // rest of container actions
 +
</pre>
 +
 
 +
 
 +
And everything else can follow from there.

Latest revision as of 20:04, 29 July 2008

The ofbiz framework has a container architecture that allows you to set up containers which load up system infrastructure such as the delegator (database access), dispatcher (business logic tier), and web servers like Tomcat. The standard containers are used to run opentaps from the Tomcat server, run the POS terminal as a desktop application, or install data or write unit tests. You can also create your own containers for other purposes. For example, we created a custom container to generate Java classes for all the entities in the entitymodel XML files.

To write your own container, you would need to create two configuration files, and a Java container file. Your container will be called based on the commandline parameters when the office framework is started. For example,

$ ant make-base-entities

causes the following target in the build.xml to be called:

 <target name="make-base-entities">
        <!-- some other stuff -->
        <java jar="ofbiz.jar" fork="true">
            <jvmarg value="${memory.max.param}"/>
            <arg value="pojoentities"/>
        </java>
    </target>

which in turn calls ofbiz with the following commandline parameters:

$ java -jar ofbiz.jar pojoentities

means that it will call up the pojoentities container. When ofbiz starts up, it will look for a file called pojoentities.properties in the org.ofbiz.base.start package. This file is in fact located in framework/base/src/start/org/ofbiz/base/start/pojoentities.properties and defines the runtime configuration of ofbiz. For example, it defines where the configuration files are, where the log directory is, and whether the container will shut itself down automatically. The most important definition is an XML file which configures the container:

# --- Location (relative to ofbiz.home) for (normal) container configuration
ofbiz.container.config=framework/base/config/pojoentities-containers.xml

This file is in framework/base/config and defines the loaders for the container and then the container classes. In this case, it is org.opentaps.domain.container.PojoGeneratorContainer. The XML file also specifies the parameters for the container, which in this case is the name of the delegator and where the template and output file path for the POJOs are:

    <container name="pojo-generator-container" class="org.opentaps.domain.container.PojoGeneratorContainer">
        <property name="delegator-name" value="default"/>
        <property name="template" value="hot-deploy/opentaps-common/templates/BaseEntity.ftl"/>
        <property name="output-path" value="hot-deploy/opentaps-common/src/org/opentaps/domain/base/entities/"/>
    </container>

Finally, your container must have a standard init method, and the start() method will call the logic of the container. You can get the configuration properties of your container like this:

  public boolean start() throws ContainerException {
        ContainerConfig.Container cfg = ContainerConfig.getContainer(containerName, configFile);
        ContainerConfig.Container.Property delegatorNameProp = cfg.getProperty("delegator-name");
        ContainerConfig.Container.Property outputPathProp = cfg.getProperty("output-path");
        ContainerConfig.Container.Property templateProp = cfg.getProperty("template");
  // rest of container actions


And everything else can follow from there.