|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.emf.validation.ocl.AbstractOCLModelConstraint<C,CT,CLS,E>
C
- The metaclass corresponding to the UML Classifier in the environment
provided by subclasses.CT
- The metaclass corresponding to the UML Constraint in the environment
provided by subclasses.CLS
- The metaclass corresponding to the UML Class in the environment
provided by subclasses.E
- The metaclass of run-time instances in the environment
provided by subclasses.public abstract class AbstractOCLModelConstraint<C,CT,CLS,E>
An OCL-language implementation of the
IModelConstraint
interface.
This class considers the OCL constraint text as a context-free expression,
possibly targeting multiple model types (because the validation framework
permits declaration of any number of targets). A separate OCL Query
is created and cached for each of these target types as required.
Any problems in parsing or executing the OCL will result in the constraint being disabled at run-time.
This class is intended to be used by clients of the validation framework that need to customize the OCL parsing environment for their constraints.
The generic type parameters declared by this class correspond to the like-named
parameters of the EnvironmentFactory
interface.
Field Summary |
---|
Fields inherited from interface org.eclipse.emf.validation.model.IModelConstraint |
---|
STATUS_CODE_SUCCESS |
Constructor Summary | |
---|---|
AbstractOCLModelConstraint(IConstraintDescriptor descriptor)
Initializes me with the descriptor which contains my OCL
body. |
Method Summary | |
---|---|
protected EnvironmentFactory |
createEnvironmentFactory()
Deprecated. Override the createOCLEnvironmentFactory() method,
instead. |
protected EnvironmentFactory<?,C,?,?,?,?,?,?,?,CT,CLS,E> |
createOCLEnvironmentFactory()
Creates an Environment Factory suitable for the parsing of the client's OCL constraints. |
Query |
getCondition(EClass eClass)
Deprecated. Use the getConstraintCondition(EObject) method, instead. |
Query<C,CLS,E> |
getConstraintCondition(EObject target)
Obtains the cached OCL query/constraint that implements me for the specified element's metaclass. |
IConstraintDescriptor |
getDescriptor()
Obtains my descriptor, which provides a variety of meta-data about me. |
IStatus |
validate(IValidationContext ctx)
Validates an object in the specified context. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractOCLModelConstraint(IConstraintDescriptor descriptor)
descriptor
which contains my OCL
body.
descriptor
- the descriptor, which must contain an OCL expression
in its bodyMethod Detail |
---|
protected EnvironmentFactory<?,C,?,?,?,?,?,?,?,CT,CLS,E> createOCLEnvironmentFactory()
null
,
signalling that compatibility with the OCL 1.0 API is required. In such
case, the result of the createEnvironmentFactory()
method is
used.
null
to use the result of the
createEnvironmentFactory()
method@Deprecated protected EnvironmentFactory createEnvironmentFactory()
createOCLEnvironmentFactory()
method,
instead.
public Query<C,CLS,E> getConstraintCondition(EObject target)
target
- a model element
@Deprecated public Query getCondition(EClass eClass)
getConstraintCondition(EObject)
method, instead.
eClass
- an EMF model object type
public IStatus validate(IValidationContext ctx)
IModelConstraint
Validates an object in the specified context. The
target
of the validation operation
is available from the context object.
Note that it is best to use the
IValidationContext.createSuccessStatus()
and
IValidationContext.createFailureStatus(Object...)
methods of the context
object to create the status object returned from this method, to ensure
that the status object returned is correctly handled by the validation
system.
A single constraint implementation may check multiple conditions. In such
cases, it can return a
multi-status
of
multiple results created by the overloaded variants of the
ConstraintStatus.createStatus(IValidationContext, org.eclipse.emf.ecore.EObject, Collection, String, Object...)
method. In these cases, also, each resulting status can store a distinct
result locus. For example:
public IStatus validate(IValidationContext ctx) { List problems = new java.util.ArrayList(); // check the first condition. This method adds results to the // ctx's result locus if it finds a problem IStatus problem = checkFirstCondition(ctx); if (problem != null) problems.add(problem); // check another condition, involving different objects problem = checkSecondCondition(ctx); if (problem != null) problems.add(problem); return problems.isEmpty()? ctx.createSuccessStatus() : ConstraintStatus.createMultiStatus(ctx, problems); } private IStatus checkFirstCondition(IValidationContext ctx) { EObject target = ctx.getTarget(); Collection problemElements = ...; // collect problem elements boolean ok = ... ; // check the target and some related objects return ok? null : ConstraintStatus.createStatus( ctx, problemElements, "Problem with {0}", new Object[] {problemElements}); } private IStatus checkSecondCondition(IValidationContext ctx) ...
validate
in interface IModelConstraint
ctx
- the validation context that provides access to the current
constraint evaluation environment. The framework will never
pass a null
value
IStatus.getSeverity()
of the record is either
IStatus.OK
to indicate success,
or some other value to indicate that validation failed.
Must not return null
IValidationContext.createSuccessStatus()
,
IValidationContext.createFailureStatus(Object...)
,
ConstraintStatus.createStatus(IValidationContext, org.eclipse.emf.ecore.EObject, Collection, String, Object[])
public IConstraintDescriptor getDescriptor()
IModelConstraint
getDescriptor
in interface IModelConstraint
|
Copyright 2002, 2007 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |