de.tuberlin.cs.cis.ocl.model.mofbridge
Class MofInstance

java.lang.Object
  |
  +--de.tuberlin.cs.cis.ocl.model.mofbridge.MofInstance
All Implemented Interfaces:
InstanceDescriptor

public class MofInstance
extends java.lang.Object
implements InstanceDescriptor

Describes an instance from the MOF-Model for OCL.

Author:
fchabar

Constructor Summary
MofInstance(ClassifierDescriptor type, java.lang.Object object, ConceptFactory oclMapper)
          Constructs a primitive MOF-Instance.
MofInstance(javax.jmi.reflect.RefObject refObject, ConceptFactory oclMapper)
          Constructs a non-primitive MOF-Instance.
 
Method Summary
 InstanceDescriptor cast(ClassifierDescriptor mtd)
          Casts the actual runtime type of this instance to the specified classifier.
 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.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.tuberlin.cs.cis.ocl.model.eval.InstanceDescriptor
equals
 

Constructor Detail

MofInstance

public MofInstance(javax.jmi.reflect.RefObject refObject,
                   ConceptFactory oclMapper)
Constructs a non-primitive MOF-Instance.

Parameters:
refObject - reflects the instance.

MofInstance

public MofInstance(ClassifierDescriptor type,
                   java.lang.Object object,
                   ConceptFactory oclMapper)
Constructs a primitive MOF-Instance.

Parameters:
type - the primitve type of the instance.
object - the jmi-representation of the instance.
Method Detail

cast

public InstanceDescriptor cast(ClassifierDescriptor mtd)
                        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:
mtd - 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.

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.

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)

navigate

public InstanceDescriptor[] navigate(TypedAssociation association,
                                     Instance[] qualifiers)
                              throws FeatureInvocationException
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:
FeatureInvocationException - if an exception occurs while navigating the association.
See Also:
de.tuberlin.cs.cis.ocl.eval.instance

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.

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

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.