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:
java.io.Serializable, NamespaceComponent

public class MetafacadeMappings
extends BaseNamespaceComponent
implements java.io.Serializable

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

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

Field Summary
protected  java.util.Collection inProcessMappings
           Stores the mappings which are currently "in process" (within the getMapping(Object, String, Collection).
protected  java.util.Collection 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(java.lang.String reference)
          Adds a language mapping reference.
protected  java.util.List getContextHierarchy(java.lang.String context)
          Retrieves all inherited contexts (including the root context) from the given context and returns a list containing all of them.
protected  MetafacadeMapping getMapping(java.lang.Object mappingObject, java.lang.String context, java.util.Collection stereotypes)
          

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

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

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

 MetafacadeMappings getModelMetafacadeMappings(java.lang.String metafacadeModelNamespace)
          Should be used used instead of "this", retrieves the appropriate metafacade mappings instance based on the current model type.
 java.util.Collection 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.
 void setDefaultMetafacadeClass(java.lang.String defaultMetafacadeClass)
          Sets the default metafacade class to use if no other is found for the mapping class.
 void setMetaclassPattern(java.lang.String metaclassPattern)
          Sets the pattern of the metaclass implementations based on a metaclass interface name.
 java.lang.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 java.util.Collection 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 java.util.Collection 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 java.lang.Class getMetafacadeInterface(java.lang.Class metafacadeClass)
Gets the class of the metafacade interface that belongs to the given metafacadeClass.

Returns:
the metafacade interface Class.

getPropertyReferences

public java.util.Collection getPropertyReferences()
Gets all property references defined in this mappings instance.

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

getMapping

protected MetafacadeMapping getMapping(java.lang.Object mappingObject,
                                       java.lang.String context,
                                       java.util.Collection 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 hiearchy started with this 'root' context).
Returns:
MetafacadeMapping (or null if none was found matching the criteria).

getMappingObjectHierarchy

protected java.util.List getMappingObjectHierarchy(java.lang.Object mappingObject)
Retrieves the hiearchy 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 java.util.List getContextHierarchy(java.lang.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 visibilty 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(java.lang.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(java.lang.Object mappingObject,
                                              java.lang.String namespace,
                                              java.lang.String context,
                                              java.util.Collection 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 precendence over stereotypes).
stereotypes - collection of sterotype names. We'll check to see if the mapping for the given mappingClass is defined for it.

initialize

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


setMetaclassPattern

public void setMetaclassPattern(java.lang.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.

getModelMetafacadeMappings

public MetafacadeMappings getModelMetafacadeMappings(java.lang.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.

setDefaultMetafacadeClass

public void setDefaultMetafacadeClass(java.lang.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 java.util.Collection getMappings()
Retrieves all child MetafacadeMapping instances belonging to this metafacade mappings instance.

Returns:
the collection of MetafacadeMapping instances

toString

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


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