Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » EMF object serialization into xml
EMF object serialization into xml [message #531880] Thu, 06 May 2010 13:21 Go to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi I have a problem in serializing my EMF objects to a XML file.
I want to serialize all Objects but my program create a xml file with only one object in it.

Look on my code:

public void serialize() throws IOException {

ResourceSet rs = new ResourceSetImpl();

// Register the base XML resource factory implementation in the local resource factory registry.

rs.getResourceFactoryRegistry().getExtensionToFact oryMap().put( "xml", new XMLResourceFactoryImpl());
URI fileURI = URI.createFileURI( FILE.getAbsolutePath());

Resource resource = rs.createResource( fileURI);
// serialize all ComputerResources objects into xml
Iterator<ComputerResources> itr = ComputerCollectionGenerator.computerResoucres.iter ator();
while ( itr.hasNext()) {
ComputerResources next = itr.next();
resource.getContents().add( next);
}
resource.save( null);

The objects are created and stored at runtime in ArrayList computerResoucres.

What do I have to do?

Thank you in advance
Re: EMF object serialization into xml [message #531898 is a reply to message #531880] Thu, 06 May 2010 13:32 Go to previous messageGo to next message
Cyril Jaquier is currently offline Cyril JaquierFriend
Messages: 80
Registered: July 2009
Member
Hi,

> Hi I have a problem in serializing my EMF objects to a XML file.
> I want to serialize all Objects but my program create a xml file with
> only one object in it.
>

A XMLResource can only contain a single root element. Use a XMIResource
instead.

The easiest way to do it is 1/ register XMIResourceFactoryImpl with the
".xmi" extension and 2/ end your URI with ".xmi". That's it :-)

Regards,
Cyril
Re: EMF object serialization into xml [message #531962 is a reply to message #531898] Thu, 06 May 2010 15:27 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Yes that's it
Thank you very very MUCH

Best regards
Ugur
Re: EMF object serialization into xml [message #531965 is a reply to message #531962] Thu, 06 May 2010 15:30 Go to previous messageGo to next message
Cyril Jaquier is currently offline Cyril JaquierFriend
Messages: 80
Registered: July 2009
Member
> Yes that's it
> Thank you very very MUCH

Nice :-) You're welcome.

Cheers,
Cyril
Re: EMF object serialization into xml [message #531970 is a reply to message #531898] Thu, 06 May 2010 15:48 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Cyril,

I have an additional problem:
I have more than ComputerResources objects for example:
1) PrinterResources objects which have an attribute of type boolean (I can't see attributes with value=true)
2nd) Group objects which have associations in my ecore diagram hasMember and memberOf . These associations are handled as attributres with values, too. Some of this attribute values are numbers and not String names like
in System.out

Do you know the reason for these dilemma Confused

Thank you again.

Br
Ugur
Re: EMF object serialization into xml [message #531980 is a reply to message #531970] Thu, 06 May 2010 16:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugur,

Comments below.

Ugur Kocak wrote:
> Hi Cyril,
>
> I have an additional problem:
> I have more than ComputerResources objects for example:
> 1) PrinterResources objects which have an attribute of type boolean (I
> can't see attributes with value=true)
EMF can serialize any instance to XML.
> 2nd) Group objects which have associations in my ecore diagram
> hasMember and memberOf . These associations are handled as attributres
> with values, too.
How so and by whom?
> Some of this attribute values are numbers and not String names like
> in System.out
I don't follow.
>
> Do you know the reason for these dilemma :?
What's the dilemma?
> Thank you again.
You just need to put all your objects in one or more resources and they
should just serialize. What aspect of that isn't working well for you?
>
> Br Ugur


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #532416 is a reply to message #531980] Sun, 09 May 2010 19:40 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,

my question concerns the following case: I have an ecore model with classes: Group, ComputerResources, PrinterResources...... The class Group has two recursive associations hasMember and MemberOf. Then I have the 2 methods getHasMember() and getMemberOf(). I extract the values for all of the attributes of the objects from Active Directory with LDAP/JNDI. There are two attributes member and memberOf in the Acitve Directory. I create an object for every Group. A group object has "member" attribute (values are all Group objects which are members of this group) and "memberOf "attribute (values are all Groups objects inversely contain this Group object ).
My problem first Problem is that if i create my .xmi file then all of the attribute values for "member" and "memberOf" are integer id's like "/652". But I have set the attribute "distinguishedName" a String value as identification for the Group attribute's.

My 2nd porblem is that all boolean attributes with a value "true" are hidden in the xmi.file . That means that I can't see for some object's that they have such an attribute.

Could you explain me why it's so.

Thank you in advance.

Best regards
Ugur Kocak

Re: EMF object serialization into xml [message #532447 is a reply to message #532416] Mon, 10 May 2010 06:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugar,

Comments below.

Ugur Kocak wrote:
> Hi Ed,
>
> my question concerns the following case: I have an ecore model with
> classes: Group, ComputerResources, PrinterResources...... The class
> Group has two recursive associations hasMember and MemberOf. Then I
> have the 2 methods getHasMember() and getMemberOf(). I extract the
> values for all of the attributes of the objects from Active Directory
> with LDAP/JNDI. There are two attributes member and memberOf in the
> Acitve Directory. I create an object for every Group. A group object
> has "member" attribute (values are all Group objects which are members
> of this group) and "memberOf "attribute (values are all Groups objects
> inversely contain this Group object ). My problem first Problem is
> that if i create my .xmi file then all of the attribute values for
> "member" and "memberOf" are integer id's like "/652". But I have set
> the attribute "distinguishedName" a String value as identification for
> the Group attribute's.
You can specialize a resource's getURIFragmentRootSegment and
getEObjectForURIFragmentRootSegment methods.
>
> My 2nd porblem is that all boolean attributes with a value "true" are
> hidden in the xmi.file .
Yes, features for which eIsSet if false don't need to be serialized.
> That means that I can't see for some object's that they have such an
> attribute.
Try OPTION_KEEP_DEFAULT_CONTENT.
>
> Could you explain me why it's so.
>
> Thank you in advance.
>
> Best regards
> Ugur Kocak
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #532503 is a reply to message #532447] Mon, 10 May 2010 10:07 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,

thank you for the hint's

Best regards
U.Kocak
Smile
Re: EMF object serialization into xml [message #532509 is a reply to message #532447] Mon, 10 May 2010 10:35 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,

I have the following Code, but I can't see any attributes with boolean value "true" in my .xmi file.

public class SerializationUtility {

public void serialize() throws IOException {

ResourceSet rs = new ResourceSetImpl();

XMIResourceImpl myXMResourceImpl = new XMIResourceImpl();
myXMResourceImpl.getDefaultSaveOptions().put( XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);

// Register the base XML resource factory implementation in the local resource factory registry.
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut( "xmi", new XMIResourceFactoryImpl());
URI fileURI = URI.createFileURI( "ResourcesFZI.xmi");

Resource resource = rs.createResource( fileURI);
// add the root objects to the resource
Iterator<ComputerResources> itr = ComputerCollectionGenerator.computerResoucres.iterator();
while ( itr.hasNext()) {
ComputerResources next = itr.next();
resource.getContents().add( next);
}

Iterator<PrinterResources> itr2 = PrinterCollectionGenerator.printerResources.iterator();
while ( itr2.hasNext()) {
PrinterResources next = itr2.next();
resource.getContents().add( next);
}

Iterator<RoomResources> itr3 = RoomCollectionGenerator.roomResoucres.iterator();
while ( itr3.hasNext()) {
RoomResources next = itr3.next();
resource.getContents().add( next);
}

Collection<Group> groups = GroupCollectionGenerator.groupMap.values();
Iterator<Group> itr4 = groups.iterator();
while ( itr4.hasNext()) {
Group next = itr4.next();
resource.getContents().add( next);
}

Iterator<ExternerUser> itr5 = ExternerUserCollectionGenerator.externeUser.iterator();
while ( itr5.hasNext()) {
ExternerUser next = itr5.next();
resource.getContents().add( next);
}

Collection<Studenten> studenten = UserCollectionGenerator.studentMap.values();
Iterator<Studenten> itr6 = studenten.iterator();
while ( itr6.hasNext()) {
Studenten next = itr6.next();
resource.getContents().add( next);
}

Collection<Mitarbeiter> mitarbeiter = UserCollectionGenerator.mitarbeiterMap.values();
Iterator<Mitarbeiter> itr7 = mitarbeiter.iterator();
while ( itr7.hasNext()) {
Mitarbeiter next = itr7.next();
resource.getContents().add( next);
}

Collection<Manager> manager = UserCollectionGenerator.managerMap.values();
Iterator<Manager> itr8 = manager.iterator();
while ( itr8.hasNext()) {
Manager next = itr8.next();
resource.getContents().add( next);
}

Collection<Vorstand> vorstand = UserCollectionGenerator.vorstandMap.values();
Iterator<Vorstand> itr9 = vorstand.iterator();
while ( itr9.hasNext()) {
Vorstand next = itr9.next();
resource.getContents().add( next);
}

resource.save( null);

}
}

Maybe do you know where's the problem?
You see I have tried it with "OPTION_KEEP_DEFAULT_CONTENT" = false and true, but I can't see anything.

Best regards
U.Kocak
Re: EMF object serialization into xml [message #532850 is a reply to message #532509] Tue, 11 May 2010 11:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugar,

Did you also set an explicit default on the feature itself? Except for
primitive types, all features implicitly default to null. For
primitives, they default to the same value as the implicit Java
default. You'll need to set an explicit default if you want something
serialized with that option.


Ugur Kocak wrote:
> Hi Ed,
>
> I have the following Code, but I can't see any attributes with boolean
> value "true" in my .xmi file.
>
> public class SerializationUtility {
>
> public void serialize() throws IOException {
>
> ResourceSet rs = new ResourceSetImpl();
>
> XMIResourceImpl myXMResourceImpl = new XMIResourceImpl();
> myXMResourceImpl.getDefaultSaveOptions().put(
> XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
>
> // Register the base XML resource factory implementation in the
> local resource factory registry.
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
> "xmi", new XMIResourceFactoryImpl());
> URI fileURI = URI.createFileURI( "ResourcesFZI.xmi");
>
> Resource resource = rs.createResource( fileURI);
> // add the root objects to the resource
> Iterator<ComputerResources> itr =
> ComputerCollectionGenerator.computerResoucres.iterator();
> while ( itr.hasNext()) {
> ComputerResources next = itr.next();
> resource.getContents().add( next);
> }
>
> Iterator<PrinterResources> itr2 =
> PrinterCollectionGenerator.printerResources.iterator();
> while ( itr2.hasNext()) {
> PrinterResources next = itr2.next();
> resource.getContents().add( next);
> }
>
> Iterator<RoomResources> itr3 =
> RoomCollectionGenerator.roomResoucres.iterator();
> while ( itr3.hasNext()) {
> RoomResources next = itr3.next();
> resource.getContents().add( next);
> }
>
> Collection<Group> groups =
> GroupCollectionGenerator.groupMap.values();
> Iterator<Group> itr4 = groups.iterator();
> while ( itr4.hasNext()) {
> Group next = itr4.next();
> resource.getContents().add( next);
> }
>
> Iterator<ExternerUser> itr5 =
> ExternerUserCollectionGenerator.externeUser.iterator();
> while ( itr5.hasNext()) {
> ExternerUser next = itr5.next();
> resource.getContents().add( next);
> }
>
> Collection<Studenten> studenten =
> UserCollectionGenerator.studentMap.values();
> Iterator<Studenten> itr6 = studenten.iterator();
> while ( itr6.hasNext()) {
> Studenten next = itr6.next();
> resource.getContents().add( next);
> }
>
> Collection<Mitarbeiter> mitarbeiter =
> UserCollectionGenerator.mitarbeiterMap.values();
> Iterator<Mitarbeiter> itr7 = mitarbeiter.iterator();
> while ( itr7.hasNext()) {
> Mitarbeiter next = itr7.next();
> resource.getContents().add( next);
> }
>
> Collection<Manager> manager =
> UserCollectionGenerator.managerMap.values();
> Iterator<Manager> itr8 = manager.iterator();
> while ( itr8.hasNext()) {
> Manager next = itr8.next();
> resource.getContents().add( next);
> }
>
> Collection<Vorstand> vorstand =
> UserCollectionGenerator.vorstandMap.values();
> Iterator<Vorstand> itr9 = vorstand.iterator();
> while ( itr9.hasNext()) {
> Vorstand next = itr9.next();
> resource.getContents().add( next);
> }
>
> resource.save( null);
>
> }
> }
>
> Maybe do you know where's the problem?
> You see I have tried it with "OPTION_KEEP_DEFAULT_CONTENT" = false and
> true, but I can't see anything.
>
> Best regards
> U.Kocak


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #532880 is a reply to message #532850] Tue, 11 May 2010 13:05 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,
you're right I didn't set any explicit default on the feature.
How can I do this. Which methods and classes are responsible to set an explicit default on the feature.

Best regards
Ugur
Re: EMF object serialization into xml [message #532889 is a reply to message #532880] Tue, 11 May 2010 13:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugar,

You do that in the properties view in the editor by specifying either
the string false or true for the Default Value Literal.


Ugur Kocak wrote:
> Hi Ed, you're right I didn't set any explicit default on the feature.
> How can I do this. Which methods and classes are responsible to set an
> explicit default on the feature.
>
> Best regards
> Ugur


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #545032 is a reply to message #532889] Tue, 06 July 2010 13:21 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,
simple question:
do I have to type false/true in the Value field of the attribute.
I ask because there isn't any given value false/true for the Default Value Literal in the Properties view.

Best regards
Ugur
Re: EMF object serialization into xml [message #545055 is a reply to message #545032] Tue, 06 July 2010 13:53 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugur,

You need to enter true or false in the Properties view for the Default
Value Literal feature for the EAttribute of your model. It should be there.


Ugur Kocak wrote:
> Hi Ed,
> simple question:
> do I have to type false/true in the Value field of the attribute.
> I ask because there isn't any given value false/true for the Default
> Value Literal in the Properties view.
>
> Best regards
> Ugur


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #622841 is a reply to message #531898] Thu, 06 May 2010 15:27 Go to previous message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Yes that's it
Thank you very very MUCH

Best regards
Ugur
Re: EMF object serialization into xml [message #622844 is a reply to message #531962] Thu, 06 May 2010 15:30 Go to previous message
Cyril Jaquier is currently offline Cyril JaquierFriend
Messages: 80
Registered: July 2009
Member
> Yes that's it
> Thank you very very MUCH

Nice :-) You're welcome.

Cheers,
Cyril
Re: EMF object serialization into xml [message #622845 is a reply to message #531898] Thu, 06 May 2010 15:48 Go to previous message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Cyril,

I have an additional problem:
I have more than ComputerResources objects for example:
1) PrinterResources objects which have an attribute of type boolean (I can't see attributes with value=true)
2nd) Group objects which have associations in my ecore diagram hasMember and memberOf . These associations are handled as attributres with values, too. Some of this attribute values are numbers and not String names like
in System.out

Do you know the reason for these dilemma :?

Thank you again.

Br
Ugur
Re: EMF object serialization into xml [message #622846 is a reply to message #531970] Thu, 06 May 2010 16:30 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugur,

Comments below.

Ugur Kocak wrote:
> Hi Cyril,
>
> I have an additional problem:
> I have more than ComputerResources objects for example:
> 1) PrinterResources objects which have an attribute of type boolean (I
> can't see attributes with value=true)
EMF can serialize any instance to XML.
> 2nd) Group objects which have associations in my ecore diagram
> hasMember and memberOf . These associations are handled as attributres
> with values, too.
How so and by whom?
> Some of this attribute values are numbers and not String names like
> in System.out
I don't follow.
>
> Do you know the reason for these dilemma :?
What's the dilemma?
> Thank you again.
You just need to put all your objects in one or more resources and they
should just serialize. What aspect of that isn't working well for you?
>
> Br Ugur


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #622865 is a reply to message #531980] Sun, 09 May 2010 19:40 Go to previous message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,

my question concerns the following case: I have an ecore model with classes: Group, ComputerResources, PrinterResources...... The class Group has two recursive associations hasMember and MemberOf. Then I have the 2 methods getHasMember() and getMemberOf(). I extract the values for all of the attributes of the objects from Active Directory with LDAP/JNDI. There are two attributes member and memberOf in the Acitve Directory. I create an object for every Group. A group object has "member" attribute (values are all Group objects which are members of this group) and "memberOf "attribute (values are all Groups objects inversely contain this Group object ).
My problem first Problem is that if i create my .xmi file then all of the attribute values for "member" and "memberOf" are integer id's like "/652". But I have set the attribute "distinguishedName" a String value as identification for the Group attribute's.

My 2nd porblem is that all boolean attributes with a value "true" are hidden in the xmi.file . That means that I can't see for some object's that they have such an attribute.

Could you explain me why it's so.

Thank you in advance.

Best regards
Ugur Kocak
Re: EMF object serialization into xml [message #622867 is a reply to message #622865] Mon, 10 May 2010 06:30 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugar,

Comments below.

Ugur Kocak wrote:
> Hi Ed,
>
> my question concerns the following case: I have an ecore model with
> classes: Group, ComputerResources, PrinterResources...... The class
> Group has two recursive associations hasMember and MemberOf. Then I
> have the 2 methods getHasMember() and getMemberOf(). I extract the
> values for all of the attributes of the objects from Active Directory
> with LDAP/JNDI. There are two attributes member and memberOf in the
> Acitve Directory. I create an object for every Group. A group object
> has "member" attribute (values are all Group objects which are members
> of this group) and "memberOf "attribute (values are all Groups objects
> inversely contain this Group object ). My problem first Problem is
> that if i create my .xmi file then all of the attribute values for
> "member" and "memberOf" are integer id's like "/652". But I have set
> the attribute "distinguishedName" a String value as identification for
> the Group attribute's.
You can specialize a resource's getURIFragmentRootSegment and
getEObjectForURIFragmentRootSegment methods.
>
> My 2nd porblem is that all boolean attributes with a value "true" are
> hidden in the xmi.file .
Yes, features for which eIsSet if false don't need to be serialized.
> That means that I can't see for some object's that they have such an
> attribute.
Try OPTION_KEEP_DEFAULT_CONTENT.
>
> Could you explain me why it's so.
>
> Thank you in advance.
>
> Best regards
> Ugur Kocak
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #622868 is a reply to message #532447] Mon, 10 May 2010 10:07 Go to previous message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,

thank you for the hint's

Best regards
U.Kocak
:)
Re: EMF object serialization into xml [message #622869 is a reply to message #532447] Mon, 10 May 2010 10:35 Go to previous message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,

I have the following Code, but I can't see any attributes with boolean value "true" in my .xmi file.

public class SerializationUtility {

public void serialize() throws IOException {

ResourceSet rs = new ResourceSetImpl();

XMIResourceImpl myXMResourceImpl = new XMIResourceImpl();
myXMResourceImpl.getDefaultSaveOptions().put( XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);

// Register the base XML resource factory implementation in the local resource factory registry.
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut( "xmi", new XMIResourceFactoryImpl());
URI fileURI = URI.createFileURI( "ResourcesFZI.xmi");

Resource resource = rs.createResource( fileURI);
// add the root objects to the resource
Iterator<ComputerResources> itr = ComputerCollectionGenerator.computerResoucres.iterator();
while ( itr.hasNext()) {
ComputerResources next = itr.next();
resource.getContents().add( next);
}

Iterator<PrinterResources> itr2 = PrinterCollectionGenerator.printerResources.iterator();
while ( itr2.hasNext()) {
PrinterResources next = itr2.next();
resource.getContents().add( next);
}

Iterator<RoomResources> itr3 = RoomCollectionGenerator.roomResoucres.iterator();
while ( itr3.hasNext()) {
RoomResources next = itr3.next();
resource.getContents().add( next);
}

Collection<Group> groups = GroupCollectionGenerator.groupMap.values();
Iterator<Group> itr4 = groups.iterator();
while ( itr4.hasNext()) {
Group next = itr4.next();
resource.getContents().add( next);
}

Iterator<ExternerUser> itr5 = ExternerUserCollectionGenerator.externeUser.iterator();
while ( itr5.hasNext()) {
ExternerUser next = itr5.next();
resource.getContents().add( next);
}

Collection<Studenten> studenten = UserCollectionGenerator.studentMap.values();
Iterator<Studenten> itr6 = studenten.iterator();
while ( itr6.hasNext()) {
Studenten next = itr6.next();
resource.getContents().add( next);
}

Collection<Mitarbeiter> mitarbeiter = UserCollectionGenerator.mitarbeiterMap.values();
Iterator<Mitarbeiter> itr7 = mitarbeiter.iterator();
while ( itr7.hasNext()) {
Mitarbeiter next = itr7.next();
resource.getContents().add( next);
}

Collection<Manager> manager = UserCollectionGenerator.managerMap.values();
Iterator<Manager> itr8 = manager.iterator();
while ( itr8.hasNext()) {
Manager next = itr8.next();
resource.getContents().add( next);
}

Collection<Vorstand> vorstand = UserCollectionGenerator.vorstandMap.values();
Iterator<Vorstand> itr9 = vorstand.iterator();
while ( itr9.hasNext()) {
Vorstand next = itr9.next();
resource.getContents().add( next);
}

resource.save( null);

}
}

Maybe do you know where's the problem?
You see I have tried it with "OPTION_KEEP_DEFAULT_CONTENT" = false and true, but I can't see anything.

Best regards
U.Kocak
Re: EMF object serialization into xml [message #622876 is a reply to message #622869] Tue, 11 May 2010 11:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugar,

Did you also set an explicit default on the feature itself? Except for
primitive types, all features implicitly default to null. For
primitives, they default to the same value as the implicit Java
default. You'll need to set an explicit default if you want something
serialized with that option.


Ugur Kocak wrote:
> Hi Ed,
>
> I have the following Code, but I can't see any attributes with boolean
> value "true" in my .xmi file.
>
> public class SerializationUtility {
>
> public void serialize() throws IOException {
>
> ResourceSet rs = new ResourceSetImpl();
>
> XMIResourceImpl myXMResourceImpl = new XMIResourceImpl();
> myXMResourceImpl.getDefaultSaveOptions().put(
> XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
>
> // Register the base XML resource factory implementation in the
> local resource factory registry.
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
> "xmi", new XMIResourceFactoryImpl());
> URI fileURI = URI.createFileURI( "ResourcesFZI.xmi");
>
> Resource resource = rs.createResource( fileURI);
> // add the root objects to the resource
> Iterator<ComputerResources> itr =
> ComputerCollectionGenerator.computerResoucres.iterator();
> while ( itr.hasNext()) {
> ComputerResources next = itr.next();
> resource.getContents().add( next);
> }
>
> Iterator<PrinterResources> itr2 =
> PrinterCollectionGenerator.printerResources.iterator();
> while ( itr2.hasNext()) {
> PrinterResources next = itr2.next();
> resource.getContents().add( next);
> }
>
> Iterator<RoomResources> itr3 =
> RoomCollectionGenerator.roomResoucres.iterator();
> while ( itr3.hasNext()) {
> RoomResources next = itr3.next();
> resource.getContents().add( next);
> }
>
> Collection<Group> groups =
> GroupCollectionGenerator.groupMap.values();
> Iterator<Group> itr4 = groups.iterator();
> while ( itr4.hasNext()) {
> Group next = itr4.next();
> resource.getContents().add( next);
> }
>
> Iterator<ExternerUser> itr5 =
> ExternerUserCollectionGenerator.externeUser.iterator();
> while ( itr5.hasNext()) {
> ExternerUser next = itr5.next();
> resource.getContents().add( next);
> }
>
> Collection<Studenten> studenten =
> UserCollectionGenerator.studentMap.values();
> Iterator<Studenten> itr6 = studenten.iterator();
> while ( itr6.hasNext()) {
> Studenten next = itr6.next();
> resource.getContents().add( next);
> }
>
> Collection<Mitarbeiter> mitarbeiter =
> UserCollectionGenerator.mitarbeiterMap.values();
> Iterator<Mitarbeiter> itr7 = mitarbeiter.iterator();
> while ( itr7.hasNext()) {
> Mitarbeiter next = itr7.next();
> resource.getContents().add( next);
> }
>
> Collection<Manager> manager =
> UserCollectionGenerator.managerMap.values();
> Iterator<Manager> itr8 = manager.iterator();
> while ( itr8.hasNext()) {
> Manager next = itr8.next();
> resource.getContents().add( next);
> }
>
> Collection<Vorstand> vorstand =
> UserCollectionGenerator.vorstandMap.values();
> Iterator<Vorstand> itr9 = vorstand.iterator();
> while ( itr9.hasNext()) {
> Vorstand next = itr9.next();
> resource.getContents().add( next);
> }
>
> resource.save( null);
>
> }
> }
>
> Maybe do you know where's the problem?
> You see I have tried it with "OPTION_KEEP_DEFAULT_CONTENT" = false and
> true, but I can't see anything.
>
> Best regards
> U.Kocak


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #622881 is a reply to message #532850] Tue, 11 May 2010 13:05 Go to previous message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,
you're right I didn't set any explicit default on the feature.
How can I do this. Which methods and classes are responsible to set an explicit default on the feature.

Best regards
Ugur
Re: EMF object serialization into xml [message #622882 is a reply to message #622881] Tue, 11 May 2010 13:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugar,

You do that in the properties view in the editor by specifying either
the string false or true for the Default Value Literal.


Ugur Kocak wrote:
> Hi Ed, you're right I didn't set any explicit default on the feature.
> How can I do this. Which methods and classes are responsible to set an
> explicit default on the feature.
>
> Best regards
> Ugur


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF object serialization into xml [message #623041 is a reply to message #532889] Tue, 06 July 2010 13:21 Go to previous message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi Ed,
simple question:
do I have to type false/true in the Value field of the attribute.
I ask because there isn't any given value false/true for the Default Value Literal in the Properties view.

Best regards
Ugur
Re: EMF object serialization into xml [message #623042 is a reply to message #623041] Tue, 06 July 2010 13:53 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Ugur,

You need to enter true or false in the Properties view for the Default
Value Literal feature for the EAttribute of your model. It should be there.


Ugur Kocak wrote:
> Hi Ed,
> simple question:
> do I have to type false/true in the Value field of the attribute.
> I ask because there isn't any given value false/true for the Default
> Value Literal in the Properties view.
>
> Best regards
> Ugur


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Xtext] Scoping on objects at runtime
Next Topic:extending the ecore
Goto Forum:
  


Current Time: Tue Apr 16 22:59:41 GMT 2024

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

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

Back to the top