Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » ocl file parsing
ocl file parsing [message #869960] Sat, 05 May 2012 04:19
Lucy Chan is currently offline Lucy Chan
Messages: 29
Registered: March 2012
Junior Member
I wrote some code and hope to parse the xx.ocl file. The sourcode is as follows:

public class Main{

public static void main(String[] args) throws IOException,ParserException {

try {
OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);

// get an OCL text file via some hypothetical API

//IFile file = getWorkspaceFile("/Architecture/model/instance.ocl");

String path = "model/test.ocl";
File file = new File(path);
InputStream in = new FileInputStream( file );

Map<String, Constraint> constraintMap = new HashMap<String, Constraint>();

// parse the contents as an OCL document
InputStreamReader r = new InputStreamReader(new FileInputStream(file));
OCLInput document = new OCLInput(in, r.getEncoding());

// List<Constraint> constraints = ocl.parse(input);
List<Constraint> constraints = ocl.parse(document);
for (Constraint next : constraints) {
constraintMap.put(next.getName(), next);

// OCLExpression<EClassifier> body =
// next.getSpecification().getBodyExpression();
OCLExpression<EClassifier> body = next.getSpecification().getBodyExpression();
System.out.printf("%s: %s%n", next.getName(), body);
}
in.close();
} catch (Exception err) {
throw err;
}
}
}
very similar with the codes in the ocl document guide. But it has some errors:


Exception in thread "main" org.eclipse.ocl.SyntaxException: 13:1:13:28 "import 'instance.ecore'" unexpected token(s)
at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:350)
at org.eclipse.ocl.OCL.parse(OCL.java:323)
at Main.main(Main.java:66)

Can you tell me how should I modify my codes?
Thanks
  • Attachment: L-Main.java
    (Size: 2.42KB, Downloaded 106 times)
Previous Topic:Making OCL.parse() and import directives
Next Topic:Overload resolution and dynamic dispatch patch
Goto Forum:
  


Current Time: Fri Aug 29 18:33:37 EDT 2014

Powered by FUDForum. Page generated in 0.01760 seconds