org.javagen.agile.core.model
Class AbstractModel

java.lang.Object
  extended by org.javagen.agile.core.model.AbstractModel
All Implemented Interfaces:
Serializable, ContextHolder, Model
Direct Known Subclasses:
BasicModel, Class, Column, ColumnReference, Database, FkConstraint, Property, Table, UniqueConstraint

public abstract class AbstractModel
extends Object
implements Model, ContextHolder, Serializable

Generic implementation of Model interface. See Model for documentation. Xml binding annotations are defined to support serialization of subclasses of AbstractModel.

Author:
Richard Easterling
See Also:
Serialized Form

Field Summary
protected  List<Model> childModels
           
protected  Map<String,Object> context
           
protected  String id
           
protected  String modelType
           
protected  String name
           
protected  Model parentModel
           
 
Fields inherited from interface org.javagen.agile.core.model.Model
DEFAULT_MODEL_TYPE
 
Constructor Summary
AbstractModel()
           
AbstractModel(String name)
           
 
Method Summary
 void addChildModel(Model child)
          Add child model, making sure the parent is set.
 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.
 boolean equals(Object obj)
           
 Object get(String key)
          Convienience method to access the local context of key-value pairs.
 List<Model> getChildModels()
           
 Map<String,Object> getContext()
           
 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)
          Set child models, making sure the parent is set.
 void setContext(Map<String,Object> context)
           
 void setId(String id)
           
 void setModelType(String modelType)
           
 void setName(String name)
           
 void setParentModel(Model parentModel)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected String name

id

protected String id

modelType

protected String modelType

context

protected Map<String,Object> context

parentModel

protected Model parentModel

childModels

protected List<Model> childModels
Constructor Detail

AbstractModel

public AbstractModel()

AbstractModel

public AbstractModel(String name)
Method Detail

getName

public String getName()
Description copied from interface: Model
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.

Specified by:
getName in interface Model

setName

public void setName(String name)
Specified by:
setName in interface Model

getId

public String getId()
Description copied from interface: Model
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.

Specified by:
getId in interface Model

setId

public void setId(String id)
Specified by:
setId in interface Model

getModelType

public String getModelType()
Description copied from interface: Model
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.

Specified by:
getModelType in interface Model

setModelType

public void setModelType(String modelType)
Specified by:
setModelType in interface Model

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getParentModel

public Model getParentModel()
Description copied from interface: Model
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.

Specified by:
getParentModel in interface Model
Returns:
the parent model or null if this is the root node of the tree.

setParentModel

public void setParentModel(Model parentModel)
Specified by:
setParentModel in interface Model

getChildModels

public List<Model> getChildModels()
Specified by:
getChildModels in interface Model
Returns:
the assigned List or if null an immutable empty list constant.

setChildModels

public void setChildModels(List<Model> childModels)
Set child models, making sure the parent is set.

Specified by:
setChildModels in interface Model

addChildModel

public void addChildModel(Model child)
Add child model, making sure the parent is set.

Specified by:
addChildModel in interface Model

lookupChildByName

public Model lookupChildByName(String name)
Specified by:
lookupChildByName in interface Model

allOwnedModels

public List<Model> allOwnedModels()
Description copied from interface: Model
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.

Specified by:
allOwnedModels in interface Model
Returns:
union of the child models.

get

public Object get(String key)
Description copied from interface: Model
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.

Specified by:
get in interface Model
Parameters:
key - a unique string value.
Returns:
value given a unique key

put

public void put(String key,
                Object value)
Specified by:
put in interface Model

getContext

public Map<String,Object> getContext()
Specified by:
getContext in interface ContextHolder
Returns:
either a map instance populated with key-value pairs or null

setContext

public void setContext(Map<String,Object> context)

copyTo

public void copyTo(Model target)
Description copied from interface: Model
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.

Specified by:
copyTo in interface Model
Parameters:
target - model to set properties on


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