org.andromda.core.metafacade
Class MetafacadeMappings

java.lang.Object
  extended by org.andromda.core.namespace.BaseNamespaceComponent
      extended by org.andromda.core.metafacade.MetafacadeMappings
All Implemented Interfaces:
Serializable, NamespaceComponent

public class MetafacadeMappings
extends BaseNamespaceComponent
implements Serializable

The Metafacade mapping class. Used to map metafacade objects to metamodel objects.

Author:
Chad Brandon, Bob Fields
See Also:
MetafacadeMapping, XmlObjectFactory, Serialized Form

Nested Class Summary
(package private) static interface MetafacadeMappings.Condition
          Provides a means to evaluate whether or not a condition is true.
 
Field Summary
protected  Collection<MetafacadeMapping> inProcessMappings
           Stores the mappings which are currently "in process" (within the getMapping(Object, String, Collection).
protected  Collection<MetafacadeBase> inProcessMetafacades
           Stores the metafacades which are currently "in process" (within the getMapping(Object, String, Collection).
 
Constructor Summary
MetafacadeMappings()
           
 
Method Summary
 void addMapping(MetafacadeMapping mapping)
          Adds a MetafacadeMapping instance to the set of current mappings.
 void addPropertyReference(String reference)
          Adds a language mapping reference.
(package private) static Map<Class,Set<String>> getAllMetafacadeMappingInstances()
          Stores every metafacade mapping instance, this is used from MetafacadeUtils.getInheritedMappingClassNames(MetafacadeMapping).
protected  List<String> getContextHierarchy(String context)
          Retrieves all inherited contexts (including the root context) from the given context and returns a list containing all of them.
(package private)  Class getDefaultMetafacadeClass(String namespace)
          Gets the defaultMetafacadeClass, first looks for it in the namespace mapping, if it can't find it it then takes the default mappings, setting.
protected  MetafacadeMapping getMapping(Object mappingObject, String context, Collection<String> stereotypes)
          

Retrieves the MetafacadeMapping belonging to the unique key created from the mappingObject's class, context and given stereotypes.

protected  Collection<String> getMappingObjectHierarchy(Object mappingObject)
          Retrieves the hierarchy of class names of the given mappingObject.
protected  Collection<MetafacadeMapping> getMappings()
          Retrieves all child MetafacadeMapping instances belonging to this metafacade mappings instance.
 Class getMetafacadeInterface(Class metafacadeClass)
          Gets the class of the metafacade interface that belongs to the given metafacadeClass.
 MetafacadeMapping getMetafacadeMapping(Object mappingObject, String namespace, String context, Collection<String> stereotypes)
          

Attempts to get the MetafacadeMapping identified by the given mappingClass,context and stereotypes, from the mappings for the given namespace.

 MetafacadeMappings getModelMetafacadeMappings(String metafacadeModelNamespace)
          Should be used used instead of "this", retrieves the appropriate metafacade mappings instance based on the current model type.
 Collection<String> getPropertyReferences()
          Gets all property references defined in this mappings instance.
 void initialize()
          Initializes this mappings instance, which includes discovery of all metafacade mappings instances on the classpath.
static MetafacadeMappings newInstance()
          Constructs a new instance of this class.
(package private)  void registerAllProperties()
          Registers all namespace properties in the shared MetafacadeFactory instance.
(package private)  void registerProperties(String namespace, Collection<String> propertyReferences, String metafacadeName)
          Registers the defined property references properties in the metafacade factory.
 void setDefaultMetafacadeClass(String defaultMetafacadeClass)
          Sets the default metafacade class to use if no other is found for the mapping class.
 void setMetaclassPattern(String metaclassPattern)
          Sets the pattern of the metaclass implementations based on a metaclass interface name.
(package private)  void shutdown()
          Performs shutdown procedures for the factory.
 String toString()
           
 
Methods inherited from class org.andromda.core.namespace.BaseNamespaceComponent
getNamespace, getResource, setNamespace, setResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inProcessMappings

protected final Collection<MetafacadeMapping> inProcessMappings

Stores the mappings which are currently "in process" (within the getMapping(Object, String, Collection). This means the mapping is being processed by the getMapping(Object, String, Collection) operation. We store these "in process" mappings in order to keep track of the mappings currently being evaluated so we avoid stack over flow errors getMapping(Object, String, Collection)when finding mappings that are mapped to super metafacade properties.

Note: visibility is defined as protected in order to improve inner class access performance.


inProcessMetafacades

protected final Collection<MetafacadeBase> inProcessMetafacades

Stores the metafacades which are currently "in process" (within the getMapping(Object, String, Collection). This means the metafacade being processed by the getMapping(Object, String, Collection)operation. We store these "in process" metafacades in order to keep track of the metafacades currently being evaluated so we avoid stack over flow errors getMapping(Object, String, Collection)when finding metafacades that are mapped to super metafacade properties.

Note: visibility is defined as protected in order to improve inner class access performance.

Constructor Detail

MetafacadeMappings

public MetafacadeMappings()
Method Detail

newInstance

public static MetafacadeMappings newInstance()
Constructs a new instance of this class.

Returns:
MetafacadeMappings

addMapping

public void addMapping(MetafacadeMapping mapping)
Adds a MetafacadeMapping instance to the set of current mappings.

Parameters:
mapping - the MetafacadeMapping instance.

getMetafacadeInterface

public Class getMetafacadeInterface(Class metafacadeClass)
Gets the class of the metafacade interface that belongs to the given metafacadeClass.

Parameters:
metafacadeClass -
Returns:
the metafacade interface Class.

getPropertyReferences

public Collection<String> getPropertyReferences()
Gets all property references defined in this mappings instance.

Returns:
the map of property references (names and values).

getMapping

protected MetafacadeMapping getMapping(Object mappingObject,
                                       String context,
                                       Collection<String> stereotypes)

Retrieves the MetafacadeMapping belonging to the unique key created from the mappingObject's class, context and given stereotypes. It's IMPORTANT to note that contexts have a higher priority than stereotypes. This allows us to retrieve mappings based on the following combinations:

NOTE: mapping properties are inherited from super metafacades.

Parameters:
mappingObject - an instance of the class to which the mapping applies.
stereotypes - the stereotypes to check.
context - the context within the namespace for which the mapping applies (has 'root' in the name because of the fact that we also search the context inheritance hierarchy started with this 'root' context).
Returns:
MetafacadeMapping (or null if none was found matching the criteria).

getMappingObjectHierarchy

protected Collection<String> getMappingObjectHierarchy(Object mappingObject)
Retrieves the hierarchy of class names of the given mappingObject.

Parameters:
mappingObject - the object from which to retrieve the hierarchy.
Returns:
a list containing all inherited class names.

getContextHierarchy

protected final List<String> getContextHierarchy(String context)
Retrieves all inherited contexts (including the root context) from the given context and returns a list containing all of them. Note that the visibility of this operation is protected to improve inner class access performance.

Parameters:
context - the root contexts
Returns:
a list containing all inherited contexts

addPropertyReference

public void addPropertyReference(String reference)
Adds a language mapping reference. This are used to populate metafacade impl classes with mapping files (such as those that map from model types to Java, JDBC, SQL types, etc). If its added here as opposed to each child MetafacadeMapping, then the reference will apply to all mappings.

Parameters:
reference - the name of the reference.

getMetafacadeMapping

public MetafacadeMapping getMetafacadeMapping(Object mappingObject,
                                              String namespace,
                                              String context,
                                              Collection<String> stereotypes)

Attempts to get the MetafacadeMapping identified by the given mappingClass,context and stereotypes, from the mappings for the given namespace. If it can not be found, it will search the default mappings and return that instead.

IMPORTANT: The context will take precedence over any stereotypes with the mapping.

Parameters:
mappingObject - the meta object for the mapping we are trying to find.
namespace - the namespace (i.e. a cartridge, name, etc.)
context - to which the mapping applies (note this takes precedence over stereotypes).
stereotypes - collection of stereotype names. We'll check to see if the mapping for the given mappingClass is defined for it.
Returns:
mapping

initialize

public void initialize()
Initializes this mappings instance, which includes discovery of all metafacade mappings instances on the classpath.


registerAllProperties

final void registerAllProperties()
Registers all namespace properties in the shared MetafacadeFactory instance.


setMetaclassPattern

public void setMetaclassPattern(String metaclassPattern)
Sets the pattern of the metaclass implementations based on a metaclass interface name. This should only be set on a metafacade mappings instances that is marked as shared.

Parameters:
metaclassPattern - the pattern for the meta classes.

getAllMetafacadeMappingInstances

static Map<Class,Set<String>> getAllMetafacadeMappingInstances()
Stores every metafacade mapping instance, this is used from MetafacadeUtils.getInheritedMappingClassNames(MetafacadeMapping).

Returns:
all metafacade mapping instances.

getModelMetafacadeMappings

public MetafacadeMappings getModelMetafacadeMappings(String metafacadeModelNamespace)
Should be used used instead of "this", retrieves the appropriate metafacade mappings instance based on the current model type.

Parameters:
metafacadeModelNamespace - the namespace that contains a metafacade model facade implementation.
Returns:
the MetafacadeMappings instance.

getDefaultMetafacadeClass

final Class getDefaultMetafacadeClass(String namespace)
Gets the defaultMetafacadeClass, first looks for it in the namespace mapping, if it can't find it it then takes the default mappings, setting.

Parameters:
namespace - mapping to check for defaultMetafacadeClass
Returns:
Returns the defaultMetafacadeClass.

setDefaultMetafacadeClass

public void setDefaultMetafacadeClass(String defaultMetafacadeClass)
Sets the default metafacade class to use if no other is found for the mapping class.

Parameters:
defaultMetafacadeClass - the default metafacade class.

getMappings

protected Collection<MetafacadeMapping> getMappings()
Retrieves all child MetafacadeMapping instances belonging to this metafacade mappings instance.

Returns:
the collection of MetafacadeMapping instances

registerProperties

final void registerProperties(String namespace,
                              Collection<String> propertyReferences,
                              String metafacadeName)
Registers the defined property references properties in the metafacade factory.

Parameters:
propertyReferences - the property references to register.
metafacadeName - the name of the metafacade under which to register the properties.
namespace - the namespace of the property reference.

shutdown

final void shutdown()
Performs shutdown procedures for the factory. This should be called ONLY when MetafacadeFactory.shutdown()is called.


toString

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


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