Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » newInstance runtime error
newInstance runtime error [message #716814] Thu, 18 August 2011 14:08 Go to next message
Williams Mising name is currently offline Williams Mising name
Messages: 43
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 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
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 Go to previous messageGo to next message
Williams Mising name is currently offline Williams Mising name
Messages: 43
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: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

Re: newInstance runtime error [message #716934 is a reply to message #716924] Thu, 18 August 2011 20:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
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
>
>
Re: newInstance runtime error [message #716945 is a reply to message #716934] Thu, 18 August 2011 21:12 Go to previous messageGo to next message
Williams Mising name is currently offline Williams Mising name
Messages: 43
Registered: July 2009
Member
Ed,
The problem is gone after the conversion. Now, I have another problem according to the following code:

Constraint oclConstraint = helper
.createInvariant("self.books->size() < 2");

Query eval = ocl.createQuery(oclConstraint);


I got a cast exception error

java.lang.ClassCastException: org.eclipse.ocl.internal.evaluation.QueryImpl
at myPackage.MyClass.<init>(MyClass.java:109)
at myPackage.MyClass.main(MyClass.java:124)

Then, I add Query<EClassifier, EClass, EObject> instead of Query and I got the following error message:


The type OCL.Query is not generic; it cannot be parameterized with arguments <EClassifier, EClass, EObject>

In this case which package should I import? Thanks
Will
Re: newInstance runtime error [message #716952 is a reply to message #716945] Thu, 18 August 2011 21:29 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

Use the ocl.ecore package whenever possible since that avoids the
nightmare template argument lists.

Regards

Ed Willink

On 18/08/2011 22:12, Williams wrote:

> Ed,
> The problem is gone after the conversion. Now, I have another
> problem according to the following code:
>
> Constraint oclConstraint = helper
> .createInvariant("self.books->size() < 2");
>
> Query eval = ocl.createQuery(oclConstraint);
>
>
> I got a cast exception error
>
> java.lang.ClassCastException:
> org.eclipse.ocl.internal.evaluation.QueryImpl
> at myPackage.MyClass.<init>(MyClass.java:109)
> at myPackage.MyClass.main(MyClass.java:124)
>
> Then, I add Query<EClassifier, EClass, EObject> instead of Query and
> I got the following error message:
>
>
> The type OCL.Query is not generic; it cannot be parameterized with
> arguments <EClassifier, EClass, EObject>
>
> In this case which package should I import? Thanks
> Will
Previous Topic:OCL Nightly Builds
Next Topic:Support for OCL constraints in a particular profile of UML.
Goto Forum:
  


Current Time: Tue Sep 23 04:37:12 GMT 2014

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

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