blob: 1ec73ae851dc9333ffe5634b569d31828b9c23f4 [file] [log] [blame]
// Copied from org.eclipse.ocl.ecore.tests.DocumentationExamples.java
EPackage.Registry registry = new EPackageRegistryImpl();
registry.put(EXTLibraryPackage.eNS_URI, EXTLibraryPackage.eINSTANCE);
EcoreEnvironmentFactory environmentFactory = new EcoreEnvironmentFactory(registry);
OCL ocl = OCL.newInstance(environmentFactory);
// get an OCL text file via some hypothetical API
InputStream in = getInputStream("/model/parsingDocumentsExample.ocl");
Map<String, Constraint> constraintMap = new HashMap<String, Constraint>();
// parse the contents as an OCL document
try {
OCLInput document = new OCLInput(in);
List<Constraint> constraints = ocl.parse(document);
for (Constraint next : constraints) {
constraintMap.put(next.getName(), next);
OCLExpression<EClassifier> body = next.getSpecification().getBodyExpression();
System.out.printf("%s: %s%n", next.getName(), body);
}
} finally {
in.close();
}