org.eclipse.ocl
Class AbstractTypeResolver<PK,C,O,P,PM>

java.lang.Object
  extended by org.eclipse.ocl.AbstractTypeResolver<PK,C,O,P,PM>
All Implemented Interfaces:
TypeResolver<C,O,P>
Direct Known Subclasses:
TypeResolverImpl, TypeResolverImpl

public abstract class AbstractTypeResolver<PK,C,O,P,PM>
extends java.lang.Object
implements TypeResolver<C,O,P>

A partial implementation of the TypeResolver interface, useful for providers of environment implementations to build their type resolvers.

It is recommended that clients extend this class to customize resolution of types based on their models, rather than implementing the interface. Simply override a few protected methods for creating metamodel-specific constructs.

See the Environment class for a description of the generic type parameters of this class.

Author:
Christian W. Damus (cdamus)

Field Summary
protected static java.lang.String ADDITIONS_PACKAGE
           
protected static java.lang.String COLLECTIONS_PACKAGE
           
protected static java.lang.String MESSAGES_PACKAGE
           
protected static java.lang.String TUPLES_PACKAGE
           
protected static java.lang.String TYPES_PACKAGE
           
 
Constructor Summary
AbstractTypeResolver(Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> env)
          Initializes me with an environment.
AbstractTypeResolver(Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> env, org.eclipse.emf.ecore.resource.Resource resource)
          Initializes me with a resource in which I will persist the model-based types that I generate in my associated Environment.
 
Method Summary
protected abstract  void addClassifier(PK pkg, C classifier)
          Adds a classifier to the specified package, which is one that I use to store OCL-generated types.
protected abstract  void addOperation(C owner, O operation)
          Adds the specified operation to a classifier.
protected abstract  void addProperty(C owner, P property)
          Adds the specified property to a classifier.
protected  PK createAdditionalFeaturesPackage()
          Creates the package containing the additional operations and properties parsed in my environment.
protected  PK createCollectionPackage()
          Creates the package containing the collection types that I generate.
protected  CollectionType<C,O> createCollectionType(CollectionKind kind, C elementType)
          Creates a new collection type of the specified kind and element type, assuming that it does not already exist.
protected  PK createMessagePackage()
          Creates the package containing the message types that I generate.
protected  MessageType<C,O,P> createOperationMessageType(O operation)
          Creates a new message type for the specified element, assuming that it does not already exist.
protected abstract  PK createPackage(java.lang.String name)
          Creates a package with the specified name.
protected  org.eclipse.emf.ecore.resource.Resource createResource()
          Creates the resource that persists my generated types.
protected abstract  C createShadowClass(C type)
          Creates the shadow class to contain additional features defined for the specified OCL type.
protected  MessageType<C,O,P> createSignalMessageType(C signal)
          Creates a new message type for the specified element, assuming that it does not already exist.
protected  PK createTuplePackage()
          Creates the package containing the tuple types that I generate.
protected  TupleType<O,P> createTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
          Creates a new tuple type from the specified parts, assuming that it does not already exist.
protected  PK createTypePackage()
          Creates the package containing the type types that I generate.
protected  TypeType<C,O> createTypeType(C type)
          Creates a new type type for the specified type, assuming that it does not already exist.
 void dispose()
          Disposes me by unloading my resource, if and only if I created it in the first place.
protected  PK findAdditionalFeaturesPackage()
          Finds the package storing additional features, if our resource already contains it.
protected  PK findCollectionPackage()
          Finds the package storing collection types, if our resource already contains it.
protected  CollectionType<C,O> findCollectionType(CollectionKind kind, C elementType)
          Finds an existing collection type matching the specified kind and element type, if any has already been created.
protected  O findMatchingOperation(C shadow, O operation)
          Finds an operation already existing in the specified shadow class that matches the specified operation signature.
protected  P findMatchingProperty(C shadow, P property)
          Finds a property already existing in the specified shadow class that matches the specified property signature.
protected  PK findMessagePackage()
          Finds the package storing message types, if our resource already contains it.
