Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » No name when attribute=class name
No name when attribute=class name [message #1062342] Fri, 07 June 2013 05:59 Go to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Hi,

I've the following code snippet of my emf model:

class FeatureModel{

  	attr EString name = "FeatureModel";


When an element of "FeatureModel" is created, it seems that it get no name attribute because the name string and the class name are the same. Is this a normal behaviour? Normally I would expect that this shouldn't be a problem.

Cheers,
Phil
Re: No name when attribute=class name [message #1062376 is a reply to message #1062342] Fri, 07 June 2013 08:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

What makes it seem that way? You don't see that value in the generated
NAME_EDFAULT in the FeatureModelImpl class?

On 07/06/2013 11:59 AM, Phil H wrote:
> Hi,
>
> I've the following code snippet of my emf model:
>
> class FeatureModel{
>
> attr EString name = "FeatureModel";
>
> When an element of "FeatureModel" is created, it seems that it get no
> name attribute because the name string and the class name are the
> same. Is this a normal behaviour? Normally I would expect that this
> shouldn't be a problem.
>
> Cheers,
> Phil
Re: No name when attribute=class name [message #1062415 is a reply to message #1062376] Fri, 07 June 2013 10:56 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
When I give my node FeatureModel a name like "FeatureModel" or "Feature_Model" I have the following xmi structure:

<featureModels xmi:type="p:FeatureModel" xmi:id="_yAvmEs-BEeK_RJOnOSnKfg">


But when I give it a name like "Test" it seems to work:

<featureModels xmi:type="p:FeatureModel" xmi:id="_yAvmEs-BEeK_RJOnOSnKfg" name="Test">


The strange thing is that for another node Feature it seems to be no problem:

<feature xmi:type="p:Feature" xmi:id="_HLblsM-DEeKEvvzBy6rviw" name="Feature"/>

[Updated on: Fri, 07 June 2013 11:07]

Report message to a moderator

Re: No name when attribute=class name [message #1062515 is a reply to message #1062415] Sat, 08 June 2013 03:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

Comments below.

On 07/06/2013 4:56 PM, Phil H wrote:
> When I give my node FeatureModel a name like "FeatureModel" or
> "Feature_Model" I have the following xmi structure:
>
> <featureModels xmi:type="p:FeatureModel"
> xmi:id="_yAvmEs-BEeK_RJOnOSnKfg">
>
> But when I give it a name like "Test" it seems to work:
>
> <featureModels xmi:type="p:FeatureModel"
> xmi:id="_yAvmEs-BEeK_RJOnOSnKfg" name="Test">
No doubt your feature is not marked as unsettable and given that
"FeatureModel" is the default value for the feature, the feature will be
considered unset (eIsSet(XyxPackage.Literals.FEATURE_MODEL__NAME) ==
false), so by default it (or any other feature for which eIsSet is
false) will not be serialized. You could mark the feature as unsettable
(so you can tell the difference between the value just being the default
verses explicitly set to a value that happens to be equal to the
default) or you can use
org.eclipse.emf.ecore.xmi.XMLResource.OPTION_KEEP_DEFAULT_CONTENT if you
want to serialize any default values explicitly specified in your Ecore
model.
>
>
Re: No name when attribute=class name [message #1062582 is a reply to message #1062515] Sun, 09 June 2013 08:24 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Thanks Ed for this suggestions.

I would like to use the org.eclipse.emf.ecore.xmi.XMLResource.OPTION_KEEP_DEFAULT_CONTENT but I'm not sure where.

After some search I found out that ResourceFactoryImpl should the right class. I expected this class in my .util package, but there is only an adapterfactory and switch class.

Can you give me a hint?

Re: No name when attribute=class name [message #1062586 is a reply to message #1062582] Sun, 09 June 2013 09:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

Perhaps you're just using the default. In that case, you can define
your own resource factory, use it to create an XMIResourceImpl,
configure it with the options you want, and then register it

<extension point="org.eclipse.emf.ecore.extension_parser">
<parser
type="<your-extension>"
class="<your-package>.util.<your-model-name>ResourceFactoryImpl"/>
</extension>

You can set the GenPackage's Resource Type property to XMI, but that
will generate an XyzResourceImpl as well, which you don't really need;
as of EMF 2.9, the plugin.xml will merge when regenerating but with
older versions you'd need to delete it to regenerate it.


On 09/06/2013 2:24 PM, Phil H wrote:
> Thanks Ed for this suggestions.
>
> I would like to use the
> org.eclipse.emf.ecore.xmi.XMLResource.OPTION_KEEP_DEFAULT_CONTENT but
> I'm not sure where.
> After some search I found out that ResourceFactoryImpl should the
> right class. I expected this class in my .util package, but there is
> only an adapterfactory and switch class.
> Can you give me a hint?
>
>
Re: No name when attribute=class name [message #1062589 is a reply to message #1062586] Sun, 09 June 2013 11:04 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Thx, but then I think it's easier to mark it as unsettable. Since I using Eugenai, I used this annotation:

class FeatureModel{
  	unsettable attr EString name = "FeatureModel";


But it still doesn't worked. Shouldn't this do the trick?
Re: No name when attribute=class name [message #1062590 is a reply to message #1062589] Sun, 09 June 2013 11:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

You need to explicitly set the value of this feature for each
FeatureModel instance for it to serialize, otherwise eIsSet is false and
it behaves as I already described.


On 09/06/2013 5:04 PM, Phil H wrote:
> Thx, but then I think it's easier to mark it as unsettable. Since I
> using Eugenai, I used this annotation:
>
> class FeatureModel{
> unsettable attr EString name = "FeatureModel";
>
> But it still doesn't worked. Shouldn't this do the trick?
Re: No name when attribute=class name [message #1062592 is a reply to message #1062590] Sun, 09 June 2013 11:39 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Sry but I don't understand this.
When I write
unsettable attr EString name = "FeatureModel";
shouldn't this be set to all FeatureModel instances then? Otherwise, this annotation doesn't make sense for me..

Where else have I to set the value then? Sry for this dumb question, but I'm not that EMF experienced yet Wink
Re: No name when attribute=class name [message #1062598 is a reply to message #1062592] Sun, 09 June 2013 13:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

Comments below.

On 09/06/2013 5:39 PM, Phil H wrote:
> Sry but I don't understand this. When I write unsettable attr EString
> name = "FeatureModel"; shouldn't this be set to all FeatureModel
> instances then?
No, you're mixing up setting something in the Ecore model with setting
something in an instance.
> Otherwise, this annotation doesn't make sense for me..
Think of it as modeling one extra state for the field such that you can
tell the difference between the feature never having been set, and the
feature being set to a value that happens to be the same as the
default. In XML terms, it's the difference between the attribute being
present or absent (and hence semantically having only the default)...
>
> Where else have I to set the value then?
You have to call setName on the instance; that will also be done
(reflectively) when you deserialize and the attribute is in the
serialization.
> Sry for this dumb question, but I'm not that EMF experienced yet ;)
I'm not sure why you're worrying about defaults being serialized out.
That's the whole point of a default: the feature will have that value in
the model even when there's nothing in the serialization.
Re: No name when attribute=class name [message #1062704 is a reply to message #1062598] Mon, 10 June 2013 08:31 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Thx Ed,

>>
>> Where else have I to set the value then?
>You have to call setName on the instance; that will also be done
>(reflectively) when you deserialize and the attribute is in the
>serialization.

Ok, I understand, but I still don't know where I have to call setname()..when an instance is created? Which class is responsible for this? It's a little bit confusing at the moment for me

>> Sry for this dumb question, but I'm not that EMF experienced yet Wink
>I'm not sure why you're worrying about defaults being serialized out.
>That's the whole point of a default: the feature will have that value in
>the model even when there's nothing in the serialization.

The model will be processed further and there are no exeption handlings for empty values at the moment (not my work..)
Re: No name when attribute=class name [message #1062796 is a reply to message #1062704] Mon, 10 June 2013 15:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

Comments below.

On 10/06/2013 2:31 PM, Phil H wrote:
> Thx Ed,
>
>>>
>>> Where else have I to set the value then?
>> You have to call setName on the instance; that will also be done
>> (reflectively) when you deserialize and the attribute is in the
>> serialization.
>
> Ok, I understand, but I still don't know where I have to call
> setname()..when an instance is created?
That's up to you. It should be called when you have a good name to set.
> Which class is responsible for this?
You're responsible.
> It's a little bit confusing at the moment for me
It's like creating a Person, you give them a name when they're born.
It's a meaningful name and a default is not all that helpful.
>
>>> Sry for this dumb question, but I'm not that EMF experienced yet ;)
>> I'm not sure why you're worrying about defaults being serialized out.
>> That's the whole point of a default: the feature will have that value
>> in the model even when there's nothing in the serialization.
>
> The model will be processed further and there are no exeption
> handlings for empty values at the moment (not my work..)
No, I wouldn't expect that. But in the end, a default is just a
default, but something like you name, you'd expect to be somewhat
unique, so a default is only semi-useful as a non-null value...
Re: No name when attribute=class name [message #1062993 is a reply to message #1062342] Tue, 11 June 2013 12:22 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
I'm trying now to implement my own ResourceFactoryImpl but I'm not sure if it's the right way. Have I to create a new resource or where have I to apply the OPTION_KEEP_DEFAULT_CONTENT?

public class PldResourceFactoryImpl extends ResourceFactoryImpl {
	/**
	 * Creates an instance of the resource factory. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @generated
	 */
	public PldResourceFactoryImpl() {
		super();
	}
	
	public Resource createResource(URI uri){
		Resource result = new Resource(uri);
		result.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, 
				Boolean.TRUE);
	}
}
Re: No name when attribute=class name [message #1063009 is a reply to message #1062993] Tue, 11 June 2013 14:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

What kind of resource implementation was being created before you
registered your own factory. Probably and XMIResourceImpl. Whatever it
was, create one of those.

On 11/06/2013 6:22 PM, Phil H wrote:
> I'm trying now to implement my own ResourceFactoryImpl but I'm not
> sure if it's the right way. Have I to create a new resource or where
> have I to apply the OPTION_KEEP_DEFAULT_CONTENT?
>
>
> public class PldResourceFactoryImpl extends ResourceFactoryImpl {
> /**
> * Creates an instance of the resource factory. <!--
> begin-user-doc --> <!--
> * end-user-doc -->
> * * @generated
> */
> public PldResourceFactoryImpl() {
> super();
> }
>
> public Resource createResource(URI uri){
> Resource result = new Resource(uri);
> result.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT,
> Boolean.TRUE);
> }
> }
>
Re: No name when attribute=class name [message #1063099 is a reply to message #1063009] Wed, 12 June 2013 06:10 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
I modified the generated classes now in the following way:

public class PldResourceFactoryImpl extends ResourceFactoryImpl {

	public PldResourceFactoryImpl() {
		super();
	}

	@Override
	public Resource createResource(URI uri) {
	        PldResourceImpl result = new PldResourceImpl(uri);
		result.getDefaultSaveOptions().put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_KEEP_DEFAULT_CONTENT,Boolean.TRUE);
		return result;
	}

}


and

public class PldResourceImpl extends XMIResourceImpl {

	public PldResourceImpl(URI uri) {
		super(uri);
	}

}


But now I get a long error stacktrace starting with this:

java.lang.NullPointerException
	at pld.diagram.part.PldDiagramEditor.getEditingDomain(PldDiagramEditor.java:150)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.shouldAddUndoContext(DiagramEditor.java:563)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor$3.historyNotification(DiagramEditor.java:537)
	at org.eclipse.core.commands.operations.DefaultOperationHistory$2.run(DefaultOperationHistory.java:941)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyListeners(DefaultOperationHistory.java:930)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyDone(DefaultOperationHistory.java:1004)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:529)
	at pld.diagram.part.PldDiagramEditorUtil.createDiagram(PldDiagramEditorUtil.java:207)
	at pld.diagram.part.PldCreationWizard$1.execute(PldCreationWizard.java:147)
....


I should probably mention that I've integrated EMF/GMF according to this article: http://www.eclipse.org/articles/article.php?file=Article-Integrating-EMF-GMF-Editors/index.html - Maybe this is causing the errors?
Re: No name when attribute=class name [message #1063204 is a reply to message #1063099] Wed, 12 June 2013 11:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

I don't see how what you're dong is related to your GMF exception. Have
you set breakpoints? You've confirmed that your resource factory is
being used? You've looked at the line of code with the exception?

On 12/06/2013 12:10 PM, Phil H wrote:
> I modified the generated classes now in the following way:
>
>
> public class PldResourceFactoryImpl extends ResourceFactoryImpl {
>
> public PldResourceFactoryImpl() {
> super();
> }
>
> @Override
> public Resource createResource(URI uri) {
> PldResourceImpl result = new PldResourceImpl(uri);
> result.getDefaultSaveOptions().put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_KEEP_DEFAULT_CONTENT,Boolean.TRUE);
> return result;
> }
>
> }
>
>
> and
>
> public class PldResourceImpl extends XMIResourceImpl {
>
> public PldResourceImpl(URI uri) {
> super(uri);
> }
>
> }
>
>
> But now I get a long error stacktrace starting with this:
>
>
> java.lang.NullPointerException
> at
> pld.diagram.part.PldDiagramEditor.getEditingDomain(PldDiagramEditor.java:150)
> at
> org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.shouldAddUndoContext(DiagramEditor.java:563)
> at
> org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor$3.historyNotification(DiagramEditor.java:537)
> at
> org.eclipse.core.commands.operations.DefaultOperationHistory$2.run(DefaultOperationHistory.java:941)
> at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
> at
> org.eclipse.core.commands.operations.DefaultOperationHistory.notifyListeners(DefaultOperationHistory.java:930)
> at
> org.eclipse.core.commands.operations.DefaultOperationHistory.notifyDone(DefaultOperationHistory.java:1004)
> at
> org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:529)
> at
> pld.diagram.part.PldDiagramEditorUtil.createDiagram(PldDiagramEditorUtil.java:207)
> at
> pld.diagram.part.PldCreationWizard$1.execute(PldCreationWizard.java:147)
> ...
>
>
> I should probably mention that I've integrated EMF/GMF according to
> this article:
> http://www.eclipse.org/articles/article.php?file=Article-Integrating-EMF-GMF-Editors/index.html
> - Maybe this is causing the errors?
Re: No name when attribute=class name [message #1063211 is a reply to message #1063204] Wed, 12 June 2013 12:23 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
I thought it wouldn't be a big deal to change the serialization behaviour of EMF regarding default values, but at the end it causes too much problems.

I haven't that much knowledge about EMF/GMF to understand the exceptions or the underlying problem, so it's maybe better not to alter the default behaviour of EMF..
Re: No name when attribute=class name [message #1063213 is a reply to message #1063211] Wed, 12 June 2013 12:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

Comments below.

On 12/06/2013 6:23 PM, Phil H wrote:
> I thought it wouldn't be a big deal to change the serialization
> behaviour of EMF regarding default values, but at the end it causes
> too much problems.
As I said, I see nothing about this option nor can I imagine this option
causing some type of problem, especially given it's a save option and
your stack trace appears completely unrelated to calling save.
> I haven't that much knowledge about EMF/GMF to understand the
> exceptions or the underlying problem, so it's maybe better not to
> alter the default behaviour of EMF..
You didn't answer any of my questions about breakpoints. Without using
the debugger you will be forever lost...
Re: No name when attribute=class name [message #1063219 is a reply to message #1063213] Wed, 12 June 2013 13:02 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
The problem appears when I comment out this extension point:

Quote:

<extension point="org.eclipse.emf.ecore.extension_parser">
<parser
type="pld"
class="pld.util.PldResourceFactoryImpl"/>
</extension>


So my implementation of the resourcefactory must be the problem. Maybe the createResource method isn't right?

By default I initialize some elements when a diagram is created. I disabled this and therefor the aboved posted error stack trace doesn't appear while creating a diagram.

But it's still not possible to save and when I create an element, the XMI looks like this:

<featureModels name="FeatureModel">


With disabled extension points it looks like this:

<featureModels xmi:type="p:FeatureModel" xmi:id="_14czINOBEeKEedIb1WXe7g">
Re: No name when attribute=class name [message #1063229 is a reply to message #1063219] Wed, 12 June 2013 14:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

Comments below.

On 12/06/2013 7:02 PM, Phil H wrote:
> The problem appears when I comment out this extension point:
>
> Quote:
>> <extension point="org.eclipse.emf.ecore.extension_parser">
>> <parser
>> type="pld"
>> class="pld.util.PldResourceFactoryImpl"/>
>> </extension>
>
>
> So my implementation of the resourcefactory must be the problem.
You mean it disappears?
> Maybe the createResource method isn't right?
>
> By default I initialize some elements when a diagram is created. I
> disabled this and therefor the aboved posted error stack trace doesn't
> appear while creating a diagram.
So this stack trace completely unrelated to the resource registration?
>
> But it's still not possible to save and when I create an element, the
> XMI looks like this:
>
> <featureModels name="FeatureModel">
>
> With disabled extension points it looks like this:
>
> <featureModels xmi:type="p:FeatureModel"
> xmi:id="_14czINOBEeKEedIb1WXe7g">
Again, have you set a breakpoint to see that your resource factory
method is being called?
Re: No name when attribute=class name [message #1063694 is a reply to message #1063229] Thu, 13 June 2013 14:34 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
>> By default I initialize some elements when a diagram is created. I
>> disabled this and therefor the aboved posted error stack trace doesn't
>> appear while creating a diagram.
>So this stack trace completely unrelated to the resource registration?

The stack trace is GMF related, because it appears when I add an element to the diagram. But the the activation of the ResourceFactory is causing this errors. When I deactivate the extension point, everything works as expected (except the serizialation of default values)

>Again, have you set a breakpoint to see that your resource factory
>method is being called?

I've set a breakpoint at the createResource method and it's called several times..

[Updated on: Thu, 13 June 2013 14:35]

Report message to a moderator

Re: No name when attribute=class name [message #1063697 is a reply to message #1063694] Thu, 13 June 2013 14:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

And if you comment out the option it all works well but with the option
it doesn't?

On 13/06/2013 8:34 PM, Phil H wrote:
> Ed Merks wrote on Wed, 12 June 2013 20:03
>> >> By default I initialize some elements when a diagram is created. I
>> >> disabled this and therefor the aboved posted error stack trace
>> doesn't >> appear while creating a diagram.
>> >So this stack trace completely unrelated to the resource registration?
>>
>> The stack trace is GMF related, because it appears when I add an
>> element to the diagram. But the the activation of the ResourceFactory
>> is causing this errors. When I deactivate the extension point,
>> everything works as expected (except the serizialation of default
>> values)
>> >Again, have you set a breakpoint to see that your resource factory
>> >method is being called?
>>
>> I've set a breakpoint at the createResource method and it's called
>> several times..
>
>
Re: No name when attribute=class name [message #1063709 is a reply to message #1063697] Thu, 13 June 2013 15:48 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

it doesn't matter if I comment out the option or not - it either doesn't work..So the option doesn't seems to be the problem..

A few post earlier you mentioned that I don't need the PldResourceImpl class, but nevertheless I'm using it in my createRespurce method:

PldResourceImpl result = new PldResourceImpl(uri);


Maybe I've to use another class?
Re: No name when attribute=class name [message #1063712 is a reply to message #1063709] Thu, 13 June 2013 15:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

I believe you're basically providing a factory that replaces what this
one does:
org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl.createResource(URI)


On 13/06/2013 9:48 PM, Phil H wrote:
> Hi Ed,
>
> it doesn't matter if I comment out the option or not - it either
> doesn't work..So the option doesn't seems to be the problem..
>
> A few post earlier you mentioned that I don't need the PldResourceImpl
> class, but nevertheless I'm using it in my createRespurce method:
>
> PldResourceImpl result = new PldResourceImpl(uri);
>
> Maybe I've to use another class?
Re: No name when attribute=class name [message #1063717 is a reply to message #1063712] Thu, 13 June 2013 16:22 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Ed,

I'm currently using this, as emf generated this:

import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;


Should I use instead a XMIResourceFactoryImpl ?
Re: No name when attribute=class name [message #1063757 is a reply to message #1063717] Fri, 14 June 2013 02:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

Look at the class you're asking about. The only method it has is the
create method and that's the only class you're implementing, so
extending that class won't buy you anything. It's only purpose is to
create a resource, so if you literally just created an XMIResourceImpl
in your create method, you'd have something that (should) produce
identical behavior... What you've shown is that you're creating a class
derived from XMIResourceImpl, but you've done nothing to specialize it,
so that too should produce identical behavior. But you show a stack
trace with a problem that seems completely unrelated...

On 13/06/2013 10:22 PM, Phil H wrote:
> Ed,
>
> I'm currently using this, as emf generated this:
>
> import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
>
> Should I use instead a XMIResourceFactoryImpl ?
Re: No name when attribute=class name [message #1063960 is a reply to message #1063757] Sun, 16 June 2013 16:01 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Thx for the answer Ed, but I'm afraid that I don't understand what you exactly want to tell me..So I disabled the extension point for now.

I looked a little a bit at my editor class (the class which handles EMF/GMF - see http://www.eclipse.org/articles/article.php?file=Article-Integrating-EMF-GMF-Editors/index.html) which contains the method doSave(IProgressMonitor progressMonitor). I extended this method with the mentioned OPTION_KEEP_DEFAULT_CONTENT:

final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
    saveOptions.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE); 


At a first glance it seems to have done the trick. Default name attributes from elements of type FeatureModel are serialized well. But with other elements there are occuring still problems. For example the class Alternative:

class Alternative extends SubFeatureGroupReference {
	unsettable readonly attr EString type = "Alternative";
}



Caused by: java.lang.IllegalArgumentException: The feature 'type' is not a valid changeable feature
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1091)
	at pld.impl.SubFeatureGroupReferenceImpl.eSet(SubFeatureGroupReferenceImpl.java:129)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1156)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2653)
	... 48 more


and

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
	at org.eclipse.swt.SWT.error(SWT.java:4361)
	at org.eclipse.swt.SWT.error(SWT.java:4276)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4144)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:173)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:388)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
	at pld.presentation.PldEditor.doSave(PldEditor.java:1468)
	at org.eclipse.ui.internal.SaveableHelper$2.run(SaveableHelper.java:151)
	at org.eclipse.ui.internal.SaveableHelper$5.run(SaveableHelper.java:274)



I reckon the readonly attribute is causing this, but why?
Re: No name when attribute=class name [message #1063976 is a reply to message #1063960] Mon, 17 June 2013 01:41 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25946
Registered: July 2009
Senior Member
Phil,

The method
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.Lookup.featureKind(EStructuralFeature)
should determine that the feature is transient and as such
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(EObject,
boolean) should not save the feature's value in the XML. Yet somehow
the location at which you're saving the modified resource contains a
value for that feature.


On 16/06/2013 10:01 PM, Phil H wrote:
> Thx for the answer Ed, but I'm afraid that I don't understand what you
> exactly want to tell me..So I disabled the extension point for now.
>
> I looked a little a bit at my editor class (the class which handles
> EMF/GMF - see
> http://www.eclipse.org/articles/article.php?file=Article-Integrating-EMF-GMF-Editors/index.html)
> which contains the method doSave(IProgressMonitor progressMonitor). I
> extended this method with the mentioned OPTION_KEEP_DEFAULT_CONTENT:
>
>
> final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
> saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED,
> Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
> saveOptions.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT,
> Boolean.TRUE);
>
> At a first glance it seems to have done the trick. Default name
> attributes from elements of type FeatureModel are serialized well. But
> with other elements there are occuring still problems. For example the
> class Alternative:
>
>
> class Alternative extends SubFeatureGroupReference {
> unsettable readonly attr EString type = "Alternative";
> }
>
>
>
> Caused by: java.lang.IllegalArgumentException: The feature 'type' is
> not a valid changeable feature
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1091)
> at
> pld.impl.SubFeatureGroupReferenceImpl.eSet(SubFeatureGroupReferenceImpl.java:129)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1156)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2653)
> ... 48 more
>
>
> and
>
>
> org.eclipse.swt.SWTException: Failed to execute runnable
> (java.lang.NullPointerException)
> at org.eclipse.swt.SWT.error(SWT.java:4361)
> at org.eclipse.swt.SWT.error(SWT.java:4276)
> at
> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
> at
> org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4144)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
> at
> org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:173)
> at
> org.eclipse.jface.operation.ModalContext.run(ModalContext.java:388)
> at
> org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
> at pld.presentation.PldEditor.doSave(PldEditor.java:1468)
> at
> org.eclipse.ui.internal.SaveableHelper$2.run(SaveableHelper.java:151)
> at
> org.eclipse.ui.internal.SaveableHelper$5.run(SaveableHelper.java:274)
>
>
>
> I reckon the readonly attribute is causing this, but why?
>
Previous Topic:[CDO 4.2M5] Security Model &amp; H2 DB
Next Topic:Newbie question: not all classes of the ecore available in the editor
Goto Forum:
  


Current Time: Wed Jul 30 21:19:15 EDT 2014

Powered by FUDForum. Page generated in 0.02639 seconds