Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Entities extending from EObject
Entities extending from EObject [message #855845] Wed, 25 April 2012 06:36 Go to next message
borobudur Missing name is currently offline borobudur Missing nameFriend
Messages: 15
Registered: March 2010
Junior Member
Hi, I tried to extend my Entities from EObject and EObjectImpl to be able to use the xmi-export and -import mechanism:

URI uri = URI.createFileURI("tmp/dir");
Resource resource = new XMIResourceFactoryImpl().createResource(uri);
resource.getContents().add(myEntity);
try {
     resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
     System.out.println(e.getMessage());
}


What is the minimum implementation I need to do for my properties in my entity object?
Or is this only designed to use the generated objects?
Re: Entities extending from EObject [message #855865 is a reply to message #855845] Wed, 25 April 2012 07:01 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
The serialization/deserialization needs the informations found in the
EPackage's so it can't work for any arbitary class which implements EObject.

Tom

Am 25.04.12 08:36, schrieb borobudur Mising name:
> Hi, I tried to extend my Entities from EObject and EObjectImpl to be
> able to use the xmi-export and -import mechanism:
>
> URI uri = URI.createFileURI("tmp/dir");
> Resource resource = new XMIResourceFactoryImpl().createResource(uri);
> resource.getContents().add(myEntity);
> try {
> resource.save(Collections.EMPTY_MAP);
> } catch (IOException e) {
> System.out.println(e.getMessage());
> }
>
> What is the minimum implementation I need to do for my properties in my
> entity object?
> Or is this only designed to use the generated objects?
Re: Entities extending from EObject [message #855980 is a reply to message #855865] Wed, 25 April 2012 09:03 Go to previous messageGo to next message
borobudur Missing name is currently offline borobudur Missing nameFriend
Messages: 15
Registered: March 2010
Junior Member
Tom Schindl wrote on Wed, 25 April 2012 03:01
The serialization/deserialization needs the informations found in the
EPackage's so it can't work for any arbitary class which implements EObject.

Tom

Thanks Tom, what about if I would generate kind of a dummy project to get the EPackage initialized:
ModelPackageImpl.init();

Would that be enough?
What about the properties and all those flags and e-methods? Hier a generated version:
package org.domain.model.impl;

import org.domain.model.Komponente;
import org.domain.model.ModelPackage;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Komponente</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.domain.model.impl.KomponenteImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.domain.model.impl.KomponenteImpl#getIndex <em>Index</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class KomponenteImpl extends EObjectImpl implements Komponente {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getIndex() <em>Index</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIndex()
	 * @generated
	 * @ordered
	 */
	protected static final int INDEX_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getIndex() <em>Index</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIndex()
	 * @generated
	 * @ordered
	 */
	protected int index = INDEX_EDEFAULT;

	/**
	 * This is true if the Index attribute has been set.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 * @ordered
	 */
	protected boolean indexESet;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected KomponenteImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ModelPackage.Literals.KOMPONENTE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.KOMPONENTE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getIndex() {
		return index;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIndex(int newIndex) {
		int oldIndex = index;
		index = newIndex;
		boolean oldIndexESet = indexESet;
		indexESet = true;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.KOMPONENTE__INDEX, oldIndex, index, !oldIndexESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void unsetIndex() {
		int oldIndex = index;
		boolean oldIndexESet = indexESet;
		index = INDEX_EDEFAULT;
		indexESet = false;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.UNSET, ModelPackage.KOMPONENTE__INDEX, oldIndex, INDEX_EDEFAULT, oldIndexESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isSetIndex() {
		return indexESet;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ModelPackage.KOMPONENTE__NAME:
				return getName();
			case ModelPackage.KOMPONENTE__INDEX:
				return new Integer(getIndex());
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ModelPackage.KOMPONENTE__NAME:
				setName((String)newValue);
				return;
			case ModelPackage.KOMPONENTE__INDEX:
				setIndex(((Integer)newValue).intValue());
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ModelPackage.KOMPONENTE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case ModelPackage.KOMPONENTE__INDEX:
				unsetIndex();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ModelPackage.KOMPONENTE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case ModelPackage.KOMPONENTE__INDEX:
				return isSetIndex();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", index: ");
		if (indexESet) result.append(index); else result.append("<unset>");
		result.append(')');
		return result.toString();
	}

} //KomponenteImpl

[Updated on: Wed, 25 April 2012 09:10]

Report message to a moderator

Re: Entities extending from EObject [message #856012 is a reply to message #855980] Wed, 25 April 2012 09:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
You need a model and to end up with something consistent, you'll want to
use instances of that generated model. I.e, it's important that
EObject.eClass() returns the actual class, and that you can call
EObject.eGet() for each of the EClass.getEAllStructuralFeatures(). A
generated model will do that; it seems pointless to try to write
something like that by hand.


On 25/04/2012 11:03 AM, borobudur Mising name wrote:
> Tom Schindl wrote on Wed, 25 April 2012 03:01
>> The serialization/deserialization needs the informations found in the
>> EPackage's so it can't work for any arbitary class which implements
>> EObject.
>>
>> Tom
>
> Thanks Tom, what about if I would generate kind of a dummy project to
> get the EPackage initialized:
> ModelPackageImpl.init();
> Would that be enough?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Entities extending from EObject [message #857727 is a reply to message #856012] Thu, 26 April 2012 20:12 Go to previous message
borobudur Missing name is currently offline borobudur Missing nameFriend
Messages: 15
Registered: March 2010
Junior Member
Ed Merks wrote on Wed, 25 April 2012 05:39
You need a model and to end up with something consistent, you'll want to
use instances of that generated model. I.e, it's important that
EObject.eClass() returns the actual class, and that you can call
EObject.eGet() for each of the EClass.getEAllStructuralFeatures(). A
generated model will do that; it seems pointless to try to write
something like that by hand.

Thanks, yes it's a no go
Previous Topic:Transactional command stack non-redoable with command or wrapped operation trigger
Next Topic:ResourceSet default save options?
Goto Forum:
  


Current Time: Fri Apr 19 20:47:09 GMT 2024

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

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

Back to the top