diff options
18 files changed, 378 insertions, 75 deletions
diff --git a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Book.java b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Book.java index 8effd9f6d..c8e73c640 100644 --- a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Book.java +++ b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Book.java @@ -2,11 +2,10 @@ * <copyright> * </copyright> * - * $Id: Book.java,v 1.1 2006/07/11 16:57:12 mtaal Exp $ + * $Id: Book.java,v 1.2 2006/08/25 23:04:14 mtaal Exp $ */ package org.eclipse.emf.teneo.samples.emf.sample.library; -import org.eclipse.emf.ecore.EObject; /** * <!-- begin-user-doc --> @@ -25,9 +24,10 @@ import org.eclipse.emf.ecore.EObject; * * @see org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage#getBook() * @model extendedMetaData="name='Book' kind='elementOnly'" + * @extends SerializableEObject * @generated */ -public interface Book extends EObject { +public interface Book extends SerializableEObject { /** * Returns the value of the '<em><b>Title</b></em>' attribute. * <!-- begin-user-doc --> diff --git a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/BookCategory.java b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/BookCategory.java index c902f5eb9..c2bdcc885 100644 --- a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/BookCategory.java +++ b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/BookCategory.java @@ -2,10 +2,16 @@ * <copyright> * </copyright> * - * $Id: BookCategory.java,v 1.1 2006/07/11 16:57:12 mtaal Exp $ + * $Id: BookCategory.java,v 1.2 2006/08/25 23:04:14 mtaal Exp $ */ package org.eclipse.emf.teneo.samples.emf.sample.library; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.ObjectStreamException; +import java.io.Serializable; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -13,21 +19,19 @@ import java.util.List; import org.eclipse.emf.common.util.AbstractEnumerator; /** - * <!-- begin-user-doc --> - * A representation of the literals of the enumeration '<em><b>Book Category</b></em>', - * and utility methods for working with them. - * <!-- end-user-doc --> + * <!-- begin-user-doc --> A representation of the literals of the enumeration '<em><b>Book Category</b></em>', and + * utility methods for working with them. <!-- end-user-doc --> * @see org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage#getBookCategory() * @model * @generated */ -public final class BookCategory extends AbstractEnumerator { +public final class BookCategory extends AbstractEnumerator implements Serializable { /** * The '<em><b>Mystery</b></em>' literal value. * <!-- begin-user-doc --> * <p> - * If the meaning of '<em><b>Mystery</b></em>' literal object isn't clear, - * there really should be more of a description here... + * If the meaning of '<em><b>Mystery</b></em>' literal object isn't clear, there really should be more of a + * description here... * </p> * <!-- end-user-doc --> * @see #MYSTERY_LITERAL @@ -41,8 +45,8 @@ public final class BookCategory extends AbstractEnumerator { * The '<em><b>Science Fiction</b></em>' literal value. * <!-- begin-user-doc --> * <p> - * If the meaning of '<em><b>Science Fiction</b></em>' literal object isn't clear, - * there really should be more of a description here... + * If the meaning of '<em><b>Science Fiction</b></em>' literal object isn't clear, there really should be more + * of a description here... * </p> * <!-- end-user-doc --> * @see #SCIENCE_FICTION_LITERAL @@ -56,8 +60,8 @@ public final class BookCategory extends AbstractEnumerator { * The '<em><b>Biography</b></em>' literal value. * <!-- begin-user-doc --> * <p> - * If the meaning of '<em><b>Biography</b></em>' literal object isn't clear, - * there really should be more of a description here... + * If the meaning of '<em><b>Biography</b></em>' literal object isn't clear, there really should be more of a + * description here... * </p> * <!-- end-user-doc --> * @see #BIOGRAPHY_LITERAL @@ -69,8 +73,7 @@ public final class BookCategory extends AbstractEnumerator { /** * The '<em><b>Mystery</b></em>' literal object. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> * @see #MYSTERY * @generated * @ordered @@ -79,8 +82,7 @@ public final class BookCategory extends AbstractEnumerator { /** * The '<em><b>Science Fiction</b></em>' literal object. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> * @see #SCIENCE_FICTION * @generated * @ordered @@ -89,8 +91,7 @@ public final class BookCategory extends AbstractEnumerator { /** * The '<em><b>Biography</b></em>' literal object. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> * @see #BIOGRAPHY * @generated * @ordered @@ -98,9 +99,9 @@ public final class BookCategory extends AbstractEnumerator { public static final BookCategory BIOGRAPHY_LITERAL = new BookCategory(BIOGRAPHY, "Biography", "Biography"); /** - * An array of all the '<em><b>Book Category</b></em>' enumerators. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * An array of all the '<em><b>Book Category</b></em>' enumerators. <!-- begin-user-doc --> <!-- end-user-doc + * --> + * * @generated */ private static final BookCategory[] VALUES_ARRAY = @@ -112,16 +113,16 @@ public final class BookCategory extends AbstractEnumerator { /** * A public read-only list of all the '<em><b>Book Category</b></em>' enumerators. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- + * end-user-doc --> * @generated */ public static final List VALUES = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY)); /** * Returns the '<em><b>Book Category</b></em>' literal with the specified literal value. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc + * --> <!-- end-user-doc --> * @generated */ public static BookCategory get(String literal) { @@ -136,8 +137,8 @@ public final class BookCategory extends AbstractEnumerator { /** * Returns the '<em><b>Book Category</b></em>' literal with the specified name. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- + * end-user-doc --> * @generated */ public static BookCategory getByName(String name) { @@ -152,8 +153,8 @@ public final class BookCategory extends AbstractEnumerator { /** * Returns the '<em><b>Book Category</b></em>' literal with the specified integer value. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc + * --> <!-- end-user-doc --> * @generated */ public static BookCategory get(int value) { @@ -167,12 +168,39 @@ public final class BookCategory extends AbstractEnumerator { /** * Only this class can construct instances. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> * @generated */ private BookCategory(int value, String name, String literal) { super(value, name, literal); } -} //BookCategory + /** Translates the enumerate into a serializable object */ + public static class AbstractEnumeratorExternalizable implements Externalizable { + protected AbstractEnumerator enumerate; + + public AbstractEnumeratorExternalizable() { + } + + public AbstractEnumeratorExternalizable(AbstractEnumerator enumerate) { + this.enumerate = enumerate; + } + + public void writeExternal(ObjectOutput objectOutput) throws IOException { + objectOutput.writeUTF(enumerate.getName()); + } + + public void readExternal(ObjectInput objectInput) throws IOException, ClassNotFoundException { + String name = objectInput.readUTF(); + enumerate = get(name); + } + + protected Object readResolve() { + return enumerate; + } + } + + Object writeReplace() throws ObjectStreamException { + return new AbstractEnumeratorExternalizable(this); + } +} // BookCategory diff --git a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Library.java b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Library.java index dcaa2f184..857f7155f 100644 --- a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Library.java +++ b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Library.java @@ -2,14 +2,12 @@ * <copyright> * </copyright> * - * $Id: Library.java,v 1.1 2006/07/11 16:57:12 mtaal Exp $ + * $Id: Library.java,v 1.2 2006/08/25 23:04:14 mtaal Exp $ */ package org.eclipse.emf.teneo.samples.emf.sample.library; import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; - /** * <!-- begin-user-doc --> * A representation of the model object '<em><b>Library</b></em>'. @@ -26,9 +24,10 @@ import org.eclipse.emf.ecore.EObject; * * @see org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage#getLibrary() * @model extendedMetaData="name='Library' kind='elementOnly'" + * @extends SerializableEObject * @generated */ -public interface Library extends EObject { +public interface Library extends SerializableEObject { /** * Returns the value of the '<em><b>Name</b></em>' attribute. * <!-- begin-user-doc --> @@ -67,7 +66,7 @@ public interface Library extends EObject { * <!-- end-user-doc --> * @return the value of the '<em>Writers</em>' containment reference list. * @see org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage#getLibrary_Writers() - * @model type="org.eclipse.emf.teneo.samples.emf.sample.library.Writer" containment="true" resolveProxies="false" + * @model type="org.eclipse.emf.teneo.samples.emf.sample.library.Writer" containment="true" * extendedMetaData="kind='element' name='writers'" * @generated */ @@ -84,7 +83,7 @@ public interface Library extends EObject { * <!-- end-user-doc --> * @return the value of the '<em>Books</em>' containment reference list. * @see org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage#getLibrary_Books() - * @model type="org.eclipse.emf.teneo.samples.emf.sample.library.Book" containment="true" resolveProxies="false" + * @model type="org.eclipse.emf.teneo.samples.emf.sample.library.Book" containment="true" * extendedMetaData="kind='element' name='books'" * @generated */ diff --git a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/SerializableEObject.java b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/SerializableEObject.java new file mode 100644 index 000000000..b947b9665 --- /dev/null +++ b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/SerializableEObject.java @@ -0,0 +1,17 @@ +/** + * <copyright> + * </copyright> + * + * $Id: SerializableEObject.java,v 1.1 2006/08/25 23:04:14 mtaal Exp $ + */ +package org.eclipse.emf.teneo.samples.emf.sample.library; + +import java.io.Serializable; + +import org.eclipse.emf.ecore.EObject; + +/** + * Combines EObject and Serilizable + */ +public interface SerializableEObject extends EObject, Serializable { +} diff --git a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Writer.java b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Writer.java index d150c2d7e..225819e5c 100644 --- a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Writer.java +++ b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/Writer.java @@ -2,14 +2,12 @@ * <copyright> * </copyright> * - * $Id: Writer.java,v 1.1 2006/07/11 16:57:12 mtaal Exp $ + * $Id: Writer.java,v 1.2 2006/08/25 23:04:14 mtaal Exp $ */ package org.eclipse.emf.teneo.samples.emf.sample.library; import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; - /** * <!-- begin-user-doc --> * A representation of the model object '<em><b>Writer</b></em>'. @@ -25,9 +23,10 @@ import org.eclipse.emf.ecore.EObject; * * @see org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage#getWriter() * @model extendedMetaData="name='Writer' kind='elementOnly'" + * @extends SerializableEObject * @generated */ -public interface Writer extends EObject { +public interface Writer extends SerializableEObject { /** * Returns the value of the '<em><b>Name</b></em>' attribute. * <!-- begin-user-doc --> diff --git a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/impl/BookImpl.java b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/impl/BookImpl.java index 2fafb45c2..bf29f1d86 100644 --- a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/impl/BookImpl.java +++ b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/impl/BookImpl.java @@ -2,13 +2,14 @@ * <copyright> * </copyright> * - * $Id: BookImpl.java,v 1.2 2006/07/22 13:01:18 mtaal Exp $ + * $Id: BookImpl.java,v 1.3 2006/08/25 23:04:14 mtaal Exp $ */ package org.eclipse.emf.teneo.samples.emf.sample.library.impl; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.NotificationChain; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.impl.ENotificationImpl; import org.eclipse.emf.ecore.impl.EObjectImpl; @@ -259,7 +260,7 @@ public class BookImpl extends EObjectImpl implements Book { * @generated */ public Writer getAuthor() { - if (author != null && author.eIsProxy()) { + if (author != null && ((EObject)author).eIsProxy()) { InternalEObject oldAuthor = (InternalEObject)author; author = (Writer)eResolveProxy(oldAuthor); if (author != oldAuthor) { diff --git a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/impl/LibraryFactoryImpl.java b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/impl/LibraryFactoryImpl.java index 68d88694b..2e584c1e0 100644 --- a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/impl/LibraryFactoryImpl.java +++ b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/impl/LibraryFactoryImpl.java @@ -2,7 +2,7 @@ * <copyright> * </copyright> * - * $Id: LibraryFactoryImpl.java,v 1.2 2006/07/22 13:01:18 mtaal Exp $ + * $Id: LibraryFactoryImpl.java,v 1.3 2006/08/25 23:04:14 mtaal Exp $ */ package org.eclipse.emf.teneo.samples.emf.sample.library.impl; @@ -63,9 +63,9 @@ public class LibraryFactoryImpl extends EFactoryImpl implements LibraryFactory { */ public EObject create(EClass eClass) { switch (eClass.getClassifierID()) { - case LibraryPackage.BOOK: return createBook(); - case LibraryPackage.LIBRARY: return createLibrary(); - case LibraryPackage.WRITER: return createWriter(); + case LibraryPackage.BOOK: return (EObject)createBook(); + case LibraryPackage.LIBRARY: return (EObject)createLibrary(); + case LibraryPackage.WRITER: return (EObject)createWriter(); default: throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); } diff --git a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/model/library.genmodel b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/model/library.genmodel index 2235705a1..e6216b5cf 100644 --- a/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/model/library.genmodel +++ b/examples/org.eclipse.emf.teneo.samples/src/org/eclipse/emf/teneo/samples/emf/sample/library/model/library.genmodel @@ -5,10 +5,11 @@ editDirectory="/Scratch/src" editorDirectory="/Scratch/src" modelPluginID="Scratch" runtimeJar="true" modelName="Library" editPluginClass="org.eclipse.emf.teneo.samples.emf.library.provider.LibraryEditPlugin" editorPluginClass="org.eclipse.emf.teneo.test.store.library.presentation.LibraryEditorPlugin" - importerID="org.eclipse.xsd.ecore.importer"> + rootExtendsInterface="org.eclipse.emf.teneo.samples.emf.sample.library.SerializableEObject" + rootImplementsInterface="" importerID="org.eclipse.xsd.ecore.importer"> <foreignModel>library.xsd</foreignModel> - <genPackages prefix="Library" basePackage="org.eclipse.emf.teneo.samples.emf.sample" resource="XML" - disposableProviderFactory="true" ecorePackage="library.ecore#/"> + <genPackages prefix="Library" basePackage="org.eclipse.emf.teneo.samples.emf.sample" + resource="XML" disposableProviderFactory="true" ecorePackage="library.ecore#/"> <genEnums ecoreEnum="library.ecore#//BookCategory"> <genEnumLiterals ecoreEnumLiteral="library.ecore#//BookCategory/Mystery"/> <genEnumLiterals ecoreEnumLiteral="library.ecore#//BookCategory/ScienceFiction"/> diff --git a/plugins/org.eclipse.emf.teneo.hibernate/src/org/eclipse/emf/teneo/hibernate/mapping/elist/HibernateFeatureMapEntry.java b/plugins/org.eclipse.emf.teneo.hibernate/src/org/eclipse/emf/teneo/hibernate/mapping/elist/HibernateFeatureMapEntry.java index 092d8283a..ae1f6fd44 100644 --- a/plugins/org.eclipse.emf.teneo.hibernate/src/org/eclipse/emf/teneo/hibernate/mapping/elist/HibernateFeatureMapEntry.java +++ b/plugins/org.eclipse.emf.teneo.hibernate/src/org/eclipse/emf/teneo/hibernate/mapping/elist/HibernateFeatureMapEntry.java @@ -11,11 +11,13 @@ * Martin Taal * </copyright> * - * $Id: HibernateFeatureMapEntry.java,v 1.3 2006/08/21 13:27:29 mtaal Exp $ + * $Id: HibernateFeatureMapEntry.java,v 1.4 2006/08/25 23:04:12 mtaal Exp $ */ package org.eclipse.emf.teneo.hibernate.mapping.elist; +import java.io.IOException; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -39,10 +41,10 @@ import org.eclipse.emf.teneo.util.StoreUtil; * member. * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ -public class HibernateFeatureMapEntry implements FeatureMap.Entry.Internal { +public class HibernateFeatureMapEntry implements FeatureMap.Entry.Internal, Serializable { /** * Gets an 'normal' FeatureMap.Entry and if it is not a FeatureMapEntry replaces it with a specific implementation. @@ -94,6 +96,9 @@ public class HibernateFeatureMapEntry implements FeatureMap.Entry.Internal { /** The structural feature which defines which element this is */ private EStructuralFeature eStructuralFeature; + /** To store the efeature during serialization */ + private String eFeaturePath; + /** * The featuremap to which we are connected. Is used to determine if entries have been added to another featuremap. * This happens in copy actions. @@ -131,6 +136,19 @@ public class HibernateFeatureMapEntry implements FeatureMap.Entry.Internal { return owningMap == fm; // object equality! } + /** Takes care of serializing the efeature */ + private void writeObject(java.io.ObjectOutputStream out) throws IOException { + eFeaturePath = StoreUtil.structuralFeatureToString(eStructuralFeature); + eStructuralFeature = null; + out.defaultWriteObject(); + } + + /** Takes care of deserializing the efeature */ + private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + eStructuralFeature = StoreUtil.stringToStructureFeature(eFeaturePath); + } + /** Set the value from a previous entry */ public void setEntry(FeatureMap.Entry entry, FeatureMap.Internal owningMap) { eStructuralFeature = entry.getEStructuralFeature(); @@ -318,10 +336,13 @@ public class HibernateFeatureMapEntry implements FeatureMap.Entry.Internal { } /** Class to store feature value pairs together with their validator */ - private class FeatureValue { + private class FeatureValue implements Serializable { /** The feature */ - protected final EStructuralFeature feature; + protected EStructuralFeature feature; + + /** The featurepath, is used during serialization */ + private String featurePath; /** Its value (can be null) */ protected final Object value; @@ -332,6 +353,21 @@ public class HibernateFeatureMapEntry implements FeatureMap.Entry.Internal { this.value = value; } + /** Takes care of serializing the efeature */ + private void writeObject(java.io.ObjectOutputStream out) throws IOException { + featurePath = StoreUtil.structuralFeatureToString(feature); + feature = null; + out.defaultWriteObject(); + } + + /** Takes care of deserializing the efeature */ + private void readObject(java.io.ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + feature = StoreUtil.stringToStructureFeature(featurePath); + } + /** Returns true if this feature value corresponds to the passed feature (taking into account substitution groups */ private boolean matchesFeature(EStructuralFeature eFeature) { if (feature.equals(eFeature)) diff --git a/plugins/org.eclipse.emf.teneo.jpox/src/org/eclipse/emf/teneo/jpox/emf/elist/EListWrapper.java b/plugins/org.eclipse.emf.teneo.jpox/src/org/eclipse/emf/teneo/jpox/emf/elist/EListWrapper.java index 61e50c9a0..ef4698930 100644 --- a/plugins/org.eclipse.emf.teneo.jpox/src/org/eclipse/emf/teneo/jpox/emf/elist/EListWrapper.java +++ b/plugins/org.eclipse.emf.teneo.jpox/src/org/eclipse/emf/teneo/jpox/emf/elist/EListWrapper.java @@ -11,11 +11,12 @@ * Martin Taal * </copyright> * - * $Id: EListWrapper.java,v 1.4 2006/08/03 09:57:10 mtaal Exp $ + * $Id: EListWrapper.java,v 1.5 2006/08/25 23:04:05 mtaal Exp $ */ package org.eclipse.emf.teneo.jpox.emf.elist; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -68,7 +69,7 @@ import org.jpox.util.ClassUtils; * the jpox arraylist is the delegate. * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.4 $ $Date: 2006/08/03 09:57:10 $ + * @version $Revision: 1.5 $ $Date: 2006/08/25 23:04:05 $ */ public class EListWrapper extends PersistableEList implements SCO, Queryable, SCOList, JPOXEList { @@ -157,6 +158,13 @@ public class EListWrapper extends PersistableEList implements SCO, Queryable, SC log.debug("Cloned elist: " + getLogString()); } + /** Nullify the delegate and stateManager before serializing */ + private void writeObject(java.io.ObjectOutputStream out) throws IOException { + jdoDelegate = null; + stateManager = null; + out.defaultWriteObject(); + } + /** Replace normal EObject with AnyTypeImpl */ private Object replaceForAnyType(Object obj) { if (isEObjectList) @@ -168,6 +176,11 @@ public class EListWrapper extends PersistableEList implements SCO, Queryable, SC // replace is always tried } + /** Do your subclass thing for serialization */ + protected void additionalWriteObject() { + stateManager = null; + } + /** Replace normal EObject with AnyTypeImpl */ private Object replaceForAnyTypeObject(Object obj) { assert (isObjectList); diff --git a/plugins/org.eclipse.emf.teneo.jpox/src/org/eclipse/emf/teneo/jpox/emf/elist/FeatureMapWrapper.java b/plugins/org.eclipse.emf.teneo.jpox/src/org/eclipse/emf/teneo/jpox/emf/elist/FeatureMapWrapper.java index 6bbc4f168..17ef39dda 100644 --- a/plugins/org.eclipse.emf.teneo.jpox/src/org/eclipse/emf/teneo/jpox/emf/elist/FeatureMapWrapper.java +++ b/plugins/org.eclipse.emf.teneo.jpox/src/org/eclipse/emf/teneo/jpox/emf/elist/FeatureMapWrapper.java @@ -11,11 +11,12 @@ * Martin Taal * </copyright> * - * $Id: FeatureMapWrapper.java,v 1.2 2006/07/22 13:04:20 mtaal Exp $ + * $Id: FeatureMapWrapper.java,v 1.3 2006/08/25 23:04:05 mtaal Exp $ */ package org.eclipse.emf.teneo.jpox.emf.elist; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -65,7 +66,7 @@ import org.jpox.util.ClassUtils; * to use the backingstore as the delegate because the list can be detached. * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.2 $ $Date: 2006/07/22 13:04:20 $ + * @version $Revision: 1.3 $ $Date: 2006/08/25 23:04:05 $ */ public class FeatureMapWrapper extends PersistableFeatureMap implements SCO, Queryable, SCOList, JPOXEList { @@ -135,6 +136,13 @@ public class FeatureMapWrapper extends PersistableFeatureMap implements SCO, Que } } + /** Nullify the delegate and stateManager before serializing */ + private void writeObject(java.io.ObjectOutputStream out) throws IOException { + jdoDelegate = null; + stateManager = null; + out.defaultWriteObject(); + } + /* * (non-Javadoc) * diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/elist/PersistableEList.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/elist/PersistableEList.java index 787f042e5..8d5f1f61e 100644 --- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/elist/PersistableEList.java +++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/elist/PersistableEList.java @@ -12,11 +12,12 @@ * * </copyright> * - * $Id: PersistableEList.java,v 1.2 2006/07/04 21:28:53 mtaal Exp $ + * $Id: PersistableEList.java,v 1.3 2006/08/25 23:04:09 mtaal Exp $ */ package org.eclipse.emf.teneo.mapping.elist; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -29,13 +30,14 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.util.DelegatingEcoreEList; +import org.eclipse.emf.teneo.util.StoreUtil; /** * A persistable elist which can be used by different or mappers. This persistable elist works around the idea that the * persisted list (e.g. PersistentList in Hibernate) is the delegate for this elist. * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ public abstract class PersistableEList extends DelegatingEcoreEList implements PersistableDelegateList { @@ -48,6 +50,9 @@ public abstract class PersistableEList extends DelegatingEcoreEList implements P /** The structural feature modeled by this list */ private EStructuralFeature estructuralFeature; + /** The unique path to the efeature, used to support serializaion */ + private String eFeaturePath = ""; + /** Is loaded from backend */ private boolean isLoaded = false; @@ -81,8 +86,25 @@ public abstract class PersistableEList extends DelegatingEcoreEList implements P log.debug("Created persistable list " + logString); } + /** Takes care of serializing the efeature */ + private void writeObject(java.io.ObjectOutputStream out) throws IOException { + eFeaturePath = StoreUtil.structuralFeatureToString(estructuralFeature); + estructuralFeature = null; + additionalWriteObject(); + out.defaultWriteObject(); + } + + /** Do your subclass thing for serialization */ + protected void additionalWriteObject() {} + + /** Takes care of deserializing the efeature */ + private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + estructuralFeature = StoreUtil.stringToStructureFeature(eFeaturePath); + } + /* - * (non-Javadoc) + * Get the underlying efeature * * @see org.eclipse.emf.ecore.util.DelegatingEcoreEList#getEStructuralFeature() */ diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/type/FeatureMapEntry.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/type/FeatureMapEntry.java index f73b3c369..319280c9f 100644 --- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/type/FeatureMapEntry.java +++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/type/FeatureMapEntry.java @@ -12,11 +12,14 @@ * * </copyright> * - * $Id: FeatureMapEntry.java,v 1.3 2006/08/21 13:27:27 mtaal Exp $ + * $Id: FeatureMapEntry.java,v 1.4 2006/08/25 23:04:09 mtaal Exp $ */ package org.eclipse.emf.teneo.type; +import java.io.IOException; +import java.io.Serializable; + import org.eclipse.emf.common.notify.NotificationChain; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; @@ -34,14 +37,17 @@ import org.eclipse.emf.teneo.util.StoreUtil; * the correct delegate is created. * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ -public abstract class FeatureMapEntry implements FeatureMap.Entry.Internal { +public abstract class FeatureMapEntry implements FeatureMap.Entry.Internal, Serializable { /** The structural feature which defines which element this is */ private EStructuralFeature eStructuralFeature; + /** Path to the efeature for serialization support */ + private String eFeaturePath; + /** And its value */ private Object value; @@ -70,6 +76,19 @@ public abstract class FeatureMapEntry implements FeatureMap.Entry.Internal { setInverseAction(); } + /** Takes care of serializing the efeature */ + private void writeObject(java.io.ObjectOutputStream out) throws IOException { + eFeaturePath = StoreUtil.structuralFeatureToString(eStructuralFeature); + eStructuralFeature = null; + out.defaultWriteObject(); + } + + /** Takes care of deserializing the efeature */ + private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + eStructuralFeature = StoreUtil.stringToStructureFeature(eFeaturePath); + } + /** Set the inverseaction delegate, must be called after the efeature is set */ private void setInverseAction() { if (eStructuralFeature instanceof EReference) { diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java new file mode 100644 index 000000000..49438eb44 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java @@ -0,0 +1,155 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006 Springsite BV (The Netherlands) and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Taal + * </copyright> + * + * $Id: LibrarySerializationAction.java,v 1.1 2006/08/25 23:04:10 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.URL; + +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests serialization of the library example, also after persistence solution has replaced members. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class LibrarySerializationAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibrarySerializationAction() { + super(LibraryPackage.eINSTANCE); + } + + /** Does its thing */ + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // first serialize a non persisted document set + serialize(getTestSet(factory, "one"), "one"); + + // then persist a set and check serialization after persisting + { + store.beginTransaction(); + Library lib = getTestSet(factory, "two"); + store.store(lib); + store.commitTransaction(); + serialize(lib, "two"); + } + + // then serialize after reading + { + store.beginTransaction(); + Library lib = (Library)store.getObject(Library.class); + assertEquals(2, lib.getBooks().size()); + assertEquals(1, lib.getWriters().size()); + assertEquals(2, ((Writer)lib.getWriters().get(0)).getBooks().size()); + serialize(lib, "two"); + store.commitTransaction(); + } + } + + /** Serialize and check result */ + private void serialize(Library lib, String prefix) { + try { + final ObjectOutputStream oos = new ObjectOutputStream( + new FileOutputStream(serializeFile(prefix + "library", true))); + oos.writeObject(lib); + oos.close(); + + final ObjectInputStream ois = new ObjectInputStream( + new FileInputStream(serializeFile(prefix + "library", false))); + checkTestSet((Library)ois.readObject(), prefix); + ois.close(); + } catch (Exception e) { + throw new StoreTestException("IOException during serialization test", e); + } + + } + + /** Creates a test set and returns a library */ + private Library getTestSet(LibraryFactory factory, String preFix) { + final Writer writer = factory.createWriter(); + writer.setName(preFix + "JRR Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(5); + book.setTitle(preFix + "The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(7); + book2.setTitle(preFix + "The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName(preFix + "Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + return library; + } + + /** Checks the test set */ + private void checkTestSet(Library library, String preFix) { + assertEquals(preFix + "Science Fiction Library", library.getName()); + assertEquals(2, library.getBooks().size()); + assertEquals(1, library.getWriters().size()); + + Writer writer = (Writer)library.getWriters().get(0); + assertEquals(preFix + "JRR Tolkien", writer.getName()); + assertEquals(2, writer.getBooks().size()); + + Book bk1 = (Book)library.getBooks().get(0); + assertEquals(preFix + "The Hobbit", bk1.getTitle()); + assertEquals(5, bk1.getPages()); + assertEquals(BookCategory.SCIENCE_FICTION_LITERAL, bk1.getCategory()); + + Book bk2 = (Book)library.getBooks().get(1); + assertEquals(preFix + "The fellowship of the ring", bk2.getTitle()); + assertEquals(7, bk2.getPages()); + assertEquals(BookCategory.SCIENCE_FICTION_LITERAL, bk2.getCategory()); + } + + /** Get serializable file */ + private File serializeFile(String preFix, boolean remove) throws IOException { + final URL classUrl = Library.class.getResource("Library.class"); + final File classFile = new File(classUrl.getFile()); + final File outFile = new File(classFile.getParentFile(), preFix + ".ser"); + if (outFile.exists() && remove) { + outFile.delete(); + } + return outFile; + } +} diff --git a/tests/org.eclipse.emf.teneo.jpox.libraries/jpox-enhancer-1.1.1.jar b/tests/org.eclipse.emf.teneo.jpox.libraries/jpox-enhancer-1.1.1.jar Binary files differindex 73d85dfdc..50fd13000 100644 --- a/tests/org.eclipse.emf.teneo.jpox.libraries/jpox-enhancer-1.1.1.jar +++ b/tests/org.eclipse.emf.teneo.jpox.libraries/jpox-enhancer-1.1.1.jar diff --git a/tests/org.eclipse.emf.teneo.jpox.test/src/dbadapters.properties b/tests/org.eclipse.emf.teneo.jpox.test/src/dbadapters.properties index 404191575..7cf2b07cd 100644 --- a/tests/org.eclipse.emf.teneo.jpox.test/src/dbadapters.properties +++ b/tests/org.eclipse.emf.teneo.jpox.test/src/dbadapters.properties @@ -10,7 +10,7 @@ # Martin Taal # </copyright> # -# $Id: dbadapters.properties,v 1.3 2006/07/23 19:28:58 mtaal Exp $ +# $Id: dbadapters.properties,v 1.4 2006/08/25 23:04:07 mtaal Exp $ # used to set database connection props in the test classes @@ -27,7 +27,7 @@ mysql.dburl=jdbc:mysql://127.0.0.1:3306/ mysql.dbuser=teneo -mysql.dbpassword=teneo +mysql.dbpassword=teneo1 mysql.dbdriver=com.mysql.jdbc.Driver mysql.dbadapter=org.eclipse.emf.teneo.test.stores.BaseTestDatabaseAdapter diff --git a/tests/org.eclipse.emf.teneo.jpox.test/src/org/eclipse/emf/teneo/jpox/test/emf/sample/AllGenerateTests.java b/tests/org.eclipse.emf.teneo.jpox.test/src/org/eclipse/emf/teneo/jpox/test/emf/sample/AllGenerateTests.java index bbda6e013..23d7b1190 100644 --- a/tests/org.eclipse.emf.teneo.jpox.test/src/org/eclipse/emf/teneo/jpox/test/emf/sample/AllGenerateTests.java +++ b/tests/org.eclipse.emf.teneo.jpox.test/src/org/eclipse/emf/teneo/jpox/test/emf/sample/AllGenerateTests.java @@ -11,7 +11,7 @@ * Martin Taal * </copyright> * - * $Id: AllGenerateTests.java,v 1.5 2006/08/22 22:24:55 mtaal Exp $ + * $Id: AllGenerateTests.java,v 1.6 2006/08/25 23:04:07 mtaal Exp $ */ package org.eclipse.emf.teneo.jpox.test.emf.sample; @@ -28,6 +28,7 @@ import org.eclipse.emf.teneo.test.emf.sample.LibraryGlobalEagerAction; import org.eclipse.emf.teneo.test.emf.sample.LibraryNonResolvingAction; import org.eclipse.emf.teneo.test.emf.sample.LibraryResourceAction; import org.eclipse.emf.teneo.test.emf.sample.LibraryResourceCutPasteAction; +import org.eclipse.emf.teneo.test.emf.sample.LibrarySerializationAction; import org.eclipse.emf.teneo.test.emf.sample.LibraryValidateResourceAction; import org.eclipse.emf.teneo.test.emf.sample.PlayAction; import org.eclipse.emf.teneo.test.emf.sample.PrimerPOAction; @@ -41,12 +42,14 @@ import extlibrary.ExtLibraryAction; * All tests * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ public class AllGenerateTests { public static Test suite() { MultiCfgTestSuite suite = new MultiCfgTestSuite("Test for org.eclipse.emf.teneo.test.samples", JPOXTestbed .instance().getConfigurations()); + suite.addTest(new JPOXGenerateTest(LibrarySerializationAction.class)); + suite.addTest(new JPOXGenerateTest(WorkFlowAction.class)); suite.addTest(new JPOXGenerateTest(SunBooksAction.class)); diff --git a/tests/org.eclipse.emf.teneo.jpox.test/src/org/eclipse/emf/teneo/jpox/test/emf/sample/AllTests.java b/tests/org.eclipse.emf.teneo.jpox.test/src/org/eclipse/emf/teneo/jpox/test/emf/sample/AllTests.java index 3c402d8b0..e5a9942df 100644 --- a/tests/org.eclipse.emf.teneo.jpox.test/src/org/eclipse/emf/teneo/jpox/test/emf/sample/AllTests.java +++ b/tests/org.eclipse.emf.teneo.jpox.test/src/org/eclipse/emf/teneo/jpox/test/emf/sample/AllTests.java @@ -11,7 +11,7 @@ * Martin Taal * </copyright> * - * $Id: AllTests.java,v 1.5 2006/08/22 22:24:55 mtaal Exp $ + * $Id: AllTests.java,v 1.6 2006/08/25 23:04:07 mtaal Exp $ */ package org.eclipse.emf.teneo.jpox.test.emf.sample; @@ -27,6 +27,7 @@ import org.eclipse.emf.teneo.test.emf.sample.InventoryAction; import org.eclipse.emf.teneo.test.emf.sample.LibraryGlobalEagerAction; import org.eclipse.emf.teneo.test.emf.sample.LibraryNonResolvingAction; import org.eclipse.emf.teneo.test.emf.sample.LibraryResourceAction; +import org.eclipse.emf.teneo.test.emf.sample.LibrarySerializationAction; import org.eclipse.emf.teneo.test.emf.sample.LibraryValidateResourceAction; import org.eclipse.emf.teneo.test.emf.sample.PlayAction; import org.eclipse.emf.teneo.test.emf.sample.PrimerPOAction; @@ -40,13 +41,14 @@ import extlibrary.ExtLibraryAction; * All tests * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ public class AllTests { public static Test suite() { TestSuite suite = new MultiCfgTestSuite("Test for org.eclipse.emf.teneo.test.samples", JPOXTestbed.instance() .getConfigurations()); + suite.addTestSuite(LibrarySerializationAction.class); suite.addTestSuite(WorkFlowAction.class); suite.addTestSuite(SunBooksAction.class); |