No name when attribute=class name [message #1062342] |
Fri, 07 June 2013 05:59  |
Eclipse User |
|
|
|
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 #1062586 is a reply to message #1062582] |
Sun, 09 June 2013 09:58   |
Eclipse User |
|
|
|
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 #1062796 is a reply to message #1062704] |
Mon, 10 June 2013 15:14   |
Eclipse User |
|
|
|
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 #1063757 is a reply to message #1063717] |
Fri, 14 June 2013 02:41   |
Eclipse User |
|
|
|
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 #1063976 is a reply to message #1063960] |
Mon, 17 June 2013 01:41  |
Eclipse User |
|
|
|
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?
>
|
|
|