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 08:19
Lucy Chan is currently offline Lucy ChanFriend
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);
} 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(
at org.eclipse.ocl.OCL.parse(
at Main.main(

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

Current Time: Fri Jul 29 21:51:48 GMT 2016

Powered by FUDForum. Page generated in 0.02266 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software