Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Model referencing existing emf classes
Model referencing existing emf classes [message #431477] Sun, 12 July 2009 21:06 Go to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Hello

I'm creating an emf model, that uses some other model's elements. I import
a model - let's assume it is UML model.

I create my own model - Diagram, and give it a EReference pointing to
Class object from UML model. Class is an interface.

When I generate code for such a model, and try to test it with the
generated editor, I'm unable to create a proper instances of Class
objects. I'm getting NullPointerExceptions from Properties framework. It
looks to me as if the object is not created, only its EReference.

I end up with my model file having created objects written into it, but
uri's are like this:

uRI="#null" aliasURI="#null"

Do i have to instruct EMF which class implementing Class interface I want
to instantiate? This seems obvious, but how should I do this?

Marcin Cylke
Re: Model referencing existing emf classes [message #431487 is a reply to message #431477] Mon, 13 July 2009 13:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Marcin,

Comments below.

Marcin Cylke wrote:
> Hello
>
> I'm creating an emf model, that uses some other model's elements. I
> import a model - let's assume it is UML model.
> I create my own model - Diagram, and give it a EReference pointing to
> Class object from UML model. Class is an interface.
>
> When I generate code for such a model, and try to test it with the
> generated editor, I'm unable to create a proper instances of Class
> objects. I'm getting NullPointerExceptions from Properties framework.
> It looks to me as if the object is not created, only its EReference.
>
> I end up with my model file having created objects written into it,
> but uri's are like this:
>
> uRI="#null" aliasURI="#null"
>
> Do i have to instruct EMF which class implementing Class interface I
> want to instantiate? This seems obvious, but how should I do this?
It seems to me that if you extend the UML model, you need to generate
the code using UML's extended/specialized GenModel. It's best to ask
on the UML2 newsgroup how to go about extending UML2...
>
> Marcin Cylke
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Model referencing existing emf classes [message #431491 is a reply to message #431487] Mon, 13 July 2009 14:19 Go to previous messageGo to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Ed Merks wrote:

> It seems to me that if you extend the UML model, you need to generate
> the code using UML's extended/specialized GenModel. It's best to ask
> on the UML2 newsgroup how to go about extending UML2...

But this really is not an UML2 specific question. I have some other custom
EMF models, which do have those features - multiple classes implementing
the same interface.

So if I have such a situation, than I should adjust my genModel for that?
Where can I found information about that?

It really seems like a EMF question, not component specific. How should
such situations be handled with EMF?

Marcin
Re: Model referencing existing emf classes [message #431493 is a reply to message #431491] Mon, 13 July 2009 14:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Marcin,

Comments below.

Marcin Cylke wrote:
> Ed Merks wrote:
>
>> It seems to me that if you extend the UML model, you need to generate
>> the code using UML's extended/specialized GenModel. It's best to
>> ask on the UML2 newsgroup how to go about extending UML2...
>
> But this really is not an UML2 specific question. I have some other
> custom EMF models, which do have those features - multiple classes
> implementing the same interface.
> So if I have such a situation, than I should adjust my genModel for
> that? Where can I found information about that?
Not sure what you're driving at. What generic problem do you have? What
you describe is very common and I do it all the time without a problem...
>
> It really seems like a EMF question, not component specific. How
> should such situations be handled with EMF?
Perhaps you want to create a specific example with a particular
reproducible problem...
>
> Marcin


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Model referencing existing emf classes [message #431496 is a reply to message #431493] Mon, 13 July 2009 21:36 Go to previous messageGo to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Ed Merks wrote:

> Not sure what you're driving at. What generic problem do you have? What
> you describe is very common and I do it all the time without a problem...

Ok, so I define my model with this annotated interface.

class Model {
/**
* @model
*/
public abstarct String getName();

/**
* @model type="Object" containment="true"
*/
public abstract List<Object> getItems();
}

Then I generate Ecore model and import into it XSD.ecore model. I change
type of list, returned by getItems to XSDSchemaContent. Now, when I
generate my editors from such a model I'm getting exceptions like:

java.lang.NullPointerException
at
org.eclipse.xsd.provider.XSDAttributeDeclarationItemProvider $3.getPropertyDefaultValue(XSDAttributeDeclarationItemProvid er.java:223)
at
org.eclipse.xsd.provider.XSDItemProviderAdapter$ItemProperty DescriptorWithDefault.getPropertyValue(XSDItemProviderAdapte r.java:160)
at
org.eclipse.emf.edit.ui.provider.PropertySource.getPropertyV alue(PropertySource.java:92)
at
org.eclipse.ui.views.properties.PropertySheetEntry.refreshVa lues(PropertySheetEntry.java:611)
at
org.eclipse.ui.views.properties.PropertySheetEntry.createChi ldEntries(PropertySheetEntry.java:248)
at
org.eclipse.ui.views.properties.PropertySheetEntry.getChildE ntries(PropertySheetEntry.java:341)
at
org.eclipse.ui.views.properties.PropertySheetViewer.updateCa tegories(PropertySheetViewer.java:1087)
at
org.eclipse.ui.views.properties.PropertySheetViewer.updateCh ildrenOf(PropertySheetViewer.java:1258)
at
org.eclipse.ui.views.properties.PropertySheetViewer.setInput (PropertySheetViewer.java:976)
at
org.eclipse.ui.views.properties.PropertySheetPage.selectionC hanged(PropertySheetPage.java:490)
at
org.eclipse.ui.views.properties.PropertySheet.selectionChang ed(PropertySheet.java:216)
at
org.eclipse.ui.internal.AbstractSelectionService.fireSelecti on(AbstractSelectionService.java:156)
at
org.eclipse.ui.internal.AbstractSelectionService$1.selection Changed(AbstractSelectionService.java:62)
at
org.comit.xsd.editor.simple.model.presentation.ModelEditor.s etSelection(ModelEditor.java:1686)
at
org.comit.xsd.editor.simple.model.presentation.ModelEditor$6 .selectionChanged(ModelEditor.java:879)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:17 5)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer .java:160)
at
org.eclipse.jface.viewers.StructuredViewer.updateSelection(S tructuredViewer.java:2062)
at
org.eclipse.jface.viewers.StructuredViewer.handleSelect(Stru cturedViewer.java:1138)
at
org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected( StructuredViewer.java:1168)
at
org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenS trategy.java:227)
at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.ja va:221)
at
org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrate gy.java:388)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3401)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3033)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:21 98)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:113)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:193)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:386)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)


