Home » Modeling » OCL » newInstance runtime error
newInstance runtime error [message #716814] |
Thu, 18 August 2011 14:08 |
Williams Mising name Messages: 60 Registered: July 2009 |
Member |
|
|
I tried to use the dynamic EMF to create a class diagram and its instance diagram to verify an OCL invariant. When I set up the OCL invariant as follows:
...
// dynamically created a class diagram and its instance diagram
try{
OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl
= OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl.createOCLHelper();
// helper.setContext(bookStoreEPackage.Literals.BOOKSTORE );
Constraint oclConstraint = helper
.createInvariant("self.books->size() < 2");
Query eval = (Query) ocl.createQuery(oclConstraint);
Boolean result = (Boolean) eval.evaluate(bookstore);
} catch (Exception e)
{
....
}
I got runtime error at OCL.newInstance(EcoreEnvironmentFactory.INSTANCE) as follows:
Exception in thread "main" java.lang.NoClassDefFoundError: lpg/runtime/RuleAction
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at myPackage.MyClass.<init>(MyClass.java:101)
at myPackage.MyClass.main(MyClass.java:121)
Another question, how can I set up helper.setContext(). I just created a package,
classes etc and there is no Literals in my program to dynamically created the model.
Thanks.
Will
|
|
|
Re: newInstance runtime error [message #716875 is a reply to message #716814] |
Thu, 18 August 2011 16:10 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
The stack trace indicates that lpg is the first 'Eclipse' class that you
have tried to find, so I suggest a major classPath error on your part.
These are always esoteric and one of the many joys of working with Java.
I suggest checking that simpler Eclipse classes such as EClass and
OCLExpression can be constructed. I find most of the problems go away if
my project is a plugin, ratheer than native Java, since the Eclipse
tooling then writes most of the class path for me. Just remember to
'Update classpath' after using the PDE tooling to configure your project
as a plugin.
helper just wants an EObject whose eClass() is the type of self for
parsing and which is self evaluation. Any EObject will do, if you've
created a package dynamically that will do.
Regards
Ed Willink
On 18/08/2011 15:08, Williams wrote:
> I tried to use the dynamic EMF to create a class diagram and its
> instance diagram to verify an OCL invariant. When I set up the OCL
> invariant as follows:
>
>
> ...
> // dynamically created a class diagram and its instance diagram
>
> try{
> OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint,
> EClass, EObject> ocl
> = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> OCLHelper<EClassifier, ?, ?, Constraint> helper =
> ocl.createOCLHelper();
>
> // helper.setContext(bookStoreEPackage.Literals.BOOKSTORE );
>
> Constraint oclConstraint = helper
> .createInvariant("self.books->size() < 2");
> Query eval = (Query) ocl.createQuery(oclConstraint);
>
> Boolean result = (Boolean) eval.evaluate(bookstore);
>
> } catch (Exception e)
> {
> ....
> }
>
> I got runtime error at
> OCL.newInstance(EcoreEnvironmentFactory.INSTANCE) as follows:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> lpg/runtime/RuleAction
> at java.lang.ClassLoader.defineClass1(Native Method)
> at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
> at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
> at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
> at myPackage.MyClass.<init>(MyClass.java:101)
> at myPackage.MyClass.main(MyClass.java:121)
>
> Another question, how can I set up helper.setContext(). I just created
> a package,
> classes etc and there is no Literals in my program to dynamically
> created the model.
> Thanks.
> Will
|
|
|
Re: newInstance runtime error [message #716924 is a reply to message #716875] |
Thu, 18 August 2011 19:28 |
Williams Mising name Messages: 60 Registered: July 2009 |
Member |
|
|
I can create Eclipse classes such as EClass as follows:
theCoreFactory = EcoreFactory.eINSTANCE;
bookStoreEPackage = theCoreFactory.createEPackage();
bookStoreEPackage.setNsPrefix("bookStore");
bookStoreEPackage.setNsURI("http///com.ibm.dynamic.example.bookstore.ecore");
EcorePackage theCorePackage = EcorePackage.eINSTANCE;
bookStoreEPackage.setName("BookstorePackage");
EClass bookStoreClass = theCoreFactory.createEClass();
bookStoreClass.setName("BooksStore");
EAttribute bookStoreOwner = theCoreFactory.createEAttribute();
bookStoreOwner.setName("owner");
bookStoreOwner.setEType(theCorePackage.getEString());
EAttribute bookStoreLocation = theCoreFactory.createEAttribute();
bookStoreLocation.setName("location");
bookStoreLocation.setEType(theCorePackage.getEString());
bookStoreClass.getEStructuralFeatures().add(bookStoreOwner);
bookStoreClass.getEStructuralFeatures().add(bookStoreLocation);
;
EClass bookClass = theCoreFactory.createEClass();
EAttribute bookName = theCoreFactory.createEAttribute();
bookName.setName("name");
bookName.setEType(theCorePackage.getEString());
EAttribute bookISBN = theCoreFactory.createEAttribute();
bookISBN.setName("isbn");
bookISBN.setEType(theCorePackage.getEInt());
bookClass.getEStructuralFeatures().add(bookName);
bookClass.getEStructuralFeatures().add(bookISBN);
EReference bookStore_Books = theCoreFactory.createEReference();
bookStore_Books.setName("books");
bookStore_Books.setEType(bookClass);
bookStore_Books.setUpperBound(EStructuralFeature.UNBOUNDED_MULTIPLICITY);
bookStore_Books.setContainment(true);
bookStoreClass.getEStructuralFeatures().add(bookStore_Books);
bookStoreEPackage.getEClassifiers().add(bookStoreClass);
bookStoreEPackage.getEClassifiers().add(bookClass);
System.out.println("Done for the BookStore Model");
....
So, it seems that I can create them. What I did is new a Java project and
then add those jar files related to ecore, validation, and ocl via Property -> Java Build Path -> Libraries -> Add External JARs. Since I use dynamic EMF to create
models and then check OCL constraints, I didn't create a plugin project at
the beginning...
Will
Edward Willink wrote on Thu, 18 August 2011 12:10Hi
The stack trace indicates that lpg is the first 'Eclipse' class that you
have tried to find, so I suggest a major classPath error on your part.
These are always esoteric and one of the many joys of working with Java.
I suggest checking that simpler Eclipse classes such as EClass and
OCLExpression can be constructed. I find most of the problems go away if
my project is a plugin, ratheer than native Java, since the Eclipse
tooling then writes most of the class path for me. Just remember to
'Update classpath' after using the PDE tooling to configure your project
as a plugin.
helper just wants an EObject whose eClass() is the type of self for
parsing and which is self evaluation. Any EObject will do, if you've
created a package dynamically that will do.
Regards
Ed Willink
On 18/08/2011 15:08, Williams wrote:
> I tried to use the dynamic EMF to create a class diagram and its
> instance diagram to verify an OCL invariant. When I set up the OCL
> invariant as follows:
>
>
> ...
> // dynamically created a class diagram and its instance diagram
>
> try{
> OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint,
> EClass, EObject> ocl
> = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> OCLHelper<EClassifier, ?, ?, Constraint> helper =
> ocl.createOCLHelper();
>
> // helper.setContext(bookStoreEPackage.Literals.BOOKSTORE );
>
> Constraint oclConstraint = helper
> .createInvariant("self.books->size() < 2");
> Query eval = (Query) ocl.createQuery(oclConstraint);
>
> Boolean result = (Boolean) eval.evaluate(bookstore);
>
> } catch (Exception e)
> {
> ....
> }
>
> I got runtime error at
> OCL.newInstance(EcoreEnvironmentFactory.INSTANCE) as follows:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> lpg/runtime/RuleAction
> at java.lang.ClassLoader.defineClass1(Native Method)
> at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
> at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
> at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
> at myPackage.MyClass.<init>(MyClass.java:101)
> at myPackage.MyClass.main(MyClass.java:121)
>
> Another question, how can I set up helper.setContext(). I just created
> a package,
> classes etc and there is no Literals in my program to dynamically
> created the model.
> Thanks.
> Will
|
|
|
Re: newInstance runtime error [message #716934 is a reply to message #716924] |
Thu, 18 August 2011 20:12 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
You don't need to create a plugin project. Select a project in the
package explorer and use the PDE Tools menu option to convert to a plugin.
Plugin classpaths have transitive characterisrics, so using OCL as a
plugin gets its dependencies such as LPG automatically.
If you use a Java project you must resolve all the dependencies by hand.
So add the lpg jar file manually, once you find it.
Regards
Ed Willink
On 18/08/2011 20:28, Williams wrote:
> I can create Eclipse classes such as EClass as follows:
>
> theCoreFactory = EcoreFactory.eINSTANCE;
>
> bookStoreEPackage = theCoreFactory.createEPackage();
> bookStoreEPackage.setNsPrefix("bookStore");
>
> bookStoreEPackage.setNsURI("http///com.ibm.dynamic.example.bookstore.ecore");
> EcorePackage theCorePackage = EcorePackage.eINSTANCE;
> bookStoreEPackage.setName("BookstorePackage");
>
> EClass bookStoreClass = theCoreFactory.createEClass();
> bookStoreClass.setName("BooksStore");
> EAttribute bookStoreOwner = theCoreFactory.createEAttribute();
> bookStoreOwner.setName("owner");
> bookStoreOwner.setEType(theCorePackage.getEString());
> EAttribute bookStoreLocation = theCoreFactory.createEAttribute();
> bookStoreLocation.setName("location");
> bookStoreLocation.setEType(theCorePackage.getEString());
> bookStoreClass.getEStructuralFeatures().add(bookStoreOwner);
> bookStoreClass.getEStructuralFeatures().add(bookStoreLocation);
> ;
> EClass bookClass = theCoreFactory.createEClass();
> EAttribute bookName = theCoreFactory.createEAttribute();
> bookName.setName("name");
> bookName.setEType(theCorePackage.getEString());
> EAttribute bookISBN = theCoreFactory.createEAttribute();
> bookISBN.setName("isbn");
> bookISBN.setEType(theCorePackage.getEInt());
> bookClass.getEStructuralFeatures().add(bookName);
> bookClass.getEStructuralFeatures().add(bookISBN);
>
> EReference bookStore_Books = theCoreFactory.createEReference();
> bookStore_Books.setName("books");
> bookStore_Books.setEType(bookClass);
>
> bookStore_Books.setUpperBound(EStructuralFeature.UNBOUNDED_MULTIPLICITY);
> bookStore_Books.setContainment(true);
> bookStoreClass.getEStructuralFeatures().add(bookStore_Books);
>
> bookStoreEPackage.getEClassifiers().add(bookStoreClass);
> bookStoreEPackage.getEClassifiers().add(bookClass);
>
> System.out.println("Done for the BookStore Model");
> ....
>
> So, it seems that I can create them. What I did is new a Java project and
> then add those jar files related to ecore, validation, and ocl via
> Property -> Java Build Path -> Libraries -> Add External JARs. Since I
> use dynamic EMF to create
> models and then check OCL constraints, I didn't create a plugin
> project at
> the beginning...
> Will
>
> Edward Willink wrote on Thu, 18 August 2011 12:10
>> Hi
>>
>> The stack trace indicates that lpg is the first 'Eclipse' class that
>> you have tried to find, so I suggest a major classPath error on your
>> part. These are always esoteric and one of the many joys of working
>> with Java. I suggest checking that simpler Eclipse classes such as
>> EClass and OCLExpression can be constructed. I find most of the
>> problems go away if my project is a plugin, ratheer than native Java,
>> since the Eclipse tooling then writes most of the class path for me.
>> Just remember to 'Update classpath' after using the PDE tooling to
>> configure your project as a plugin.
>>
>> helper just wants an EObject whose eClass() is the type of self for
>> parsing and which is self evaluation. Any EObject will do, if you've
>> created a package dynamically that will do.
>>
>> Regards
>>
>> Ed Willink
>>
>> On 18/08/2011 15:08, Williams wrote:
>> > I tried to use the dynamic EMF to create a class diagram and its >
>> instance diagram to verify an OCL invariant. When I set up the OCL >
>> invariant as follows:
>> >
>> >
>> > ...
>> > // dynamically created a class diagram and its instance diagram
>> >
>> > try{
>> > OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?,
>> Constraint, > EClass, EObject> ocl
>> > =
>> OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
>> > OCLHelper<EClassifier, ?, ?, Constraint> helper = >
>> ocl.createOCLHelper();
>> >
>> > // helper.setContext(bookStoreEPackage.Literals.BOOKSTORE );
>> >
>> > Constraint oclConstraint = helper
>> > .createInvariant("self.books->size() < 2");
>> > Query eval = (Query) ocl.createQuery(oclConstraint);
>> >
>> > Boolean result = (Boolean) eval.evaluate(bookstore);
>> >
>> > } catch (Exception e)
>> > {
>> > ....
>> > }
>> >
>> > I got runtime error at >
>> OCL.newInstance(EcoreEnvironmentFactory.INSTANCE) as follows:
>> >
>> > Exception in thread "main" java.lang.NoClassDefFoundError: >
>> lpg/runtime/RuleAction
>> > at java.lang.ClassLoader.defineClass1(Native Method)
>> > at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>> > at >
>> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
>> > at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
>> > at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
>> > at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
>> > at java.security.AccessController.doPrivileged(Native Method)
>> > at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>> > at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>> > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
>> > at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>> > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
>> > at myPackage.MyClass.<init>(MyClass.java:101)
>> > at myPackage.MyClass.main(MyClass.java:121)
>> >
>> > Another question, how can I set up helper.setContext(). I just
>> created > a package,
>> > classes etc and there is no Literals in my program to dynamically >
>> created the model.
>> > Thanks.
>> > Will
>
>
|
|
| | |
Goto Forum:
Current Time: Thu Apr 18 07:13:42 GMT 2024
Powered by FUDForum. Page generated in 0.02507 seconds
|