// Copied from org.eclipse.ocl.examples.test.xtext.PivotDocumentationExamples.java | |
EPackage.Registry registry = new EPackageRegistryImpl(); | |
registry.put(EXTLibraryPackage.eNS_URI, EXTLibraryPackage.eINSTANCE); | |
OCL ocl = OCL.newInstance(registry); | |
// 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 asResource = ocl.parse(uri); | |
for (TreeIterator<EObject> tit = asResource.getAllContents(); tit.hasNext(); ) { | |
EObject next = tit.next(); | |
if (next instanceof Constraint) { | |
Constraint constraint = (Constraint)next; | |
ExpressionInOCL expressionInOCL = ocl.getSpecification(constraint); | |
if (expressionInOCL != null) { | |
String name = constraint.getName(); | |
if (name != null) { | |
constraintMap.put(name, expressionInOCL); | |
debugPrintf("%s: %s%n\n", name, | |
expressionInOCL.getBodyExpression()); | |
} | |
} | |
} | |
} |