org.andromda.core.metafacade
Class MetafacadeBase

java.lang.Object
  org.andromda.core.metafacade.MetafacadeBase
All Implemented Interfaces:
Serializable, Comparable

public class MetafacadeBase
extends Object
implements Serializable, Comparable

Base class for all metafacades.

Author:
Matthias Bohlen , Chad Brandon, Wouter Zoons, Bob Fields
See Also:
Serialized Form

Field Summary
protected  boolean contextRoot
          The flag indicating whether or not this metafacade is a context root.
protected  Logger logger
          The metafacade logger instance.
 
Constructor Summary
MetafacadeBase(Object metaObjectIn, String contextIn)
          Constructs a new instance of this class with the given metaObject and context.
 
Method Summary
 int compareTo(Object object)
          Allow sorting and use in TreeSet.
 boolean equals(Object object)
           
protected  Object getConfiguredProperty(String property)
          Gets a configured property from the container.
(package private)  String getContext()
          Gets the context for this metafacade.
 String getMetafacadeContext()
          Gets the context for this metafacade.
(package private)  String getMetafacadeName()
          Gets the name for this metafacade.
(package private)  String getMetafacadeNamespace()
          Gets the current namespace for this metafacade
 Object getMetaObject()
          Gets the current meta model object for this metafacade.
 String getValidationName()
          Retrieves the name of this metafacade used within the validation messages.
 Object getValidationOwner()
          Retrieves the owner of this metafacade (for example: an operation owns its parameters, a class owns its attributes).
 int hashCode()
           
 void initialize()
          A lifecycle method, providing the ability for sub classes to take any action after the factory has completely initialized a metafacade, but before it has been validated for completeness.
protected  boolean isConfiguredProperty(String property)
          Returns true or false depending on whether the property is registered or not.
(package private)  boolean isInitialized()
          Indicates if this metafacade has been initialized.
 boolean isMetafacadePropertyCachingEnabled()
          A check to verify whether or not to make use of metafacade property caching.
 void resetMetafacadeContext(String contextIn)
          Resets the metafacade context after the metafacade was retrieved from the metafacade cache.
(package private)  void setContextRoot(boolean contextRootIn)
          Sets whether or not this metafacade represents a contextRoot.
(package private)  void setInitialized()
          Sets the flag indicating this metafacade has been initialized.
(package private)  void setLogger(Logger loggerIn)
          Package-local setter, called by facade factory.
 void setMetafacadeContext(String contextIn)
          Sets the context for this metafacade.
(package private)  void setNamespace(String namespaceIn)
          Sets the namespace for this metafacade.
protected  void setProperty(String nameIn, Object value)
          Attempts to set the property with name having the specified value on this metafacade.
protected  MetafacadeBase shieldedElement(Object metaObjectIn)
          Returns one facade for a particular metaObject.
protected  List shieldedElements(Collection metaobjects)
          Returns a collection of facades for a collection of metaobjects.
protected  MetafacadeBase THIS()
          The metafacade instance of this.
 String toString()
           
 void validate(Collection<ModelValidationMessage> validationMessages)
          Validates that this facade's meta object is in a valid state.
 void validateInvariants(Collection<ModelValidationMessage> messages)
          

The logic of modeled OCL invariants from derived metafacades will be generated into this method and validation messages created and collected into the messages collection.

 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected Logger logger
The metafacade logger instance.


contextRoot

protected boolean contextRoot
The flag indicating whether or not this metafacade is a context root.

Constructor Detail

MetafacadeBase

public MetafacadeBase(Object metaObjectIn,
                      String contextIn)
Constructs a new instance of this class with the given metaObject and context. The metaObject is the meta model element which this metafacade insulates. The context is the name of the context for this metafacade instance.

Parameters:
metaObjectIn - the meta object.
contextIn - the context of this meta object.
Method Detail

getValidationOwner

public Object getValidationOwner()
Retrieves the owner of this metafacade (for example: an operation owns its parameters, a class owns its attributes).

By default null is returned, however this method is overridden by subclasses which have a parent or owner. This is used to give the model validation messages more context as to where the validation error occurred.

Returns:
the owner of this metafacade.

getValidationName

public String getValidationName()
Retrieves the name of this metafacade used within the validation messages.

By default null is returned, however this method is overridden by subclasses model elements that do have a name.

Returns:
the owner of this metafacade.

setInitialized

final void setInitialized()
Sets the flag indicating this metafacade has been initialized.


isInitialized

final boolean isInitialized()
Indicates if this metafacade has been initialized.

Returns:
true/false

validate

public final void validate(Collection<ModelValidationMessage> validationMessages)
Validates that this facade's meta object is in a valid state.

Validate is called during metafacade creation by the factory. In the lifecycle of a metafacade it is validated only once, this is enforced by the caching within the metafacade factory.

Parameters:
validationMessages - any messages generated during validation.

validateInvariants

public void validateInvariants(Collection<ModelValidationMessage> messages)

