Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EObject EGet Problem(Returns NULL based on the cardinality of the EReference object)
EObject EGet Problem [message #637620] Mon, 08 November 2010 01:06 Go to next message
Arun  is currently offline Arun Friend
Messages: 16
Registered: October 2010
Junior Member
Dear All,

I have a very small problem. Hopefully someone can help me out.

Consider the following ecore model (Kindly use the ecore model editor to view the model). The package consists of 4 classes, BookStore, Book, Editor and Publisher.

<?xml version="1.0" encoding="ASCII"?>
<ecore:EPackage 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="BookStorePackage"
    nsURI="http:///com.ibm.dynamic.example.bookstore.ecore" nsPrefix="bookStore">
  <eClassifiers xsi:type="ecore:EClass" name="BookStore">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="owner" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        defaultValueLiteral="Arun Prakash"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="location" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        defaultValueLiteral="Berlin"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Book" upperBound="-1" eType="#//Book"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Book">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        defaultValueLiteral="God of Small Things"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="isbn" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
        defaultValueLiteral="1234"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Editor" upperBound="-1"
        eType="#//Editor" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Publisher" upperBound="-1"
        eType="#//Publisher" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Editor">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        defaultValueLiteral="Ewa Slomska"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="place" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        defaultValueLiteral="Gdynia"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Publisher">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        defaultValueLiteral="Slomska Publications"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="place" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        defaultValueLiteral="Gdynia"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="country" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
</ecore:EPackage>



Bookstore has 2 attributes and 1 reference (refers to Book Eclass)
Book has 2 attributes and 2 references (refers to Editor and Publisher)
Editor and Publisher have 2 and 3 attributes respectively.

All the references have the following properties (0..*), i.e.

Lower Bound = 0
Upper Bound = -1

Now for this ecore model, I dynamically create model objects by starting with the root model class, namely Bookstore class, in a recursive manner, as shown below


	private void modelHandler()
	{
		// Get all EClasses in the package.
		EList<EObject> eObjects = ePackage.eContents();
		int numEObjects = eObjects.size();

                // I somehow use this function to get the root model class
		EClass rootModelEClass = getRootModelEClass(numEObjects, eObjects); 

		// Created RootModel EClass Object.
		EObject rootModelEObject = eFactory.create(rootModelEClass);

		filler(rootModelEClass, rootModelEObject);

		saveAsGMEModel(rootModelEObject);

	}

	private void filler(EClass rootModelEClass, EObject rootModelEObject)
	{
		log.debug("rootModelEClass :" + rootModelEClass.getName());

		// Get all the EReferences of the EClass
		EList<EReference> eReferences = rootModelEClass.getEReferences();

		int numEReferences = eReferences.size();

		log.debug("numEReferences :" + numEReferences);

		for (int j = 0; j < numEReferences; j++)
		{
			EReference eReference = eReferences.get(j);
			log.debug("eReference Name :" + eReference.getName());
			log.debug("eReference Type :" + eReference.getEType().toString());
			EClass eClass = (EClass) eReference.getEType();
			EObject eObject = eFactory.create(eClass);
			filler(eClass, eObject);

			if (rootModelEObject.eGet(eReference) == null)
			{
				System.out.println("something is wrong here");
			}
			else
			{

				((List) rootModelEObject.eGet(eReference)).add(eObject);
			}
		}
	}



The above code works perfectly fine for the above Ecore model. The check if (rootModelEObject.eGet(eReference) == null) returns false.

Now in the case of the same model, with a minor modification, namely with respect to the properties of the references .. i.e., the references of the Book EClass, namely Editor: Editor and Publisher: Publisher have their cardinality set to 1, i.e.,

Lower Bound = 1
Upper Bound = 1


<?xml version="1.0" encoding="ASCII"?>
<ecore:EPackage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="BookStorePackage" nsURI="http:///com.ibm.dynamic.example.bookstore.ecore" nsPrefix="bookStore">
  <eClassifiers xsi:type="ecore:EClass" name="BookStore">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="owner" defaultValueLiteral="Arun Prakash">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="location" defaultValueLiteral="Berlin">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Book" upperBound="-1" eType="//Book" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Book">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" defaultValueLiteral="God of Small Things">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="isbn" defaultValueLiteral="1234">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Editor" lowerBound="1" eType="//Editor" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Publisher" lowerBound="1" eType="//Publisher" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Editor">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" defaultValueLiteral="Ewa Slomska">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="place" defaultValueLiteral="Gdynia">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eStructuralFeatures>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Publisher">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" defaultValueLiteral="Slomska Publications">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="place" defaultValueLiteral="Gdynia">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="country">
      <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eStructuralFeatures>
  </eClassifiers>
</ecore:EPackage>


In this case, the check if (rootModelEObject.eGet(eReference) == null) returns true.

I am baffled as to why this happens? For the moment as a workaround I have kept the cardinalities to (0..*) in my model. However, this is not the correct model. The correct model requires the cardinalities to be set to (1..1).

Hopefully someone could answer my problem.

Thanks & Regards
Arun
Re: EObject EGet Problem [message #637675 is a reply to message #637620] Mon, 08 November 2010 09:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30554
Registered: July 2009
Senior Member
Arun,

Comments below.


Arun wrote:
> Dear All,
>
> I have a very small problem. Hopefully someone can help me out.
> Consider the following ecore model (Kindly use the ecore model editor
> to view the model). The package consists of 4 classes, BookStore,
> Book, Editor and Publisher.
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <ecore:EPackage 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="BookStorePackage"
> nsURI="http:///com.ibm.dynamic.example.bookstore.ecore"
> nsPrefix="bookStore">
> <eClassifiers xsi:type="ecore:EClass" name="BookStore">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="owner"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Arun Prakash"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="location"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Berlin"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Book"
> upperBound="-1" eType="#//Book"
> containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Book">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="God of Small Things"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="isbn"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
> defaultValueLiteral="1234"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Editor"
> upperBound="-1"
> eType="#//Editor" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Publisher"
> upperBound="-1"
> eType="#//Publisher" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Editor">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Ewa Slomska"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="place"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Gdynia"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Publisher">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Slomska Publications"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="place"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Gdynia"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="country"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
>
> Bookstore has 2 attributes and 1 reference (refers to Book Eclass)
> Book has 2 attributes and 2 references (refers to Editor and Publisher)
> Editor and Publisher have 2 and 3 attributes respectively.
>
> All the references have the following properties (0..*), i.e.
>
> Lower Bound = 0
> Upper Bound = -1
>
> Now for this ecore model, I dynamically create model objects by
> starting with the root model class, namely Bookstore class, in a
> recursive manner, as shown below
>
>
>
> private void modelHandler()
> {
> // Get all EClasses in the package.
> EList<EObject> eObjects = ePackage.eContents();
> int numEObjects = eObjects.size();
This isn't just the contained classes, but in fact all contained
objects, including annotations and subpackages.
>
> // I somehow use this function to get the root model class
> EClass rootModelEClass = getRootModelEClass(numEObjects,
> eObjects);
> // Created RootModel EClass Object.
> EObject rootModelEObject = eFactory.create(rootModelEClass);
>
> filler(rootModelEClass, rootModelEObject);
>
> saveAsGMEModel(rootModelEObject);
>
> }
>
> private void filler(EClass rootModelEClass, EObject rootModelEObject)
> {
> log.debug("rootModelEClass :" + rootModelEClass.getName());
>
> // Get all the EReferences of the EClass
> EList<EReference> eReferences = rootModelEClass.getEReferences();
>
> int numEReferences = eReferences.size();
>
> log.debug("numEReferences :" + numEReferences);
>
> for (int j = 0; j < numEReferences; j++)
> {
> EReference eReference = eReferences.get(j);
Why not use an iterator?
> log.debug("eReference Name :" + eReference.getName());
> log.debug("eReference Type :" +
> eReference.getEType().toString());
> EClass eClass = (EClass) eReference.getEType();
> EObject eObject = eFactory.create(eClass);
> filler(eClass, eObject);
>
> if (rootModelEObject.eGet(eReference) == null)
> {
> System.out.println("something is wrong here");
You should be expecting this to be null for single valued features. You
should be using eSet to set single valued features.
> }
> else
> {
>
> ((List) rootModelEObject.eGet(eReference)).add(eObject);
> }
> }
> }
>
>
>
> The above code works perfectly fine for the above Ecore model. The
> check if (rootModelEObject.eGet(eReference) == null) returns false.
>
> Now in the case of the same model, with a minor modification, namely
> with respect to the properties of the references .. i.e., the
> references of the Book EClass, namely Editor: Editor and Publisher:
> Publisher have their cardinality set to 1, i.e.,
>
> Lower Bound = 1
> Upper Bound = 1
>
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <ecore:EPackage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> name="BookStorePackage"
> nsURI="http:///com.ibm.dynamic.example.bookstore.ecore"
> nsPrefix="bookStore">
> <eClassifiers xsi:type="ecore:EClass" name="BookStore">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="owner"
> defaultValueLiteral="Arun Prakash">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="location"
> defaultValueLiteral="Berlin">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Book"
> upperBound="-1" eType="//Book" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Book">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> defaultValueLiteral="God of Small Things">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="isbn"
> defaultValueLiteral="1234">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Editor"
> lowerBound="1" eType="//Editor" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Publisher"
> lowerBound="1" eType="//Publisher" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Editor">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> defaultValueLiteral="Ewa Slomska">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="place"
> defaultValueLiteral="Gdynia">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Publisher">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> defaultValueLiteral="Slomska Publications">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="place"
> defaultValueLiteral="Gdynia">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="country">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> </eClassifiers>
> </ecore:EPackage>
>
>
> In this case, the check if (rootModelEObject.eGet(eReference) == null)
> returns true.
>
> I am baffled as to why this happens?
A single valued feature without a value will clearly return null. What
else could it possibly return.
> For the moment as a workaround I have kept the cardinalities to (0..*)
> in my model.
A multi-valued feature will always return a list; it will be empty until
you put something in it.
> However, this is not the correct model. The correct model requires the
> cardinalities to be set to (1..1).
>
> Hopefully someone could answer my problem.
Did you use the debugger to step through the eGet calls to see what's
happening? That should make it pretty clear.
>
> Thanks & Regards
> Arun
Re: EObject EGet Problem [message #637916 is a reply to message #637675] Tue, 09 November 2010 10:49 Go to previous messageGo to next message
Arun  is currently offline Arun Friend
Messages: 16
Registered: October 2010
Junior Member
Ed,

Thanks for the quick reply. I did use the debugger ... but I didnt know how single value features are handled . Nevertheless, I will read through your response in detail once more and hopefully will be able to fix the issue. Thanks again.

On a different note, I was wondering how to refer to a DataType located in a different resource in a DataType. Let me explain. As I am new to ecore, I dont even know the term used for defining this. is it cross-document references? Anyway, consider the following original scenario/model.

<?xml version="1.0" encoding="ASCII"?>
<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="BookStorePackage"
    nsURI="http:///com.ibm.dynamic.example.bookstore.ecore" nsPrefix="bookStore">
  <eClassifiers xsi:type="ecore:EClass" name="BookStore">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="owner" eType="#//CustomString"
        defaultValueLiteral="Arun Prakash"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="location" eType="#//CustomString"
        defaultValueLiteral="Berlin"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Book" upperBound="-1" eType="#//Book"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Book">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="#//CustomString"
        defaultValueLiteral="God of Small Things"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="isbn" eType="#//CustomInt"
        defaultValueLiteral="1234"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Editor" upperBound="-1"
        eType="#//Editor" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="Publisher" upperBound="-1"
        eType="#//Publisher" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="Status" eType="ecore:EEnum Util.ecore#//Status"
        defaultValueLiteral="review"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Editor">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="#//CustomString"
        defaultValueLiteral="Ewa Slomska"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="place" eType="#//CustomString"
        defaultValueLiteral="Gdynia"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Publisher">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="#//CustomString"
        defaultValueLiteral="Slomska Publications"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="place" eType="#//CustomString"
        defaultValueLiteral="Gdynia"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="country" eType="#//CustomString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EDataType" name="CustomInt" instanceClassName="int"/>
  <eClassifiers xsi:type="ecore:EDataType" name="CustomString" instanceClassName="java.lang.String"/>
  <eClassifiers xsi:type="ecore:EEnum" name="CustomStatus"/>
</ecore:EPackage>


http://img210.imageshack.us/img210/7322/bookstorestatus.png

As you can see, I refer to the Status DataType located in the Util.ecore resource, by simply loading the resource and refering to the correct DataType in the EType property of the Status:Book DataType.

Now what I want to achieve is something like this...

http://img600.imageshack.us/img600/7516/bookstorecustomstatus.png

where, I have a custom datatype defined as CustomStatus. I want this CustomStatus to refer (or what is correct term here) to the Status DataType of the Util.ecore resource. Hope you can understand me.

How do one achieve this, i.e., what should be the value of Instance Type Name property of the CustomStatus datatype? For my CustomString, I used the Instance Type Name as java.lang.String and it works fine. Its unclear to me how to achieve the same result for a user defined DataType.

Finally, it would be great if you could point me to some text that also explains how to achieve this programatically?

Thanks again for your previous reply.

Regards
Arun
Re: EObject EGet Problem [message #638268 is a reply to message #637916] Wed, 10 November 2010 14:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30554
Registered: July 2009
Senior Member
Arun,

Comments below.

Arun wrote:
> Ed,
>
> Thanks for the quick reply. I did use the debugger ... but I didnt
> know how single value features are handled .
It should be clear that the generated getter is called and it returns
the value of a field which is initially null.
> Nevertheless, I will read through your response in detail once more
> and hopefully will be able to fix the issue. Thanks again.
>
> On a different note, I was wondering how to refer to a DataType
> located in a different resource in a DataType. Let me explain. As I am
> new to ecore, I dont even know the term used for defining this. is it
> cross-document references? Anyway, consider the following original
> scenario/model.
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <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="BookStorePackage"
> nsURI="http:///com.ibm.dynamic.example.bookstore.ecore"
> nsPrefix="bookStore">
> <eClassifiers xsi:type="ecore:EClass" name="BookStore">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="owner"
> eType="#//CustomString"
> defaultValueLiteral="Arun Prakash"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="location"
> eType="#//CustomString"
> defaultValueLiteral="Berlin"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Book"
> upperBound="-1" eType="#//Book"
> containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Book">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="#//CustomString"
> defaultValueLiteral="God of Small Things"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="isbn"
> eType="#//CustomInt"
> defaultValueLiteral="1234"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Editor"
> upperBound="-1"
> eType="#//Editor" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="Publisher"
> upperBound="-1"
> eType="#//Publisher" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="Status"
> eType="ecore:EEnum Util.ecore#//Status"
> defaultValueLiteral="review"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Editor">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="#//CustomString"
> defaultValueLiteral="Ewa Slomska"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="place"
> eType="#//CustomString"
> defaultValueLiteral="Gdynia"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Publisher">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="#//CustomString"
> defaultValueLiteral="Slomska Publications"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="place"
> eType="#//CustomString"
> defaultValueLiteral="Gdynia"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="country"
> eType="#//CustomString"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EDataType" name="CustomInt"
> instanceClassName="int"/>
> <eClassifiers xsi:type="ecore:EDataType" name="CustomString"
> instanceClassName="java.lang.String"/>
> <eClassifiers xsi:type="ecore:EEnum" name="CustomStatus"/>
> </ecore:EPackage>
>
>
>
>
> As you can see, I refer to the Status DataType located in the
> Util.ecore resource, by simply loading the resource and refering to
> the correct DataType in the EType property of the Status:Book DataType.
>
> Now what I want to achieve is something like this...
>
>
>
> where, I have a custom datatype defined as CustomStatus. I want this
> CustomStatus to refer (or what is correct term here) to the Status
> DataType of the Util.ecore resource. Hope you can understand me.
Data types don't work that way. Define a new EDataType that does what
you want.
>
> How do one achieve this, i.e., what should be the value of Instance
> Type Name property of the CustomStatus datatype? For my CustomString,
> I used the Instance Type Name as java.lang.String and it works fine.
> Its unclear to me how to achieve the same result for a user defined
> DataType.
It should have the same instance type name as the generated user defined
data type. (Only EEnums actually generate a new result in the Java code,
so that's the only case where you have to set the name that's generated.)
>
> Finally, it would be great if you could point me to some text that
> also explains how to achieve this programatically?
The EMF book will have to suffice.
>
> Thanks again for your previous reply.
>
> Regards
> Arun
Re: EObject EGet Problem [message #638563 is a reply to message #637620] Thu, 11 November 2010 16:07 Go to previous message
Arun  is currently offline Arun Friend
Messages: 16
Registered: October 2010
Junior Member
Thanks Ed,

I fixed it.
Previous Topic:How to avoid childAction in TreeView?
Next Topic:EMF Generic Search
Goto Forum:
  


Current Time: Tue Oct 22 08:44:57 GMT 2019

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

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

Back to the top