de.tuberlin.cs.cis.ocl.example.eval
Class ExampleInstanceDesc

java.lang.Object
  |
  +--de.tuberlin.cs.cis.ocl.example.eval.ExampleInstanceDesc
All Implemented Interfaces:
InstanceDescriptor

public class ExampleInstanceDesc
extends java.lang.Object
implements InstanceDescriptor

Describes an instance of types contained in the Example Class Diagram of OCL1.5 chapter 6.2.2. The Java Reflection API for description purposes.

Author:
fchabar
See Also:
OCL 1.5 Standard

Constructor Summary
ExampleInstanceDesc(java.lang.Object representation)
           
 
Method Summary
 InstanceDescriptor cast(ClassifierDescriptor supertype)
          Casts the actual runtime type of this instance to the specified classifier.
 boolean equals(java.lang.Object o)
          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.
 java.lang.Object getRepresentation()
          Returns this descriptor's Java representation.
 ClassifierDescriptor getType()
           
 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.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExampleInstanceDesc

public ExampleInstanceDesc(java.lang.Object representation)
Method Detail

cast

public InstanceDescriptor cast(ClassifierDescriptor supertype)
                        throws TypeCastException
Description copied from interface: InstanceDescriptor
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).

Specified by:
cast in interface InstanceDescriptor
Parameters:
supertype - 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.

isInState

public boolean isInState(java.lang.String state)
Description copied from interface: InstanceDescriptor
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).

Specified by:
isInState in interface InstanceDescriptor
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)

getValue

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

Specified by:
getValue in interface InstanceDescriptor
Parameters:
attribute - an attribute of this instance.
Returns:
the value of the specified attribute.
Throws:
UndefinedValueException - if the value of the attribute is undefined.
FeatureInvocationException - if an exception occurs while resolving the value of the attribute.

invoke

public InstanceDescriptor invoke(TypedProperty operation,
                                 InstanceDescriptor[] args)
                          throws FeatureInvocationException,
                                 UndefinedValueException
Description copied from interface: InstanceDescriptor
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.

Specified by:
invoke in interface InstanceDescriptor
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:
UndefinedValueException - if the result of the invokation is undefined (for example null).
FeatureInvocationException - if an exception occurs while invoking the operation.

navigate

public InstanceDescriptor[] navigate(TypedAssociation association,
                                     Instance[] qualifiers)
                              throws FeatureInvocationException,
                                     UndefinedValueException
Description copied from interface: InstanceDescriptor
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.

Specified by:
navigate in interface InstanceDescriptor
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:
UndefinedValueException - if the result of the naviagtion is undefined (for example null).
FeatureInvocationException - if an exception occurs while navigating the association.
See Also:
de.tuberlin.cs.cis.ocl.eval.instance

getRepresentation

public java.lang.Object getRepresentation()
Returns this descriptor's Java representation.

Returns:
this descriptor's Java representation.

equals

public boolean equals(java.lang.Object o)
Description copied from interface: InstanceDescriptor
Returns true if the specified instance is equal to this instance. The result is used to implement the operations OclAny.= and OclAny.<>.

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

getName

public java.lang.String getName()
Description copied from interface: InstanceDescriptor
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).

Specified by:
getName in interface InstanceDescriptor
Returns:
A meaningful name for this instance, especially if this instance is an enumeration.

toString

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

getPredefinedParent

public OclAnyInstance getPredefinedParent()
Description copied from interface: InstanceDescriptor
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.

Specified by:
getPredefinedParent in interface InstanceDescriptor
Returns:
The predefined parent of this instance or null if the default parent should be used.

getType

public ClassifierDescriptor getType()

isInstanceOf

public boolean isInstanceOf(ClassifierDescriptor type,
                            boolean considerSubtype)
Description copied from interface: InstanceDescriptor
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).

Specified by:
isInstanceOf in interface InstanceDescriptor
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.