protected  MessageType<C,O,P> findMessageType(java.lang.Object element)
          Finds an existing message type matching the specified element, if any has already been created.
protected abstract  PK findPackage(java.lang.String name)
          Finds the existing package with the specified name in my resource.
protected  C findShadowClass(C type)
          Finds the shadow class to contain additional features defined for the specified OCL type, if it already exists.
protected  PK findTuplePackage()
          Finds the package storing tuple types, if our resource already contains it.
protected  TupleType<O,P> findTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
          Finds an existing tuple type matching the specified parts, if any has already been created.
protected  PK findTypePackage()
          Finds the package storing type types, if our resource already contains it.
protected  TypeType<C,O> findTypeType(C type)
          Finds an existing type type matching the specified type, if any has already been created.
 java.util.List<P> getAdditionalAttributes(C owner)
          Obtains the additional attributes defined (via OCL) in the specified classifier context.
 PK getAdditionalFeaturesPackage()
          Obtains the package containing the additional operations and properties parsed in my environment.
 java.util.List<O> getAdditionalOperations(C owner)
          Obtains the additional operations defined (via OCL) in the specified classifier context.
 PK getCollectionPackage()
          Obtains the package containing the collection types that I generate.
protected  Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> getEnvironment()
          Obtains the environment that I persist.
 PK getMessagePackage()
          Obtains the package containing the message types that I generate.
 org.eclipse.emf.ecore.resource.Resource getResource()
          Obtains the resource in which the types that I generate are stored for persistence.
protected  C getShadowClass(C type)
          Obtains the shadow class for the specified model classifier, creating it if necessary.
protected abstract  C getShadowedClassifier(C shadow)
          Obtains the classifier for which the specified shadow stores additional features.
 PK getTuplePackage()
          Obtains the package containing the tuple types that I generate.
 PK getTypePackage()
          Obtains the package containing the type types that I generate.
protected  boolean hasAdditionalFeatures()
          Queries whether the current environment has any additional features defined at all.
 C resolve(C type)
          Resolves the specified type, returning my own persistent type instance representing the same OCL type.
 P resolveAdditionalAttribute(C owner, P property)
          Resolves the specified "additional attribute" defined by the OCL client on the specified owner type.
 O resolveAdditionalOperation(C owner, O operation)
          Resolves the specified "additional operation" defined by the OCL client on the specified owner type.
 CollectionType<C,O> resolveCollectionType(CollectionKind kind, C elementType)
          Resolves the collection type of the specified kind and element type, either created anew or previously created.
 MessageType<C,O,P> resolveOperationMessageType(O operation)
          Resolves the type for a message expression referencing the specified operation.
 MessageType<C,O,P> resolveSignalMessageType(C signal)
          Resolves the type for a message expression referencing the specified signal.
 TupleType<O,P> resolveTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
          Resolves the tuple type consisting of the specified parts, in no particular order, either created anew or previously created.
 TypeType<C,O> resolveTypeType(C type)
          Resolves the type for a type expression referencing the specified type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLLECTIONS_PACKAGE

protected static final java.lang.String COLLECTIONS_PACKAGE
See Also:
Constant Field Values

MESSAGES_PACKAGE

protected static final java.lang.String MESSAGES_PACKAGE
See Also:
Constant Field Values

TUPLES_PACKAGE

protected static final java.lang.String TUPLES_PACKAGE
See Also:
Constant Field Values

TYPES_PACKAGE

protected static final java.lang.String TYPES_PACKAGE
See Also:
Constant Field Values

ADDITIONS_PACKAGE

protected static final java.lang.String ADDITIONS_PACKAGE
See Also:
Constant Field Values
Constructor Detail

AbstractTypeResolver

public AbstractTypeResolver(Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> env)
Initializes me with an environment. I create my own resource for persistence of model-based types.

Parameters:
env - the environment that I persist

AbstractTypeResolver

public AbstractTypeResolver(Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> env,
                            org.eclipse.emf.ecore.resource.Resource resource)
Initializes me with a resource in which I will persist the model-based types that I generate in my associated Environment.

