|
|
Re: No name when attribute=class name [message #1062415 is a reply to message #1062376] |
Fri, 07 June 2013 14:56 |
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 15:07] Report message to a moderator
|
|
|
|
|
Re: No name when attribute=class name [message #1062586 is a reply to message #1062582] |
Sun, 09 June 2013 13:58 |
Ed Merks Messages: 33217 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?
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
|
|
Re: No name when attribute=class name [message #1062796 is a reply to message #1062704] |
Mon, 10 June 2013 19:14 |
Ed Merks Messages: 33217 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...
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
|
|
|
|
|
Re: No name when attribute=class name [message #1063694 is a reply to message #1063229] |
Thu, 13 June 2013 18:34 |
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 18:35] Report message to a moderator
|
|
|
|
|
|
|
Re: No name when attribute=class name [message #1063757 is a reply to message #1063717] |
Fri, 14 June 2013 06:41 |
Ed Merks Messages: 33217 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 ?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: No name when attribute=class name [message #1063976 is a reply to message #1063960] |
Mon, 17 June 2013 05:41 |
Ed Merks Messages: 33217 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?
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|