Home » Modeling » OCL » operation return type as Tuple
operation return type as Tuple [message #754848] |
Fri, 04 November 2011 15:40 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
Hi,
I want to create an ocl operation with return type as Tuple.
For example if we want Integer to be return type of operation then we do like
eOperation.setEType(EcorePackage.eINSTANCE.getEInt())
and when we want to have a class as return type then
eOperation.setEType(etypeClass);
i want to have operation's return type as tuple holding class object and integer togather.
Any idea?
Thanks!
Warmest Regards
[Updated on: Fri, 04 November 2011 15:41] Report message to a moderator
|
|
| | | | |
Re: operation return type as Tuple [message #758173 is a reply to message #757875] |
Tue, 22 November 2011 08:53 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
Hi,
Here is complete code and exception:
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eAnnotation.setSource("http://www.eclipse.org/emf/2002/Ecore/OCL");
eAnnotation.getDetails().put("body", operation.getBody());
eOperation.setName(operation.getName());
eOperation.getEAnnotations().add(eAnnotation);
TupleType tt = org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createTupleType();
EAttribute eAttribute1 = EcoreFactory.eINSTANCE.createEAttribute();
EAttribute eAttribute2 = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute1.setEType(EcorePackage.eINSTANCE.getEString());
eAttribute1.setEType(EcorePackage.eINSTANCE.getEDouble());
tt.getEStructuralFeatures().add(eAttribute1);
tt.getEStructuralFeatures().add(eAttribute2);
eOperation.setEType(tt);
OCL<?, EClassifier, EOperation, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
OCLHelper<EClassifier, EOperation, ?, Constraint> helper = ocl.createOCLHelper();
OCLFunction operation = null;
helper.setOperationContext(eClass, eOperation);
try {
String body = eOperation.getEAnnotations().get(0).getDetails().get("body");
helper.createBodyCondition(body);
} catch (ParserException ex) {
ex.printStackTrace(); }
org.eclipse.ocl.ParserException
at org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLHelperImpl.java:403)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createBodyCondition(OCLHelperImpl.java:263)
at abstractmodeller.model.prm.ECoreGenerator.validateOCLOperation(ECoreGenerator.java:651)
at abstractmodeller.model.prm.Prm.parsePOClFunctionsForPrmClass(Prm.java:792)
at abstractmodeller.view.canvas.controllers.PrmClassWidgetController.parsePOCLFunctions(PrmClassWidgetController.java:338)
at abstractmodeller.view.canvas.dialogs.POCLFunctionsDialog.init(POCLFunctionsDialog.java:190)
at abstractmodeller.view.canvas.dialogs.POCLFunctionsDialog.<init>(POCLFunctionsDialog.java:92)
at abstractmodeller.view.canvas.PrmClassWidget.executePopupMenuChoice(PrmClassWidget.java:495)
at abstractmodeller.view.shared.components.PopupMenu.actionPerformed(PopupMenu.java:219)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.NullPointerException
at org.eclipse.ocl.ecore.internal.OCLFactoryImpl.createTupleType(OCLFactoryImpl.java:153)
at org.eclipse.ocl.AbstractTypeResolver.createTupleType(AbstractTypeResolver.java:403)
at org.eclipse.ocl.AbstractTypeResolver.resolveTupleType(AbstractTypeResolver.java:385)
at org.eclipse.ocl.AbstractTypeResolver$ResolveSwitch.caseTupleType(AbstractTypeResolver.java:1008)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:260)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:111)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:99)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:84)
at org.eclipse.ocl.AbstractTypeResolver.resolve(AbstractTypeResolver.java:127)
at org.eclipse.ocl.AbstractTypeResolver$ResolveSwitch.caseCollectionType(AbstractTypeResolver.java:1003)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:161)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:111)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:99)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:84)
at org.eclipse.ocl.AbstractTypeResolver.resolve(AbstractTypeResolver.java:127)
at org.eclipse.ocl.util.TypeUtil.resolveType(TypeUtil.java:617)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getOCLType(AbstractOCLAnalyzer.java:4423)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.prePostOrBodyDeclCS(AbstractOCLAnalyzer.java:969)
at org.eclipse.ocl.parser.OCLAnalyzer.parsePrePostOrBodyDeclCS(OCLAnalyzer.java:290)
at org.eclipse.ocl.internal.helper.HelperUtil.parseBodyCondition(HelperUtil.java:284)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createBodyCondition(OCLHelperImpl.java:260)
... 34 more
[Updated on: Tue, 22 November 2011 08:56] Report message to a moderator
|
|
|
Re: operation return type as Tuple [message #758188 is a reply to message #758173] |
Tue, 22 November 2011 09:41 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
This is still not complete code (where are the imports?)
You have added additional Java lines which completely change the
question; previously it was a simple Java coding problem, now there is
some OCL parsing, but you do not provide the OCL or the referenced models.
The stack trace clearly shows an NPE at OCLFactoryImpl.java:153, that on
the current code base is
Environment<?, C, O, P, ?, ?, ?, ?, ?, ?, ?, ?> env =
Environment.Registry.INSTANCE.getEnvironmentFor(parts.get(0));
which looks suspiciously like Environment.Registry.INSTANCE is null,
since parts is an EMF collection that is never null. But INSTANCE has an
initializer so it too should never be null. You need to do some
debugging. Perhaps you are using older code and the line number aligns
differently. It always helps to specify a code version.
Background: Tuples and Collections are awkward because specializations
have to be created and contained somewhere. OCL provides a default
internal package for them, but if you serialize the OCL you must take
responsibility for their containment; I doubt you're serializing, so you
can ignore doing this.
Regards
Ed Willink
On 22/11/2011 08:53, ModelGeek wrote:
> Hi,
>
> Here is complete code and exception:
>
> EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
> TupleType tt =
> org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createTupleType();
> EAttribute eAttribute1 = EcoreFactory.eINSTANCE.createEAttribute();
> EAttribute eAttribute2 = EcoreFactory.eINSTANCE.createEAttribute();
> eAttribute1.setEType(EcorePackage.eINSTANCE.getEString());
> eAttribute1.setEType(EcorePackage.eINSTANCE.getEDouble());
> tt.getEStructuralFeatures().add(eAttribute1);
> tt.getEStructuralFeatures().add(eAttribute2);
> eOperation.setEType(tt);
>
> OCL<?, EClassifier, EOperation, ?, ?, ?, ?, ?, ?,
> Constraint, EClass, EObject> ocl =
> OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> OCLHelper<EClassifier, EOperation, ?, Constraint>
> helper = ocl.createOCLHelper();
> OCLFunction operation = null;
> helper.setOperationContext(eClass, eOperation);
> try {
> String body =
> eOperation.getEAnnotations().get(0).getDetails().get("body");
> helper.createBodyCondition(body);
> } catch (ParserException ex) {
> ex.printStackTrace(); }
>
> org.eclipse.ocl.ParserException
> at
> org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLHelperImpl.java:403)
> at
> org.eclipse.ocl.internal.helper.OCLHelperImpl.createBodyCondition(OCLHelperImpl.java:263)
> at
> abstractmodeller.model.prm.ECoreGenerator.validateOCLOperation(ECoreGenerator.java:651)
> at
> abstractmodeller.model.prm.Prm.parsePOClFunctionsForPrmClass(Prm.java:792)
> at
> abstractmodeller.view.canvas.controllers.PrmClassWidgetController.parsePOCLFunctions(PrmClassWidgetController.java:338)
> at
> abstractmodeller.view.canvas.dialogs.POCLFunctionsDialog.init(POCLFunctionsDialog.java:190)
> at
> abstractmodeller.view.canvas.dialogs.POCLFunctionsDialog.<init>(POCLFunctionsDialog.java:92)
> at
> abstractmodeller.view.canvas.PrmClassWidget.executePopupMenuChoice(PrmClassWidget.java:495)
> at
> abstractmodeller.view.shared.components.PopupMenu.actionPerformed(PopupMenu.java:219)
> at
> javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
> at
> javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
> at
> javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
> at
> javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
> at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
> at
> javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223)
> at
> javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
> at java.awt.Component.processMouseEvent(Component.java:6267)
> at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
> at java.awt.Component.processEvent(Component.java:6032)
> at java.awt.Container.processEvent(Container.java:2041)
> at java.awt.Component.dispatchEventImpl(Component.java:4630)
> at java.awt.Container.dispatchEventImpl(Container.java:2099)
> at java.awt.Component.dispatchEvent(Component.java:4460)
> at
> java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
> at
> java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
> at java.awt.Container.dispatchEventImpl(Container.java:2085)
> at java.awt.Window.dispatchEventImpl(Window.java:2478)
> at java.awt.Component.dispatchEvent(Component.java:4460)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
> at
> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
> at
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
> at
> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
> at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
> at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.ocl.ecore.internal.OCLFactoryImpl.createTupleType(OCLFactoryImpl.java:153)
> at
> org.eclipse.ocl.AbstractTypeResolver.createTupleType(AbstractTypeResolver.java:403)
> at
> org.eclipse.ocl.AbstractTypeResolver.resolveTupleType(AbstractTypeResolver.java:385)
> at
> org.eclipse.ocl.AbstractTypeResolver$ResolveSwitch.caseTupleType(AbstractTypeResolver.java:1008)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:260)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:111)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:99)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:84)
> at
> org.eclipse.ocl.AbstractTypeResolver.resolve(AbstractTypeResolver.java:127)
> at
> org.eclipse.ocl.AbstractTypeResolver$ResolveSwitch.caseCollectionType(AbstractTypeResolver.java:1003)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:161)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:111)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:99)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:84)
> at
> org.eclipse.ocl.AbstractTypeResolver.resolve(AbstractTypeResolver.java:127)
> at org.eclipse.ocl.util.TypeUtil.resolveType(TypeUtil.java:617)
> at
> org.eclipse.ocl.parser.AbstractOCLAnalyzer.getOCLType(AbstractOCLAnalyzer.java:4423)
> at
> org.eclipse.ocl.parser.AbstractOCLAnalyzer.prePostOrBodyDeclCS(AbstractOCLAnalyzer.java:969)
> at
> org.eclipse.ocl.parser.OCLAnalyzer.parsePrePostOrBodyDeclCS(OCLAnalyzer.java:290)
> at
> org.eclipse.ocl.internal.helper.HelperUtil.parseBodyCondition(HelperUtil.java:284)
> at
> org.eclipse.ocl.internal.helper.OCLHelperImpl.createBodyCondition(OCLHelperImpl.java:260)
> ... 34 more
|
|
|
Re: operation return type as Tuple [message #758211 is a reply to message #758188] |
Tue, 22 November 2011 11:01 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
Hi,
I have tried to check and i have found that Environment.Registry.INSTANCE is not null but Environment.Registry.INSTANCE.getEnvironmentFor(eClass) gives null.
And i am not doing serialization.
When i try to create an ocl operation with return type not as tuple type then everything works fine, the parsing works fine as well.
Do you have any clue? what is going wrong
Thanks alot for helping
Regards,
[Updated on: Tue, 22 November 2011 11:48] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Thu Apr 18 20:56:54 GMT 2024
Powered by FUDForum. Page generated in 0.03074 seconds
|