Hello,
This is my first message in Eclipse forum and very new to OCL.I am working on OCL on Ecore.I am trying to get all the constarins into a special view i have created seperatly.I have a problem in getting the OCL file.The OCL file is of the type IFile oclFile.I have no idea how to get the OCL file out of the work bench so that i can pass it to my parase constarins.
This is the class method that i have written:
public List<Constraint> getElementConstrains() throws CoreException, ParserException {
oclpras = new OCLConstraintParserImpl();
List<Constraint> parsedConstraints = new ArrayList<Constraint>();
parsedConstraints=oclpras.parseConstraints(oclFile);
return parsedConstraints;
}
And my OCL parse constarin method is as follows:
@Override
public List<Constraint> parseConstraints(IFile oclFile) throws CoreException, ParserException {
List<Constraint> parsedConstraints = new ArrayList<Constraint>();
InputStream is =oclFile.getContents();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder builder = new StringBuilder();
try {
String line = null;
while((line = reader.readLine())!=null){
//filter all 'import' lines
if (!line.startsWith("import")){
builder.append(line);
builder.append("\n");
}
}
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OCLInput oclInput = new OCLInput(builder.toString());
for (org.eclipse.ocl.ecore.Constraint constraint : ocl.parse(oclInput)) {
if (isInvariant(constraint)) {
UserDefinedConstraint udc = ConsistencyCheckFactory.eINSTANCE.createUserDefinedConstraint();
udc.setOclConstraint(constraint);
parsedConstraints.add(udc);
}
}
return parsedConstraints;
}
Please do help me in getting the solution.Thank you
If you're new to OCL, I strongly recommend installing the additional OCL
Editors and Examples where you will find an OCLinEcore editor and OCL
Console amongst other things. These enable you to use OCL for modeling
without ever looking at a line of Java. Follow the OCLinEcore tutorial.
Once you are familiar with the interactive capabilities you can move on
to Java usage, if you really need to.
Regards
Ed Willink
On 15/02/2012 08:21, Harsha Chandran wrote:
> Hello,
> This is my first message in Eclipse forum and very new to OCL.I am
> working on OCL on Ecore.I am trying to get all the constarins into a
> special view i have created seperatly.I have a problem in getting the
> OCL file.The OCL file is of the type IFile oclFile.I have no idea how
> to get the OCL file out of the work bench so that i can pass it to my
> parase constarins.
>
>
> This is the class method that i have written:
>
> public List<Constraint> getElementConstrains() throws CoreException,
> ParserException {
> oclpras = new OCLConstraintParserImpl();
> List<Constraint> parsedConstraints = new ArrayList<Constraint>();
> parsedConstraints=oclpras.parseConstraints(oclFile);
> return parsedConstraints;
>
> }
>
> And my OCL parse constarin method is as follows:
>
> @Override
> public List<Constraint> parseConstraints(IFile oclFile) throws
> CoreException, ParserException {
> List<Constraint> parsedConstraints = new ArrayList<Constraint>();
> InputStream is =oclFile.getContents();
> BufferedReader reader = new BufferedReader(new
> InputStreamReader(is));
> StringBuilder builder = new StringBuilder();
> try {
> String line = null;
> while((line = reader.readLine())!=null){
> //filter all 'import' lines
> if (!line.startsWith("import")){
> builder.append(line);
> builder.append("\n");
> }
> }
> reader.close();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> OCLInput oclInput = new OCLInput(builder.toString());
>
> for (org.eclipse.ocl.ecore.Constraint constraint :
> ocl.parse(oclInput)) {
> if (isInvariant(constraint)) {
> UserDefinedConstraint udc =
> ConsistencyCheckFactory.eINSTANCE.createUserDefinedConstraint();
> udc.setOclConstraint(constraint);
> parsedConstraints.add(udc);
> }
> }
>
>
> return parsedConstraints;
> }
> Please do help me in getting the solution.Thank you
Thank you for you reply.I have a task in hand where i have to creat a new view that can return me with the constrains.I have gone through OCLin Ecore once.
To be honest, I really didn't understand your first message, and your
new message is equally baffling. I have no idea what you mean by "creat
a new view"?
Regards
Ed Willink
On 15/02/2012 08:39, Harsha Chandran wrote:
> Thank you for you reply.I have a task in hand where i have to creat a
> new view that can return me with the constrains.I have gone through
> OCLin Ecore once.
>
Hello,
I am trying with the tutorial but Interctive editor console is not at all comming in my console ....I have also installed the OCL Example and editors but the console could not be seen.I went to window and tried to get the console but it was of no use .
hi,
Sorry I will make it clear now.I am trying to create a new view where i can display all the constrains that i set for my model.I want to parse the OCL file so that I will be able to get all the contrains related to my model Ecore.
Ah! You really do mean a new View in the Editor/Window sense.
You may find that Topcased, which provides extended modeling facilities
has exactly what you want.
http://wiki.eclipse.org/MDT/OCL/Debugger is an outline of an improved UI
for Eclipse OCL that I'm sure would offer what you're looking for;
unfortunately I have many other things that I also want to do. If you
want to develop a better UI for your own purposes, perhaps you are
intetested in providing it for others too.
Regards
Ed Willink
On 15/02/2012 10:24, Harsha Chandran wrote:
> hi,
> Sorry I will make it clear now.I am trying to create a new view where
> i can display all the constrains that i set for my model.I want to
> parse the OCL file so that I will be able to get all the contrains
> related to my model Ecore.
>