Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EObject to String
EObject to String [message #507044] Mon, 11 January 2010 14:07 Go to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Hi,

I have the class in EMF like this:

class Expr {
  name : String;
  body : EObject;
}


I need use this body reference as a String or a Boolean. Is it possible?

--
Regards, Milan
Re: EObject to String [message #507066 is a reply to message #507044] Mon, 11 January 2010 21:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Comments below.


Milan Milanovich wrote:
> Hi,
>
> I have the class in EMF like this:
>
> class Expr {
> name : String;
> body : EObject;
> }
>
> I need use this body reference as a String or a Boolean. Is it possible?
I don't follow. Using body.toString() and body != null seem like
possible answers...
>
> --
> Regards, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #507147 is a reply to message #507044] Tue, 12 January 2010 10:24 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

I have body : EObject, but is it possible to have a String instead of EObject in runtime?

--
thx, Milan
Re: EObject to String [message #507192 is a reply to message #507147] Tue, 12 January 2010 08:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

I'm still not sure I follow. It's possible to create an instance of
SimpleAnyType using XMLTypeFactory.eINSTANCE.createSimpleAnyType(). You
could set the instance type to EString and then set the value to a
string value. SimpleAnyType is effectively like a Java box type.

Milan Milanovich wrote:
> Dear Mr. Merks,
>
> I have body : EObject, but is it possible to have a String instead of
> EObject in runtime?
>
> --
> thx, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #507275 is a reply to message #507192] Tue, 12 January 2010 17:36 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

well, my class is defined like this:

class Expr {
name : String;
body : EObject;
}

i.e., body is EObject type, because I need to give it different reference types during runtime. Sometimes it should be instances of a String, but sometimes it should be EBoolean. I'm just wondering how to assign different types to the body in runtime.

--
Regards, Milan
Re: EObject to String [message #507290 is a reply to message #507275] Tue, 12 January 2010 18:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Well, a String can't be an EObject so that's just not going to work
other than how I've already spelled out. You could make the type be
EJavaObject, i.e., the EDataType that wraps java.lang.Object, but that's
not going to serialize nicely.


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> well, my class is defined like this:
>
> class Expr {
> name : String;
> body : EObject;
> }
>
> i.e., body is EObject type, because I need to give it different
> reference types during runtime. Sometimes it should be instances of a
> String, but sometimes it should be EBoolean. I'm just wondering how to
> assign different types to the body in runtime.
>
> --
> Regards, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508233 is a reply to message #507290] Sun, 17 January 2010 23:34 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

I have created a volatile, transient property in my EMF code and tried to implement it, like this:

final CommonFactory factory = CommonFactoryImpl.eINSTANCE;
final CommonPackage cPackage = CommonPackageImpl.eINSTANCE;

ItemDefinition itemDefintion = factory.createItemDefinition();

SimpleAnyType ant = XMLTypeFactory.eINSTANCE.createSimpleAnyType();

ant.setInstanceType((EcorePackage.eINSTANCE.getEString()));

FormalExpression fe = factory.createFormalExpression();
fe.setBody(ant);
...


and on the end of this method, I call generated method to populate it with created data: setConditionExpression(fe);

However, when I try to save this object...graphically in GMF, I'm getting an error: ItemDefinition is not contained in a resource. What do I need to do?

--
Milan

[Updated on: Sun, 17 January 2010 23:36]

Report message to a moderator

Re: EObject to String [message #508237 is a reply to message #508233] Mon, 18 January 2010 00:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Comments below.

Milan Milanovich wrote:
> Dear Mr. Merks,
>
> I have created a volatile, transient property in my EMF code and tried
> to implement it, like this:
>
> final CommonFactory factory = CommonFactoryImpl.eINSTANCE;
Why access it via the Impl class when it's defined in the interface?
> final CommonPackage cPackage = CommonPackageImpl.eINSTANCE;
>
> ItemDefinition itemDefintion = factory.createItemDefinition();
>
> SimpleAnyType ant = XMLTypeFactory.eINSTANCE
> .createSimpleAnyType();
>
> ant.setInstanceType((EcorePackage.eINSTANCE.getEString()));
EcorePackage.Literals.ESTRING works too and it's a constant.
> ..
>
>
> and on the end of this method, I call generated method to populate it
> with created data: setConditionExpression(fe);
>
> However, when I try to save this object...graphically in GMF, I'm
> getting an error: ItemDefinition is not contained in a resource. What
> do I need to do?
If it's a non-containment reference, you'll have to store it in some
other containment reference or at the root of a resource.
>
> --
> Milan
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508349 is a reply to message #508237] Mon, 18 January 2010 14:09 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

Ed Merks wrote on Sun, 17 January 2010 19:22
Milan,

Comments below.

Milan Milanovich wrote:
> Dear Mr. Merks,
>
> I have created a volatile, transient property in my EMF code and tried
> to implement it, like this:
>
> final CommonFactory factory = CommonFactoryImpl.eINSTANCE;
Why access it via the Impl class when it's defined in the interface?

Yes, you are right, my mistake...

Ed Merks wrote on Sun, 17 January 2010 19:22

> final CommonPackage cPackage = CommonPackageImpl.eINSTANCE;
>
> ItemDefinition itemDefintion = factory.createItemDefinition();
>
> SimpleAnyType ant = XMLTypeFactory.eINSTANCE
> .createSimpleAnyType();
>
> ant.setInstanceType((EcorePackage.eINSTANCE.getEString()));
EcorePackage.Literals.ESTRING works too and it's a constant.

O.K.

Ed Merks wrote on Sun, 17 January 2010 19:22

> and on the end of this method, I call generated method to populate it
> with created data: setConditionExpression(fe);
>
> However, when I try to save this object...graphically in GMF, I'm
> getting an error: ItemDefinition is not contained in a resource. What
> do I need to do?
If it's a non-containment reference, you'll have to store it in some
other containment reference or at the root of a resource.



Yes, it is a non-containment reference, and I cannot store it to some other containment reference. So, I need to store it at the root of a resource ? How can I get a resource in my model Implementation class ?

--
thanks, Milan
Re: EObject to String [message #508386 is a reply to message #508349] Mon, 18 January 2010 15:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

In general you can't assume there is always a resource, but
EObject.eResource() will return it if there is one.


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> Ed Merks wrote on Sun, 17 January 2010 19:22
>> Milan,
>>
>> Comments below.
>>
>> Milan Milanovich wrote:
>> > Dear Mr. Merks,
>> >
>> > I have created a volatile, transient property in my EMF code and
>> tried > to implement it, like this:
>> >
>> > final CommonFactory factory = CommonFactoryImpl.eINSTANCE;
>> Why access it via the Impl class when it's defined in the interface?
>
> Yes, you are right, my mistake...
>
> Ed Merks wrote on Sun, 17 January 2010 19:22
>> > final CommonPackage cPackage = CommonPackageImpl.eINSTANCE;
>> >
>> > ItemDefinition itemDefintion = factory.createItemDefinition();
>> >
>> > SimpleAnyType ant = XMLTypeFactory.eINSTANCE
>> > .createSimpleAnyType();
>> > >
>> ant.setInstanceType((EcorePackage.eINSTANCE.getEString()));
>> EcorePackage.Literals.ESTRING works too and it's a constant.
>
> O.K.
>
> Ed Merks wrote on Sun, 17 January 2010 19:22
>> > and on the end of this method, I call generated method to populate
>> it > with created data: setConditionExpression(fe);
>> >
>> > However, when I try to save this object...graphically in GMF, I'm >
>> getting an error: ItemDefinition is not contained in a resource. What
>> > do I need to do?
>> If it's a non-containment reference, you'll have to store it in some
>> other containment reference or at the root of a resource.
>
>
> Yes, it is a non-containment reference, and I cannot store it to some
> other containment reference. So, I need to store it at the root of a
> resource ? How can I get a resource in my model Implementation class ?
>
> --
> thanks, Milan
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508422 is a reply to message #508386] Mon, 18 January 2010 17:53 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

Ed Merks wrote on Mon, 18 January 2010 10:54
Milan,

In general you can't assume there is always a resource, but
EObject.eResource() will return it if there is one.


O.K. Thank you.

In the case, when I do this:

final CommonFactory factory = CommonFactory.eINSTANCE;
final CommonPackage cPackage = CommonPackage.eINSTANCE;

ItemDefinition itemDefintion = factory.createItemDefinition();


I can get eResource() from another object in this method, but how can I add the itemDefinition to the Resource?

--
Regards, Milan
Re: EObject to String [message #508425 is a reply to message #508422] Mon, 18 January 2010 17:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

resource.getContents().add(child)


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> Ed Merks wrote on Mon, 18 January 2010 10:54
>> Milan,
>>
>> In general you can't assume there is always a resource, but
>> EObject.eResource() will return it if there is one.
>
>
> O.K. Thank you.
>
> In the case, when I do this:
>
> final CommonFactory factory = CommonFactory.eINSTANCE;
> final CommonPackage cPackage = CommonPackage.eINSTANCE;
>
> ItemDefinition itemDefintion = factory.createItemDefinition();
>
> I can get eResource() from another object in this method, but how can
> I add the itemDefinition to the Resource?
>
> --
> Regards, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508436 is a reply to message #508425] Mon, 18 January 2010 19:27 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

Ed Merks wrote on Mon, 18 January 2010 12:56
Milan,

resource.getContents().add(child)


Good, now I don't get the error, however all of these elements are not saved in the file. E.g., this is saved:

<conditionExpression xsi:type="bpmn2_2:FormalExpression" language="ocl" evaluatesToTypeRef="/1" body="/2"/>


evaluatesToTypeRef and body elements are the elements which I have added to the resource, but they are not saved in the file?

--
thanks, Milan

[Updated on: Mon, 18 January 2010 19:28]

Report message to a moderator

Re: EObject to String [message #508588 is a reply to message #508436] Tue, 19 January 2010 14:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Only an XMIResourceImpl will save multiple roots, so you'll need to rely
on an XMI serialization.


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> Ed Merks wrote on Mon, 18 January 2010 12:56
>> Milan,
>>
>> resource.getContents().add(child)
>
>
> Good, now I don't get the error, however all of these elements are not
> saved in the file. E.g., this is saved:
>
> <conditionExpression xsi:type="bpmn2_2:FormalExpression"
> language="ocl" evaluatesToTypeRef="/1" body="/2"/>
>
> evaluatesToTypeRef and body elements are the elements which I have
> added to the resource, but they are not saved in the file?
>
> --
> thanks, Milan
>
> Ed Merks wrote on Mon, 18 January 2010 12:56
>> Milan Milanovich wrote:
>> > Dear Mr. Merks,
>> >
>> > Ed Merks wrote on Mon, 18 January 2010 10:54
>> >> Milan,
>> >>
>> >> In general you can't assume there is always a resource, but >>
>> EObject.eResource() will return it if there is one.
>> >
>> >
>> > O.K. Thank you.
>> >
>> > In the case, when I do this:
>> >
>> > final CommonFactory factory = CommonFactory.eINSTANCE;
>> > final CommonPackage cPackage = CommonPackage.eINSTANCE;
>> >
>> > ItemDefinition itemDefintion = factory.createItemDefinition();
>> >
>> > I can get eResource() from another object in this method, but how
>> can > I add the itemDefinition to the Resource?
>> >
>> > -- > Regards, Milan
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508694 is a reply to message #508588] Tue, 19 January 2010 21:49 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

good, thanks. I switched to XMI in genmodel and it works now...i.e., it is saved in XMI file. However, when I try to read the SimpleAnyType value I get an exception. I save like this:

Resource r =someObject.eResource();
SimpleAnyType ant = XMLTypeFactory.eINSTANCE.createSimpleAnyType();

ant.setInstanceType(EcorePackage.Literals.ESTRING);
ant.setValue(newCondition);
r.getContents().add(ant); // add to resource


this works well, however when I tried to load the value later:

SimpleAnyType ant = (SimpleAnyType)((FormalExpression) e).getBody();
String s = (String)ant.getValue(); <- here I get an exception:

java.lang.NullPointerException 
at org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreUtil.java:3257) 
at org.eclipse.emf.ecore.xml.type.impl.SimpleAnyTypeImpl.getValue(SimpleAnyTypeImpl.java:124)


what is the problem here?

--
Regards, Milan

[Updated on: Tue, 19 January 2010 21:51]

Report message to a moderator

Re: EObject to String [message #508797 is a reply to message #508694] Wed, 20 January 2010 06:32 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Are you using the extended metadata option. I'm pretty sure that's
necessary to support xsi/xmi:types that are EDataTypes... I've never
tried one as a root object either. Normally (in an XML Schema derived
model) they'd be contained by a DocumentRoot, so maybe that's a problem too.


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> good, thanks. I switched to XMI in genmodel and it works now...i.e.,
> it is saved in XMI file. However, when I try to read the SimpleAnyType
> value I get an exception. I save like this:
>
> Resource r =someObject.eResource();
> SimpleAnyType ant = XMLTypeFactory.eINSTANCE.createSimpleAnyType();
> ant.setInstanceType(EcorePackage.Literals.ESTRING);
> ant.setValue(newCondition);
> r.getContents().add(ant); // add to resource
>
> this works well, however when I tried to load the value later:
>
> SimpleAnyType ant = (SimpleAnyType)((FormalExpression) e).getBody();
> String s = (String)ant.getValue(); <- here I get an exception:
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3257)
>
> at
> org.eclipse.emf.ecore.xml.type.impl.SimpleAnyTypeImpl.getVal ue(SimpleAnyTypeImpl.java:124)
>
>
> what is the problem here?
>
> --
> Regards, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508841 is a reply to message #508797] Wed, 20 January 2010 14:22 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,


Ed Merks wrote on Wed, 20 January 2010 01:32
Milan,

Are you using the extended metadata option. I'm pretty sure that's
necessary to support xsi/xmi:types that are EDataTypes...


O.K. Where can I found this option?

Ed Merks wrote on Wed, 20 January 2010 01:32

I've never
tried one as a root object either. Normally (in an XML Schema derived
model) they'd be contained by a DocumentRoot, so maybe that's a problem too.


I'm not sure about this.

--
Milan
Re: EObject to String [message #508850 is a reply to message #508841] Wed, 20 January 2010 14:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Look for OPTION_EXTENDED_META_DATA in XMLResource.


Milan Milanovich wrote:
> Dear Mr. Merks,
>
>
> Ed Merks wrote on Wed, 20 January 2010 01:32
>> Milan,
>>
>> Are you using the extended metadata option. I'm pretty sure that's
>> necessary to support xsi/xmi:types that are EDataTypes...
>
>
> O.K. Where can I found this option?
>
> Ed Merks wrote on Wed, 20 January 2010 01:32
>> I've never tried one as a root object either. Normally (in an XML
>> Schema derived model) they'd be contained by a DocumentRoot, so maybe
>> that's a problem too.
>
>
> I'm not sure about this.
>
> --
> Milan
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508855 is a reply to message #508850] Wed, 20 January 2010 14:58 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

O.K., but where can I found XMLResource in this case?

Is it O.K. to do this in my PackageResourceImpl extends XMIResourceImpl constructor:

Map options = new HashMap();
		
options.put(XMIResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
	
save(options);


?

btw- I'm using XMI serialization now.

--
Regards, Milan

[Updated on: Wed, 20 January 2010 15:19]

Report message to a moderator

Re: EObject to String [message #508865 is a reply to message #508855] Wed, 20 January 2010 15:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Ctrl-Shift-T should be one of your best friends.


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> O.K., but where can I found XMLResource in this case?
>
> --
> Regards, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508873 is a reply to message #508865] Wed, 20 January 2010 15:43 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

yes, I know that, I meant in my code. I updated the message below, is it correct?

--
Thanks, Milan
Re: EObject to String [message #508881 is a reply to message #508873] Wed, 20 January 2010 15:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Options are typically set in the resource factory. I don't see anything
below...


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> yes, I know that, I meant in my code. I updated the message below, is
> it correct?
>
> --
> Thanks, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508888 is a reply to message #508881] Wed, 20 January 2010 16:08 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

I meant above...sorry. I repeat it here:

I put this code in my PackageResourceFactory:

Map options = new HashMap();

options.put(XMIResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

save(options);

However, the problem remains. Everything is written good with this code:

FormalExpression fe = (FormalExpression) e;
Resource r = fe.eResource();

SimpleAnyType ant = XMLTypeFactory.eINSTANCE.createSimpleAnyType();

ant.setInstanceType(EcorePackage.Literals.ESTRING);
ant.setValue(newCondition);
r.getContents().add(ant); // add to resource
...
fe.setBody(ant);


this is what I get in the model file (an excerpt):

....
<conditionExpression xsi:type="bpmn2_2:FormalExpression" language="ocl" evaluatesToTypeRef="/1" body="/2"/>
...
<bpmn2_2:ItemDefinition structure="/3"/>

<xsd:SimpleAnyType>
some string    <instanceType href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </xsd:SimpleAnyType>


however, when I try to read this by using this code:

SimpleAnyType ant = (SimpleAnyType)((FormalExpression) e).getBody();
String s = (String)ant.getValue(); <- here I get an exception shown below


I get and exception:

java.lang.NullPointerException
at org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreUtil.java:3257)
at org.eclipse.emf.ecore.xml.type.impl.SimpleAnyTypeImpl.getValue(SimpleAnyTypeImpl.java:124)
at ca.athabascau.semtech.bpmn2.common.impl.SequenceFlowImpl.getCondition(SequenceFlowImpl.java:330)
...


--
Milan

[Updated on: Wed, 20 January 2010 16:43]

Report message to a moderator

Re: EObject to String [message #508899 is a reply to message #508888] Wed, 20 January 2010 16:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090404060803040702020805
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Milan,

Here's what the resource factory looks like for a model generated from
XML Schema:

/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Resource createResource(URI uri) {
XMLResource result = new LibraryResourceImpl(uri);

result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);

result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);


result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
Boolean.TRUE);


result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);

result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);


result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
Boolean.TRUE);
return result;
}



Milan Milanovich wrote:
> Dear Mr. Merks,
> I meant above...sorry. I repeat it here:
>
> Is it O.K. to do this in my PackageResourceImpl extends
> XMIResourceImpl constructor:
>
> Map options = new HashMap();
>
> options.put(XMIResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>
> save(options);
>
> ?
>
> --
> Milan

--------------090404060803040702020805
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Milan,<br>
<br>
Here's what the resource factory looks like for a model generated from
XML Schema:<br>
<blockquote><small>    /**</small><br>
<small>     * Creates an instance of the resource.</small><br>
<small>     * &lt;!-- begin-user-doc --&gt;</small><br>
<small>     * &lt;!-- end-user-doc --&gt;</small><br>
<small>     * @generated</small><br>
<small>     */</small><br>
<small>    @Override</small><br>
<small>    public Resource createResource(URI uri) {</small><br>
<small>        XMLResource result = new LibraryResourceImpl(uri);</small><br>
<small>       
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);</small><br>
<small>       
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);</small><br>
<br>
<small>       
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
Boolean.TRUE);</small><br>
<br>
<small>       
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);</small><br>
<small>       
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);</small><br>
<br>
<small>       
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
Boolean.TRUE);</small><br>
<small>        return result;</small><br>
<small>    }</small><br>
</blockquote>
<br>
<br>
Milan Milanovich wrote:
<blockquote cite="mid:hj79qn$s7u$1@build.eclipse.org" type="cite">Dear
Mr. Merks, <br>
I meant above...sorry. I repeat it here:
<br>
<br>
Is it O.K. to do this in my PackageResourceImpl extends XMIResourceImpl
constructor:
<br>
<br>
Map options = new HashMap();
<br>
        <br>
