The Web Graph Database

wiki:Docs/GeneratingCode

Generating Code from Models

If a ModelModule is set up according to the instructions in Creating a New ModelModule, the default InfoGrid build process should automatically generate the appropriate code when the project is built.

The InfoGrid CodeGenerator is contained in Module org.infogrid.codegen in project Graph Database. From the root directory of a Subversion branch, if ig-graphdb/tests/org.infogrid.model.Test is the ModelModule, it can be invoked as follows:

java -classpath ig-utils/modules/org.infogrid.module/dist/org.infogrid.module.jar:ig-utils/modules/org.infogrid.module.commandline/dist/org.infogrid.module.commandline.jar
     -rootmodule org.infogrid.codegen
     -moduleadvertisementpath */*/*/dist/*.adv
     ig-graphdb/tests/org.infogrid.model.Test
     -o ig-graphdb/tests/org.infogrid.model.Test/build/module-generated/

Here is an outline over the generated code:

  • For each SubjectArea named XXX (e.g. org.infogrid.model.Test), the following Java packages are created:
    • XXX, containing the generated interfaces (e.g. org.infogrid.model.Test)
    • XXX.VERSION, containing the generated implementations (e.g. org.infogrid.model.Test.V)
  • In the SubjectArea's top package, the class XXXSubjectArea representing the SubjectArea itself is created, if the SubjectArea is named XXX.
  • For each EntityType with the short name YYY (e.g. SimpleBlobTest), a Java interface is created with the same name YYY (e.g. SimpleBlobTest).
  • For each EntityType with the short name YYY (e.g. SimpleBlobTest) that is not abstract, a Java class is created with the same name YYY but prefixed with Impl (e.g. ImplSimpleBlobTest)
  • For each EntityType with the short name YYY (e.g. SimpleBlobTest) that is abstract but marked as a possible ForwardReference, a Java class is created with the same name YYY but prefixed with Impl (e.g. ImplSimpleBlobTest)
  • No class or interface is generated for a RelationshipType.
  • For each PropertyType with the short name ZZZ (e.g. LastName), a getter method is generated according to JavaBeans conventions (e.g. getLastName).
  • For each PropertyType with the short name ZZZ that is not read-only (e.g. LastName), a setter method is generated according to JavaBeans conventions (e.g. setLastName );

In addition, for each MeshType, a static declaration is generated in the SubjectArea class, such as:

public static final EntityType SIMPLEBLOBTEST = ...
public static final RelationshipType RR = ...

These static declarations make it easy to refer to Model information in application code. For example, to traverse RelationshipType RR from source to destination, one can simply refer to the static constants like this:

MeshObject    start          = ...
MeshObjectSet destinationSet = start.traverse( TestSubjectArea.RR.getSource() );
Last modified 4 years ago Last modified on 01/19/10 19:11:37