Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » Creating objects with multi-valued children
Creating objects with multi-valued children [message #483529] Tue, 01 September 2009 21:33 Go to next message
Doug Bercot is currently offline Doug BercotFriend
Messages: 5
Registered: July 2009
Junior Member
... sorry in advance for cross-posting, but I'm a complete noob. I also
posted this query in eclipse.modeling.mdt.

If I were to create a simple object that has a containment association
with an N..N value (as shown in the "simple" model below), is there a
proper place in which I can modify the generated code such that the
contained objects are always of the correct number?

In this example, could I modify one of the factories such that a "Car"
object is always created with 4 "Tire" child objects?

TIA


<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"; name="simple"
nsURI="http://nunjobiznezz.com/emf/simple"; nsPrefix="simple">
<eClassifiers xsi:type="ecore:EClass" name="Car">
<eStructuralFeatures xsi:type="ecore:EReference" name="tires"
lowerBound="4" upperBound="4"
eType="#//Tires" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Tires"/>
</ecore:EPackage>
Re: Creating objects with multi-valued children [message #483674 is a reply to message #483529] Wed, 02 September 2009 14:31 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090001090207010602060208
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Doug,

Please use the EMF newsgroup for basic EMF questions like this:

news://new.eclipse.org/eclipse.tools.emf

More comments below.

Doug Bercot wrote:
> .. sorry in advance for cross-posting, but I'm a complete noob. I also
> posted this query in eclipse.modeling.mdt.
>
> If I were to create a simple object that has a containment association
> with an N..N value (as shown in the "simple" model below), is there a
> proper place in which I can modify the generated code such that the
> contained objects are always of the correct number?
No.
>
> In this example, could I modify one of the factories such that a "Car"
> object is always created with 4 "Tire" child objects?
No, that's a bad idea, because when the deserializer creates a new Car
and then deserializes the Tires (it's generally a bad idea to given an
EClass a plural name), the Car will end up with 8 wheels instead of 4.
The Copier will have the same problem.

You could add an additional factory method (by hand) that creates Tires,
but don't change the default ones because the framework requires bare
uninitialized objects to be created.
>
> TIA
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"; name="simple"
> nsURI="http://nunjobiznezz.com/emf/simple"; nsPrefix="simple">
> <eClassifiers xsi:type="ecore:EClass" name="Car">
> <eStructuralFeatures xsi:type="ecore:EReference" name="tires"
> lowerBound="4" upperBound="4"
> eType="#//Tires" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Tires"/>
> </ecore:EPackage>
>
>

--------------090001090207010602060208
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Doug,<br>
<br>
Please use the EMF newsgroup for basic EMF questions like this:<br>
<blockquote><a href="news://new.eclipse.org/eclipse.tools.emf">news://new.eclipse.org/eclipse.tools.emf</a><br>
</blockquote>
More comments below.<br>
<br>
Doug Bercot wrote:
<blockquote
cite="mid:b5676bb5c31a3ca16783d165c89294b4$1@www.eclipse.org"
type="cite">.. sorry in advance for cross-posting, but I'm a complete
noob. I also posted this query in eclipse.modeling.mdt.
<br>
<br>
If I were to create a simple object that has a containment association
with an N..N value (as shown in the "simple" model below), is there a
proper place in which I can modify the generated code such that the
contained objects are always of the correct number?
<br>
</blockquote>
No.<br>
<blockquote
cite="mid:b5676bb5c31a3ca16783d165c89294b4$1@www.eclipse.org"
type="cite"><br>
In this example, could I modify one of the factories such that a "Car"
object is always created with 4 "Tire" child objects?
<br>
</blockquote>
No, that's a bad idea, because when the deserializer creates a new Car
and then deserializes the Tires (it's generally a bad idea to given an
EClass a plural name), the Car will end up with 8 wheels instead of 4.
Re: Creating objects with multi-valued children [message #617805 is a reply to message #483529] Wed, 02 September 2009 14:31 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090001090207010602060208
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Doug,

Please use the EMF newsgroup for basic EMF questions like this:

news://new.eclipse.org/eclipse.tools.emf

More comments below.

Doug Bercot wrote:
> .. sorry in advance for cross-posting, but I'm a complete noob. I also
> posted this query in eclipse.modeling.mdt.
>
> If I were to create a simple object that has a containment association
> with an N..N value (as shown in the "simple" model below), is there a
> proper place in which I can modify the generated code such that the
> contained objects are always of the correct number?
No.
>
> In this example, could I modify one of the factories such that a "Car"
> object is always created with 4 "Tire" child objects?
No, that's a bad idea, because when the deserializer creates a new Car
and then deserializes the Tires (it's generally a bad idea to given an
EClass a plural name), the Car will end up with 8 wheels instead of 4.
The Copier will have the same problem.

You could add an additional factory method (by hand) that creates Tires,
but don't change the default ones because the framework requires bare
uninitialized objects to be created.
>
> TIA
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"; name="simple"
> nsURI="http://nunjobiznezz.com/emf/simple"; nsPrefix="simple">
> <eClassifiers xsi:type="ecore:EClass" name="Car">
> <eStructuralFeatures xsi:type="ecore:EReference" name="tires"
> lowerBound="4" upperBound="4"
> eType="#//Tires" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Tires"/>
> </ecore:EPackage>
>
>

--------------090001090207010602060208
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Doug,<br>
<br>
Please use the EMF newsgroup for basic EMF questions like this:<br>
<blockquote><a href="news://new.eclipse.org/eclipse.tools.emf">news://new.eclipse.org/eclipse.tools.emf</a><br>
</blockquote>
More comments below.<br>
<br>
Doug Bercot wrote:
<blockquote
cite="mid:b5676bb5c31a3ca16783d165c89294b4$1@www.eclipse.org"
type="cite">.. sorry in advance for cross-posting, but I'm a complete
noob. I also posted this query in eclipse.modeling.mdt.
<br>
<br>
If I were to create a simple object that has a containment association
with an N..N value (as shown in the "simple" model below), is there a
proper place in which I can modify the generated code such that the
contained objects are always of the correct number?
<br>
</blockquote>
No.<br>
<blockquote
cite="mid:b5676bb5c31a3ca16783d165c89294b4$1@www.eclipse.org"
type="cite"><br>
In this example, could I modify one of the factories such that a "Car"
object is always created with 4 "Tire" child objects?
<br>
</blockquote>
No, that's a bad idea, because when the deserializer creates a new Car
and then deserializes the Tires (it's generally a bad idea to given an
EClass a plural name), the Car will end up with 8 wheels instead of 4.
Previous Topic:Creating objects with multi-valued children
Next Topic:How to make sure that a resource is written
Goto Forum:
  


Current Time: Fri Dec 19 07:18:43 GMT 2014

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

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