org.javagen.agile.core.model
Interface Model

All Superinterfaces:
ContextHolder
All Known Implementing Classes:
AbstractModel, BasicModel, Class, Column, ColumnReference, Database, FkConstraint, PkColumn, Property, Reference, Table, UniqueConstraint

public interface Model
extends ContextHolder

A Model is the basic unit of metadata used to drive code generation in JavaGen light. This interface was designed to be as simple as possible to model the structural aspects of code or data. It is also 'light' in the sense that no attempt was made to model behavior.

All models have name, id and ModelType properties. Each model also has a map of key-value pairs (aka context) allowing arbitrary values to be associated with a given model instance. Contexts are combined with parent contexts in such a way that child values override parent values providing a customization mechanism (for naming patterns for example).

Super classes should be designed as specific as possible to the particular domain they target. When a model from one domain is related or generated from another model instance in another domain use context references to link the two rather than properties that hard-code the two domains together. This keeps the two domains pure and more reusable in other code generation applications.

Models play a second role as templates for customization in conjunction with XML serialization. This only works if properties can be nullable (ie are non-primitive types) and sub classes should stick to this convention.

Author:
Richrd Easterling

Field Summary
static String DEFAULT_MODEL_TYPE
          Default modelType value for generic model instances.
 
Method Summary
 void addChildModel(Model child)
           
 List<Model> allOwnedModels()
          This method is used by the visitor patterns to navigate the model tree hierarchy.
 void copyTo(Model target)
          Copy non-null properties into target model instance.
 Object get(String key)
          Convienience method to access the local context of key-value pairs.
 List<Model> getChildModels()
           
 String getId()
          Ids are used to serialize Model references and allow fast lookups of unique Model instances.
 String getModelType()
          A modelType is just that, the type of thing being modeled.
 String getName()
          A name that describes what is being modeled and forms the basis of the generated artifact names.
 Model getParentModel()
          A parent is usually the owner or source of the child node.
 Model lookupChildByName(String name)
           
 void put(String key, Object value)
           
 void setChildModels(List<Model> childModels)
           
 void setId(String id)
           
 void setModelType(String modelType)
           
 void setName(String name)
           
 void setParentModel(Model parent)
           
 
Methods inherited from interface org.javagen.agile.core.context.ContextHolder
getContext
 

Field Detail

DEFAULT_MODEL_TYPE

static final String DEFAULT_MODEL_TYPE
Default modelType value for generic model instances.

See Also:
Constant Field Values
Method Detail

getName

String getName()
A name that describes what is being modeled and forms the basis of the generated artifact names. A name should be unique among its siblings to allow lookupChildByName to work effectively.


setName

void setName(String name)

getId

String getId()
Ids are used to serialize Model references and allow fast lookups of unique Model instances. An id should be unique across the entire model tree. Visitors are provided to generate and index Ids.


setId

void setId(String id)

getModelType

String getModelType()
A modelType is just that, the type of thing being modeled. Examples are: 'entity', 'primaryKey', 'table', 'class'. ModelTypes are used to bind emitters (ie templates) to model instances. Sets of modelTypes are also used to form itineraries that control which nodes are visited during model tree traversal.


setModelType

void setModelType(String modelType)

getParentModel

Model getParentModel()
A parent is usually the owner or source of the child node. For example a Table would be the parent of a Column in the database realm and a Class would be the parent of a Property in the object oriented realm. Non-artifact producing parent nodes may also be used to provide global context values or contain groups of related model instances. A given model instance can only have one parent.

Returns:
the parent model or null if this is the root node of the tree.

setParentModel

void setParentModel(Model parent)

getChildModels

List<Model> getChildModels()
Returns:
a list of child models or an empty list.

setChildModels

void setChildModels(List<Model> childModels)

addChildModel

void addChildModel(Model child)

lookupChildByName

Model lookupChildByName(String name)

allOwnedModels

List<Model> allOwnedModels()
This method is used by the visitor patterns to navigate the model tree hierarchy. It is provided to handle exceptional cases were the child instances are held in 2 or more collections (ie not all in childModels List) in which case it returns the union of the child collections. Most of the time it just calls getChildModles.

Returns:
union of the child models.

get

Object get(String key)
Convienience method to access the local context of key-value pairs. Context is used to hold arbitrary key-value pairs. Common uses are to hold value-replacement templates used in customizing artifact names or to store references to other model instances needed for model or template processing.

Parameters:
key - a unique string value.
Returns:
value given a unique key

put

void put(String key,
         Object value)

copyTo

void copyTo(Model target)
Copy non-null properties into target model instance. Child values are generally not copied. Used in conjunction with XML serialization to allow individual model instances to be custimized.

Parameters:
target - model to set properties on


Copyright 2006-2006-2007 Outsource Cafe Inc.. All Rights Reserved.