Parameters:
env - my environment
resource - my resource
Method Detail

resolve

public C resolve(C type)
Description copied from interface: TypeResolver
Resolves the specified type, returning my own persistent type instance representing the same OCL type.

The type may have been newly created by the parser and be a duplicate of a type previously resolved, or it may actually be a type that was previously resolved. In the latter case, the type is returned as is. The null type is considered to be resolved (i.e., the result is also null).

Usually, this method will delegate to one of the resolveXyzType() methods defined by this interface.

Specified by:
resolve in interface TypeResolver<C,O,P>
Parameters:
type - a type to resolve
Returns:
the resolved type, or type if it is already resolved

getEnvironment

protected final Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> getEnvironment()
Obtains the environment that I persist.

Returns:
my environment

getResource

public org.eclipse.emf.ecore.resource.Resource getResource()
Description copied from interface: TypeResolver
Obtains the resource in which the types that I generate are stored for persistence.

Specified by:
getResource in interface TypeResolver<C,O,P>
Returns:
my resource

createResource

protected org.eclipse.emf.ecore.resource.Resource createResource()
Creates the resource that persists my generated types. Subclasses requiring persistence must override this default implementation, as it creates a resource that does not support persistence and does not have a useful URI. A subclass could even find some other resource, such as the model on which constraints are being parsed, if desired.

Returns:
the new resource

getCollectionPackage

public PK getCollectionPackage()
Obtains the package containing the collection types that I generate.

Returns:
my collection type package

createCollectionPackage

protected PK createCollectionPackage()
Creates the package containing the collection types that I generate.

Returns:
the new collection type package

findCollectionPackage

protected PK findCollectionPackage()
Finds the package storing collection types, if our resource already contains it.

Returns:
the existing collection types package, or null if it does not yet exist

resolveCollectionType

public CollectionType<C,O> resolveCollectionType(CollectionKind kind,
                                                 C elementType)
Description copied from interface: TypeResolver
Resolves the collection type of the specified kind and element type, either created anew or previously created.

Specified by:
resolveCollectionType in interface TypeResolver<C,O,P>
Parameters:
kind - the kind of collection type to create
elementType - the element type
Returns:
the new or existing collection type

createCollectionType

protected CollectionType<C,O> createCollectionType(CollectionKind kind,
                                                   C elementType)
Creates a new collection type of the specified kind and element type, assuming that it does not already exist.

Parameters:
kind - the kind of collection to create
elementType - the collection's element type
Returns:
the new collection type

findCollectionType

protected CollectionType<C,O> findCollectionType(CollectionKind kind,
                                                 C elementType)
Finds an existing collection type matching the specified kind and element type, if any has already been created.

Parameters:
kind - the element kind to search for
elementType - the element type to search for
Returns:
the existing collection type, or null if none found

getTuplePackage

public PK getTuplePackage()
Obtains the package containing the tuple types that I generate.

Returns:
my tuple type package

createTuplePackage

protected PK createTuplePackage()
Creates the package containing the tuple types that I generate.

Returns:
the new tuple type package

findTuplePackage

protected PK findTuplePackage()
Finds the package storing tuple types, if our resource already contains it.

Returns:
the existing tuple types package, or null if it does not yet exist

resolveTupleType

public TupleType<O,P> resolveTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
Description copied from interface: TypeResolver
Resolves the tuple type consisting of the specified parts, in no particular order, either created anew or previously created. The resulting type is uniquely defined by the names and types of its parts, and twp tuple types are considered equal if they have the same number of parts and their parts correspond one-for-one in name and type (order is not significant).

Specified by:
resolveTupleType in interface TypeResolver<C,O,P>
Parameters:
parts - a list of TypedElements defining the name and type of each tuple part. The part names are unique
Returns:
the new or existing tuple type

createTupleType

protected TupleType<O,P> createTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
Creates a new tuple type from the specified parts, assuming that it does not already exist.

Parameters:
parts - the TypedElements describing the tuple parts
Returns:
the new tuple type

findTupleType

protected TupleType<O,P> findTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
Finds an existing tuple type matching the specified parts, if any has already been created.

