Java Model projects

A Java Model project is generated from the business object model (BOM) project to be used by Java™ agents, OSGi services, and test driver clients.

All BOM classes and interfaces that are generated from the .bmd files within the BOM project and are tagged with the de.generated property generate a Java class and an interface in the Java Model project. The generated interfaces are created in a package with the same name that is used in the BOM project. The implementation classes are generated in another package.

To be able to create class instances, an interface that is named ConceptFactory is created in each package. The interface contains a create[Classname] method for each public constructor of the BOM class.

Note:

A BOM includes only public members, and therefore BOM classes do not have a default constructor. If a BOM class has a constructor without parameters, it must be declared in the BOM.

Table 1. Mapping of BOM types
BOM type BOM project Java Model project Description
Class
package myPackage;
class MyClass {}
A Java interface myPackage.MyClass. A Java class for the implementation (not for public use). A class in the BOM creates both an interface and an implementation class.
Class constructor
package myPackage;
Class MyClass {
  MyClass(string p); 
}
In addition to the Java interface MyClass, there is a myPackage.ConceptFactory interface that contains createMyClass(String p); A constructor in the BOM creates a method in the generated ConceptFactory interface.
Class with an enumerated domain
package myPackage;
class CustomerKind {
  domain { static GOLD, static COPPER, static SILVER }
  static final bom.CustomerKind GOLD;
  static final bom.CustomerKind COPPER;
  static final bom.CustomerKind SILVER;
}
A Java enum:
enum myPackage.CustomerKind {
GOLD, COPPER, SILVER }
An enumerated type in the BOM creates a Java enum type.
Interface
package myPackage;
interface MyClass {}
A Java interface myPackage.MyClass. A BOM interface creates a Java interface.

The BOM attributes are mapped to get and set methods that are named according to the JavaBeans convention. The attribute modifiers, such as readonly, writeonly, final, or static have an obvious mapping to those methods. In addition to these obvious mappings, some attributes with a specific meaning or a specific type are mapped in a different way (see table 2), as are attribute of collection types (see table 3).

Table 2. Mapping of entity, event, and special BOM attributes
BOM type BOM project Java Model project Description
Id of an entity
package myPackage;
class MyEntity implements com.ibm.ia.model.Entity { 
  string id property "ia.entity.id" "true";
}
The implementation directly implements the Java methods get$Id() and get$TypeName() from the entity interface. In addition, the hashcode and equals methods are implemented and based on the id information. An entity class is mapped as a regular class, some method implementations are generated.
Timestamp of an event
class MyEvent implements com.ibm.ia.model.Event { 
  java.time.ZonedDateTime timestamp property "ia.timestamp" "true";
}
The implementation directly implements the Java methods get$Timestamp() and get$TypeName() from the event interface. In addition, the hashcode and equals methods are implemented and based on the $Id information. An event class is mapped as a regular class, some method implementations are generated. In addition, a field to represent the event id is generated.
Attribute of an entity type
class MyConcept  { 
  MyEntity myEntity;
}
The generated Java interface contains:
Relationship<MyEntity> getMyEntity();
void setMyEntity(Relationship<MyEntity> p);
A BOM attribute of an entity type is mapped to a Java field of Relationship type. From a Relationship instance, the real entity object can be retrieved by calling the resolve method.

In the following table, the List type is used, but the mapping can also be done with Collection and Set.

Table 3. Mapping of BOM collection types
BOM type BOM project Java Model project Description
Attribute of collection type
Class MyClass {
  java.util.List concepts 
   domain 0,* 
   class myPackage.MyConcept;
}
In the Java interface, the attribute of a collection type is:
List<MyConcept> getConcepts();
void setConcepts(List<MyConcept>);
These methods are implemented in the generated implementation. The getter method returns a read only version of the collection, and never returns null. The setter method creates a shallow copy of the parameter.
The type information of the domain is used to produce generic types.
Attribute of collection type with add, remove, clear, and set methods
Class MyClass {
  java.util.List concepts 
   domain 0,* 
   class myPackage.MyConcept;

  void addTo_concepts(
    myPackage. MyConcept concept)
    property collectionAttribute  
      "concepts";
  void removeFrom_concepts(
    myPackage.Concept  concept)
    property collectionAttribute 
     "concepts";
  void clear_concepts()
    property collectionAttribute 
     "concepts";
  void set_concepts(
    java.util.Collection 
    domain 0,* 
    class myPackage.MyConcept) 
    property collectionAttribute 
      "concepts"; 
}
In addition to the get and set methods, the addTo_concepts, removeFrom_concepts, set_concepts, and clear_concepts methods are present in the interface:
void addTo_concepts(MyConcept);
void removeFrom_concepts(MyConcept);
void clear_concepts();
void set_concepts(Collection<? extends MyConcept>);
They are also included in the generated implementation.
The generated implementation depends on the prefix of the name of the method, and on the content of the collectionAttribute property. The method name after the prefix is not relevant.

The addTo_concepts method adds a concept to the collection.

The removeFrom_concepts method removes a concept from the collection.

The clear_concepts method removes all concepts from the collection.

The set_concepts method changes the content of the concepts collection.

Attribute of collection of entity type
Class MyClass {
  java.util.List entities 
   domain 0,* 
   class myPackage.MyEntity;
}
In the Java interface, the attribute of a collection type is:
List<Relationship<MyEntity>> getEntities();
void setEntities(List <Relationship<MyEntity>>);
The type information of the domain is used to produce entity types.
Attribute of collection of entity type with add, remove, clear, get, and set methods
Class MyClass {
  java.util.List entities 
   domain 0,* 
   class myPackage.MyEntity;
   void addTo_entities(
    myPackage. MyEntity entity)
    property collectionAttribute  
      "entities";
  void removeFrom_entities(
    myPackage.Entity  entity)
    property collectionAttribute 
     "entities";
  void clear_entities()
    property collectionAttribute 
     "entities";
  myPackage.Entity getFrom_entities(
    myPackage.MyEntity entity)
    property collectionAttribute 
     "entities"
    property update "false";
  void set_entities(
  java.util.Collection 
  domain 0,* 
  class myPackage.MyEntity) 
    property collectionAttribute 
     "entities";
}
In addition to the get and set methods, the addTo_entities, removeFrom_entities, clear_entities, getFrom_entities, and set_entities, methods are present in the interface:
void addTo_entities(Relationship<MyEntity>);
void removeFrom_entities(Relationship<MyEntity>);
void clear_entities();
myPackage.Entity getFrom_Entities(Relationship<MyEntity>);
void set_entities(Collection<? extends Relationship<MyEntity>>);
They are also included in the generated implementation.
The generated implementation depends on the prefix of the name of the method, and on the content of the collectionAttribute property. The method name after the prefix is not relevant.

The addTo_entities method adds an entity to the collection.

The removeFrom_entities method removes an entity from the collection.

The clear_entities method removes all entities from the collection.

The getFrom_entities method returns the entity from its ID.

The set_entities method changes the content of the concepts collection.