diff options
author | mtaal | 2007-03-20 15:39:16 +0000 |
---|---|---|
committer | mtaal | 2007-03-20 15:39:16 +0000 |
commit | fffafd9bdbc8f966fea9c0d0f371705a647ae38f (patch) | |
tree | 5d446e35fb294dbcc2920ecd78a3aa073c5276fb | |
parent | e7ecc4aab3ea491919915fd16238200a8669f6e7 (diff) | |
download | org.eclipse.emf.teneo-fffafd9bdbc8f966fea9c0d0f371705a647ae38f.tar.gz org.eclipse.emf.teneo-fffafd9bdbc8f966fea9c0d0f371705a647ae38f.tar.xz org.eclipse.emf.teneo-fffafd9bdbc8f966fea9c0d0f371705a647ae38f.zip |
[178311]
-rw-r--r-- | plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/AbstractProcessingContext.java | 165 |
1 files changed, 65 insertions, 100 deletions
diff --git a/plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/AbstractProcessingContext.java b/plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/AbstractProcessingContext.java index 1ad590535..8b3469c88 100644 --- a/plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/AbstractProcessingContext.java +++ b/plugins/org.eclipse.emf.teneo.annotations/src/org/eclipse/emf/teneo/annotations/mapper/AbstractProcessingContext.java @@ -11,13 +11,14 @@ * Martin Taal * </copyright> * - * $Id: AbstractProcessingContext.java,v 1.4 2007/02/08 23:12:35 mtaal Exp $ + * $Id: AbstractProcessingContext.java,v 1.3.2.1 2007/03/20 15:39:16 mtaal Exp $ */ package org.eclipse.emf.teneo.annotations.mapper; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Stack; @@ -34,69 +35,59 @@ import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature; import org.eclipse.emf.teneo.annotations.pannotation.AssociationOverride; import org.eclipse.emf.teneo.annotations.pannotation.AttributeOverride; import org.eclipse.emf.teneo.annotations.pannotation.Column; -import org.eclipse.emf.teneo.annotations.pannotation.JoinColumn; /** * ProcessingContext which handles attributes overrides. * * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.4 $ + * @version $Revision: 1.3.2.1 $ */ public class AbstractProcessingContext { /** The logger for all these exceptions */ - protected static final Log log = LogFactory - .getLog(AbstractProcessingContext.class); + protected static final Log log = LogFactory.getLog(AbstractProcessingContext.class); /** The current list of overrides */ - private Map<String, Object> currentOverrides = new HashMap<String, Object>(); + private Map currentOverrides = new HashMap(); - /** - * Pushes the current overrides on the stack, to be popped later, this is to - * handle nested components - */ - private Stack<Map<String, Object>> overrideStack = new Stack<Map<String, Object>>(); + /** Pushes the current overrides on the stack, to be popped later, this is to handle nested components */ + private Stack overrideStack = new Stack(); /** - * Pushes the current embedding feature on the stack, to be popped later, - * this is to handle nested components and automatic renaming of props + * Pushes the current embedding feature on the stack, to be popped later, this is to handle nested components and + * automatic renaming of props */ - private Stack<PAnnotatedEReference> embeddingFeatureStack = new Stack<PAnnotatedEReference>(); + private Stack embeddingFeatureStack = new Stack(); - /** - * Add attribute overrides, happens for each mapped superclass and each - * embedded component - */ - public void addAttributeOverrides(EList<AttributeOverride> aos) { + /** Add attribute overrides, happens for each mapped superclass and each embedded component */ + public void addAttributeOverrides(EList aos) { if (aos != null) { - for (AttributeOverride override : aos) { + for (Iterator i = aos.iterator(); i.hasNext();) { + AttributeOverride override = (AttributeOverride) i.next(); currentOverrides.put(override.getName(), override.getColumn()); } } } /** Add association overrides, for each mapped subclass */ - public void addAssociationOverrides(EList<AssociationOverride> overrides) { + public void addAssociationOverrides(EList overrides) { if (overrides != null) { - for (AssociationOverride override : overrides) { - currentOverrides.put(override.getName(), override - .getJoinColumns()); + for (Iterator it = overrides.iterator(); it.hasNext();) { + AssociationOverride override = (AssociationOverride) it.next(); + currentOverrides.put(override.getName(), override.getJoinColumns()); } } } - /** - * Pushes the current overrides on the stack, to be popped later, this is to - * handle nested components - */ + /** Pushes the current overrides on the stack, to be popped later, this is to handle nested components */ public void pushOverrideOnStack() { - overrideStack.push(new HashMap<String, Object>(currentOverrides)); + overrideStack.push(new HashMap(currentOverrides)); } /** Pop the current overrides on the stack */ public void popOverrideStack() { - currentOverrides = overrideStack.pop(); + currentOverrides = (HashMap) overrideStack.pop(); } /** Pushes the current embedding feature on the stack */ @@ -123,85 +114,65 @@ public class AbstractProcessingContext { /** Return the overridden column for the passed attribute */ public Column getOverride(PAnnotatedEAttribute paAttribute) { - return (Column) currentOverrides.get(paAttribute - .getAnnotatedEAttribute().getName()); + return (Column) currentOverrides.get(paAttribute.getAnnotatedEAttribute().getName()); } /** Return the overridden JoinColumns for this reference */ - @SuppressWarnings("unchecked") - public EList<JoinColumn> getOverride(PAnnotatedEReference paReference) { - return (EList<JoinColumn>) currentOverrides.get(paReference - .getAnnotatedEReference().getName()); - } - - /** Return the overridden Joincolumns for the indicated featureName */ - public Column getOverride(String featureName) { - return (Column) currentOverrides.get(featureName); + public List getOverride(PAnnotatedEReference paReference) { + return (List) currentOverrides.get(paReference.getAnnotatedEReference().getName()); } + + /** Return the overridden Joincolumns for the indicated featureName */ + public Column getOverride(String featureName) { + return (Column) currentOverrides.get(featureName); + } /** - * Returns the flattened list of all features of the supertypes for which - * the features should be added to the mapping of the passed eclass. This is - * required to (more-or-less) support multiple inheritance scenarios. In the - * case of multiple inheritance the first supertype is the 'real' mapped - * supertype, the other types are treated as mappedsuperclasses. + * Returns the flattened list of all features of the supertypes for which the features should be added to the + * mapping of the passed eclass. This is required to (more-or-less) support multiple inheritance scenarios. In the + * case of multiple inheritance the first supertype is the 'real' mapped supertype, the other types are treated as + * mappedsuperclasses. */ - public List<PAnnotatedEStructuralFeature> getMultipleInheritedFeatures( - PAnnotatedEClass aClass) { + public List getMultipleInheritedFeatures(PAnnotatedEClass aClass) { + final EClass eclass = aClass.getAnnotatedEClass(); // if one or less supertype then no multiple inheritance - if (aClass.getAnnotatedEClass().getESuperTypes().size() <= 1) { - return new ArrayList<PAnnotatedEStructuralFeature>(); + if (eclass.getESuperTypes().size() <=1) { + return new ArrayList(); } + + log.debug("Determining synthetic mapped features for " + aClass.getAnnotatedEClass().getName()); + final List mappedFeatures = new ArrayList(eclass.getEAllStructuralFeatures()); - log.debug("Determining synthetic mapped features for " - + aClass.getAnnotatedEClass().getName()); - final List<EStructuralFeature> mappedFeatures = new ArrayList<EStructuralFeature>( - aClass.getAnnotatedEClass().getEAllStructuralFeatures()); - // remove all first inherited features - mappedFeatures.removeAll(getFirstInheritedFeatures(aClass - .getAnnotatedEClass(), new ArrayList<EStructuralFeature>())); + // remove all of our own features + mappedFeatures.removeAll(eclass.getEStructuralFeatures()); + + // remove all features inherited from the first supertype + // as this part is modeled in the hbm anyway + mappedFeatures.removeAll(((EClass)eclass.getESuperTypes().get(0)).getEAllStructuralFeatures()); // then remove all id features, these can not be used - final ArrayList<PAnnotatedEStructuralFeature> toReturn = new ArrayList<PAnnotatedEStructuralFeature>(); - for (EStructuralFeature esf : mappedFeatures) { - final PAnnotatedEStructuralFeature pef = aClass.getPaModel() - .getPAnnotated(esf); - if (!(pef instanceof PAnnotatedEAttribute) - || ((PAnnotatedEAttribute) pef).getId() == null) { + final ArrayList toReturn = new ArrayList(); + for (Iterator it = mappedFeatures.iterator(); it.hasNext();) { + final EStructuralFeature esf = (EStructuralFeature) it.next(); + final PAnnotatedEStructuralFeature pef = aClass.getPaModel().getPAnnotated(esf); + if (!(pef instanceof PAnnotatedEAttribute) || ((PAnnotatedEAttribute) pef).getId() == null) { toReturn.add(pef); } } return toReturn; } - /** - * Returns the list of all features which are in the first inheritance - * structure - */ - private List<EStructuralFeature> getFirstInheritedFeatures(EClass eClass, - List<EStructuralFeature> features) { - features.addAll(eClass.getEStructuralFeatures()); - if (eClass.getESuperTypes().size() > 0) { - return getFirstInheritedFeatures((EClass) eClass.getESuperTypes() - .get(0), features); - } - return features; - } - /** Returns all mapped super classes */ - public List<PAnnotatedEClass> getMappedSuperClasses(PAnnotatedEClass entity) { - final List<PAnnotatedEClass> result = new ArrayList<PAnnotatedEClass>(); - for (EClass superEClass : entity.getAnnotatedEClass().getESuperTypes()) { - final PAnnotatedEClass superPAClass = entity.getPaModel() - .getPAnnotated(superEClass); - if (superPAClass != null - && superPAClass.getMappedSuperclass() != null) { + public List getMappedSuperClasses(PAnnotatedEClass entity) { + final List result = new ArrayList(); + for (Iterator it = entity.getAnnotatedEClass().getESuperTypes().iterator(); it.hasNext();) { + final EClass superEClass = (EClass) it.next(); + PAnnotatedEClass superPAClass = entity.getPaModel().getPAnnotated(superEClass); + if (superPAClass != null && superPAClass.getMappedSuperclass() != null) { result.add(superPAClass); // and add the mapped super classes of the mapped superclass - // note that only the unbroken chain of mappedsuperclasses is - // added to the result, if there - // is a non-mappedsuperclass in the inheritance then it stops - // there + // note that only the unbroken chain of mappedsuperclasses is added to the result, if there + // is a non-mappedsuperclass in the inheritance then it stops there // issue also identified by Douglas Bitting result.addAll(getMappedSuperClasses(superPAClass)); } @@ -210,23 +181,17 @@ public class AbstractProcessingContext { return result; } - /** - * Returns true if the eclass only has mappedsuperclasses without id - * annotated property - */ + /** Returns true if the eclass only has mappedsuperclasses without id annotated property */ public boolean mustAddSyntheticID(PAnnotatedEClass entity) { if (entity.hasIdAnnotatedFeature()) { return false; } - for (EClass superEClass : entity.getAnnotatedEClass() - .getEAllSuperTypes()) { - final PAnnotatedEClass superPAClass = entity.getPaModel() - .getPAnnotated(superEClass); - if (superPAClass != null - && superPAClass.getMappedSuperclass() == null) { + for (Iterator it = entity.getAnnotatedEClass().getEAllSuperTypes().iterator(); it.hasNext();) { + final EClass superEClass = (EClass) it.next(); + PAnnotatedEClass superPAClass = entity.getPaModel().getPAnnotated(superEClass); + if (superPAClass != null && superPAClass.getMappedSuperclass() == null) { return false; - } else if (superPAClass != null - && superPAClass.getMappedSuperclass() != null) { + } else if (superPAClass != null && superPAClass.getMappedSuperclass() != null) { if (superPAClass.hasIdAnnotatedFeature()) { return false; } |