Parameters:
parts - the TypedElements describing the tuple parts
Returns:
the existing tuple type, or null if none found

getTypePackage

public PK getTypePackage()
Obtains the package containing the type types that I generate.

Returns:
my type type package

createTypePackage

protected PK createTypePackage()
Creates the package containing the type types that I generate.

Returns:
the new type type package

findTypePackage

protected PK findTypePackage()
Finds the package storing type types, if our resource already contains it.

Returns:
the existing type types package, or null if it does not yet exist

resolveTypeType

public TypeType<C,O> resolveTypeType(C type)
Description copied from interface: TypeResolver
Resolves the type for a type expression referencing the specified type. This is, effectively, the OCL metatype counterpart for the specified model type.

Specified by:
resolveTypeType in interface TypeResolver<C,O,P>
Parameters:
type - a model type
Returns:
the new or existing type type

createTypeType

protected TypeType<C,O> createTypeType(C type)
Creates a new type type for the specified type, assuming that it does not already exist.

Parameters:
type - the referenced model type
Returns:
the new type type

findTypeType

protected TypeType<C,O> findTypeType(C type)
Finds an existing type type matching the specified type, if any has already been created.

Parameters:
type - the referenced model type
Returns:
the existing type type, or null if none found

getMessagePackage

public PK getMessagePackage()
Obtains the package containing the message types that I generate.

Returns:
my message type package

createMessagePackage

protected PK createMessagePackage()
Creates the package containing the message types that I generate.

Returns:
the new message type package

findMessagePackage

protected PK findMessagePackage()
Finds the package storing message types, if our resource already contains it.

Returns:
the existing message types package, or null if it does not yet exist

resolveOperationMessageType

public MessageType<C,O,P> resolveOperationMessageType(O operation)
Description copied from interface: TypeResolver
Resolves the type for a message expression referencing the specified operation.

Specified by:
resolveOperationMessageType in interface TypeResolver<C,O,P>
Parameters:
operation - the operation call that the message represents
Returns:
the new or existing message type

resolveSignalMessageType

public MessageType<C,O,P> resolveSignalMessageType(C signal)
Description copied from interface: TypeResolver
Resolves the type for a message expression referencing the specified signal.

Specified by:
resolveSignalMessageType in interface TypeResolver<C,O,P>
Parameters:
signal - the signal send that the message represents
Returns:
the new or existing message type

createOperationMessageType

protected MessageType<C,O,P> createOperationMessageType(O operation)
Creates a new message type for the specified element, assuming that it does not already exist.

Parameters:
operation - the operation referenced by the message type
Returns:
the new message type

createSignalMessageType

protected MessageType<C,O,P> createSignalMessageType(C signal)
Creates a new message type for the specified element, assuming that it does not already exist.

Parameters:
signal - the signal referenced by the message type
Returns:
the new message type

findMessageType

protected MessageType<C,O,P> findMessageType(java.lang.Object element)
Finds an existing message type matching the specified element, if any has already been created.

Parameters:
element - the referenced model element
Returns:
the existing message type, or null if none found

getAdditionalFeaturesPackage

public PK getAdditionalFeaturesPackage()
Obtains the package containing the additional operations and properties parsed in my environment.

Returns:
my additional features package

createAdditionalFeaturesPackage

protected PK createAdditionalFeaturesPackage()
Creates the package containing the additional operations and properties parsed in my environment.

Returns:
the new additional features package

findAdditionalFeaturesPackage

protected PK findAdditionalFeaturesPackage()
Finds the package storing additional features, if our resource already contains it.

Returns:
the existing additional features package, or null if it does not yet exist

resolveAdditionalOperation

public O resolveAdditionalOperation(C owner,
                                    O operation)
Description copied from interface: TypeResolver
Resolves the specified "additional operation" defined by the OCL client on the specified owner type.

Specified by:
resolveAdditionalOperation in interface TypeResolver<C,O,P>
Parameters:
owner - the type on which the additional operation is defined
operation - the additional operation
Returns:
the persistent operation

