Writing an ofbiz Container

From Opentaps Wiki

Jump to: navigation, search

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"/>

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

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/"/>

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.

© Open Source Strategies, Inc. Development of this documentation site is sponsored by Open Source Strategies, Inc.
Help support opentaps with a subscription to this documentation site.