de.tuberlin.cs.cis.ocl.model.eval
Interface InstanceDescriptor

All Known Implementing Classes:
ExampleInstanceDesc, MofInstance

public interface InstanceDescriptor

Describes an instance of a type within the model. Each instance is specified by its {link de.tuberlin.cs.cis.ocl.model.check.ClassifierDescriptor classifier}. An instance must therefore define all properties declared by the classifier and its supertypes. This especially includes the predefined supertypes within the OCL-context.

Author:
fchabar
See Also:
ClassifierDescriptor, OCL 1.5 Standard

Method Summary
 InstanceDescriptor cast(ClassifierDescriptor type)
          Casts the actual runtime type of this instance to the specified classifier.
 boolean equals(java.lang.Object modelInstanceDesc)
          Returns true if the specified instance is equal to this instance.
 java.lang.String getName()
          Returns the name of this instance.
 OclAnyInstance getPredefinedParent()
          Defines the predefined parent of this instance.
 InstanceDescriptor getValue(TypedProperty attribute)
          Returns the value of the specified attribute.
 InstanceDescriptor invoke(TypedProperty operation, InstanceDescriptor[] args)
          Invokes an operation on this instance with the arguments args.
 boolean isInstanceOf(ClassifierDescriptor type, boolean considerSubtype)
          Determines if this instance is an instance of the specified type.
 boolean isInState(java.lang.String state)
          Determines if this instance is in state state.
 InstanceDescriptor[] navigate(TypedAssociation association, Instance[] qualifiers)
          Navigates an association of this instance with the specified qualifiers.
 

Method Detail

isInState

public boolean isInState(java.lang.String state)
Determines if this instance is in state state. It is generally checked if the state-machine (if existent) defines the state. If that is the case the result is used to implement the Operation OclAny.oclIsInState(OclState).

Parameters:
state - a state described according to the OCL-Standard.
Returns:
true if this instance is in state state.
See Also:
ClassifierDescriptor.isStateDefined(java.lang.String)

cast

public InstanceDescriptor cast(ClassifierDescriptor type)
                        throws TypeCastException
Casts the actual runtime type of this instance to the specified classifier. A cast can be performed if the static type of this instance is a {link de.tuberlin.cs.cis.ocl.model.check.ClassifierDescriptor#isSubtypeOf(ClassifierDescriptor) subtype} of the specified classifier. The consequences of a cast is that properties of the instance's supertypes can be accessed even if they are overridden. The result is then used to implement the operation OclAny.oclAsType(OclType).

Parameters:
type - a supertype of this instance.
Returns:
The same instance (not necessarily with the same, but equal instance descriptor) with the actual runtime type type.
Throws:
TypeCastException - if this instance cannot be casted to the specified type.

invoke

public InstanceDescriptor invoke(TypedProperty operation,
                                 InstanceDescriptor[] args)
                          throws FeatureInvocationException,
                                 UndefinedValueException
Invokes an operation on this instance with the arguments args. The operation {link de.tuberlin.cs.cis.ocl.model.check.ClassifierDescriptor#isSubtypeOf(ClassifierDescriptor) is obtained} from this instance's static type. Therefore the arguments conform to the operations parameter types.

Parameters:
operation - an operation defined through this instance's static type.
args - arguments that conform to the parameters of operation.
Returns:
The resulting instance of invoking operation on this instance with the specified arguments.
Throws:
FeatureInvocationException - if an exception occurs while invoking the operation.
UndefinedValueException - if the result of the invokation is undefined (for example null).

navigate

public InstanceDescriptor[] navigate(TypedAssociation association,
                                     Instance[] qualifiers)
                              throws FeatureInvocationException,
                                     UndefinedValueException
Navigates an association of this instance with the specified qualifiers. The qualifiers can be used denotationally. Therefore its evaluation can result in a type/instance outside the model. The navigation results in all navigatable association ends of the specified association.

Parameters:
association - an association declared by the instance's classifier.
qualifiers - association qualifiers.
Returns:
All associated Association Ends that can result by navigating the specified association from this instance.
Throws:
FeatureInvocationException - if an exception occurs while navigating the association.
UndefinedValueException - if the result of the naviagtion is undefined (for example null).
See Also:
de.tuberlin.cs.cis.ocl.eval.instance

getValue

public InstanceDescriptor getValue(TypedProperty attribute)
                            throws FeatureInvocationException,
                                   UndefinedValueException
Returns the value of the specified attribute. The attribute is resolved the instance's classifier.

Parameters:
attribute - an attribute of this instance.
Returns:
the value of the specified attribute.
Throws:
FeatureInvocationException - if an exception occurs while resolving the value of the attribute.
UndefinedValueException - if the value of the attribute is undefined.

getPredefinedParent

public OclAnyInstance getPredefinedParent()
Defines the predefined parent of this instance. Each model type is the subtype of a predefined type (derived from OclAny) within the OCL-context. Each predefined type declares behaviour, that is not defined within the model. It is therefore necessary to specify this instance's predefined parent, defining the predefined behaviour of this instance. Defaultly it is assumed that OclAny is the direct predefined parent of this instance. If that is the case the predefined parent can be constructed through the information provided by this instance.

Returns:
The predefined parent of this instance or null if the default parent should be used.

equals

public boolean equals(java.lang.Object modelInstanceDesc)
Returns true if the specified instance is equal to this instance. The result is used to implement the operations OclAny.= and OclAny.<>.

Overrides:
equals in class java.lang.Object
Parameters:
modelInstanceDesc - an instance (!= null)
Returns:
true if the specified instance is equal to this instance, false otherwise.

getName

public java.lang.String getName()
Returns the name of this instance. The name is primaryly used to describe the result of the evaluation of a constraint in dependency to its instances. In the case of an enumeration it is used to resolve the specified instance from its enumeration type. Therefore this method must then result in the OCL-specifier of the enumeration (qualified or unqualified).

Returns:
A meaningful name for this instance, especially if this instance is an enumeration.

isInstanceOf

public boolean isInstanceOf(ClassifierDescriptor type,
                            boolean considerSubtype)
Determines if this instance is an instance of the specified type. That is the case if this instance's actual runtime type is the same type as the specified type or (if considerSubtype is true) one of its subtypes. The result is then used to define the operations OclAny.oclIsKindOf(OclType) and OclAny.isTypeOf(OclType).

Parameters:
type - a model classifier
considerSubtype - determines if subtypes should also be considered.
Returns:
true if this instance is a subtype of the specified type, false otherwise.