blob: 73c918f9ebb54417c0c8297bfe2630024e13d107 [file] [log] [blame]
// Copied from org.eclipse.ocl.examples.test.xtext.PivotDocumentationExamples.java
EPackage.Registry registry = new EPackageRegistryImpl();
registry.put(EXTLibraryPackage.eNS_URI, EXTLibraryPackage.eINSTANCE);
PivotEnvironmentFactory environmentFactory = new PivotEnvironmentFactory(registry, null);
OCL ocl = OCL.newInstance(environmentFactory);
// get an OCL text file via some hypothetical API
URI uri = getInputURI("/model/parsingDocumentsExample.ocl");
Map<String, ExpressionInOCL> constraintMap = new HashMap<String, ExpressionInOCL>();
// parse the contents as an OCL document
Resource pivotResource = ocl.parse(uri);
for (TreeIterator<EObject> tit = pivotResource.getAllContents(); tit.hasNext(); ) {
EObject next = tit.next();
if (next instanceof Constraint) {
Constraint constraint = (Constraint)next;
String stereotype = constraint.getStereotype();
if (UMLReflection.INVARIANT.equals(stereotype)) {
ExpressionInOCL expressionInOCL = ocl.getSpecification(constraint);
if (expressionInOCL != null) {
String name = constraint.getName();
if (name != null) {
constraintMap.put(name, expressionInOCL);
System.out.printf("%s: %s%n", name, expressionInOCL.getBodyExpression());
}
}
}
}
}