The logic of modeled OCL invariants from derived metafacades will be generated into this method and validation messages created and collected into the messages collection. This method is called by validate(Collection validationMessages)

By default this method is empty.

Parameters:
messages - Collection of org.andromda.core.metafacade.ModelValidationMessage

initialize

public void initialize()
A lifecycle method, providing the ability for sub classes to take any action after the factory has completely initialized a metafacade, but before it has been validated for completeness.


shieldedElement

protected MetafacadeBase shieldedElement(Object metaObjectIn)
Returns one facade for a particular metaObject. Contacts the MetafacadeFactory to manufacture the proper metafacade. In certain cases metaObject can also be a metafacade instance; in that case the actual meta model element is retrieved from the metafacade and a metafacade is constructed from that.

Parameters:
metaObjectIn - the underlying meta model element. A metafacade is created for each.
Returns:
MetafacadeBase the facade
See Also:
MetafacadeFactory

shieldedElements

protected List shieldedElements(Collection metaobjects)
Returns a collection of facades for a collection of metaobjects. Contacts the MetafacadeFactory to manufacture the proper facades.

Parameters:
metaobjects - the objects to decorate
Returns:
Collection of MetafacadeBase-derived objects
See Also:
MetafacadeFactory

getContext

final String getContext()
Gets the context for this metafacade.

Returns:
the context name.

setMetafacadeContext

public void setMetafacadeContext(String contextIn)
Sets the context for this metafacade. This is used to pass the context along from a metafacade specializing this metafacade (since we use delegate inheritance between shared and non-shared metafacades), as well as to pass the context to a metafacade being created within another.

Parameters:
contextIn - the metafacade interface name representing the context.
See Also:
MetafacadeMapping.isContextRoot()

resetMetafacadeContext

public void resetMetafacadeContext(String contextIn)
Resets the metafacade context after the metafacade was retrieved from the metafacade cache. DO NOT CALL THIS METHOD BY HAND, it is reserved for use in the MetafacadeFactory.

Parameters:
contextIn - the context defined by MetafacadeFactory
See Also:
MetafacadeFactory

getMetafacadeNamespace

final String getMetafacadeNamespace()
Gets the current namespace for this metafacade

Returns:
String

setNamespace

final void setNamespace(String namespaceIn)
Sets the namespace for this metafacade.

Parameters:
namespaceIn -

isConfiguredProperty

protected boolean isConfiguredProperty(String property)
Returns true or false depending on whether the property is registered or not.

Parameters:
property - the name of the property to check.
Returns:
true/false on whether or not its registered.

getConfiguredProperty

protected Object getConfiguredProperty(String property)
Gets a configured property from the container. Note that the configured property must be registered first.

Parameters:
property - the property name
Returns:
Object the configured property instance (mappings, etc)

setProperty

protected void setProperty(String nameIn,
                           Object value)
Attempts to set the property with name having the specified value on this metafacade.

Parameters:
nameIn -
value -

getMetaObject

public final Object getMetaObject()
Gets the current meta model object for this metafacade. This is used from MetafacadeFactory when attempting to construct a metafacade from a metafacade. This allows us to get the meta object for this metafacade so that the meta object can be used instead.

Returns:
the underlying model's meta object instance.

setLogger

final void setLogger(Logger loggerIn)
Package-local setter, called by facade factory. Sets the logger to use inside the facade's code.

Parameters:
loggerIn - the logger to set

setContextRoot

final void setContextRoot(boolean contextRootIn)
Sets whether or not this metafacade represents a contextRoot. If it does represent a context root, then getMetafacadeContext()returns the metafacade interface for this metafacade, otherwise the regular context is returned.

Parameters:
contextRootIn -

getMetafacadeContext

public String getMetafacadeContext()
Gets the context for this metafacade. This is either the contextRoot (if one exists), or the regular context.

Returns:
the metafacade's context.

getMetafacadeName

final String getMetafacadeName()
Gets the name for this metafacade.

Returns:
the metafacade's name.

equals

public boolean equals(Object object)
Overrides:
equals in class Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

isMetafacadePropertyCachingEnabled

public final boolean isMetafacadePropertyCachingEnabled()
A check to verify whether or not to make use of metafacade property caching. This method check if the MetafacadeProperties.ENABLE_METAFACADE_PROPERTY_CACHING namespace property has been set, if this is not the case then the caching will be enabled by default.

Returns:
this.metafacadePropertyCachingEnabled.booleanValue()

THIS

protected final MetafacadeBase THIS()
The metafacade instance of this. This should be used when you'd need to check if this was an instance of a given metafacade. For example: THIS() instanceof SomeMetafacade. This MUST be used instead of this in order to access the correct metafacade instance in the hierarchy (since we use delegate inheritance).

Returns:
this.shieldedElement(this.metaObject)

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

compareTo

public int compareTo(Object object)
Allow sorting and use in TreeSet. ValidationName is overridden in descendants.

Specified by:
compareTo in interface Comparable
See Also:
Comparable.compareTo(Object)


Copyright © 2003-2012 AndroMDA.org. All Rights Reserved.