Home » Modeling » OCL » HOW TO PARSE UML2.1 class diagram with OCL?
HOW TO PARSE UML2.1 class diagram with OCL? [message #629068] |
Mon, 27 September 2010 04:09 |
hutzu Messages: 15 Registered: September 2010 |
Junior Member |
|
|
Hello,
I want to read UML2.1 class diagram with OCL(.txt)
it means need to read two files(class diagram is .uml,OCL use txt to write and name .ocl)
First ,i thought i could only read ocl file ,but it couldn't.
It must need class diagram?is it right?
my snippet code:
OCL< Package,Classifier,Operation,Property,EnumerationLiteral,Par ameter,State,CallOperationAction,SendSignalAction,Constraint ,Class,EObject > ocl;
org.eclipse.emf.common.util.URI uri = URI.createFileURI("Triangle.uml");
final ResourceSet set = new ResourceSetImpl();
Registry registry = set.getPackageRegistry();
UMLEnvironmentFactory umlEnv = new UMLEnvironmentFactory(registry ,set);
umlEnv.loadEnvironment(set.getResource(uri, true));
OCL ocl = OCL.newInstance(umlEnv);
FileInputStream in = null;
in = new FileInputStream("Triangle.ocl");
OCLInput document = new OCLInput(in);
List<Constraint> constraints = ocl.parse(document); //error?
Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'Triangle.uml'; a registered resource factory is needed
Can someone help me to solve the problem?
Or some snippet code?
best regards
hutzu
|
|
|
Re: HOW TO PARSE UML2.1 class diagram with OCL? [message #629072 is a reply to message #629068] |
Mon, 27 September 2010 05:50 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi hutzu
You're nearly there, but this is a basic EMF problem, so you may want to
consider using Ecore in isolation for a little practice first.
When running within Eclipse, plugin registrations provide most of your
required environment automatically. When running standalone as you
appear to be you must define the environment yourself, so you need to
register a UMLResourceFactory to service uml files.
Invoking org.eclipse.ocl.uml.OCL.initialize(resourceSet) should solve
this and a number of similar problems. Read the Javadoc.
Regards
Ed Willink
On 27/09/2010 05:09, hutzu wrote:
> Hello,
> I want to read UML2.1 class diagram with OCL(.txt)
> it means need to read two files(class diagram is .uml,OCL use txt to
> write and name .ocl)
>
> First ,i thought i could only read ocl file ,but it couldn't.
> It must need class diagram?is it right?
>
> my snippet code:
> OCL< Package,Classifier,Operation,Property,EnumerationLiteral,Par
> ameter,State,CallOperationAction,SendSignalAction,Constraint
> ,Class,EObject > ocl;
>
> org.eclipse.emf.common.util.URI uri = URI.createFileURI("Triangle.uml");
> final ResourceSet set = new ResourceSetImpl();
> Registry registry = set.getPackageRegistry();
> UMLEnvironmentFactory umlEnv = new UMLEnvironmentFactory(registry ,set);
> umlEnv.loadEnvironment(set.getResource(uri, true));
> OCL ocl = OCL.newInstance(umlEnv);
> FileInputStream in = null;
> in = new FileInputStream("Triangle.ocl");
> OCLInput document = new OCLInput(in);
> List<Constraint> constraints = ocl.parse(document); //error?
>
> Exception in thread "main" java.lang.RuntimeException: Cannot create a
> resource for 'Triangle.uml'; a registered resource factory is needed
>
> Can someone help me to solve the problem?
> Or some snippet code?
>
> best regards
> hutzu
>
>
|
|
| | |
Re: HOW TO PARSE UML2.1 class diagram with OCL? [message #630819 is a reply to message #629676] |
Tue, 05 October 2010 07:51 |
hutzu Messages: 15 Registered: September 2010 |
Junior Member |
|
|
Sorry , Ed Willink
i try to find the answer , but still can't .
You say i must create additional UMLEnvironmentFactory .
But how?
in UMLEnvironmentFactory only have some method .
like createEnvironment() , createEvaluationEnvironment() ,...
But i thought UML2 tool class diagram with OCL(.txt) should be the most popular!
why so few document and information about it?
can you show me some useful document , contain som snippet code?
thank a lot.
my snippet coee:
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put (Resource.Factory.Registry.DEFAULT_EXTENSION,new UMLResourceFactoryImpl());
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
URI uri = URI.createFileURI(umlfile.getAbsolutePath());//umlfile is my class diagram
Resource resource = resourceSet.createResource(uri);
UMLEnvironmentFactory umlEnvFactory = new UMLEnvironmentFactory(resourceSet);
umlEnvFactory.loadEnvironment(resource);
OCL ocl = OCL.newInstance(umlEnvFactory);
FileInputStream in = null;
in = new FileInputStream(oclfile);//my ocl file is .txt .
OCLInput document = new OCLInput(in);
List<Constraint> constraints = ocl.parse(document);
and i got
org.eclipse.ocl.SemanticException: Unable to find package:
it means my oclfile possible wrong?
and last i know my " List<Constraint> constraints = ocl.parse(document);"
ocl is null,
how to get an INSTANCE to it?
best regards
hutzu
[Updated on: Tue, 05 October 2010 08:16] Report message to a moderator
|
|
|
Re: HOW TO PARSE UML2.1 class diagram with OCL? [message #630831 is a reply to message #630819] |
Tue, 05 October 2010 08:32 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi Hutzu
UMLEnvironmentFactory also has three constructors, including a no
argument one, so your original problem of 'no INSTANCE' was solved by
changing
ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
to
ocl = OCL.newInstance(new UMLEnvironmentFactory());
----
Historically, MDT/OCL was for Ecore meta-models with a Java API. This
has grown to support UML meta-models, however the support for UML
throughout Eclipse is much more challenging.
Current work is providing a sensible user IDE, for which prototype
(Ecore-only) editors can be found in the additional MDT/OCL Examples
install. This should provide comprehensive Ecore an UML support fopr
Indigo, at which point we might also go for a major revision of the
documentation that has not always tracked all options.
In the mean-time you seem happy to try to use the Java API, so I suggest
that you import the tests plugin sources into your workspace.
Then by searching on all references to UMLEnvironmentFactory you will
find for instance that
org.eclipse.ocl.uml.tests.UMLEnvironmentTest.test_extensibil ity_156360()
has code that loads UML OCL.
Regards
Ed Willink
On 05/10/2010 08:51, hutzu wrote:
> Sorry , Ed Willink
> i try to find the answer , but still can't .
> You say i must create additional UMLEnvironmentFactory .
> But how?
> in UMLEnvironmentFactory only have some method .
> like createEnvironment() , createEvaluationEnvironment() ,...
>
>
> But i thought UML2 tool class diagram with OCL(.txt) should be the most
> popular!
> why so few document and information about it?
>
> can you show me some useful document , contain som snippet code?
> thank a lot.
>
> best regards
> hutzu
>
>
>
>
>
|
|
|
Re: HOW TO PARSE UML2.1 class diagram with OCL? [message #631315 is a reply to message #630831] |
Thu, 07 October 2010 03:17 |
hutzu Messages: 15 Registered: September 2010 |
Junior Member |
|
|
Tanks again!!!
I am already have a ecore parser with OCL ,so I always want to do little change to parser UML with OCL.
But so far , it seems more difficult than ecore .
In ecore:
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
"ecore", new EcoreResourceFactoryImpl());
URI myEcoreURI = URI.createFileURI(file.getAbsolutePath()); //file is .ecore file.
Resource myEcoreResource = resourceSet.getResource(myEcoreURI, true);
i can easily get my resource.
But in UML:
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "uml", new UMLResourceFactoryImpl());
URI UMLuri = URI.createFileURI(umlfile.getAbsolutePath()); umlfile is .uml file.
***Resource resource = resourceSet.getResource(UMLuri, true);
I got exception about my resources...OH my goodness!
Exception in thread "main" java.lang.NoSuchMethodError: org.eclipse.emf.ecore.resource.URIConverter.createInputStrea m(Lorg/eclipse/emf/common/util/URI;Ljava/util/Map;)Ljava/io/ InputStream;
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2533)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:2421)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1299)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1468)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1019)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:83)
and i saw your code~, it really helps me a lot.
but in your code , in your method "public void test_linkNavigationInReverse_259630()"
UMLEnvironmentFactory factory = new UMLEnvironmentFactory(resourceSet);
OCL ocl = OCL.newInstance(factory);
EvaluationOptions
.setOption(ocl.getEvaluationEnvironment(),
UMLEvaluationOptions.EVALUATION_MODE,
EvaluationMode.INSTANCE_MODEL);
URI uri = getTestModelURI("/model/instances.uml");
Resource res = resourceSet.getResource(uri, true);
have you register your environment? how can you do like this.
it seems like my problem...
And what is the "resourceSet" here?
best regards
hutzu
|
|
| | | | | | | | | | |
Re: HOW TO PARSE UML2.1 class diagram with OCL? [message #632736 is a reply to message #632242] |
Thu, 14 October 2010 06:23 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi Hutzu
Well there are still no attachments but the 1kB and 4kB google docs are
readable.
I still don't understand your questions, but looking at the documents,
your question might be "how do I use the OCL editor for them?", so I'll
answer that.
The Complete OCL editor does not yet support UML meta-models so you need
to use the UML editor to convert to Ecore, which applies name/style
corrections by default and produces a triangleuml.ecore and a
triangleuml package and leading lowerrcase on operations.
The editor supports an 'import' extension, so adding
import 'triangleuml.ecore'
enables the editor to see your model and report many erroprs until the
packagename is changed to 'triangleuml'. It now reports far fewer errors
and these go away when you change your 'constructor' spelling to match
the adjusted name.
The parser accessible using the org.eclipse.ocl.uml.OCL facade does
support UML meta-models, but does not (yet) support an import statement,
so your models should be useable unchanged; it is your responsibility to
load the UML package into the UMLEnvironment.
You may find the OCL Interpreter Tutorial in the OCL Developers Guide
acessible via Help Contents useful. Unfortunately it only covers Ecore.
However once you understnad it you should be able to step sideways to
the UML variant. I have added a comment to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=304642 to enciurage us to
improve the documentation here.
Regards
Ed Willink
On 12/10/2010 10:04, hutzu wrote:
> OK, it's open now .
>
> regards
> hutzu
|
|
| |
Re: HOW TO PARSE UML2.1 class diagram with OCL? [message #1048498 is a reply to message #629068] |
Wed, 24 April 2013 14:55 |
Xiang Qiu Messages: 4 Registered: April 2013 |
Junior Member |
|
|
Hello,I want to do the same work as yours. But I do not know how to build a new eclipse project for this work? Can you tell me which kind of eclipse project I should build? Thank you.
if I build the new java project, I write some code in the main function. It can not identify the type e.g. OCL< Package,Classifier,Operation,Property,EnumerationLiteral,Par ameter,State,CallOperationAction,SendSignalAction,Constraint ,Class,EObject >
|
|
|
Re: HOW TO PARSE UML2.1 class diagram with OCL? [message #1048574 is a reply to message #1048498] |
Wed, 24 April 2013 17:07 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
This is a very novice quiestion. You should gain much more familiarity
with the basics of Eclipse Java development before attempting something
hard.
If you use a Java project you are responsible for defining the classpath.
If you use a Plugin project, Eclipse will help you maintain the manifest.
Regards
Ed Willink
On 24/04/2013 15:57, Xiang Qiu wrote:
> Hello,I want to do the same work as yours. But I do not know how to
> build a new eclipse project for this work? Can you tell me which kind
> of eclipse project I should build? Thank you.
>
> if I build the new java project, I write some code in the main
> function. It can not identify the type e.g. OCL<
> Package,Classifier,Operation,Property,EnumerationLiteral,Par
> ameter,State,CallOperationAction,SendSignalAction,Constraint
> ,Class,EObject >
|
|
| |
Goto Forum:
Current Time: Fri Apr 19 16:09:13 GMT 2024
Powered by FUDForum. Page generated in 0.03305 seconds
|