getAdditionalOperations

public java.util.List<O> getAdditionalOperations(C owner)
Description copied from interface: TypeResolver
Obtains the additional operations defined (via OCL) in the specified classifier context.

Specified by:
getAdditionalOperations in interface TypeResolver<C,O,P>
Parameters:
owner - the context classifier
Returns:
its additional operations, or an empty list if none

findMatchingOperation

protected O findMatchingOperation(C shadow,
                                  O operation)
Finds an operation already existing in the specified shadow class that matches the specified operation signature.

Parameters:
shadow - the shadow class to search
operation - the operation to match
Returns:
the matching operation, or null if not found

findMatchingProperty

protected P findMatchingProperty(C shadow,
                                 P property)
Finds a property already existing in the specified shadow class that matches the specified property signature.

Parameters:
shadow - the shadow class to search
property - the property to match
Returns:
the matching operation, or null if not found

resolveAdditionalAttribute

public P resolveAdditionalAttribute(C owner,
                                    P property)
Description copied from interface: TypeResolver
Resolves the specified "additional attribute" defined by the OCL client on the specified owner type.

Specified by:
resolveAdditionalAttribute in interface TypeResolver<C,O,P>
Parameters:
owner - the type on which the additional attribute is defined
property - the additional attribute
Returns:
the persistent attribute

hasAdditionalFeatures

protected boolean hasAdditionalFeatures()
Queries whether the current environment has any additional features defined at all.

Returns:
whether I have any additional features

getAdditionalAttributes

public java.util.List<P> getAdditionalAttributes(C owner)
Description copied from interface: TypeResolver
Obtains the additional attributes defined (via OCL) in the specified classifier context.

Specified by:
getAdditionalAttributes in interface TypeResolver<C,O,P>
Parameters:
owner - the context classifier
Returns:
its additional attributes, or an empty list if none

createShadowClass

protected abstract C createShadowClass(C type)
Creates the shadow class to contain additional features defined for the specified OCL type.

Parameters:
type - an OCL type
Returns:
the class containing its additional features

addProperty

protected abstract void addProperty(C owner,
                                    P property)
Adds the specified property to a classifier.

Parameters:
owner - the classifier to own the property
property - the property to add to the classifier

addOperation

protected abstract void addOperation(C owner,
                                     O operation)
Adds the specified operation to a classifier.

Parameters:
owner - the classifier to own the operation
operation - the operation to add to the classifier

findShadowClass

protected C findShadowClass(C type)
Finds the shadow class to contain additional features defined for the specified OCL type, if it already exists.

Parameters:
type - an OCL type
Returns:
the class containing its additional features, or null if not found

getShadowedClassifier

protected abstract C getShadowedClassifier(C shadow)
Obtains the classifier for which the specified shadow stores additional features.

Parameters:
shadow - a class originally created to shadow a model classifier
Returns:
the model classifier that it supports
See Also:
createShadowClass(Object), getShadowClass(Object)

getShadowClass

protected C getShadowClass(C type)
Obtains the shadow class for the specified model classifier, creating it if necessary. The shadow class will store attributes and operations on behalf of this model classifier.

Parameters:
type - a classifier in the model
Returns:
its shadow

createPackage

protected abstract PK createPackage(java.lang.String name)
Creates a package with the specified name. This puts the new package in an appropriate place in my resource.

Parameters:
name - the package name
Returns:
the new package, persisted in my resource

findPackage

protected abstract PK findPackage(java.lang.String name)
Finds the existing package with the specified name in my resource. This will be one of the packages that I would create for storing OCL-generated types.

Parameters:
name - the package to seek
Returns:
the package, or null if none

addClassifier

protected abstract void addClassifier(PK pkg,
                                      C classifier)
Adds a classifier to the specified package, which is one that I use to store OCL-generated types.

Parameters:
pkg - one of my packages
classifier - a classifier to add to it

dispose

public void dispose()
Disposes me by unloading my resource, if and only if I created it in the first place. If I was loaded from an existing resource, then it is the client's responsibility to manage it.

Since:
1.2