Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Getting the OCL File
Getting the OCL File [message #798917] Wed, 15 February 2012 08:21 Go to next message
Harsha Chandran is currently offline Harsha ChandranFriend
Messages: 8
Registered: February 2012
Junior Member
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
Re: Getting the OCL File [message #798927 is a reply to message #798917] Wed, 15 February 2012 08:29 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

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
Re: Getting the OCL File [message #798934 is a reply to message #798927] Wed, 15 February 2012 08:39 Go to previous messageGo to next message
Harsha Chandran is currently offline Harsha ChandranFriend
Messages: 8
Registered: February 2012
Junior Member
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.
Re: Getting the OCL File [message #798953 is a reply to message #798934] Wed, 15 February 2012 09:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

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.
>
Re: Getting the OCL File [message #798984 is a reply to message #798934] Wed, 15 February 2012 09:56 Go to previous messageGo to next message
Harsha Chandran is currently offline Harsha ChandranFriend
Messages: 8
Registered: February 2012
Junior Member
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 .
Re: Getting the OCL File [message #798985 is a reply to message #798984] Wed, 15 February 2012 09:58 Go to previous messageGo to next message
Harsha Chandran is currently offline Harsha ChandranFriend
Messages: 8
Registered: February 2012
Junior Member
Thank you I got it now....I was not seeing it correctly....
Re: Getting the OCL File [message #799007 is a reply to message #798953] Wed, 15 February 2012 10:24 Go to previous messageGo to next message
Harsha Chandran is currently offline Harsha ChandranFriend
Messages: 8
Registered: February 2012
Junior Member
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.
Re: Getting the OCL File [message #799241 is a reply to message #799007] Wed, 15 February 2012 16:39 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

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.
>
Previous Topic:3rd Biannual Eclipse/OMG Workshop on March 25
Next Topic:Problem with Xtext based OCL and accessing inherited properties
Goto Forum:
  


Current Time: Thu Mar 28 15:47:58 GMT 2024

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

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

Back to the top