Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.teneo/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.emf.teneo/plugin/schema/entity_name_strategy.exsd114
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/DataStore.java44
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java165
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java95
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/BasicPamodelBuilder.java344
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java96
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/PersistenceMappingBuilder.java82
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/parser/EAnnotationParserImporter.java82
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/xml/XmlPersistenceMapper.java27
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/classloader/ClassLoaderStrategy.java8
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/DatastoreAware.java32
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/DefaultExtensionManager.java180
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/Extension.java109
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionInitializable.java32
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionManager.java52
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionManagerAware.java32
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionPoint.java30
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionUtil.java110
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/PaModelAware.java33
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/PersistenceOptionsAware.java33
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/TeneoExtensionException.java48
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/EntityNameStrategy.java21
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/SQLNameStrategy.java11
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/StrategyUtil.java12
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/ClassicSQLNameStrategy.java63
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/DefaultEntityNameStrategy.java67
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/EntityResolvingNameStrategy.java182
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/QualifyingEntityNameStrategy.java52
29 files changed, 1786 insertions, 371 deletions
diff --git a/plugins/org.eclipse.emf.teneo/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.teneo/META-INF/MANIFEST.MF
index 1087e9085..3b20e70b4 100644
--- a/plugins/org.eclipse.emf.teneo/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.teneo/META-INF/MANIFEST.MF
@@ -20,6 +20,7 @@ Export-Package: org.eclipse.emf.teneo,
org.eclipse.emf.teneo.annotations.xml,
org.eclipse.emf.teneo.classloader,
org.eclipse.emf.teneo.ecore,
+ org.eclipse.emf.teneo.extension,
org.eclipse.emf.teneo.mapping.elist,
org.eclipse.emf.teneo.mapping.strategy,
org.eclipse.emf.teneo.mapping.strategy.impl,
diff --git a/plugins/org.eclipse.emf.teneo/plugin/schema/entity_name_strategy.exsd b/plugins/org.eclipse.emf.teneo/plugin/schema/entity_name_strategy.exsd
new file mode 100644
index 000000000..b084ac2a2
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/plugin/schema/entity_name_strategy.exsd
@@ -0,0 +1,114 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.emf.teneo">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.emf.teneo" id="entity_name_strategy" name="Entity Name Strategy"/>
+ </appInfo>
+ <documentation>
+ Defines the entity name strategy used by the default annotation logic and the eclass/class entity resolver.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="strategy">
+ <complexType>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+ A descriptive name which is used to define.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class-name" type="string" use="required">
+ <annotation>
+ <documentation>
+ The name of the class implementing the EntityNameStrategy interface.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ The 0.8.0 release July 2007
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2007 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 - Initial API and implementation
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/DataStore.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/DataStore.java
new file mode 100644
index 000000000..c1a947748
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/DataStore.java
@@ -0,0 +1,44 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: DataStore.java,v 1.1 2007/07/11 14:41:06 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo;
+
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+
+/**
+ * Generic datastore interface used by hibernate and jpox.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface DataStore {
+
+ /** @return the mapped epackages */
+ EPackage[] getEPackages();
+
+ /**
+ * @return the properties, the combination of jpox and hibernate properties
+ */
+ Properties getProperties();
+
+ /** Return the extension manager */
+ ExtensionManager getExtensionManager();
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java
index 2a0e149e9..0b605127a 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: ERuntime.java,v 1.10 2007/06/29 07:31:47 mtaal Exp $
+ * $Id: ERuntime.java,v 1.11 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo;
@@ -39,15 +39,13 @@ import org.eclipse.emf.teneo.ecore.EModelResolver;
import org.eclipse.emf.teneo.util.StoreUtil;
/**
- * The ERuntime contains references to EPackages which are persistable, i.e. are
- * persisted.
+ * The ERuntime contains references to EPackages which are persistable, i.e. are persisted.
*
- * It is used to compute information related to concrete class - eclass mapping,
- * interface to concrete class, references for cross reference computation,
- * contained computations.
+ * It is used to compute information related to concrete class - eclass mapping, interface to
+ * concrete class, references for cross reference computation, contained computations.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class ERuntime extends EModelResolver {
@@ -56,8 +54,7 @@ public class ERuntime extends EModelResolver {
private static Log log = LogFactory.getLog(ERuntime.class);
/**
- * The name of the document root class generated by emf, is ignored in
- * topclasses computation
+ * The name of the document root class generated by emf, is ignored in topclasses computation
*/
private static final String DOCUMENT_ROOT_NAME = "DocumentRoot";
@@ -69,7 +66,7 @@ public class ERuntime extends EModelResolver {
log.debug("Setting ERunTime as EModelResolver");
EModelResolver.setInstance(INSTANCE);
}
-
+
/** The list of epackages processed here */
private final ArrayList<EPackage> epackages = new ArrayList<EPackage>();
@@ -87,6 +84,7 @@ public class ERuntime extends EModelResolver {
private final ArrayList<Class<?>> containedClasses = new ArrayList<Class<?>>();
/** Register the epackages */
+ @Override
public synchronized void register(EPackage[] epacks) {
for (int i = 0; i < epacks.length; i++) {
@@ -100,6 +98,7 @@ public class ERuntime extends EModelResolver {
}
/** Resets the maps/lists */
+ @Override
public void clear() {
epackages.clear();
containedClasses.clear();
@@ -110,8 +109,8 @@ public class ERuntime extends EModelResolver {
}
/**
- * Computes which classes are contained and which are non-contained. Method
- * must be called after the computeReferers method!
+ * Computes which classes are contained and which are non-contained. Method must be called after
+ * the computeReferers method!
*/
private void computeContainedClasses() {
@@ -119,36 +118,41 @@ public class ERuntime extends EModelResolver {
containedClasses.clear();
for (int i = 0; i < epackages.size(); i++) {
- final EPackage epack = (EPackage) epackages.get(i);
+ final EPackage epack = epackages.get(i);
if (ignorePackage(epack)) {
continue;
}
for (EClassifier eclassifier : epack.getEClassifiers()) {
- if (!(eclassifier instanceof EClass))
+ if (!(eclassifier instanceof EClass)) {
continue;
+ }
final EClass eclass = (EClass) eclassifier;
// bit ugly compare on name, but document root should be ignored
// otherwise everything is contained
- if (eclass.getName().compareTo(DOCUMENT_ROOT_NAME) == 0)
+ if (eclass.getName().compareTo(DOCUMENT_ROOT_NAME) == 0) {
continue;
+ }
for (EReference eref : eclass.getEReferences()) {
- if (!eref.isContainment())
+ if (!eref.isContainment()) {
continue;
+ }
final Class<?> toClass = eref.getEType().getInstanceClass();
- if (!containedClasses.contains(toClass))
+ if (!containedClasses.contains(toClass)) {
containedClasses.add(toClass);
+ }
}
}
}
// and then when it is not contained add it to the contained list
for (Class<?> clazz : interfaceToEClass.keySet()) {
- if (containedClasses.contains(clazz))
+ if (containedClasses.contains(clazz)) {
continue; // already determined so continue
+ }
if (isSelfOrSuperContained(clazz, containedClasses)) {
containedClasses.add(clazz);
@@ -165,26 +169,26 @@ public class ERuntime extends EModelResolver {
}
/**
- * Walks through a interface inheritance structure and determines if a
- * superclass is contained if so then the class is added to the
- * containedclasses
+ * Walks through a interface inheritance structure and determines if a superclass is contained
+ * if so then the class is added to the containedclasses
*/
- private boolean isSelfOrSuperContained(Class<?> checkClass,
- ArrayList<Class<?>> containedClasses) {
+ private boolean isSelfOrSuperContained(Class<?> checkClass, ArrayList<Class<?>> containedClasses) {
assert (checkClass.isInterface());
- if (containedClasses.contains(checkClass))
+ if (containedClasses.contains(checkClass)) {
return true;
+ }
final Class<?>[] interfaces = checkClass.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- if (isSelfOrSuperContained(interfaces[i], containedClasses))
+ for (Class<?> element : interfaces) {
+ if (isSelfOrSuperContained(element, containedClasses)) {
return true;
+ }
}
return false;
}
/** Returns the list of topclasses */
public Class<?>[] getTopClasses() {
- return (Class[]) topClasses.toArray(new Class[topClasses.size()]);
+ return topClasses.toArray(new Class[topClasses.size()]);
}
/** Return the list of interfaces */
@@ -198,17 +202,18 @@ public class ERuntime extends EModelResolver {
}
/**
- * Retains only the root parent class in a list, so if an entry in the list
- * as a parent in the same list then the child is deleted from the list
+ * Retains only the root parent class in a list, so if an entry in the list as a parent in the
+ * same list then the child is deleted from the list
*/
private void cleanList(ArrayList<Class<?>> list) {
final ArrayList<Class<?>> toRemove = new ArrayList<Class<?>>();
for (Class<?> clazz : list) {
- if (clazz == null)
+ if (clazz == null) {
continue;
+ }
final Class<?>[] supers = clazz.getInterfaces();
- for (int j = 0; j < supers.length; j++) {
- if (list.contains(supers[j])) {
+ for (Class<?> element : supers) {
+ if (list.contains(element)) {
toRemove.add(clazz);
break;
}
@@ -225,31 +230,27 @@ public class ERuntime extends EModelResolver {
// walk through all the epackages
for (int i = 0; i < epackages.size(); i++) {
- final EPackage epack = (EPackage) epackages.get(i);
+ final EPackage epack = epackages.get(i);
if (ignorePackage(epack)) {
- log.debug("Not determining concrete classes for package "
- + epack.getName());
+ log.debug("Not determining concrete classes for package " + epack.getName());
continue;
}
- log.debug("Determining concrete classes for package "
- + epack.getName());
+ log.debug("Determining concrete classes for package " + epack.getName());
for (EClassifier eclassifier : epack.getEClassifiers()) {
- if (!(eclassifier instanceof EClass))
+ if (!(eclassifier instanceof EClass)) {
continue;
+ }
- final Object instance = create((EClass)eclassifier);
+ final Object instance = create((EClass) eclassifier);
if (instance != null) {
- eclassifierToConcrete.put((EClass) eclassifier, instance
- .getClass());
- concreteToEClass.put(instance.getClass(),
- (EClass) eclassifier);
+ eclassifierToConcrete.put(eclassifier, instance.getClass());
+ concreteToEClass.put(instance.getClass(), (EClass) eclassifier);
}
if (eclassifier.getInstanceClass() != null) {
- interfaceToEClass.put(eclassifier.getInstanceClass(),
- (EClass) eclassifier);
+ interfaceToEClass.put(eclassifier.getInstanceClass(), (EClass) eclassifier);
}
}
}
@@ -263,14 +264,15 @@ public class ERuntime extends EModelResolver {
}
/**
- * Walks up the class hierarchy and adds the superclasses to the
- * concrete-interface mapping class sets
+ * Walks up the class hierarchy and adds the superclasses to the concrete-interface mapping
+ * class sets
*/
private void addAbstractSupers(Class<?> clazz) {
// clazz is null or not an eobject
- if (clazz == null || !EObject.class.isAssignableFrom(clazz))
+ if (clazz == null || !EObject.class.isAssignableFrom(clazz)) {
return;
+ }
// if already been here then go on for the superclasses
if (concreteToEClass.get(clazz) != null) {
@@ -280,9 +282,9 @@ public class ERuntime extends EModelResolver {
// new one, find all its interfaces
final Class<?>[] interf = clazz.getInterfaces();
- for (int i = 0; i < interf.length; i++) {
- if (EObject.class.isAssignableFrom(interf[i])) {
- final EClass eclass = (EClass) interfaceToEClass.get(interf[i]);
+ for (Class<?> element : interf) {
+ if (EObject.class.isAssignableFrom(element)) {
+ final EClass eclass = interfaceToEClass.get(element);
concreteToEClass.put(clazz, eclass);
eclassifierToConcrete.put(eclass, clazz);
}
@@ -294,27 +296,34 @@ public class ERuntime extends EModelResolver {
*
* @see org.eclipse.emf.teneo.jpox.emf.IEMFDataStore#getEPackages()
*/
+ @Override
public EPackage[] getEPackages() {
- return (EPackage[]) epackages.toArray(new EPackage[epackages.size()]);
+ return epackages.toArray(new EPackage[epackages.size()]);
}
/** Returns true if the epackage is registered here */
+ @Override
public boolean isRegistered(EPackage epackage) {
return epackages.contains(epackage);
}
-
+
/** Convenience method to easily determine which packages should be ignored */
private static boolean ignorePackage(EPackage epack) {
- if (epack instanceof XMLTypePackageImpl)
+ if (true) {
+ return false;
+ }
+ if (epack instanceof XMLTypePackageImpl) {
return true; // ignore this
- if (epack instanceof EcorePackageImpl)
+ }
+ if (epack instanceof EcorePackageImpl) {
return true; // ignore this
+ }
return false;
}
/** Returns the instanceclass for a passed interface */
public Class<?> getInstanceClass(Class<?> interf) {
- final EClass eclass = (EClass) interfaceToEClass.get(interf);
+ final EClass eclass = interfaceToEClass.get(interf);
if (eclass == null) {
throw new TeneoException("No eclass for interf " + interf.getName());
}
@@ -322,31 +331,36 @@ public class ERuntime extends EModelResolver {
}
/** Returns the instanceclass for a passed eclass */
+ @Override
public Class<?> getJavaClass(EClassifier eclassifier) {
if (eclassifier instanceof EClass) {
- final EClass eclass = (EClass)eclassifier;
+ final EClass eclass = (EClass) eclassifier;
if (eclass.isInterface()) {
return eclass.getInstanceClass();
}
}
- return (Class<?>) eclassifierToConcrete.get(eclassifier);
+ return eclassifierToConcrete.get(eclassifier);
}
-
+
/** Returns the interface class for a passed eclass */
+ @Override
public Class<?> getJavaInterfaceClass(EClass eclass) {
return eclass.getInstanceClass();
}
/** Returns true if the passed EClass has a javaClass representation. */
+ @Override
public boolean hasImplementationClass(EClassifier eclassifier) {
return null != getJavaClass(eclassifier);
}
/** Returns null */
+ @Override
public Object create(EClass eclass) {
// abstract instance classes are added later
- if (eclass.isAbstract() || eclass.isInterface())
+ if (eclass.isAbstract() || eclass.isInterface()) {
return null;
+ }
// Check if the class is persistable
try {
@@ -355,21 +369,21 @@ public class ERuntime extends EModelResolver {
// log but do nothing because this happens when we try to create an
// object
// with an invalid classifier, which is a eclass!
- log.debug("The classifier: " + eclass.getName()
- + " is not a valid eclass");
+ log.debug("The classifier: " + eclass.getName() + " is not a valid eclass");
return null;
}
}
-
+
/** Get the eclass for a certain class */
+ @Override
public EClass getEClass(Class<?> clazz) {
if (clazz.isInterface()) {
- return (EClass) interfaceToEClass.get(clazz);
+ return interfaceToEClass.get(clazz);
}
- return (EClass) concreteToEClass.get(clazz);
+ return concreteToEClass.get(clazz);
}
-
+
/** Get the eclass for a certain class name */
public EClass getEClass(String classname) {
try {
@@ -381,26 +395,25 @@ public class ERuntime extends EModelResolver {
}
/**
- * Returns the structural feature for a certain field and object comby. Null
- * is returned if nothing is found
+ * Returns the structural feature for a certain field and object comby. Null is returned if
+ * nothing is found
*/
- public EStructuralFeature getStructuralFeature(Class<?> clazz,
- String FieldName) {
+ public EStructuralFeature getStructuralFeature(Class<?> clazz, String FieldName) {
final EClass eclass = getEClass(clazz);
- if (eclass == null)
+ if (eclass == null) {
return null;
+ }
return StoreUtil.getEStructuralFeature(eclass, FieldName);
}
/**
- * Returns the list of EMF interfaces which are contained. Only the topmost
- * interface in a class hierarchy is returned. This can be used to
- * automatically create the econtainer field mappings.
+ * Returns the list of EMF interfaces which are contained. Only the topmost interface in a class
+ * hierarchy is returned. This can be used to automatically create the econtainer field
+ * mappings.
*
* Note that multiple classes in one inheritance structure can be present.
*/
public Class<?>[] getContainedInterfaces() {
- return (Class<?>[]) containedClasses.toArray(new Class[containedClasses
- .size()]);
+ return containedClasses.toArray(new Class[containedClasses.size()]);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java
index 4b7106f09..1a27b3d36 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: PersistenceOptions.java,v 1.26 2007/07/09 12:54:58 mtaal Exp $
+ * $Id: PersistenceOptions.java,v 1.27 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo;
@@ -28,12 +28,6 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.eclipse.emf.teneo.classloader.ClassLoaderResolver;
-import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy;
-import org.eclipse.emf.teneo.mapping.strategy.SQLNameStrategy;
-import org.eclipse.emf.teneo.mapping.strategy.impl.ClassicSQLNameStrategy;
-import org.eclipse.emf.teneo.mapping.strategy.impl.DefaultEntityNameStrategy;
-import org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy;
/**
* Defines the property names used in the persistence mapping.
@@ -41,7 +35,7 @@ import org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy;
* As a convenience, this class offers type-safe property accessor wrappers.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.26 $
+ * @version $Revision: 1.27 $
*/
public class PersistenceOptions {
@@ -59,11 +53,14 @@ public class PersistenceOptions {
// START: ++++++++++++++++++++++ SQL Naming related Options ++++++++++++++++++++++++++++++++++++
/**
* Join table naming strategy, two values: ejb3 and unique
+ *
+ * @Deprecated use the extensionManager concept
*/
public static final String JOIN_TABLE_NAMING_STRATEGY = NAMING_PREFIX + "join_table_naming_strategy";
- /**
- * Deprecated use JOIN_TABLE_NAMING_STRATEGY
+ /**
+ * Deprecated use JOIN_TABLE_NAMING_STRATEGY
+ *
* @Deprecated
*/
public static final String JOIN_TABLE_NAMING_STRATEGY_OLD = MAPPING_PREFIX + "join_table_naming_strategy";
@@ -100,6 +97,8 @@ public class PersistenceOptions {
/**
* The sql name strategy, if not set then the ClassicSQLNameStrategy is used.
+ *
+ * @Deprecated use the extensionManager concept
*/
public static final String SQL_NAME_STRATEGY = NAMING_PREFIX + "sql_name_strategy";
@@ -145,14 +144,25 @@ public class PersistenceOptions {
*/
public static final String USE_IMPLEMENTATION_CLASSES_AS_ENTITYNAME = NAMING_PREFIX + "java_class_entity_names";
- /** Qualify the entity name */
+ /**
+ * Qualify the entity name
+ *
+ * @Deprecated use the EntityNameStrategy and extensionManager concept
+ */
public static final String QUALIFY_ENTITY_NAME = NAMING_PREFIX + "qualify_entity_name";
- /** With the values */
+ /**
+ * With the values
+ *
+ * @Deprecated use the EntityNameStrategy and extensionManager concept
+ *
+ */
public static final String QUALIFY_ENTITY_NAME_NO = "no";
/**
* The value of the QUALIFY_ENTITY_NAME when nsprefix qualification should occur
+ *
+ * @Deprecated use the EntityNameStrategy and extensionManager concept
*/
public static final String QUALIFY_ENTITY_NAME_NSPREFIX = "nsprefix";
@@ -291,11 +301,6 @@ public class PersistenceOptions {
*/
private final Properties properties;
- /**
- * Local member to store the sql name strategy instance
- */
- private SQLNameStrategy sqlNameStrategy = null;
-
/**
* Construct a new instance using Properties.
*/
@@ -495,10 +500,11 @@ public class PersistenceOptions {
/**
* Returns the qualify entity names option, returns QUALIFY_ENTITY_NAME_NO ("no")
+ *
+ * @Deprecated use the EntityNameStrategy and extensionManager concept
*/
- public EntityNameStrategy getEntityNameStrategy() {
- // note create uses singletons
- return createEntityNameStrategy(properties.getProperty(QUALIFY_ENTITY_NAME, QUALIFY_ENTITY_NAME_NO));
+ public String getEntityNameOption() {
+ return properties.getProperty(QUALIFY_ENTITY_NAME, QUALIFY_ENTITY_NAME_NO);
}
/**
@@ -574,53 +580,12 @@ public class PersistenceOptions {
return properties;
}
- // TODO: Add remaining accessor wrappers.
-
- /**
- * Creates the correct eclass name strategy based on the String setting.
- */
- private EntityNameStrategy createEntityNameStrategy(String option) {
- try {
- if (option == null) {
- log.debug("Creating " + DefaultEntityNameStrategy.class.getName() + " as eclass name strategy");
- return DefaultEntityNameStrategy.INSTANCE;
- }
- if (option.compareToIgnoreCase(PersistenceOptions.QUALIFY_ENTITY_NAME_NO) == 0) {
- log.debug("Creating " + DefaultEntityNameStrategy.class.getName() + " as eclass name strategy");
- return DefaultEntityNameStrategy.INSTANCE;
- }
- if (option.compareToIgnoreCase(PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX) == 0) {
- log.debug("Creating " + QualifyingEntityNameStrategy.class.getName() + " as case strategy");
- return QualifyingEntityNameStrategy.INSTANCE;
- }
-
- log.debug("Assuming class name creating instance of " + option);
- return (EntityNameStrategy) ClassLoaderResolver.classForName(option).newInstance();
- } catch (Exception e) {
- throw new TeneoException("Could not instantiate: " + option, e);
- }
- }
-
/**
* Creates the correct sql name strategy based on the String setting.
+ *
+ * @Deprecated use the SQLNameStrategy and extensionManager concept
*/
- public SQLNameStrategy getSQLNameStrategy() {
- if (sqlNameStrategy != null) {
- return sqlNameStrategy;
- }
- String option = properties.getProperty(SQL_NAME_STRATEGY);
- try {
- if (!properties.contains(SQL_NAME_STRATEGY)) {
- log.debug("Creating " + ClassicSQLNameStrategy.class.getName());
- sqlNameStrategy = new ClassicSQLNameStrategy();
- } else {
- log.debug("Assuming class name creating instance of " + option);
- sqlNameStrategy = (SQLNameStrategy) ClassLoaderResolver.classForName(option).newInstance();
- }
- } catch (Exception e) {
- throw new TeneoException("Could not instantiate: " + option, e);
- }
- sqlNameStrategy.setPersistenceOptions(this);
- return sqlNameStrategy;
+ public String getSQLNameStrategy() {
+ return properties.getProperty(SQL_NAME_STRATEGY);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/BasicPamodelBuilder.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/BasicPamodelBuilder.java
new file mode 100644
index 000000000..1cf19691e
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/BasicPamodelBuilder.java
@@ -0,0 +1,344 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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
+ * Davide Marchignoli
+ * </copyright>
+ *
+ * $Id: BasicPamodelBuilder.java,v 1.1 2007/07/11 14:41:06 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.annotations.mapper;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEDataType;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEModelElement;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
+import org.eclipse.emf.teneo.annotations.pamodel.PamodelFactory;
+import org.eclipse.emf.teneo.extension.ExtensionPoint;
+
+/**
+ * Convience class for building a <code>PAnnotatedModel</code>.
+ *
+ * @author <a href="mailto:marchign at elver.org">Davide Marchignoli</a>
+ */
+public class BasicPamodelBuilder implements ExtensionPoint {
+
+ private PAnnotatedModel target = null;
+
+ /**
+ * Uses an empty freshly instantiated PAnnotatedModel as target.
+ */
+ public BasicPamodelBuilder() {
+ setPAnnotatedModel(PamodelFactory.eINSTANCE.createPAnnotatedModel());
+ }
+
+ /**
+ * Uses the given PAnnotatedMmodel as target.
+ */
+ public BasicPamodelBuilder(PAnnotatedModel target) {
+ setPAnnotatedModel(target);
+ }
+
+ /**
+ * Sets the target PAnnotatedModel
+ */
+ public void setPAnnotatedModel(PAnnotatedModel target) {
+ this.target = target;
+ }
+
+ /**
+ * @return the target model.
+ */
+ public PAnnotatedModel getPAnnotatedModel() {
+ return target;
+ }
+
+ /**
+ * @return a <code>PAnnotatedModelElement</code> assoiciated to the given
+ * <code>EModelElement</code>. The element is created only if not already present in
+ * the model.
+ */
+ protected PAnnotatedEModelElement create(EModelElement eModelElement) {
+ PAnnotatedEModelElement paElement = target.getPAnnotated(eModelElement);
+ if (paElement == null) {
+ // Factor out actual model creation so that extensions can create their
+ // own model elements.
+ paElement = doCreate(eModelElement);
+ }
+ return paElement;
+ }
+
+ /**
+ * @return A newly created PAnnotatedEModelElement. This method is only responsible for the
+ * actual creation (and initialization) of this object. No other logic should happen
+ * here. This allows subclasses to alter how objects are created. If you'd like to alter
+ * any other logic around the creation, you should override the <code>create</code>
+ * method(s).
+ * @throws AssertionError
+ */
+ protected PAnnotatedEModelElement doCreate(EModelElement eModelElement) throws AssertionError {
+ final EClass eModelElementEClass = eModelElement.eClass();
+ PAnnotatedEModelElement paElement;
+ switch (eModelElementEClass.getClassifierID()) {
+ case EcorePackage.EATTRIBUTE:
+ paElement = PamodelFactory.eINSTANCE.createPAnnotatedEAttribute();
+ break;
+ case EcorePackage.EREFERENCE:
+ paElement = PamodelFactory.eINSTANCE.createPAnnotatedEReference();
+ break;
+ case EcorePackage.ECLASS:
+ paElement = PamodelFactory.eINSTANCE.createPAnnotatedEClass();
+ break;
+ case EcorePackage.EPACKAGE:
+ paElement = PamodelFactory.eINSTANCE.createPAnnotatedEPackage();
+ break;
+ case EcorePackage.EENUM:
+ case EcorePackage.EDATA_TYPE:
+ paElement = PamodelFactory.eINSTANCE.createPAnnotatedEDataType();
+ break;
+ default:
+ throw new AssertionError("Trying to build PAnnotatedEModelElement for a " + eModelElementEClass);
+ }
+ paElement.setAnnotatedElement((ENamedElement) eModelElement);
+ return paElement;
+ }
+
+ /**
+ * @return a <code>PAnnotatedEPackage</code> associated to the given <code>EPackage</code>
+ * and adds it the model.
+ * <p>
+ * The <code>PAnnotatedEPackage</code> is created only if not already present in the
+ * model.
+ */
+ protected PAnnotatedEPackage pElement(EPackage ePackage) {
+ PAnnotatedEPackage pPackage = (PAnnotatedEPackage) create(ePackage);
+ if (pPackage.eContainer() == null) {
+ target.getPaEPackages().add(pPackage);
+ }
+ return pPackage;
+ }
+
+ /**
+ * @return a <code>PAnnotatedEClass</code> associated to the given <code>EClass</code> and
+ * adds it the model.
+ * <p>
+ * The <code>PAnnotatedEClass</code> is created only if not already present in the
+ * model.
+ * <p>
+ * The operation may involve the creation of a <code>PAnnotatedEPackage</code>
+ * associated to the given <code>EClass</code> package.
+ */
+ protected PAnnotatedEClass pElement(EClass eClass) {
+ PAnnotatedEClass pClass = (PAnnotatedEClass) create(eClass);
+ pElement(eClass.getEPackage()).getPaEClasses().add(pClass);
+ return pClass;
+ }
+
+ /**
+ * @return a <code>PAnnotatedEStructuralFeature</code> associated to the given
+ * <code>EStructuralFeature</code> and adds it the model.
+ * <p>
+ * The <code>PAnnotatedEStructuralFeature</code> is created only if not already
+ * present in the model.
+ * <p>
+ * The operation may involve the creation of a <code>PAnnotatedEPackage</code> and a
+ * <code>PAnnotatedEClass</code>.
+ */
+ protected PAnnotatedEModelElement pElement(EStructuralFeature eFeature) {
+ PAnnotatedEStructuralFeature pFeature = (PAnnotatedEStructuralFeature) create(eFeature);
+ pElement(eFeature.getEContainingClass()).getPaEStructuralFeatures().add(pFeature);
+ return pFeature;
+ }
+
+ /**
+ * @return a <code>PAnnotatedEStructuralFeature</code> associated to the given
+ * <code>EStructuralFeature</code> and adds it the model.
+ * <p>
+ * The <code>PAnnotatedEStructuralFeature</code> is created only if not already
+ * present in the model.
+ * <p>
+ * The operation may involve the creation of a <code>PAnnotatedEPackage</code> and a
+ * <code>PAnnotatedEClass</code>.
+ */
+ protected PAnnotatedEDataType pElement(EDataType eDataType) {
+ PAnnotatedEDataType pDataType = (PAnnotatedEDataType) create(eDataType);
+ pElement(eDataType.getEPackage()).getPaEDataTypes().add(pDataType);
+ return pDataType;
+ }
+
+ /**
+ * @return a <code>PAnnotatedEModelElement</code> associated to the given
+ * <code>EModelElement</code> and adds it the model.
+ * @see #pElement(EPackage)
+ * @see #pElement(EClass)
+ * @see #pElement(EStructuralFeature)
+ */
+ protected PAnnotatedEModelElement pElement(final EModelElement eElement) throws AssertionError {
+ PAnnotatedEModelElement pElement = null;
+ switch (eElement.eClass().getClassifierID()) {
+ case EcorePackage.EATTRIBUTE:
+ case EcorePackage.EREFERENCE:
+ pElement = pElement((EStructuralFeature) eElement);
+ break;
+ case EcorePackage.ECLASS:
+ pElement = pElement((EClass) eElement);
+ break;
+ case EcorePackage.EPACKAGE:
+ pElement = pElement((EPackage) eElement);
+ break;
+ case EcorePackage.EDATA_TYPE:
+ pElement = pElement((EDataType) eElement);
+ break;
+ default:
+ throw new AssertionError("Trying to build PAnnotatedEModelElement for a " + eElement.eClass());
+ }
+ return pElement;
+ }
+
+ /**
+ * Builds a <code>PAnnotatedEPackage</code> associated to the given <code>EPackage</code>
+ * (if such an <code>PAnnotatedEPackage</code> does not yet exists) and adds it to the target
+ * model.
+ */
+ public void add(EPackage ePackage) {
+ pElement(ePackage);
+ }
+
+ /**
+ * Builds a <code>PAnnotatedEClass</code> associated to the given <code>EClass</code> (if
+ * such an <code>PAnnotatedEClass</code> does not yet exists) and adds it to the target model.
+ *
+ * <p>
+ * The creation of a new <code>PAnnotatedEClass</code> may involve the creation of a
+ * <code>PAnnotatedEPackage</code> associated to the containing <code>EPackage</code> of the
+ * given class.
+ */
+ public void add(EClass eClass) {
+ pElement(eClass);
+ }
+
+ /**
+ * Add to the the target model a new <code>PAnnotatedEStructuralFeature</code> refering to the
+ * given EStructuralFeature.
+ *
+ * <p>
+ * A PAnnotatedEClass and a PAnnotatedEPackage for the containing EClass and EPackage are added
+ * if needed.
+ *
+ * <p>
+ * The added element have no annotations. Elements for which a corresponding PAnnotatedElement
+ * is already present in the target model are ignored.
+ */
+ public void add(EStructuralFeature eFeature) {
+ pElement(eFeature);
+ }
+
+ /**
+ * Add the given annotation to the given PAnnotatedEModelElement.
+ *
+ * @throws IllegalArgumentException
+ * if the given PAnnotation is not admitted for the given PAnnotatedEModelElement.
+ * protected void setPAnnotation(PAnnotatedEModelElement pElement, PAnnotation
+ * pAnnotation) { EReference pAnnotationRef =
+ * PamodelPackage.eINSTANCE.pAnnotationReference(pElement.eClass(),
+ * pAnnotation.eClass()); if (pAnnotationRef == null) throw new
+ * IllegalArgumentException("PAnnotation of type '" + pAnnotation.eClass() + "' does
+ * not apply to elements of type '" + pElement.eClass() + "'");
+ * pElement.eSet(pAnnotationRef, pAnnotation); }
+ */
+
+ /**
+ * Add the given PAnnotation to the target model.
+ *
+ * <p>
+ * This operation may involve the addition to the model of a newly created
+ * PAnnotatedEModelElement for the PAnnotation EModelElement.
+ *
+ * @throws NullPointerException
+ * if either <code>pAnnotation</code> or
+ * <code>pAnnotation.getEModelElement()</code> are null.
+ * @throws IllegalArgumentException
+ * if the given <code>PAnnotation</code> references an invalid
+ * <code>PAnnotatedElement</code> public void add(PAnnotation pAnnotation) {
+ * PAnnotatedEModelElement pElement = pElement(pAnnotation.getEModelElement());
+ * setPAnnotation(pElement, pAnnotation); }
+ */
+
+ /**
+ * Add to the the target model a new PAnnotatedPackage refering to the given EPackage.
+ * Recursively adds a PAnnotatedEClass for each EClass in the given EPackage (see
+ * {@link addEClass}).
+ *
+ * <p>
+ * The added elements have no annotations. Elements for which a corresponding PAnnotatedElement
+ * is already present in the target model are ignored.
+ */
+ public void addRecurse(EPackage ePackage) {
+ PAnnotatedEPackage paPackage = pElement(ePackage);
+ for (EClassifier eClassifier : ePackage.getEClassifiers()) {
+ if (eClassifier instanceof EClass) {
+ addRecurse(paPackage, (EClass) eClassifier);
+ } else if (eClassifier instanceof EDataType) {
+ pElement((EDataType) eClassifier);
+ }
+ }
+ }
+
+ /**
+ * used by {@link #addRecurse(EPackage)} to avoid recomputing the container multiple times.
+ */
+ protected void addRecurse(PAnnotatedEPackage paPackage, EClass eClass) {
+ PAnnotatedEClass paClass = (PAnnotatedEClass) create(eClass);
+ if (paClass.eContainer() == null) {
+ paPackage.getPaEClasses().add(paClass);
+ }
+ for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
+ add(paClass, eStructuralFeature);
+ }
+ }
+
+ /**
+ * Add to the the target model a new PAnnotatedPackage refering to the given EClass. Recursively
+ * adds a PAnnotatedEStructuralFeature for each EStructuralFeature in the given EClass (see
+ * {@link addEStructuralFeature}).
+ *
+ * <p>
+ * A PAnnotatedEPackage for the containng EPackage is added if needed.
+ *
+ * <p>
+ * The added elements have no annotations.
+ *
+ * <p>
+ * Elements for which a corresponding PAnnotatedElement is already present in the target model
+ * are ignored. public void addRecurse(EClass eClass) { addRecurse((PAnnotatedEPackage)
+ * pElement(eClass), eClass); }
+ */
+
+ /**
+ * used by {@link #addRecurse(EClass)} to avoid recomputing the container multiple times.
+ */
+ protected void add(PAnnotatedEClass paClass, EStructuralFeature eFeature) {
+ PAnnotatedEStructuralFeature paFeature = (PAnnotatedEStructuralFeature) create(eFeature);
+ if (paFeature.eContainer() == null) {
+ paClass.getPaEStructuralFeatures().add(paFeature);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java
index 9591fe6fc..6f70a5c1a 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/DefaultAnnotator.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: DefaultAnnotator.java,v 1.4 2007/07/09 17:39:19 mtaal Exp $
+ * $Id: DefaultAnnotator.java,v 1.5 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo.annotations.mapper;
@@ -75,6 +75,9 @@ import org.eclipse.emf.teneo.annotations.pannotation.Temporal;
import org.eclipse.emf.teneo.annotations.pannotation.TemporalType;
import org.eclipse.emf.teneo.annotations.pannotation.Transient;
import org.eclipse.emf.teneo.ecore.EModelResolver;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+import org.eclipse.emf.teneo.extension.ExtensionManagerAware;
+import org.eclipse.emf.teneo.extension.ExtensionPoint;
import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy;
import org.eclipse.emf.teneo.mapping.strategy.SQLNameStrategy;
import org.eclipse.emf.teneo.mapping.strategy.StrategyUtil;
@@ -85,9 +88,9 @@ import org.eclipse.emf.teneo.util.StoreUtil;
* the emf type information. It sets the default annotations according to the ejb3 spec.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
-public class DefaultAnnotator {
+public class DefaultAnnotator implements ExtensionPoint, ExtensionManagerAware {
// The source of the annotations of extended metadata used by emf
private static final String ANNOTATION_SOURCE_METADATA = "http:///org/eclipse/emf/ecore/util/ExtendedMetaData";
@@ -97,12 +100,15 @@ public class DefaultAnnotator {
// Several options, coming from persistenceOptions
private InheritanceType optionDefaultInheritanceMapping = InheritanceType.SINGLE_TABLE;
- private SQLNameStrategy optionSQLNameStrategy = null;
+ private SQLNameStrategy sqlNameStrategy = null;
private TemporalType optionDefaultTemporal = null;
- private EntityNameStrategy optionEntityNameStrategy = null;
+ private EntityNameStrategy entityNameStrategy = null;
protected PersistenceOptions persistenceOptions;
+ // the extension manager
+ private ExtensionManager extensionManager;
+
// Convenience link to pamodel factory
private final PannotationFactory aFactory = PannotationFactory.eINSTANCE;
@@ -118,6 +124,8 @@ public class DefaultAnnotator {
*/
public synchronized void map(PAnnotatedModel annotatedModel, PersistenceOptions po) {
+ persistenceOptions = po;
+
// check if the emodelresolver has been set, if not then
// use the ERuntime as the default
try {
@@ -132,8 +140,6 @@ public class DefaultAnnotator {
ERuntime.setAsEModelResolver();
}
- setLocalOptions(po);
-
final List<PAnnotatedEPackage> apacks = annotatedModel.getPaEPackages();
final EPackage[] epacks = new EPackage[apacks.size()];
@@ -161,6 +167,8 @@ public class DefaultAnnotator {
annotatedModel.setInitialized(true);
this.annotatedModel = annotatedModel;
+ setLocalOptions(po);
+
for (PAnnotatedEPackage pae : annotatedModel.getPaEPackages()) {
processPackage(pae);
}
@@ -168,7 +176,6 @@ public class DefaultAnnotator {
/** Sets the options in a number of members */
protected void setLocalOptions(PersistenceOptions po) {
- persistenceOptions = po;
if (po.getInheritanceMapping() != null) {
InheritanceType it = InheritanceType.get(po.getInheritanceMapping());
if (it == InheritanceType.JOINED) {
@@ -185,12 +192,14 @@ public class DefaultAnnotator {
" is not supported");
}
}
- optionEntityNameStrategy = po.getEntityNameStrategy();
optionDefaultTemporal = TemporalType.get(po.getDefaultTemporalValue());
if (optionDefaultTemporal == null) {
throw new IllegalArgumentException("Temporal value not found: " + po.getDefaultTemporalValue());
}
- optionSQLNameStrategy = po.getSQLNameStrategy();
+ entityNameStrategy = getExtensionManager().getExtension(EntityNameStrategy.class);
+ entityNameStrategy.setPaModel(annotatedModel); // is maybe already set?
+ sqlNameStrategy = getExtensionManager().getExtension(SQLNameStrategy.class);
+ sqlNameStrategy.setPersistenceOptions(po);
}
/** Maps one epackage */
@@ -272,7 +281,7 @@ public class DefaultAnnotator {
aClass.setEntity(entity);
}
if (aClass.getEntity() != null && aClass.getEntity().getName() == null) {
- aClass.getEntity().setName(getEntityName(eclass));
+ aClass.getEntity().setName(entityNameStrategy.toEntityName(eclass));
}
// get the inheritance from the supertype or use the global inheritance
@@ -312,7 +321,7 @@ public class DefaultAnnotator {
for (String idFeature : idFeatures) {
final PrimaryKeyJoinColumn pkjc = aFactory.createPrimaryKeyJoinColumn();
- pkjc.setName(optionSQLNameStrategy.getPrimaryKeyJoinColumnName(aSuperClass, idFeature));
+ pkjc.setName(sqlNameStrategy.getPrimaryKeyJoinColumnName(aSuperClass, idFeature));
aClass.getPrimaryKeyJoinColumns().add(pkjc);
}
}
@@ -330,7 +339,7 @@ public class DefaultAnnotator {
aClass.setTable(table);
}
if (aClass.getTable() != null && aClass.getTable().getName() == null) {
- aClass.getTable().setName(optionSQLNameStrategy.getTableName(aClass));
+ aClass.getTable().setName(sqlNameStrategy.getTableName(aClass));
}
// For hibernate as well as jpox the discriminator column is only
@@ -341,7 +350,7 @@ public class DefaultAnnotator {
// note defaults of primitive types are all defined in the model
final DiscriminatorColumn dc = aFactory.createDiscriminatorColumn();
dc.setEModelElement(eclass);
- dc.setName(optionSQLNameStrategy.getDiscriminatorColumnName());
+ dc.setName(sqlNameStrategy.getDiscriminatorColumnName());
aClass.setDiscriminatorColumn(dc);
}
@@ -367,7 +376,7 @@ public class DefaultAnnotator {
final List<PAnnotatedEStructuralFeature> aIdFeatures = aClass.getPaIdFeatures();
for (PAnnotatedEStructuralFeature idef : aIdFeatures) {
final PrimaryKeyJoinColumn pkJoinColumn = PannotationFactory.eINSTANCE.createPrimaryKeyJoinColumn();
- pkJoinColumn.setName(optionSQLNameStrategy.getSecondaryTablePrimaryKeyJoinColumnName(idef));
+ pkJoinColumn.setName(sqlNameStrategy.getSecondaryTablePrimaryKeyJoinColumnName(idef));
pkJoinColumns.add(pkJoinColumn);
}
}
@@ -446,7 +455,7 @@ public class DefaultAnnotator {
}
if (aAttribute.getColumn() != null && aAttribute.getColumn().getName() == null) {
- aAttribute.getColumn().setName(optionSQLNameStrategy.getColumnName(aAttribute));
+ aAttribute.getColumn().setName(sqlNameStrategy.getColumnName(aAttribute));
}
} else if (aStructuralFeature instanceof PAnnotatedEReference) {
@@ -504,7 +513,7 @@ public class DefaultAnnotator {
// handle column naming at this level
if (aReference.getColumn() != null && aReference.getColumn().getName() == null) {
- aReference.getColumn().setName(optionSQLNameStrategy.getColumnName(aReference));
+ aReference.getColumn().setName(sqlNameStrategy.getColumnName(aReference));
}
} else {
@@ -694,7 +703,7 @@ public class DefaultAnnotator {
if (aAttribute.getJoinTable() == null) {
// note not optional because lists of simple types are embedded
- final List<String> names = optionSQLNameStrategy.getOneToManyEAttributeJoinColumns(aAttribute);
+ final List<String> names = sqlNameStrategy.getOneToManyEAttributeJoinColumns(aAttribute);
aAttribute.getJoinColumns().addAll(
getJoinColumns(names, FeatureMapUtil.isFeatureMap(eAttribute), true, otm));
}
@@ -845,13 +854,13 @@ public class DefaultAnnotator {
// see remark in manytomany about naming of jointables
if (joinTable.getName() == null) {
- joinTable.setName(optionSQLNameStrategy.getJoinTableName(aReference));
+ joinTable.setName(sqlNameStrategy.getJoinTableName(aReference));
}
// note joincolumns in jointable can be generated automatically by
// hib/jpox.
} else if (aReference.getJoinColumns() == null || aReference.getJoinColumns().isEmpty()) { // add
- final List<String> names = optionSQLNameStrategy.getOneToManyEReferenceJoinColumns(aReference);
+ final List<String> names = sqlNameStrategy.getOneToManyEReferenceJoinColumns(aReference);
aReference.getJoinColumns().addAll(getJoinColumns(names, aReference.getEmbedded() == null, true, otm));
}
}
@@ -931,14 +940,14 @@ public class DefaultAnnotator {
// if the inheritance strategy is single_table.
// now possibility to use a different naming strategy
if (joinTable.getName() == null) {
- joinTable.setName(optionSQLNameStrategy.getJoinTableName(aReference));
+ joinTable.setName(sqlNameStrategy.getJoinTableName(aReference));
}
if (joinTable.getJoinColumns().size() == 0) {
- final List<String> names = optionSQLNameStrategy.getJoinTableJoinColumns(aReference, false);
+ final List<String> names = sqlNameStrategy.getJoinTableJoinColumns(aReference, false);
joinTable.getJoinColumns().addAll(getJoinColumns(names, false, true, mtm));
}
if (joinTable.getInverseJoinColumns().size() == 0) {
- final List<String> names = optionSQLNameStrategy.getJoinTableJoinColumns(aReference, true);
+ final List<String> names = sqlNameStrategy.getJoinTableJoinColumns(aReference, true);
joinTable.getInverseJoinColumns().addAll(getJoinColumns(names, false, true, mtm));
}
}
@@ -980,10 +989,10 @@ public class DefaultAnnotator {
// the name of the targetentity
// because that's the one which is known here
if (joinTable.getName() == null) {
- joinTable.setName(optionSQLNameStrategy.getJoinTableName(aReference));
+ joinTable.setName(sqlNameStrategy.getJoinTableName(aReference));
}
if (joinTable.getJoinColumns() == null) {
- final List<String> names = optionSQLNameStrategy.getJoinTableJoinColumns(aReference, false);
+ final List<String> names = sqlNameStrategy.getJoinTableJoinColumns(aReference, false);
joinTable.getJoinColumns().addAll(getJoinColumns(names, false, true, mtm));
}
}
@@ -1077,7 +1086,7 @@ public class DefaultAnnotator {
// that it is managed from the other side. In reality this only needs to
// be done if the other side is indexed.
// NOTE: otm/mto with join table is not supported at the moment!
- final List<String> names = optionSQLNameStrategy.getManyToOneJoinColumnNames(aReference);
+ final List<String> names = sqlNameStrategy.getManyToOneJoinColumnNames(aReference);
aReference.getJoinColumns().addAll(
getJoinColumns(names, mto.isOptional(), eReference.getEOpposite() == null ||
eReference.getEOpposite().isTransient(), mto));
@@ -1282,16 +1291,16 @@ public class DefaultAnnotator {
*/
protected String getEntityName(EClass eClass) {
- if (persistenceOptions.isMapEMapAsTrueMap() && StoreUtil.isMapEntry(eClass)) {
- // ok, it is an EMAp, get the annotaetd class of the child
- EStructuralFeature feature = eClass.getEStructuralFeature("value");
- if (feature instanceof EReference) {
- return getEntityName(((EReference) feature).getEReferenceType());
- } else {
- return ((EAttribute) feature).getEType().getInstanceClassName();
- }
- }
- return StrategyUtil.getEntityName(optionEntityNameStrategy, persistenceOptions, annotatedModel, eClass);
+// if (persistenceOptions.isMapEMapAsTrueMap() && StoreUtil.isMapEntry(eClass)) {
+// // ok, it is an EMAp, get the annotaetd class of the child
+// EStructuralFeature feature = eClass.getEStructuralFeature("value");
+// if (feature instanceof EReference) {
+// return getEntityName(((EReference) feature).getEReferenceType());
+// } else {
+// return ((EAttribute) feature).getEType().getInstanceClassName();
+// }
+// }
+ return StrategyUtil.getEntityName(entityNameStrategy, persistenceOptions, annotatedModel, eClass);
}
/** Get a specific extended metadate */
@@ -1313,4 +1322,19 @@ public class DefaultAnnotator {
}
return eAnnotation.getDetails().get(key);
}
+
+ /**
+ * @return the extensionManager
+ */
+ public ExtensionManager getExtensionManager() {
+ return extensionManager;
+ }
+
+ /**
+ * @param extensionManager
+ * the extensionManager to set
+ */
+ public void setExtensionManager(ExtensionManager extensionManager) {
+ this.extensionManager = extensionManager;
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/PersistenceMappingBuilder.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/PersistenceMappingBuilder.java
index f796bb042..104003e58 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/PersistenceMappingBuilder.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/mapper/PersistenceMappingBuilder.java
@@ -27,9 +27,10 @@ import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEDataType;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
-import org.eclipse.emf.teneo.annotations.pamodel.util.BasicPamodelBuilder;
import org.eclipse.emf.teneo.annotations.parser.EAnnotationParserImporter;
import org.eclipse.emf.teneo.annotations.xml.XmlPersistenceMapper;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+import org.eclipse.emf.teneo.extension.ExtensionPoint;
import org.eclipse.emf.teneo.util.StoreUtil;
/**
@@ -37,9 +38,9 @@ import org.eclipse.emf.teneo.util.StoreUtil;
* mapping model is returned.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
-public class PersistenceMappingBuilder {
+public class PersistenceMappingBuilder implements ExtensionPoint {
/** The logger */
protected static final Log log = LogFactory.getLog(PersistenceMappingBuilder.class);
@@ -47,19 +48,23 @@ public class PersistenceMappingBuilder {
/** The instance to use */
public static final PersistenceMappingBuilder INSTANCE = new PersistenceMappingBuilder();
- /** Receives a list of ecore files and returns a Mapping */
- public PAnnotatedModel buildMapping(String[] ecoreFiles, PersistenceOptions po) {
- return buildMapping(StoreUtil.readEPackages(ecoreFiles), po);
+ /**
+ * Receives a list of ecore files and returns a Mapping
+ */
+ public PAnnotatedModel buildMapping(String[] ecoreFiles, PersistenceOptions po, ExtensionManager extensionManager) {
+ return buildMapping(StoreUtil.readEPackages(ecoreFiles), po, extensionManager);
}
- /** Builds a persistence mapping for one or more epackages */
- public PAnnotatedModel buildMapping(EPackage[] epackages, PersistenceOptions po) {
+ /**
+ * Builds a persistence mapping for one or more epackages
+ */
+ public PAnnotatedModel buildMapping(EPackage[] epackages, PersistenceOptions po, ExtensionManager extensionManager) {
// create the pamodel
// DCB: Introduce indirection so that extensions to annotation
// processing mechanism
// can provide their own model builder.
- BasicPamodelBuilder pamodelBuilder = getModelBuilder();
+ BasicPamodelBuilder pamodelBuilder = extensionManager.getExtension(BasicPamodelBuilder.class);
log.debug("Creating pamodel for the following epackages");
for (EPackage element : epackages) {
log.debug(element.getName());
@@ -69,8 +74,7 @@ public class PersistenceMappingBuilder {
log.debug("Create base pannotated model");
PAnnotatedModel pam = pamodelBuilder.getPAnnotatedModel();
- log
- .debug("Deprecated eannotations with http://annotations.elver.org or http://ejb.elver.org are ignored.");
+ log.debug("Deprecated eannotations with http://annotations.elver.org or http://ejb.elver.org are ignored.");
// if (po.isIgnoreEAnnotations()) {
// log.debug("Ignoring eannotations");
// } else {
@@ -87,19 +91,18 @@ public class PersistenceMappingBuilder {
log.debug("Ignoring annotations");
} else {
log.debug("Parse annotations");
- getEAnnotationParserImporter().process(pam);
+ extensionManager.getExtension(EAnnotationParserImporter.class).process(pam);
}
if (po.getPersistenceXmlPath() != null) {
try {
- final InputStream in = this.getClass().getClassLoader().getResourceAsStream(
- po.getPersistenceXmlPath());
+ final InputStream in = this.getClass().getClassLoader().getResourceAsStream(po.getPersistenceXmlPath());
if (in == null) {
- throw new RuntimeException(
- "Could not find persistence XML resource in classpath: \""
- + po.getPersistenceXmlPath() + "\".");
+ throw new RuntimeException("Could not find persistence XML resource in classpath: \"" +
+ po.getPersistenceXmlPath() + "\".");
}
- final XmlPersistenceMapper xmlPersistenceMapper = getXmlPersistenceMapper();
+ final XmlPersistenceMapper xmlPersistenceMapper =
+ extensionManager.getExtension(XmlPersistenceMapper.class);
xmlPersistenceMapper.setXmlMapping(in);
xmlPersistenceMapper.applyPersistenceMapping(pam);
in.close();
@@ -110,8 +113,7 @@ public class PersistenceMappingBuilder {
element.close();
}
} catch (IOException e) {
- throw new StoreAnnotationsException(
- "Exception while loading xml persistence mappings", e);
+ throw new StoreAnnotationsException("Exception while loading xml persistence mappings", e);
}
}
@@ -125,7 +127,7 @@ public class PersistenceMappingBuilder {
// processing mechanism
// can provide their own default annotation.
pam.setInitialized(true);
- getDefaultAnnotator().map(pam, po);
+ extensionManager.getExtension(DefaultAnnotator.class).map(pam, po);
log.debug("Returning created pamodel");
return pam;
@@ -144,14 +146,14 @@ public class PersistenceMappingBuilder {
final PAnnotatedEAttribute pea = (PAnnotatedEAttribute) pef;
final EDataType et = pea.getAnnotatedEAttribute().getEAttributeType();
final PAnnotatedEDataType ped = pam.getPAnnotated(et);
- if (ped == null) continue; // not an explicit modeled edatatype
+ if (ped == null) {
+ continue; // not an explicit modeled edatatype
+ }
for (EStructuralFeature esf : ped.eClass().getEAllStructuralFeatures()) {
- final EStructuralFeature asf = pea.eClass().getEStructuralFeature(
- esf.getName());
+ final EStructuralFeature asf = pea.eClass().getEStructuralFeature(esf.getName());
if (asf != null && !pea.eIsSet(asf) && ped.eIsSet(esf)) {
- log.debug("Copying value for feature " + esf.getName()
- + " from edatatype " + et.getName() + " to "
- + pea.getAnnotatedEAttribute().getName());
+ log.debug("Copying value for feature " + esf.getName() + " from edatatype " +
+ et.getName() + " to " + pea.getAnnotatedEAttribute().getName());
final Object obj = ped.eGet(esf);
if (obj instanceof Collection) {
@@ -159,9 +161,8 @@ public class PersistenceMappingBuilder {
} else if (obj instanceof EObject) {
pea.eSet(asf, EcoreUtil.copy((EObject) obj));
} else {
- throw new StoreAnnotationsException("Class "
- + obj.getClass().getName()
- + " not supported should be eobject or collection");
+ throw new StoreAnnotationsException("Class " + obj.getClass().getName() +
+ " not supported should be eobject or collection");
}
}
}
@@ -171,27 +172,6 @@ public class PersistenceMappingBuilder {
}
}
- // DCB: New methods to allow for extension
- protected DefaultAnnotator getDefaultAnnotator() {
- return new DefaultAnnotator();
- }
-
- protected BasicPamodelBuilder getModelBuilder() {
- return new BasicPamodelBuilder();
- }
-
- /** Return a java annotation parser */
- protected EAnnotationParserImporter getEAnnotationParserImporter() {
- return new EAnnotationParserImporter();
- }
-
- /**
- * Returns an XmlPersistenceMapper.
- */
- protected XmlPersistenceMapper getXmlPersistenceMapper() {
- return new XmlPersistenceMapper();
- }
-
/** Additional inputstreams for xml mappings */
protected InputStream[] getAdditionalXMLMappings() {
return new InputStream[0];
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/parser/EAnnotationParserImporter.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/parser/EAnnotationParserImporter.java
index e2a8db770..8228dd0ce 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/parser/EAnnotationParserImporter.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/parser/EAnnotationParserImporter.java
@@ -11,13 +11,12 @@
* Martin Taal
* </copyright>
*
- * $Id: EAnnotationParserImporter.java,v 1.1 2007/06/29 07:31:47 mtaal Exp $
+ * $Id: EAnnotationParserImporter.java,v 1.2 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo.annotations.parser;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -37,17 +36,17 @@ import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
import org.eclipse.emf.teneo.annotations.pannotation.PannotationPackage;
+import org.eclipse.emf.teneo.extension.ExtensionPoint;
/**
- * Walks over the pamodel and the paepackages and translates eannotations to
- * pannotation types and sets the corresponding values in the pamodel.
+ * Walks over the pamodel and the paepackages and translates eannotations to pannotation types and
+ * sets the corresponding values in the pamodel.
*
* @author <a href="mailto:mtaal at elver.org">Martin Taal</a>
*/
-public class EAnnotationParserImporter implements EClassResolver {
+public class EAnnotationParserImporter implements EClassResolver, ExtensionPoint {
/** Log it */
- private final static Log log = LogFactory
- .getLog(EAnnotationParserImporter.class);
+ private final static Log log = LogFactory.getLog(EAnnotationParserImporter.class);
/** annotation parser */
private AnnotationParser annotationParser = new AnnotationParser();
@@ -58,8 +57,7 @@ public class EAnnotationParserImporter implements EClassResolver {
/** Parse an pamodel */
public void process(PAnnotatedModel paModel) {
for (PAnnotatedEPackage pap : paModel.getPaEPackages()) {
- log.debug("Processing package "
- + pap.getAnnotatedEPackage().getName());
+ log.debug("Processing package " + pap.getAnnotatedEPackage().getName());
processAnnotatedModelElement(pap, pap.eClass().getEPackage());
// and now the eclasses
@@ -70,13 +68,11 @@ public class EAnnotationParserImporter implements EClassResolver {
/** Process package */
protected void process(PAnnotatedEPackage pap) {
for (PAnnotatedEClass pac : pap.getPaEClasses()) {
- processAnnotatedModelElement(pac, pac.getAnnotatedEClass()
- .getEPackage());
+ processAnnotatedModelElement(pac, pac.getAnnotatedEClass().getEPackage());
process(pac);
}
for (PAnnotatedEDataType pac : pap.getPaEDataTypes()) {
- processAnnotatedModelElement(pac, pac.getAnnotatedEDataType()
- .getEPackage());
+ processAnnotatedModelElement(pac, pac.getAnnotatedEDataType().getEPackage());
}
}
@@ -84,53 +80,43 @@ public class EAnnotationParserImporter implements EClassResolver {
protected void process(PAnnotatedEClass pac) {
log.debug("Processing eclass " + pac.getAnnotatedEClass().getName());
for (PAnnotatedEStructuralFeature paf : pac.getPaEStructuralFeatures()) {
- processAnnotatedModelElement(paf, paf
- .getAnnotatedEStructuralFeature().eClass().getEPackage());
+ processAnnotatedModelElement(paf, paf.getAnnotatedEStructuralFeature().eClass().getEPackage());
}
}
/** Process a type with its eannotations */
@SuppressWarnings("unchecked")
- protected void processAnnotatedModelElement(PAnnotatedEModelElement pee,
- EPackage epack) {
+ protected void processAnnotatedModelElement(PAnnotatedEModelElement pee, EPackage epack) {
log.debug("Processing " + pee.getAnnotatedElement().getName());
final ArrayList<NamedParserNode> parsedNodes = new ArrayList<NamedParserNode>();
- for (Iterator<EAnnotation> it = pee.getAnnotatedElement()
- .getEAnnotations().iterator(); it.hasNext();) {
- parsedNodes.addAll(process(it.next(), pee.getAnnotatedElement()));
+ for (EAnnotation annotation : pee.getAnnotatedElement().getEAnnotations()) {
+ parsedNodes.addAll(process(annotation, pee.getAnnotatedElement()));
}
// now also do the annotations on the edatatype (if any)
/*
- * if (pee.getAnnotatedElement() instanceof EAttribute) { final
- * EAttribute eattr = (EAttribute)pee.getAnnotatedElement(); final
- * EDataType edt = (EDataType)eattr.getEType(); for (Iterator it =
- * edt.getEAnnotations().iterator(); it.hasNext();) {
- * parsedNodes.addAll(process((EAnnotation)it.next(),
- * pee.getAnnotatedElement())); } }
+ * if (pee.getAnnotatedElement() instanceof EAttribute) { final EAttribute eattr =
+ * (EAttribute)pee.getAnnotatedElement(); final EDataType edt = (EDataType)eattr.getEType();
+ * for (Iterator it = edt.getEAnnotations().iterator(); it.hasNext();) {
+ * parsedNodes.addAll(process((EAnnotation)it.next(), pee.getAnnotatedElement())); } }
*/
// now the parsed nodes should be translated into features of the
// enamedelement
// this is done multiplelevel
- log
- .debug("Number of parsed typename annotations "
- + parsedNodes.size());
- for (Iterator<NamedParserNode> it = parsedNodes.iterator(); it
- .hasNext();) {
- final ComplexNode cn = (ComplexNode) it.next();
+ log.debug("Number of parsed typename annotations " + parsedNodes.size());
+ for (NamedParserNode namedParserNode : parsedNodes) {
+ final ComplexNode cn = (ComplexNode) namedParserNode;
if (cn.isList()) {
// find the efeature
- final EStructuralFeature ef = getEStructuralFeature(pee
- .eClass(), cn.getName());
+ final EStructuralFeature ef = getEStructuralFeature(pee.eClass(), cn.getName());
pee.eSet(ef, cn.convert(this));
} else {
EObject eobj = (EObject) cn.convert(this);
boolean found = false;
for (EReference eref : pee.eClass().getEAllReferences()) {
if (eref.getEReferenceType().isInstance(eobj)) {
- log.debug("Found EReference " + eref.getName()
- + " for " + eobj.eClass().getName());
+ log.debug("Found EReference " + eref.getName() + " for " + eobj.eClass().getName());
if (eref.isMany()) {
((List) pee.eGet(eref)).add(eobj);
} else {
@@ -141,10 +127,8 @@ public class EAnnotationParserImporter implements EClassResolver {
}
}
if (!found) {
- throw new AnnotationParserException("The eclass: "
- + pee.eClass().getName()
- + " does not have an efeature for "
- + eobj.eClass().getName());
+ throw new AnnotationParserException("The eclass: " + pee.eClass().getName() +
+ " does not have an efeature for " + eobj.eClass().getName());
}
}
}
@@ -167,16 +151,12 @@ public class EAnnotationParserImporter implements EClassResolver {
}
log.debug("Processing annotations ");
- for (Map.Entry<String, String> pAnnotationDetails : ea.getDetails()
- .entrySet()) {
+ for (Map.Entry<String, String> pAnnotationDetails : ea.getDetails().entrySet()) {
final String fName = pAnnotationDetails.getKey();
// todo externalize
- if (fName.compareToIgnoreCase("appinfo") == 0
- || fName.compareToIgnoreCase("value") == 0) {
- log.debug("Annotation content: \n "
- + (String) pAnnotationDetails.getValue());
- result.addAll(annotationParser.parse(ene,
- (String) pAnnotationDetails.getValue()));
+ if (fName.compareToIgnoreCase("appinfo") == 0 || fName.compareToIgnoreCase("value") == 0) {
+ log.debug("Annotation content: \n " + pAnnotationDetails.getValue());
+ result.addAll(annotationParser.parse(ene, pAnnotationDetails.getValue()));
}
}
return result;
@@ -196,11 +176,11 @@ public class EAnnotationParserImporter implements EClassResolver {
/** Is a valid source */
protected boolean isValidSource(String source) {
- if (source == null)
+ if (source == null) {
return false;
+ }
// todo externalize
- return source.startsWith("teneo.jpa")
- || source.startsWith("teneo.mapping");
+ return source.startsWith("teneo.jpa") || source.startsWith("teneo.mapping");
}
/** Find the efeature */
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/xml/XmlPersistenceMapper.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/xml/XmlPersistenceMapper.java
index b89f1256c..447f98df4 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/xml/XmlPersistenceMapper.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/annotations/xml/XmlPersistenceMapper.java
@@ -12,7 +12,7 @@
* Martin Taal
* </copyright>
*
- * $Id: XmlPersistenceMapper.java,v 1.1 2007/06/29 07:31:47 mtaal Exp $
+ * $Id: XmlPersistenceMapper.java,v 1.2 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo.annotations.xml;
@@ -27,6 +27,7 @@ import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
+import org.eclipse.emf.teneo.extension.ExtensionPoint;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
@@ -35,11 +36,11 @@ import org.xml.sax.SAXNotRecognizedException;
*
* @author <a href="lmfridael@elver.org">Laurens Fridael</a>
*/
-public class XmlPersistenceMapper {
-
+public class XmlPersistenceMapper implements ExtensionPoint {
+
/** The inputStream containing the xml document */
private InputStream xmlMapping;
-
+
/** The logger */
protected static final Log log = LogFactory.getLog(XmlPersistenceMapper.class);
@@ -75,7 +76,7 @@ public class XmlPersistenceMapper {
final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
saxParserFactory.setValidating(true);
-
+
saxParser = saxParserFactory.newSAXParser();
} catch (ParserConfigurationException e) {
throw new ParseXMLAnnotationsException(e);
@@ -86,20 +87,20 @@ public class XmlPersistenceMapper {
try {
try {
saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
- "http://www.w3.org/2001/XMLSchema");
+ "http://www.w3.org/2001/XMLSchema");
saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", this.getClass()
- .getResourceAsStream("persistence-mapping.xsd"));
+ .getResourceAsStream("persistence-mapping.xsd"));
} catch (SAXNotRecognizedException s) {
- log.warn("Properties schemaSource and/or schemaLanguage are not supported, setvalidating=false. " +
- "Probably running 1.4 with an old crimson sax parser. Ignoring this and continuing with " +
- "a non-validating and name-space-aware sax parser");
+ log.warn("Properties schemaSource and/or schemaLanguage are not supported, setvalidating=false. "
+ + "Probably running 1.4 with an old crimson sax parser. Ignoring this and continuing with "
+ + "a non-validating and name-space-aware sax parser");
final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
saxParserFactory.setValidating(false);
saxParser = saxParserFactory.newSAXParser();
}
- saxParser.parse(xmlMapping, new XmlPersistenceContentHandler(pAnnotatedModel, getPrefix(),
- this.getClass().getResourceAsStream("persistence-mapping.xsd")));
+ saxParser.parse(xmlMapping, new XmlPersistenceContentHandler(pAnnotatedModel, getPrefix(), this.getClass()
+ .getResourceAsStream("persistence-mapping.xsd")));
} catch (SAXException e) {
throw new ParseXMLAnnotationsException(e);
} catch (IOException e) {
@@ -118,5 +119,5 @@ public class XmlPersistenceMapper {
/** Return a prefix which are used by a subpackage to make efeatures unique */
protected String getPrefix() {
return "";
- }
+ }
}
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/classloader/ClassLoaderStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/classloader/ClassLoaderStrategy.java
index 6c1a888a5..b6b037970 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/classloader/ClassLoaderStrategy.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/classloader/ClassLoaderStrategy.java
@@ -12,19 +12,21 @@
*
* </copyright>
*
- * $Id: ClassLoaderStrategy.java,v 1.2 2007/02/01 12:34:21 mtaal Exp $
+ * $Id: ClassLoaderStrategy.java,v 1.3 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo.classloader;
+import org.eclipse.emf.teneo.extension.ExtensionPoint;
+
/**
* Interface for classes which determine which classloader to use.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
-public interface ClassLoaderStrategy {
+public interface ClassLoaderStrategy extends ExtensionPoint {
/**
* Return the classloader
*/
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/DatastoreAware.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/DatastoreAware.java
new file mode 100644
index 000000000..592189228
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/DatastoreAware.java
@@ -0,0 +1,32 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: DatastoreAware.java,v 1.1 2007/07/11 14:41:06 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+import org.eclipse.emf.teneo.DataStore;
+
+/**
+ * An extension implementing this interface will be able to 'receive' an instance of a Pamodel.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface DatastoreAware {
+ /** Set the relevant pamodel */
+ void setDatastore(DataStore dataStore);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/DefaultExtensionManager.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/DefaultExtensionManager.java
new file mode 100644
index 000000000..2e1faeacd
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/DefaultExtensionManager.java
@@ -0,0 +1,180 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: DefaultExtensionManager.java,v 1.1 2007/07/11 14:41:06 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.emf.teneo.classloader.ClassLoaderResolver;
+import org.eclipse.emf.teneo.classloader.ClassLoaderStrategy;
+
+/**
+ * Manages a set of extensions. Currently for each extension point there will always be only one
+ * extension instance.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public class DefaultExtensionManager implements ExtensionManager {
+
+ private static Log log = LogFactory.getLog(DefaultExtensionManager.class);
+
+ // Uses the default for now
+ private ConcurrentHashMap<String, Extension> extensionRegistry = new ConcurrentHashMap<String, Extension>();
+
+ // The instances of the extensions
+ private ConcurrentHashMap<String, ExtensionPoint> extensionInstances =
+ new ConcurrentHashMap<String, ExtensionPoint>();
+
+ public DefaultExtensionManager() {
+ ExtensionUtil.registerDefaultExtensions(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.extension.ExtensionManager#registerExtension(org.eclipse.emf.teneo.extension.Extension)
+ */
+ public void registerExtension(Extension extension) {
+ // check if there is already a non-default plugin registered with the same name
+ if (extension.isDefaultExtension()) {
+ final Extension currentExtension = extensionRegistry.get(extension.getPoint());
+ if (currentExtension != null && !currentExtension.isDefaultExtension()) {
+ log.debug("Not registering extension " + extension);
+ log.debug("There is already a user plugin defined: " + currentExtension);
+ return;
+ }
+ }
+ if (extension.getPoint() == null) {
+ throw new TeneoExtensionException("Point of extension may not be null");
+ }
+ if (extension.getClassName() == null) {
+ throw new TeneoExtensionException("Classname of extension: " + extension.getPoint() + " may not be null");
+ }
+ log.debug("Registering " + extension);
+ extensionRegistry.put(extension.getPoint(), extension);
+
+ // remove any instances for this extension
+ extensionInstances.remove(extension.getPoint());
+ }
+
+ public void registerExtension(String point, String className) {
+ final Extension currentExtension = extensionRegistry.get(point);
+ if (currentExtension == null) {
+ throw new TeneoExtensionException("No default extension found using point: " + point +
+ " is the point value correct?");
+ }
+ final Extension newExtension = new Extension();
+ newExtension.setPoint(point);
+ newExtension.setClassName(className);
+ newExtension.setDefaultExtension(false);
+ newExtension.setSingleton(currentExtension.isSingleton());
+ registerExtension(newExtension);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.extension.ExtensionManager#getExtension(java.lang.String)
+ */
+ public ExtensionPoint getExtension(String point) {
+ log.debug("Searching extension " + point);
+ final Extension extension = extensionRegistry.get(point);
+ if (extension == null) {
+ throw new TeneoExtensionException("Extension point " + point + " not registered");
+ }
+
+ if (extension.isSingleton()) {
+ final ExtensionPoint extensionInstance = extensionInstances.get(point);
+ if (extensionInstance != null) {
+ log.debug("Found instance " + extensionInstance.getClass().getClass());
+ return extensionInstance;
+ }
+ }
+
+ // get the clz
+ final Class<?> clz;
+ // see if the classloader strategy was already registered
+ final ClassLoaderStrategy cls =
+ (ClassLoaderStrategy) extensionInstances.get(ClassLoaderStrategy.class.getName());
+ try {
+ if (cls != null) { // already there use it to load the class
+ clz = cls.getClassLoader().loadClass(extension.getClassName());
+ } else {
+ // not there try to find it in the extension registry
+ final Extension clsExtension = extensionRegistry.get(ClassLoaderStrategy.class.getName());
+ if (clsExtension == null) {
+ // not there use the default classloader
+ clz = ClassLoaderResolver.classForName(extension.getClassName());
+ } else {
+ // create the classloader extension and register it
+ final Class<?> clsClass = ClassLoaderResolver.classForName(clsExtension.getClassName());
+ ClassLoaderStrategy clsInstance = null;
+ try {
+ clsInstance = (ClassLoaderStrategy) clsClass.newInstance();
+ extensionInstances.put(clsExtension.getPoint(), clsInstance);
+ } catch (Exception e) {
+ throw new TeneoExtensionException("Exception while instantiating class " + clsClass.getName(),
+ e);
+ }
+ // now get the class we were looking for
+ clz = clsInstance.getClassLoader().loadClass(extension.getClassName());
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ throw new TeneoExtensionException("Class not found: " + extension.getClassName(), e);
+ }
+
+ // check if this class indeed implements ExtensionPoint
+ if (!(ExtensionPoint.class.isAssignableFrom(clz))) {
+ throw new TeneoExtensionException("The requested extension " + clz.getName() +
+ " does not implement the interface " + ExtensionPoint.class.getName());
+ }
+
+ try {
+ final ExtensionPoint extensionInstance = (ExtensionPoint) clz.newInstance();
+ log.debug("Created extensionPoint instance: " + extensionInstance.getClass().getName());
+ if (extensionInstance instanceof ExtensionManagerAware) {
+ ((ExtensionManagerAware) extensionInstance).setExtensionManager(this);
+ }
+ if (extensionInstance instanceof ExtensionInitializable) {
+ log.debug("Initializing extension " + extensionInstance.getClass().getName());
+ ((ExtensionInitializable) extensionInstance).initializeExtension();
+ }
+ if (extension.isSingleton()) {
+ log.debug("Caching extension instance as singleton " + extension);
+ extensionInstances.put(point, extensionInstance);
+ }
+ return extensionInstance;
+ } catch (Exception e) {
+ throw new TeneoExtensionException("Exception while instantiating: " + extension.getClassName(), e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.extension.ExtensionManager#getExtension(java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T getExtension(Class<T> clz) {
+ return (T) getExtension(clz.getName());
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/Extension.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/Extension.java
new file mode 100644
index 000000000..bb82b358b
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/Extension.java
@@ -0,0 +1,109 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: Extension.java,v 1.1 2007/07/11 14:41:05 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+/**
+ * An Extension sets a certain ExtensionPoint in Teneo. Teneo will register default Extensions which
+ * can be overridden by a user.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public class Extension {
+
+ // the extension point id, normally a classname of an ExtensionPoint
+ private String point;
+
+ // the classname of the extensionpoint implementor
+ private String className;
+
+ // Is this a default extension registered by Teneo or a user plugin
+ private boolean defaultExtension = false;
+
+ // Is this a singleton within one ExtensionManager, default is true
+ private boolean singleton = true;
+
+ /**
+ * @return the point
+ */
+ public String getPoint() {
+ return point;
+ }
+
+ /**
+ * @param point
+ * the point to set
+ */
+ public void setPoint(String point) {
+ this.point = point;
+ }
+
+ /**
+ * @return the className
+ */
+ public String getClassName() {
+ return className;
+ }
+
+ /**
+ * @param className
+ * the className to set
+ */
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ /**
+ * @return the defaultExtension
+ */
+ public boolean isDefaultExtension() {
+ return defaultExtension;
+ }
+
+ /**
+ * Default is false, this is the correct value for extensions created by users of Teneo. So
+ * normally this method does not need to be called.
+ *
+ * @param defaultExtension
+ * the defaultExtension to set
+ */
+ public void setDefaultExtension(boolean defaultExtension) {
+ this.defaultExtension = defaultExtension;
+ }
+
+ @Override
+ public String toString() {
+ return " point: " + getPoint() + " classname: " + getClassName() + " default: " + isDefaultExtension();
+ }
+
+ /**
+ * @return the singleton
+ */
+ public boolean isSingleton() {
+ return singleton;
+ }
+
+ /**
+ * @param singleton
+ * the singleton to set
+ */
+ public void setSingleton(boolean singleton) {
+ this.singleton = singleton;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionInitializable.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionInitializable.java
new file mode 100644
index 000000000..2164df9c0
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionInitializable.java
@@ -0,0 +1,32 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ExtensionInitializable.java,v 1.1 2007/07/11 14:41:05 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+
+/**
+ * Defines an initialize method which is called after creating the object and after setting the
+ * extensionmanager (if the object is ExtensionManagerAware).
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface ExtensionInitializable {
+ /** Initialize the object */
+ void initializeExtension();
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionManager.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionManager.java
new file mode 100644
index 000000000..1dc1ff712
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionManager.java
@@ -0,0 +1,52 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ExtensionManager.java,v 1.1 2007/07/11 14:41:05 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+/**
+ * Manages a set of extensions. Currently for each extension point there will always be only one
+ * extension instance.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ExtensionManager {
+
+ /**
+ * Register an extension. If there is already a non-default extension registered then it is not
+ * overwritten.
+ */
+ public abstract void registerExtension(Extension extension);
+
+ /** Return an instance of an extension */
+ public abstract ExtensionPoint getExtension(String point);
+
+ /**
+ * Convenience method which also performs the casting and uses the classname of the class
+ * parameter to search for the plugin.
+ */
+ @SuppressWarnings("unchecked")
+ public abstract <T> T getExtension(Class<T> clz);
+
+ /**
+ * Convenience method to register a user extension overriding a current extension. It will
+ * search for an existing extension using the point. If not found then an exception is thrown.
+ * In case a completely new extension is to be registered then use the registerExtension method.
+ * The singleton value from the existing extension is used. value is used from that extension.
+ */
+ public void registerExtension(String point, String className);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionManagerAware.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionManagerAware.java
new file mode 100644
index 000000000..749337f88
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionManagerAware.java
@@ -0,0 +1,32 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ExtensionManagerAware.java,v 1.1 2007/07/11 14:41:06 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+
+/**
+ * An extension implementing this interface will be able to 'receive' an instance of the
+ * ExtensionManager which created it.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface ExtensionManagerAware {
+ /** Set the extensionManager */
+ void setExtensionManager(ExtensionManager extensionManager);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionPoint.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionPoint.java
new file mode 100644
index 000000000..70f0ba48e
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionPoint.java
@@ -0,0 +1,30 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ExtensionPoint.java,v 1.1 2007/07/11 14:41:05 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+/**
+ * Is a marker interface to mark a class to be replacable by a user extension. The classname or
+ * interface implementing this interface is also the name of the ExtensionPoint (the value of the
+ * point attribute in the extension).
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface ExtensionPoint {
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionUtil.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionUtil.java
new file mode 100644
index 000000000..83e8c000f
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/ExtensionUtil.java
@@ -0,0 +1,110 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ExtensionUtil.java,v 1.1 2007/07/11 14:41:06 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+import org.eclipse.emf.teneo.annotations.mapper.BasicPamodelBuilder;
+import org.eclipse.emf.teneo.annotations.mapper.DefaultAnnotator;
+import org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingBuilder;
+import org.eclipse.emf.teneo.annotations.parser.EAnnotationParserImporter;
+import org.eclipse.emf.teneo.annotations.xml.XmlPersistenceMapper;
+import org.eclipse.emf.teneo.classloader.ClassLoaderStrategy;
+import org.eclipse.emf.teneo.classloader.ContextClassLoaderStrategy;
+import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy;
+import org.eclipse.emf.teneo.mapping.strategy.SQLNameStrategy;
+import org.eclipse.emf.teneo.mapping.strategy.impl.ClassicSQLNameStrategy;
+import org.eclipse.emf.teneo.mapping.strategy.impl.EntityResolvingNameStrategy;
+
+/**
+ * Contains simple utility methods.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public class ExtensionUtil {
+
+ /** Creates a default extension */
+ public static Extension createExtension(Class<?> extensionPoint, Class<?> clz) {
+ final Extension extension = new Extension();
+ extension.setPoint(extensionPoint.getName());
+ extension.setClassName(clz.getName());
+ extension.setDefaultExtension(true);
+ return extension;
+ }
+
+ public static Extension createExtension(String pointClassName, boolean singleton) {
+ final Extension extension = new Extension();
+ extension.setPoint(pointClassName);
+ extension.setClassName(pointClassName);
+ extension.setDefaultExtension(true);
+ extension.setSingleton(singleton);
+ return extension;
+ }
+
+ /** Register a number of default Extensions */
+ public static void registerDefaultExtensions(ExtensionManager em) {
+
+ // the ones coming from this plugin
+ em.registerExtension(createExtension(BasicPamodelBuilder.class, BasicPamodelBuilder.class));
+ em.registerExtension(createExtension(DefaultAnnotator.class, DefaultAnnotator.class));
+ em.registerExtension(createExtension(EAnnotationParserImporter.class, EAnnotationParserImporter.class));
+ em.registerExtension(createExtension(PersistenceMappingBuilder.class, PersistenceMappingBuilder.class));
+ em.registerExtension(createExtension(XmlPersistenceMapper.class, XmlPersistenceMapper.class));
+ em.registerExtension(createExtension(ClassLoaderStrategy.class, ContextClassLoaderStrategy.class));
+ em.registerExtension(createExtension(EntityNameStrategy.class, EntityResolvingNameStrategy.class));
+ em.registerExtension(createExtension(SQLNameStrategy.class, ClassicSQLNameStrategy.class));
+
+ // from the hibernate plugin
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.HbContext", true));
+
+ // hibernate mapper
+ em
+ .registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGenerator",
+ false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.MappingContext", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.BasicMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.EmbeddedMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.EntityMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.IdMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.ManyAttributeMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.ManyToManyMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.ManyToOneMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.MappingContext", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.OneToManyMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.hibernate.mapper.OneToOneMapper", false));
+
+ // jpox mapping
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.association.EmbeddedMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.association.ManyToManyMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.association.ManyToOneMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.association.OneToManyMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.association.OneToOneMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.property.BasicMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.property.ColumnMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.property.EClassFeatureMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.property.IdMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.property.InheritanceMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.property.JoinColumnMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.property.ManyBasicMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.property.TableMapper", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.JPOXMappingGenerator", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.MappingContext", false));
+ em.registerExtension(createExtension("org.eclipse.emf.teneo.jpox.mapper.NamingHandler", false));
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/PaModelAware.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/PaModelAware.java
new file mode 100644
index 000000000..18d377db9
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/PaModelAware.java
@@ -0,0 +1,33 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: PaModelAware.java,v 1.1 2007/07/11 14:41:05 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
+
+/**
+ * A extension implementing this interface will be able to 'receive' an instance of a
+ * PAnnotatedModel.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface PaModelAware {
+ /** Set the relevant pamodel */
+ void setPaModel(PAnnotatedModel paModel);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/PersistenceOptionsAware.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/PersistenceOptionsAware.java
new file mode 100644
index 000000000..67619dc77
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/PersistenceOptionsAware.java
@@ -0,0 +1,33 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: PersistenceOptionsAware.java,v 1.1 2007/07/11 14:41:05 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+
+/**
+ * An extension implementing this interface will be able to 'receive' an instance of the
+ * PersistenceOptions.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface PersistenceOptionsAware {
+ /** Set the relevant pamodel */
+ void setPersistenceOptions(PersistenceOptions persistenceOptions);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/TeneoExtensionException.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/TeneoExtensionException.java
new file mode 100644
index 000000000..1447313dc
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/extension/TeneoExtensionException.java
@@ -0,0 +1,48 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: TeneoExtensionException.java,v 1.1 2007/07/11 14:41:06 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.extension;
+
+import org.eclipse.emf.teneo.TeneoException;
+
+/**
+ * Is thrown in case of an illegal situation in handling extensions.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+
+public class TeneoExtensionException extends TeneoException {
+ /**
+ * Serializable id
+ */
+ private static final long serialVersionUID = 7433341056815136417L;
+
+ /**
+ * The constructor, logs the exception also
+ */
+ public TeneoExtensionException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ /**
+ * The constructor, logs the exception also
+ */
+ public TeneoExtensionException(String msg) {
+ super(msg);
+ }
+}
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/EntityNameStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/EntityNameStrategy.java
index 2ef6085da..80d75f5b1 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/EntityNameStrategy.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/EntityNameStrategy.java
@@ -12,23 +12,23 @@
*
* </copyright>
*
- * $Id: EntityNameStrategy.java,v 1.1 2007/06/29 07:31:47 mtaal Exp $
+ * $Id: EntityNameStrategy.java,v 1.2 2007/07/11 14:41:05 mtaal Exp $
*/
package org.eclipse.emf.teneo.mapping.strategy;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.teneo.extension.ExtensionPoint;
+import org.eclipse.emf.teneo.extension.PaModelAware;
/**
- * Converter from entityname to and from an eclass. The entityname is used in the
- * hql, etc.
+ * Converter from entityname to and from an eclass. The entityname is used in the hql, etc.
*
* @author <a href="mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
-public interface EntityNameStrategy {
+public interface EntityNameStrategy extends ExtensionPoint, PaModelAware {
/** The EObject eclass */
public static EClass EOBJECT_ECLASS = (EClass) EcorePackage.eINSTANCE.getEClassifier("EObject");
@@ -37,16 +37,15 @@ public interface EntityNameStrategy {
public static String EOBJECT_ECLASS_NAME = EcorePackage.eINSTANCE.getName() + "_" + EOBJECT_ECLASS.getName();
/**
- * Determines the name for a given EClass. This name can be used in jsf
- * pages and queries.
+ * Determines the name for a given EClass. This name can be used in jsf pages and queries.
*
- * Note if the eClass is the EObject eclass then the string
- * EOBJECT_ECLASS_NAME must be returned.
+ * Note if the eClass is the EObject eclass then the string EOBJECT_ECLASS_NAME must be
+ * returned.
*/
public String toEntityName(EClass eClass);
/**
* Return the EClass for a certain name, searches in the array of epackages
*/
- public EClass toEClass(String eClassName, EPackage[] epackages);
+ public EClass toEClass(String eClassName);
} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/SQLNameStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/SQLNameStrategy.java
index d176e9d12..2c2ae1044 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/SQLNameStrategy.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/SQLNameStrategy.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: SQLNameStrategy.java,v 1.1 2007/06/29 07:31:47 mtaal Exp $
+ * $Id: SQLNameStrategy.java,v 1.2 2007/07/11 14:41:05 mtaal Exp $
*/
package org.eclipse.emf.teneo.mapping.strategy;
@@ -24,17 +24,18 @@ import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEAttribute;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEReference;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature;
+import org.eclipse.emf.teneo.extension.ExtensionPoint;
/**
- * Takes care of creating correct names for sql artifacts such as tables, columns,
- * foreign keys, etc.
+ * Takes care of creating correct names for sql artifacts such as tables, columns, foreign keys,
+ * etc.
*
* Note that strategies are normally created once for each instance of persistenceoptions.
*
* @author <a href="mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
-public interface SQLNameStrategy {
+public interface SQLNameStrategy extends ExtensionPoint {
String getPrimaryKeyJoinColumnName(PAnnotatedEClass aSuperClass, String idFeature);
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/StrategyUtil.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/StrategyUtil.java
index 0d6e87f6e..7a6f325c7 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/StrategyUtil.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/StrategyUtil.java
@@ -3,7 +3,7 @@
* 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 - Initial API and
- * implementation </copyright> $Id: StrategyUtil.java,v 1.1 2007/06/29 07:31:47 mtaal Exp $
+ * implementation </copyright> $Id: StrategyUtil.java,v 1.2 2007/07/11 14:41:05 mtaal Exp $
*/
package org.eclipse.emf.teneo.mapping.strategy;
@@ -26,7 +26,7 @@ import org.eclipse.emf.teneo.util.StoreUtil;
* Contains different util methods related to strategies.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class StrategyUtil {
@@ -57,10 +57,10 @@ public class StrategyUtil {
return ((EAttribute) feature).getEType().getInstanceClassName();
}
}
-
- if (aclass != null && aclass.getEntity() != null && aclass.getEntity().getName() != null) {
- return aclass.getEntity().getName();
- }
+//
+// if (aclass != null && aclass.getEntity() != null && aclass.getEntity().getName() != null) {
+// return aclass.getEntity().getName();
+// }
return ens.toEntityName(eclass);
}
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/ClassicSQLNameStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/ClassicSQLNameStrategy.java
index 9df4632b2..dd69396d0 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/ClassicSQLNameStrategy.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/ClassicSQLNameStrategy.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: ClassicSQLNameStrategy.java,v 1.2 2007/07/09 12:54:58 mtaal Exp $
+ * $Id: ClassicSQLNameStrategy.java,v 1.3 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo.mapping.strategy.impl;
@@ -30,19 +30,21 @@ import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEReference;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEStructuralFeature;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+import org.eclipse.emf.teneo.extension.ExtensionManagerAware;
import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy;
import org.eclipse.emf.teneo.mapping.strategy.SQLNameStrategy;
import org.eclipse.emf.teneo.mapping.strategy.StrategyUtil;
import org.eclipse.emf.teneo.util.AssertUtil;
/**
- * Implements the sql naming strategy of older versions of Teneo. This implementation
- * is driven by the options set in the PersistenceOptions.
+ * Implements the sql naming strategy of older versions of Teneo. This implementation is driven by
+ * the options set in the PersistenceOptions.
*
* @author <a href="mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
-public class ClassicSQLNameStrategy implements SQLNameStrategy {
+public class ClassicSQLNameStrategy implements SQLNameStrategy, ExtensionManagerAware {
// The logger
protected static final Log log = LogFactory.getLog(ClassicSQLNameStrategy.class);
@@ -51,11 +53,13 @@ public class ClassicSQLNameStrategy implements SQLNameStrategy {
private String optionJoinTableNamingStrategy;
private String optionJoinColumnNamingStrategy;
private int optionMaximumSqlLength;
- private EntityNameStrategy optionEntityNameStrategy;
+ private EntityNameStrategy entityNameStrategy;
private PersistenceOptions persistenceOptions;
private boolean optionSQLUpperCase = false;
private boolean optionSQLLowerCase = false;
+ private ExtensionManager extensionManager;
+
public String getPrimaryKeyJoinColumnName(PAnnotatedEClass aSuperClass, String idFeature) {
return convert(getEntityName(aSuperClass.getPaModel(), aSuperClass.getAnnotatedEClass()) + "_" + idFeature,
true);
@@ -74,10 +78,9 @@ public class ClassicSQLNameStrategy implements SQLNameStrategy {
return convert(aStructuralFeature.getAnnotatedEStructuralFeature().getName());
}
- /**
- * Return the name of the foreign key used for this aReference.
- * If null is returned then the name of the foreign key is not set
- * Returns null in this case.
+ /**
+ * Return the name of the foreign key used for this aReference. If null is returned then the
+ * name of the foreign key is not set Returns null in this case.
*/
public String getForeignKeyName(PAnnotatedEReference aReference) {
return null;
@@ -187,7 +190,7 @@ public class ClassicSQLNameStrategy implements SQLNameStrategy {
return result;
}
- /**
+ /**
* Return a list of join columns for a join table for a many to many
*/
public List<String> getJoinTableJoinColumns(PAnnotatedEReference aReference, boolean inverse) {
@@ -274,7 +277,7 @@ public class ClassicSQLNameStrategy implements SQLNameStrategy {
return convert("DTYPE"); // replace with constant somewhere
}
- /**
+ /**
* Return the name of the version column used.
*/
public String getVersionColumnName() {
@@ -282,7 +285,7 @@ public class ClassicSQLNameStrategy implements SQLNameStrategy {
}
/**
- * Return the column name for the id column of the idbag join table.
+ * Return the column name for the id column of the idbag join table.
*/
public String getIdBagIDColumn() {
return convert(persistenceOptions.getIDBagIDColumnName());
@@ -293,15 +296,14 @@ public class ClassicSQLNameStrategy implements SQLNameStrategy {
return convert(persistenceOptions.getIdColumnName());
}
- /**
- * Sets the PersistenceOptions used. This is mainly to support backward compatibility
- * with older version in which the naming strategy was controlled by options.
+ /**
+ * Sets the PersistenceOptions used. This is mainly to support backward compatibility with older
+ * version in which the naming strategy was controlled by options.
*/
public void setPersistenceOptions(PersistenceOptions po) {
optionMaximumSqlLength = po.getMaximumSqlNameLength();
optionJoinTableNamingStrategy = po.getJoinTableNamingStrategy();
optionJoinColumnNamingStrategy = po.getJoinColumnNamingStrategy();
- optionEntityNameStrategy = po.getEntityNameStrategy();
final String optionSQLCaseStrategy = po.getSQLCaseStrategy();
if (optionSQLCaseStrategy.toLowerCase().compareTo("lowercase") == 0) {
@@ -314,7 +316,7 @@ public class ClassicSQLNameStrategy implements SQLNameStrategy {
// Returns the entityname of the refered to entity
private String getEntityName(PAnnotatedModel paModel, EClass eClass) {
- return StrategyUtil.getEntityName(optionEntityNameStrategy, persistenceOptions, paModel, eClass);
+ return StrategyUtil.getEntityName(getEntityNameStrategy(), persistenceOptions, paModel, eClass);
}
public String convert(String name) {
@@ -342,4 +344,29 @@ public class ClassicSQLNameStrategy implements SQLNameStrategy {
assert (nameHere.compareTo(nameThere) != 0);
return nameHere.compareTo(nameThere) > 0;
}
+
+ /**
+ * @return the extensionManager
+ */
+ public ExtensionManager getExtensionManager() {
+ return extensionManager;
+ }
+
+ /**
+ * @param extensionManager
+ * the extensionManager to set
+ */
+ public void setExtensionManager(ExtensionManager extensionManager) {
+ this.extensionManager = extensionManager;
+ }
+
+ /**
+ * @return the entityNameStrategy
+ */
+ public EntityNameStrategy getEntityNameStrategy() {
+ if (entityNameStrategy == null) {
+ entityNameStrategy = getExtensionManager().getExtension(EntityNameStrategy.class);
+ }
+ return entityNameStrategy;
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/DefaultEntityNameStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/DefaultEntityNameStrategy.java
index b766689e6..b1e797c90 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/DefaultEntityNameStrategy.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/DefaultEntityNameStrategy.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: DefaultEntityNameStrategy.java,v 1.1 2007/06/29 07:31:47 mtaal Exp $
+ * $Id: DefaultEntityNameStrategy.java,v 1.2 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo.mapping.strategy.impl;
@@ -20,9 +20,10 @@ package org.eclipse.emf.teneo.mapping.strategy.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
import org.eclipse.emf.teneo.classloader.ClassLoaderResolver;
import org.eclipse.emf.teneo.classloader.StoreClassLoadException;
import org.eclipse.emf.teneo.ecore.EModelResolver;
@@ -33,7 +34,7 @@ import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy;
* name.
*
* @author <a href="mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class DefaultEntityNameStrategy implements EntityNameStrategy {
@@ -43,6 +44,9 @@ public class DefaultEntityNameStrategy implements EntityNameStrategy {
/** The singleton instance as it is thread safe */
public static final DefaultEntityNameStrategy INSTANCE = new DefaultEntityNameStrategy();
+ // The pamodel for which this is done
+ private PAnnotatedModel paModel;
+
/*
* (non-Javadoc)
*
@@ -63,12 +67,12 @@ public class DefaultEntityNameStrategy implements EntityNameStrategy {
if (eClass.getName() == null) {
throw new IllegalArgumentException(
- "EClass "
- + eClass.toString()
- + " has a null name."
- + "This can occur if epackages which refer to eachother are placed in different ecore/xsd files "
- + "and they are not read using one resource set. The reference from one epackage to another must be "
- + "resolvable by EMF.");
+ "EClass " +
+ eClass.toString() +
+ " has a null name." +
+ "This can occur if epackages which refer to eachother are placed in different ecore/xsd files " +
+ "and they are not read using one resource set. The reference from one epackage to another must be " +
+ "resolvable by EMF.");
}
return eClass.getName();
@@ -79,7 +83,7 @@ public class DefaultEntityNameStrategy implements EntityNameStrategy {
*
* @see org.elver.ecore.spring.EClassResolver#resolve(java.lang.String)
*/
- public EClass toEClass(String eClassName, EPackage[] epackages) {
+ public EClass toEClass(String eClassName) {
if (eClassName == null) {
throw new IllegalArgumentException("eClassName may not be null");
}
@@ -90,16 +94,20 @@ public class DefaultEntityNameStrategy implements EntityNameStrategy {
// now try all epackages
EClass eClass = null;
- for (final EPackage ePackage : epackages) {
- final EClassifier eClassifier = ePackage.getEClassifier(eClassName);
- if (eClassifier instanceof EClass) {
- if (eClass != null) {
- // doubly entry! Actually require different resolver
- throw new IllegalArgumentException("There is more than one EClass with the same name ("
- + eClassName + " in EPackage " + eClass.getEPackage().getName() + " and "
- + ePackage.getName() + ". A different EClassResolver should be used.");
+ for (final PAnnotatedEPackage aPackage : getPaModel().getPaEPackages()) {
+ for (final PAnnotatedEClass aClass : aPackage.getPaEClasses()) {
+ final EClass checkEClass = aClass.getAnnotatedEClass();
+ if (checkEClass.getName().compareTo(eClassName) == 0) {
+ if (eClass != null) {
+ // doubly entry! Actually require different resolver
+ // doubly entry! Actually require different resolver
+ throw new IllegalArgumentException("There is more than one EClass with the same name (" +
+ eClassName + " in EPackage " + eClass.getEPackage().getName() + " and " +
+ aPackage.getAnnotatedEPackage().getName() +
+ ". A different EClassResolver should be used.");
+ }
}
- eClass = (EClass) eClassifier;
+ eClass = checkEClass;
}
}
@@ -109,8 +117,8 @@ public class DefaultEntityNameStrategy implements EntityNameStrategy {
final Class<?> cls = ClassLoaderResolver.classForName(eClassName);
eClass = EModelResolver.instance().getEClass(cls);
} catch (StoreClassLoadException e) {
- log.debug("Failed to retreive ECLass for name: " + eClassName
- + ". This is no problem if this is a featuremap.");
+ log.debug("Failed to retreive ECLass for name: " + eClassName +
+ ". This is no problem if this is a featuremap.");
}
}
@@ -119,4 +127,19 @@ public class DefaultEntityNameStrategy implements EntityNameStrategy {
}
return eClass;
}
+
+ /**
+ * @return the paModel
+ */
+ public PAnnotatedModel getPaModel() {
+ return paModel;
+ }
+
+ /**
+ * @param paModel
+ * the paModel to set
+ */
+ public void setPaModel(PAnnotatedModel paModel) {
+ this.paModel = paModel;
+ }
}
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/EntityResolvingNameStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/EntityResolvingNameStrategy.java
new file mode 100644
index 000000000..232660a3f
--- /dev/null
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/EntityResolvingNameStrategy.java
@@ -0,0 +1,182 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007 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 - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: EntityResolvingNameStrategy.java,v 1.1 2007/07/11 14:41:06 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.mapping.strategy.impl;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
+import org.eclipse.emf.teneo.classloader.ClassLoaderResolver;
+import org.eclipse.emf.teneo.classloader.StoreClassLoadException;
+import org.eclipse.emf.teneo.ecore.EModelResolver;
+import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy;
+import org.eclipse.emf.teneo.util.StoreUtil;
+
+/**
+ * This implementation will first use the name of the entity annotation and then the eclass name.
+ *
+ * @author <a href="mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+public class EntityResolvingNameStrategy implements EntityNameStrategy {
+
+ /** The logger */
+ private static Log log = LogFactory.getLog(EntityResolvingNameStrategy.class);
+
+ /** The singleton instance as it is thread safe */
+ public static final EntityResolvingNameStrategy INSTANCE = new EntityResolvingNameStrategy();
+
+ // The pamodel for which this is done
+ private PAnnotatedModel paModel;
+
+ // Internal cache name from name to eclass
+ private ConcurrentHashMap<String, EClass> entityNameToEClass = new ConcurrentHashMap<String, EClass>();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.elver.ecore.spring.EClassResolver#deResolve(org.eclipse.emf.ecore.EClass)
+ */
+ public String toEntityName(EClass eClass) {
+ if (eClass == EOBJECT_ECLASS) {
+ return EOBJECT_ECLASS_NAME;
+ }
+
+ if (eClass == null) {
+ throw new IllegalArgumentException(
+ "Passed eclass is null."
+ + "This can occur if epackages which refer to eachother are placed in different ecore/xsd files "
+ + "and they are not read using one resource set. The reference from one epackage to another must be "
+ + "resolvable by EMF.");
+ }
+
+ if (eClass.getName() == null) {
+ throw new IllegalArgumentException(
+ "EClass " +
+ eClass.toString() +
+ " has a null name." +
+ "This can occur if epackages which refer to eachother are placed in different ecore/xsd files " +
+ "and they are not read using one resource set. The reference from one epackage to another must be " +
+ "resolvable by EMF.");
+ }
+
+ // check if there is an entity annotation on the eclass with a name set
+ final PAnnotatedEClass aClass = getPaModel().getPAnnotated(eClass);
+ if (aClass.getEntity() != null && aClass.getEntity().getName() != null) {
+ return aClass.getEntity().getName();
+ }
+
+ return eClass.getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.elver.ecore.spring.EClassResolver#resolve(java.lang.String)
+ */
+ public EClass toEClass(String eClassName) {
+ if (eClassName == null) {
+ throw new IllegalArgumentException("eClassName may not be null");
+ }
+
+ if (eClassName.compareTo(EOBJECT_ECLASS_NAME) == 0) {
+ return EcorePackage.eINSTANCE.getEObject();
+ }
+
+ EClass eClass = null;
+ if ((eClass = entityNameToEClass.get(eClassName)) != null) {
+ return eClass;
+ }
+
+ // first try the entityname
+ for (final PAnnotatedEPackage aPackage : getPaModel().getPaEPackages()) {
+ for (final PAnnotatedEClass aClass : aPackage.getPaEClasses()) {
+ if (aClass.getEntity() != null && aClass.getEntity().getName() != null &&
+ aClass.getEntity().getName().compareTo(eClassName) == 0 &&
+ !StoreUtil.isMapEntry(aClass.getAnnotatedEClass())) { // map entries are
+ // ignored
+ if (eClass != null) {
+ // doubly entry! Actually require different resolver
+ throw new IllegalArgumentException("There is more than one EClass with the same name (" +
+ eClassName + " in EPackage " + eClass.getEPackage().getName() + " and " +
+ aPackage.getAnnotatedEPackage().getName() +
+ ". A different EClassResolver should be used.");
+ }
+ eClass = aClass.getAnnotatedEClass();
+ }
+ }
+ }
+ if (eClass != null) {
+ entityNameToEClass.put(eClassName, eClass);
+ return eClass;
+ }
+ // now try the eclassname itself
+ for (final PAnnotatedEPackage aPackage : getPaModel().getPaEPackages()) {
+ for (PAnnotatedEClass aClass : aPackage.getPaEClasses()) {
+ if (aClass.getEntity() != null && aClass.getEntity().getName() != null &&
+ aClass.getEntity().getName().compareTo(eClassName) == 0) {
+ if (eClass != null) {
+ // doubly entry! Actually require different resolver
+ throw new IllegalArgumentException("There is more than one EClass with the same name (" +
+ eClassName + " in EPackage " + eClass.getEPackage().getName() + " and " +
+ aPackage.getAnnotatedEPackage().getName() +
+ ". A different EClassResolver should be used.");
+ }
+ eClass = aClass.getAnnotatedEClass();
+ }
+ }
+ }
+
+ // we didn'y find it, perhaps it is fully qualified, lets try by full class name
+ if (eClass == null) {
+ try {
+ final Class<?> cls = ClassLoaderResolver.classForName(eClassName);
+ eClass = EModelResolver.instance().getEClass(cls);
+ } catch (StoreClassLoadException e) {
+ log.debug("Failed to retreive ECLass for name: " + eClassName +
+ ". This is no problem if this is a featuremap.");
+ }
+ }
+
+ if (eClass == null) {
+ throw new IllegalArgumentException("No EClass found using " + eClassName);
+ }
+ entityNameToEClass.put(eClassName, eClass);
+ return eClass;
+ }
+
+ /**
+ * @return the paModel
+ */
+ public PAnnotatedModel getPaModel() {
+ return paModel;
+ }
+
+ /**
+ * @param paModel
+ * the paModel to set
+ */
+ public void setPaModel(PAnnotatedModel paModel) {
+ this.paModel = paModel;
+ }
+}
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/QualifyingEntityNameStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/QualifyingEntityNameStrategy.java
index 6ccff683c..c97a52649 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/QualifyingEntityNameStrategy.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/QualifyingEntityNameStrategy.java
@@ -12,26 +12,31 @@
*
* </copyright>
*
- * $Id: QualifyingEntityNameStrategy.java,v 1.1 2007/06/29 07:31:47 mtaal Exp $
+ * $Id: QualifyingEntityNameStrategy.java,v 1.2 2007/07/11 14:41:06 mtaal Exp $
*/
package org.eclipse.emf.teneo.mapping.strategy.impl;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEClass;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEPackage;
+import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedModel;
import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy;
/**
- * This implementation prefixes the eclass names with the epackage nsprefix. This
- * makes it possible to handle eclass name clashes between different packages.
+ * This implementation prefixes the eclass names with the epackage nsprefix. This makes it possible
+ * to handle eclass name clashes between different packages.
*
* @author <a href="mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class QualifyingEntityNameStrategy implements EntityNameStrategy {
+ // The pamodel for which this is done
+ private PAnnotatedModel paModel;
+
public static final QualifyingEntityNameStrategy INSTANCE = new QualifyingEntityNameStrategy();
public String toEntityName(EClass eClass) {
@@ -48,7 +53,7 @@ public class QualifyingEntityNameStrategy implements EntityNameStrategy {
return nsPrefix + "." + eClass.getName();
}
- public EClass toEClass(String eClassStr, EPackage[] epackages) {
+ public EClass toEClass(String eClassStr) {
if (eClassStr == null) {
throw new IllegalArgumentException("eClassStr may not be null");
}
@@ -68,18 +73,22 @@ public class QualifyingEntityNameStrategy implements EntityNameStrategy {
// now try all epackages
EClass eClass = null;
- for (final EPackage ePackage : epackages) {
- if (ePackage.getNsPrefix().compareTo(nsPrefix) == 0 || ePackage.getName().compareTo(nsPrefix) == 0) {
- final EClassifier eClassifier = ePackage.getEClassifier(eClassName);
- if (eClassifier instanceof EClass) {
+ for (final PAnnotatedEPackage aPackage : getPaModel().getPaEPackages()) {
+ final EPackage ePackage = aPackage.getAnnotatedEPackage();
+ if (ePackage.getNsPrefix().compareTo(nsPrefix) != 0 && ePackage.getName().compareTo(nsPrefix) != 0) {
+ continue;
+ }
+ for (final PAnnotatedEClass aClass : aPackage.getPaEClasses()) {
+ final EClass checkEClass = aClass.getAnnotatedEClass();
+ if (checkEClass.getName().compareTo(eClassName) == 0) {
if (eClass != null) {
// doubly entry! Actually require different resolver
throw new IllegalArgumentException(
- "There is more than one EClass with the same identifying String (" + eClassStr
- + " in EPackage " + eClass.getEPackage().getName() + " and " + ePackage.getName()
- + ". A different EClassResolver should be used.");
+ "There is more than one EClass with the same identifying String (" + eClassStr +
+ " in EPackage " + eClass.getEPackage().getName() + " and " + ePackage.getName() +
+ ". A different EClassResolver should be used.");
}
- eClass = (EClass) eClassifier;
+ eClass = checkEClass;
}
}
}
@@ -88,4 +97,19 @@ public class QualifyingEntityNameStrategy implements EntityNameStrategy {
}
return eClass;
}
+
+ /**
+ * @return the paModel
+ */
+ public PAnnotatedModel getPaModel() {
+ return paModel;
+ }
+
+ /**
+ * @param paModel
+ * the paModel to set
+ */
+ public void setPaModel(PAnnotatedModel paModel) {
+ this.paModel = paModel;
+ }
}

Back to the top