options.put(XMIResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
<br>
    
<br>
save(options);
<br>
<br>
?
<br>
<br>
--
<br>
Milan
<br>
</blockquote>
</body>
</html>

--------------090404060803040702020805--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508902 is a reply to message #508899] Wed, 20 January 2010 16:34 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

I have updated some details in previous message.

The ResourceFactory for my package, where my elements that should be saved looks like this (generated from ecore model):

	@Override
	public Resource createResource(URI uri) {
		Resource result = new CommonResourceImpl(uri);
		
		Map options = new HashMap();
		
		
		return result;
	}


I'm using XMI resource, as you proposed. Should I cast Resource to XMIResource in order to access these methods (getDefaultSaveOptions(),etc.) ? And should I do this in all of my package resource factories?

--
thanks, Milan
Re: EObject to String [message #508905 is a reply to message #508902] Wed, 20 January 2010 16:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Presumably CommonResourceImpl extends XMIResourceImpl and so you could
change Resource to XMIResource without need for casting.


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> I have updated some details in previous message.
>
> The ResourceFactory for my package, where my elements that should be
> saved looks like this (generated from ecore model):
>
> @Override
> public Resource createResource(URI uri) {
> Resource result = new CommonResourceImpl(uri);
>
> Map options = new HashMap();
>
>
> return result;
> }
>
> I'm using XMI resource, as you proposed. Should I cast Resource to
> XMIResource in order to access these methods
> (getDefaultSaveOptions(),etc.) ? And should I do this in all of my
> package resource factories?
>
> --
> thanks, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508907 is a reply to message #508905] Wed, 20 January 2010 16:51 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

I have updated my method and it now looks like this:

	@Override
	public Resource createResource(URI uri) {
		XMIResource result= new CommonResourceImpl(uri);

		result.getDefaultSaveOptions().put(XMIResource.OPTION_EXTENDED_META_DATA,
				Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMIResource.OPTION_EXTENDED_META_DATA,
				Boolean.TRUE);

		result.getDefaultSaveOptions().put(XMIResource.OPTION_SCHEMA_LOCATION,
				Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMIResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
				Boolean.TRUE);

		result.getDefaultSaveOptions().put(XMIResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
				Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMIResource.OPTION_USE_LEXICAL_HANDLER,
				Boolean.TRUE);
		
		return result;
	}


however, I'm still gettng an exception when I try to get SimpleAnyType value, as I desribed here.

--
Thanks, Milan
Re: EObject to String [message #508912 is a reply to message #508907] Wed, 20 January 2010 17:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

What does the serialization look like?


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> I have updated my method and it now looks like this:
>
> @Override
> public Resource createResource(URI uri) {
> XMIResource result= new CommonResourceImpl(uri);
>
>
> result.getDefaultSaveOptions().put(XMIResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMIResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
>
> result.getDefaultSaveOptions().put(XMIResource.OPTION_SCHEMA _LOCATION,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMIResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>
> Boolean.TRUE);
>
>
> result.getDefaultSaveOptions().put(XMIResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMIResource.OPTION_USE_LE XICAL_HANDLER,
>
> Boolean.TRUE);
>
> return result;
> }
>
> however, I'm still gettng an exception when I try to get SimpleAnyType
> value, as I desribed
> http://www.eclipse.org/forums/index.php?t=msg&&th=16 0464&goto=508888#msg_508888
>
>
> --
> Thanks, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508917 is a reply to message #508912] Wed, 20 January 2010 17:28 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

I gave in in the post above, this is an excerpt:

....
<conditionExpression xsi:type="bpmn2_2:FormalExpression" language="ocl" evaluatesToTypeRef="/1" body="/2"/>
...
<bpmn2_2:ItemDefinition structure="/3"/>

<xsd:SimpleAnyType>
some string    <instanceType href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </xsd:SimpleAnyType>


--
Milan
Re: EObject to String [message #508932 is a reply to message #508917] Wed, 20 January 2010 17:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

That looks okay, but not what I'd expect. The stack trace you show
makes it sound like the instanceType is null though, but I'd expect it
to be set based on what I see below. One thing that seems problematic
though is that the instanceType reference is cross document and yet the
instanceType feature doesn't do cross document proxy resolution. It's
generally expected that the serialization would be using a containing
element along with an xsi:type but given you're putting this at the root
of a document, there is no good element name to use. I think the best
approach would be to define some type of "ValueContainer" EClass with a
containment reference to EObject and to nest all these "free floating
values" inside that container which in turn is nested at the root of the
resource.


Milan Milanovich wrote:
> Dear Mr. Merks,
>
> I gave in in the
> http://www.eclipse.org/forums/index.php?t=msg&&th=16 0464&goto=508888#msg_508888
> above, this is an excerpt:
>
> ...
> <conditionExpression xsi:type="bpmn2_2:FormalExpression"
> language="ocl" evaluatesToTypeRef="/1" body="/2"/>
> ..
> <bpmn2_2:ItemDefinition structure="/3"/>
>
> <xsd:SimpleAnyType>
> some string <instanceType
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </xsd:SimpleAnyType>
>
> --
> Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508935 is a reply to message #508932] Wed, 20 January 2010 18:40 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

Ed Merks wrote on Wed, 20 January 2010 12:40
Milan,

That looks okay, but not what I'd expect. The stack trace you show
makes it sound like the instanceType is null though, but I'd expect it
to be set based on what I see below. One thing that seems problematic
though is that the instanceType reference is cross document and yet the
instanceType feature doesn't do cross document proxy resolution. It's
generally expected that the serialization would be using a containing
element along with an xsi:type but given you're putting this at the root
of a document, there is no good element name to use. I think the best
approach would be to define some type of "ValueContainer" EClass with a
containment reference to EObject and to nest all these "free floating
values" inside that container which in turn is nested at the root of the
resource.


Actually, the instanceType is not null, but the value. If I try to read the instance type I get:

org.eclipse.emf.ecore.impl.EDataTypeImpl@1092e60 (eProxyURI: http://www.eclipse.org/emf/2002/Ecore#//EString)

so it's not null.

I'm what is the ValueContainer eclass, but when I set the body (of SimpleAnyType) to my FormalExpression instance, it is already initialized by using the seq initializer in gmfmap.

One general question regarding this subject, i.e., non-containament references which are not defined graphically in gmf, e.g.:

class SequenceFlow{
    expression[0..1]: Expression;
}

class FormalExpression extends Expression { <- this class is not defined graphically
    body : EObject;
    language : EString;
}


I want to enable that when a user clicks on the SequenceFlow, he can define its expression, by instantiating
the FormalExpression and populating the body with empty String and the language with asting. Then, user
should enter body of the FormalExpression. This is maybe GMF related question, but I want to ask you what strategy do you recommend me (example?) ?

--
thanks, Milan

[Updated on: Wed, 20 January 2010 18:45]

Report message to a moderator

Re: EObject to String [message #508937 is a reply to message #508935] Wed, 20 January 2010 18:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Comments below.

Milan Milanovich wrote:
> Dear Mr. Merks,
>
> Ed Merks wrote on Wed, 20 January 2010 12:40
>> Milan,
>>
>> That looks okay, but not what I'd expect. The stack trace you show
>> makes it sound like the instanceType is null though, but I'd expect
>> it to be set based on what I see below. One thing that seems
>> problematic though is that the instanceType reference is cross
>> document and yet the instanceType feature doesn't do cross document
>> proxy resolution. It's generally expected that the serialization
>> would be using a containing element along with an xsi:type but given
>> you're putting this at the root of a document, there is no good
>> element name to use. I think the best approach would be to define
>> some type of "ValueContainer" EClass with a containment reference to
>> EObject and to nest all these "free floating values" inside that
>> container which in turn is nested at the root of the resource.
>
>
> Actually, the instanceType is not null, but the value. If I try to
> read the instance type I get:
>
> mailto:org.eclipse.emf.ecore.impl.EDataTypeImpl@1092e60 (eProxyURI:
> http://www.eclipse.org/emf/2002/Ecore#//EString)
>
> so it's not null.
Yes, as I said, that feature doesn't try to resolve proxies but the
serialization would result in a proxy being created.
>
> I'm what is the ValueContainer eclass, but when I set body (of
> SimpleAnyType) to my FormalExpression instance, it is already
> initialized by using seq initializer in gmfmap.
> One general question regarding this subject, i.e., non-containament
> references which are not defined graphically in gmf, e.g.:
>
> class SequenceFlow{
> expression[0..1]: Expression;
> }
>
> class FormalExpression extends Expression { <- this class is not
> defined graphically
> body : EObject;
> language : EString;
> }
>
> I want to enable that when a user click on the SequenceFlow, he can
> define its expression, by instantiating
> the FormalExpression and populating body with empty String and
> language with some other sting. Then, user
> should enter body of the FormalExpression. This is maybe GMF related
> question, but I want to ask you what strategy do you recommend me
> (example?) ?
>
It's a GMF question for which I don't know the answer.
>
> --
> thanks, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject to String [message #508939 is a reply to message #508932] Wed, 20 January 2010 19:03 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Dear Mr. Merks,

O.K. Thank you. Regarding this:

Ed Merks wrote on Wed, 20 January 2010 12:40
Milan,

That looks okay, but not what I'd expect. The stack trace you show
makes it sound like the instanceType is null though, but I'd expect it
to be set based on what I see below. One thing that seems problematic
though is that the instanceType reference is cross document and yet the
instanceType feature doesn't do cross document proxy resolution. It's
generally expected that the serialization would be using a containing
element along with an xsi:type but given you're putting this at the root
of a document, there is no good element name to use. I think the best
approach would be to define some type of "ValueContainer" EClass with a
containment reference to EObject and to nest all these "free floating
values" inside that container which in turn is nested at the root of the
resource.


I have a top-most element of my model called Collaboration, which have containment reference to a Definitions object. This Definitions object is intended to be used for defining some types. It definition looks like this:

class Definitions {
targetNamespace : EString;
typeLanguage : EString;
rootElements : RootElement;
imports : Import;
extensions : Extension;
}

Is this class good candidate for the " ValueContainer" EClass ? Or should I add it one EObject[0..*] containment reference to hold all of the SimpleValueTypes?

--
thanks, Milan
Re: EObject to String [message #508952 is a reply to message #508939] Wed, 20 January 2010 20:25 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Milan,

Comments below.

Milan Milanovich wrote:
> Dear Mr. Merks,
>
> O.K. Thank you. Regarding this:
>
> Ed Merks wrote on Wed, 20 January 2010 12:40
>> Milan,
>>
>> That looks okay, but not what I'd expect. The stack trace you show
>> makes it sound like the instanceType is null though, but I'd expect
>> it to be set based on what I see below. One thing that seems
>> problematic though is that the instanceType reference is cross
>> document and yet the instanceType feature doesn't do cross document
>> proxy resolution. It's generally expected that the serialization
>> would be using a containing element along with an xsi:type but given
>> you're putting this at the root of a document, there is no good
>> element name to use. I think the best approach would be to define
>> some type of "ValueContainer" EClass with a containment reference to
>> EObject and to nest all these "free floating values" inside that
>> container which in turn is nested at the root of the resource.
>
>
> I have a top-most element of my model called Collaboration, which have
> containment reference to a Definitions object. This Definitions object
> is intended to be used for defining some types. It definition looks
> like this:
>
> class Definitions {
I tend to have an aversion to classes with a puralized name because it's
very hard to create well formed English sentence from such nouns. You
create a Definitions. What if there are two Definitions as opposed to
just one.
> targetNamespace : EString;
> typeLanguage : EString;
> rootElements : RootElement;
> imports : Import;
> extensions : Extension;
> }
>
> Is this class good candidate for the " ValueContainer" EClass ? Or
> should I add it one EObject[0..*] containment reference to hold all of
> the SimpleValueTypes?
Yes, you need some type of EObject containment reference somewhere.
>
> --
> thanks, Milan


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Is there a way to delete all generated code?
Next Topic:Runtime meta data with generic concept
Goto Forum:
  


Current Time: Thu Mar 28 12:51:05 GMT 2024

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

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

Back to the top