and this occures only sometimes - with XSDElementDeclaration or
XSDAttributeDeclaration.

Could You explain this to me?

Marcin
Re: Model referencing existing emf classes [message #431507 is a reply to message #431496] Tue, 14 July 2009 14:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Marcin,

Comments below.

Marcin Cylke wrote:
> Ed Merks wrote:
>
>> Not sure what you're driving at. What generic problem do you have?
>> What you describe is very common and I do it all the time without a
>> problem...
>
> Ok, so I define my model with this annotated interface.
>
> class Model {
It says class though. Is that a typo.
> /**
> * @model
> */
> public abstarct String getName();
More typos or is it really a class (which isn't going to work).
>
> /**
> * @model type="Object" containment="true"
type="Object" isn't helpful. In fact, it's less than helpful because
the signature says it's List<Object> not Object...
> */
> public abstract List<Object> getItems();
> }
>
> Then I generate Ecore model and import into it XSD.ecore model.
Not sure what you're saying. Export it to an XML Schema?
> I change type of list, returned by getItems to XSDSchemaContent.
Not sure I follow that comment.
> Now, when I generate my editors from such a model I'm getting
> exceptions like:
This comes from the the XSD model. How does that relate?
>
> java.lang.NullPointerException
> at
> org.eclipse.xsd.provider.XSDAttributeDeclarationItemProvider $3.getPropertyDefaultValue(XSDAttributeDeclarationItemProvid er.java:223)
>
> at
> org.eclipse.xsd.provider.XSDItemProviderAdapter$ItemProperty DescriptorWithDefault.getPropertyValue(XSDItemProviderAdapte r.java:160)
>
> at
> org.eclipse.emf.edit.ui.provider.PropertySource.getPropertyV alue(PropertySource.java:92)
>
> at
> org.eclipse.ui.views.properties.PropertySheetEntry.refreshVa lues(PropertySheetEntry.java:611)
>
> at
> org.eclipse.ui.views.properties.PropertySheetEntry.createChi ldEntries(PropertySheetEntry.java:248)
>
> at
> org.eclipse.ui.views.properties.PropertySheetEntry.getChildE ntries(PropertySheetEntry.java:341)
>
> at
> org.eclipse.ui.views.properties.PropertySheetViewer.updateCa tegories(PropertySheetViewer.java:1087)
>
> at
> org.eclipse.ui.views.properties.PropertySheetViewer.updateCh ildrenOf(PropertySheetViewer.java:1258)
>
> at
> org.eclipse.ui.views.properties.PropertySheetViewer.setInput (PropertySheetViewer.java:976)
>
> at
> org.eclipse.ui.views.properties.PropertySheetPage.selectionC hanged(PropertySheetPage.java:490)
>
> at
> org.eclipse.ui.views.properties.PropertySheet.selectionChang ed(PropertySheet.java:216)
>
> at
> org.eclipse.ui.internal.AbstractSelectionService.fireSelecti on(AbstractSelectionService.java:156)
>
> at
> org.eclipse.ui.internal.AbstractSelectionService$1.selection Changed(AbstractSelectionService.java:62)
>
> at
> org.comit.xsd.editor.simple.model.presentation.ModelEditor.s etSelection(ModelEditor.java:1686)
>
> at
> org.comit.xsd.editor.simple.model.presentation.ModelEditor$6 .selectionChanged(ModelEditor.java:879)
>
> at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
> at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
> at org.eclipse.core.runtime.Platform.run(Platform.java:880)
> at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
> at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:17 5)
> at
> org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer .java:160)
> at
> org.eclipse.jface.viewers.StructuredViewer.updateSelection(S tructuredViewer.java:2062)
>
> at
> org.eclipse.jface.viewers.StructuredViewer.handleSelect(Stru cturedViewer.java:1138)
>
> at
> org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected( StructuredViewer.java:1168)
>
> at
> org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenS trategy.java:227)
>
> at
> org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.ja va:221)
> at
> org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrate gy.java:388)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
> at
> org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3401)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3033)
> at
> org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2382)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:21 98)
> at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:488)
>
> at
> org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
> at
> org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:113)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:193)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:386)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:57)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:616)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
>
>
> and this occures only sometimes - with XSDElementDeclaration or
> XSDAttributeDeclaration.
>
> Could You explain this to me?
I'm totally confused by how you went from the @model stuff to an XSD
dependency...
>
> Marcin
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Model referencing existing emf classes [message #431517 is a reply to message #431507] Tue, 14 July 2009 22:06 Go to previous messageGo to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Ed Merks wrote:

Hello

The sample code from the previous post had "some" errors, but it was
written down, from what I've remembered.

Original code look like this:
/**
* @model
*/
public interface XsdSimpleModel {

/**
* @model
*/
public abstract String getTypeName();

/**
* @model
*/
public abstract String getNamespace();

/**
* @model
*/
public abstract String getServiceStatus();

/**
* @model type="Object" containment="true"
*/
public abstract EList<XSDSchemaContent> getTypes();
}


>> * @model type="Object" containment="true"
> type="Object" isn't helpful. In fact, it's less than helpful because
> the signature says it's List<Object> not Object...

Well, you're right, but this does not pose a problem either. Such
definition creates a collection of EReferences and then I change this
collection's type to XSDSchemaContent.

> This comes from the the XSD model. How does that relate?

The steps I've done are:
1. Generate ecore model from interface above.
2. import xsd ecore model - with "Load Resources" dialog, choosing
"platform:/plugin/org.eclipse.xsd/model/XSD.ecore"
3. change return type of getTypes to collection of XSDSchemaContent.
4. generate all - on genmodel, which generates edit code + editor code +
model

> I'm totally confused by how you went from the @model stuff to an XSD
> dependency...

So, I've summed up what I did. And when creating a child of that
XsdSimpleModel object - which should belong to that collection of
XSDSchemaContent, I keep getting quoted before exception.

Marcin
Re: Model referencing existing emf classes [message #431535 is a reply to message #431517] Wed, 15 July 2009 13:41 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Marcin,

Comments below.


Marcin Cylke wrote:
> Ed Merks wrote:
>
> Hello
>
> The sample code from the previous post had "some" errors, but it was
> written down, from what I've remembered.
> Original code look like this:
> /**
> * @model
> */
> public interface XsdSimpleModel {
>
> /**
> * @model
> */
> public abstract String getTypeName();
>
> /**
> * @model
> */
> public abstract String getNamespace();
>
> /**
> * @model
> */
> public abstract String getServiceStatus();
>
> /**
> * @model type="Object" containment="true"
> */
> public abstract EList<XSDSchemaContent> getTypes();
> }
Schema objects expect to be contained by an XSDSchema, so I can't
imagine this working well... No doubt that's the source of the errors.
It seems to me you'd be better to use an annotated schema than to create
something like a schema...
>
>
>>> * @model type="Object" containment="true"
>> type="Object" isn't helpful. In fact, it's less than helpful because
>> the signature says it's List<Object> not Object...
>
> Well, you're right, but this does not pose a problem either. Such
> definition creates a collection of EReferences and then I change this
> collection's type to XSDSchemaContent.
>
>> This comes from the the XSD model. How does that relate?
>
> The steps I've done are:
> 1. Generate ecore model from interface above.
> 2. import xsd ecore model - with "Load Resources" dialog, choosing
> "platform:/plugin/org.eclipse.xsd/model/XSD.ecore"
> 3. change return type of getTypes to collection of XSDSchemaContent.
> 4. generate all - on genmodel, which generates edit code + editor code
> + model
>
>> I'm totally confused by how you went from the @model stuff to an XSD
>> dependency...
>
> So, I've summed up what I did. And when creating a child of that
> XsdSimpleModel object - which should belong to that collection of
> XSDSchemaContent, I keep getting quoted before exception.
>
> Marcin
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Emf libraries to Central Maven Repository
Next Topic:How to display emf data model items in logical folders in treeview
Goto Forum:
  


Current Time: Thu Apr 25 08:50:19 GMT 2024

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

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

Back to the top