Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormtaal2011-03-17 09:21:31 +0000
committermtaal2011-03-17 09:21:31 +0000
commit1992c50bb410ca71234834d43ac67fa0a8da7a38 (patch)
treefe80964fd1bd008eee6889c7012b631e8cca15c6
parenta2f492a5d4cd226f55b597979657c7e566d5297f (diff)
downloadorg.eclipse.emf.teneo-1992c50bb410ca71234834d43ac67fa0a8da7a38.tar.gz
org.eclipse.emf.teneo-1992c50bb410ca71234834d43ac67fa0a8da7a38.tar.xz
org.eclipse.emf.teneo-1992c50bb410ca71234834d43ac67fa0a8da7a38.zip
[321765]
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java12
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/EcoreDataTypes.java162
2 files changed, 122 insertions, 52 deletions
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 84a922d46..60b06119f 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
@@ -13,7 +13,7 @@
* Jason Henriksen - XSDDate and XSDDateTime constants
* </copyright>
*
- * $Id: PersistenceOptions.java,v 1.68 2011/02/21 06:40:04 mtaal Exp $
+ * $Id: PersistenceOptions.java,v 1.69 2011/03/17 09:21:31 mtaal Exp $
*/
package org.eclipse.emf.teneo;
@@ -39,7 +39,7 @@ import org.eclipse.emf.teneo.extension.ExtensionPoint;
* As a convenience, this class offers type-safe property accessor wrappers.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.68 $
+ * @version $Revision: 1.69 $
*/
public class PersistenceOptions implements ExtensionPoint {
@@ -191,6 +191,8 @@ public class PersistenceOptions implements ExtensionPoint {
+ "UserDateType";
public static final String USER_XSDDATETIME_TYPE = MAPPING_PREFIX
+ "UserDateTimeType";
+ public static final String USER_XSDTIME_TYPE = MAPPING_PREFIX
+ + "UserTimeType";
/**
* This option can be used to control the actual xsd date class used, as a
@@ -540,6 +542,8 @@ public class PersistenceOptions implements ExtensionPoint {
"org.eclipse.emf.teneo.hibernate.mapping.XSDDate");
props.setProperty(USER_XSDDATETIME_TYPE,
"org.eclipse.emf.teneo.hibernate.mapping.XSDDateTime");
+ props.setProperty(USER_XSDTIME_TYPE,
+ "org.eclipse.emf.teneo.hibernate.mapping.XSDDateTime");
props.setProperty(XSDDATE_CLASS,
"javax.xml.datatype.XMLGregorianCalendar");
props.setProperty(SQL_DISCRIMINATOR_VERSION_IMMUTABLE_ECLASS, "true");
@@ -1182,6 +1186,10 @@ public class PersistenceOptions implements ExtensionPoint {
return properties.getProperty(USER_XSDDATE_TYPE);
}
+ public String getUserXSDTime() {
+ return properties.getProperty(USER_XSDTIME_TYPE);
+ }
+
public String getUserXSDDateTime() {
return properties.getProperty(USER_XSDDATETIME_TYPE);
}
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/EcoreDataTypes.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/EcoreDataTypes.java
index 5c3e25e66..69e5ae6d2 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/EcoreDataTypes.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/EcoreDataTypes.java
@@ -14,7 +14,7 @@
* Alexandros Karypidis (bugzilla 207799)
* </copyright>
*
- * $Id: EcoreDataTypes.java,v 1.16 2009/03/30 07:53:04 mtaal Exp $
+ * $Id: EcoreDataTypes.java,v 1.17 2011/03/17 09:21:31 mtaal Exp $
*/
package org.eclipse.emf.teneo.util;
@@ -53,7 +53,9 @@ public class EcoreDataTypes {
// The xml types
private static XMLTypePackage xmlTypePackage = XMLTypePackage.eINSTANCE;
private static EDataType xmlDateEDataType = xmlTypePackage.getDate();
- private static EDataType xmlDateTimeEDataType = xmlTypePackage.getDateTime();
+ private static EDataType xmlDateTimeEDataType = xmlTypePackage
+ .getDateTime();
+ private static EDataType xmlTimeEDataType = xmlTypePackage.getTime();
// 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";
@@ -61,23 +63,33 @@ public class EcoreDataTypes {
// XML datatype factory instance
private final DatatypeFactory dataTypeFactory;
- private static final List<EDataType> PRIMITIVES_ETYPES_LIST =
- Collections.unmodifiableList(Arrays.asList(new EDataType[] { EcorePackage.eINSTANCE.getEBoolean(),
- EcorePackage.eINSTANCE.getEByte(), EcorePackage.eINSTANCE.getEChar(),
- EcorePackage.eINSTANCE.getEDouble(), EcorePackage.eINSTANCE.getEFloat(),
- EcorePackage.eINSTANCE.getEInt(), EcorePackage.eINSTANCE.getELong(),
+ private static final List<EDataType> PRIMITIVES_ETYPES_LIST = Collections
+ .unmodifiableList(Arrays.asList(new EDataType[] {
+ EcorePackage.eINSTANCE.getEBoolean(),
+ EcorePackage.eINSTANCE.getEByte(),
+ EcorePackage.eINSTANCE.getEChar(),
+ EcorePackage.eINSTANCE.getEDouble(),
+ EcorePackage.eINSTANCE.getEFloat(),
+ EcorePackage.eINSTANCE.getEInt(),
+ EcorePackage.eINSTANCE.getELong(),
EcorePackage.eINSTANCE.getEShort(), }));
- private static final List<Class<?>> PRIMITIVE_OBJECT_TYPE_LIST =
- Collections.unmodifiableList(Arrays.asList(new Class<?>[] { java.lang.Boolean.class, java.lang.Byte.class,
- java.lang.Double.class, java.lang.Float.class, java.lang.Integer.class, java.lang.Long.class,
+ private static final List<Class<?>> PRIMITIVE_OBJECT_TYPE_LIST = Collections
+ .unmodifiableList(Arrays.asList(new Class<?>[] {
+ java.lang.Boolean.class, java.lang.Byte.class,
+ java.lang.Double.class, java.lang.Float.class,
+ java.lang.Integer.class, java.lang.Long.class,
java.math.BigDecimal.class, java.math.BigInteger.class }));
- private static final List<EDataType> WRAPPERS_ETYPES_LIST =
- Collections.unmodifiableList(Arrays.asList(new EDataType[] { EcorePackage.eINSTANCE.getEBooleanObject(),
- EcorePackage.eINSTANCE.getEByteObject(), EcorePackage.eINSTANCE.getECharacterObject(),
- EcorePackage.eINSTANCE.getEDoubleObject(), EcorePackage.eINSTANCE.getEFloatObject(),
- EcorePackage.eINSTANCE.getEIntegerObject(), EcorePackage.eINSTANCE.getELongObject(),
+ private static final List<EDataType> WRAPPERS_ETYPES_LIST = Collections
+ .unmodifiableList(Arrays.asList(new EDataType[] {
+ EcorePackage.eINSTANCE.getEBooleanObject(),
+ EcorePackage.eINSTANCE.getEByteObject(),
+ EcorePackage.eINSTANCE.getECharacterObject(),
+ EcorePackage.eINSTANCE.getEDoubleObject(),
+ EcorePackage.eINSTANCE.getEFloatObject(),
+ EcorePackage.eINSTANCE.getEIntegerObject(),
+ EcorePackage.eINSTANCE.getELongObject(),
EcorePackage.eINSTANCE.getEShortObject(), }));
public static EcoreDataTypes INSTANCE = new EcoreDataTypes();
@@ -94,12 +106,19 @@ public class EcoreDataTypes {
public String getTargetTypeName(PAnnotatedEAttribute aAttribute) {
final EAttribute eAttribute = aAttribute.getModelEAttribute();
// check on equality on object.class is used for listunion simpleunions
- final Class<?> instanceClass = eAttribute.getEAttributeType().getInstanceClass();
- if (instanceClass != null && !Object.class.equals(instanceClass) && !List.class.equals(instanceClass)) {
+ final Class<?> instanceClass = eAttribute.getEAttributeType()
+ .getInstanceClass();
+ if (instanceClass != null && !Object.class.equals(instanceClass)
+ && !List.class.equals(instanceClass)) {
if (instanceClass.isArray()) {
// get rid of the [] at the end
- return eAttribute.getEType().getInstanceClassName().substring(0,
- eAttribute.getEType().getInstanceClassName().length() - 2);
+ return eAttribute
+ .getEType()
+ .getInstanceClassName()
+ .substring(
+ 0,
+ eAttribute.getEType().getInstanceClassName()
+ .length() - 2);
}
return instanceClass.getName();
}
@@ -112,7 +131,8 @@ public class EcoreDataTypes {
// of target
// entities this is required for listunion types but is not
// according to the ejb3 spec!
- ArrayList<EClassifier> eclassifiers = getItemTypes((EDataType) eAttribute.getEType());
+ ArrayList<EClassifier> eclassifiers = getItemTypes((EDataType) eAttribute
+ .getEType());
if (eclassifiers.size() > 0) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < eclassifiers.size(); i++) {
@@ -133,9 +153,11 @@ public class EcoreDataTypes {
if (eDataType == null) {
return result;
}
- final String itemType = getEAnnotationValue(eDataType, ANNOTATION_SOURCE_METADATA, "itemType");
+ final String itemType = getEAnnotationValue(eDataType,
+ ANNOTATION_SOURCE_METADATA, "itemType");
if (itemType != null) {
- final EClassifier eClassifier = getEClassifier(eDataType.getEPackage(), itemType);
+ final EClassifier eClassifier = getEClassifier(
+ eDataType.getEPackage(), itemType);
if (eClassifier != null) {
result.add(eClassifier);
}
@@ -143,11 +165,13 @@ public class EcoreDataTypes {
return result;
}
- final String memberTypes = getEAnnotationValue(eDataType, ANNOTATION_SOURCE_METADATA, "memberTypes");
+ final String memberTypes = getEAnnotationValue(eDataType,
+ ANNOTATION_SOURCE_METADATA, "memberTypes");
if (memberTypes != null) {
String[] mtypes = memberTypes.split(" ");
for (String element : mtypes) {
- final EClassifier eclassifier = getEClassifier(eDataType.getEPackage(), element);
+ final EClassifier eclassifier = getEClassifier(
+ eDataType.getEPackage(), element);
if (eclassifier != null) {
result.addAll(getItemTypes((EDataType) eclassifier));
}
@@ -155,9 +179,11 @@ public class EcoreDataTypes {
return result;
}
- final String baseType = getEAnnotationValue(eDataType, ANNOTATION_SOURCE_METADATA, "baseType");
+ final String baseType = getEAnnotationValue(eDataType,
+ ANNOTATION_SOURCE_METADATA, "baseType");
if (baseType != null) {
- final EClassifier eClassifier = getEClassifier(eDataType.getEPackage(), baseType);
+ final EClassifier eClassifier = getEClassifier(
+ eDataType.getEPackage(), baseType);
if (eClassifier != null) {
final ArrayList<EClassifier> tmpResult = getItemTypes((EDataType) eClassifier);
if (tmpResult.size() > 0) {
@@ -173,15 +199,18 @@ public class EcoreDataTypes {
}
/**
- * Returns the eclassifier using either the name of the eclassifier or the name element
+ * Returns the eclassifier using either the name of the eclassifier or the
+ * name element
*/
public EClassifier getEClassifier(EPackage epackage, String searchName) {
for (EClassifier eclassifier : epackage.getEClassifiers()) {
if (eclassifier.getName().compareTo(searchName) == 0) {
return eclassifier;
}
- String nameAnnotation = getEAnnotationValue(eclassifier, ANNOTATION_SOURCE_METADATA, "name");
- if (nameAnnotation != null && searchName.compareTo(nameAnnotation) == 0) {
+ String nameAnnotation = getEAnnotationValue(eclassifier,
+ ANNOTATION_SOURCE_METADATA, "name");
+ if (nameAnnotation != null
+ && searchName.compareTo(nameAnnotation) == 0) {
return eclassifier;
}
}
@@ -189,7 +218,8 @@ public class EcoreDataTypes {
}
/** Returns the value of an annotation with a certain key */
- public String getEAnnotationValue(EModelElement eModelElement, String source, String key) {
+ public String getEAnnotationValue(EModelElement eModelElement,
+ String source, String key) {
final EAnnotation eAnnotation = eModelElement.getEAnnotation(source);
if (eAnnotation == null) {
return null;
@@ -201,7 +231,8 @@ public class EcoreDataTypes {
/** Return a XMLGregorianCalendar on the basis of the date */
public XMLGregorianCalendar getXMLGregorianCalendar(Date date) {
- final XMLGregorianCalendar gregCalendar = dataTypeFactory.newXMLGregorianCalendar();
+ final XMLGregorianCalendar gregCalendar = dataTypeFactory
+ .newXMLGregorianCalendar();
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
gregCalendar.setYear(calendar.get(Calendar.YEAR));
@@ -214,7 +245,8 @@ public class EcoreDataTypes {
/** Return a XMLGregorianCalendar on datetime level (milliseconds) */
public XMLGregorianCalendar getXMLGregorianCalendarDateTime(Date date) {
- final XMLGregorianCalendar gregCalendar = dataTypeFactory.newXMLGregorianCalendar();
+ final XMLGregorianCalendar gregCalendar = dataTypeFactory
+ .newXMLGregorianCalendar();
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
gregCalendar.setYear(calendar.get(Calendar.YEAR));
@@ -230,15 +262,16 @@ public class EcoreDataTypes {
}
/**
- * @return Returns an immutable list of the Ecore EDataType for java primitives.
+ * @return Returns an immutable list of the Ecore EDataType for java
+ * primitives.
*/
public List<EDataType> getEPrimitives() {
return PRIMITIVES_ETYPES_LIST;
}
/**
- * @return Returns true if and only if the the given eDataType is the Ecore EDataType for a
- * primitive type.
+ * @return Returns true if and only if the the given eDataType is the Ecore
+ * EDataType for a primitive type.
*/
public boolean isEPrimitive(EDataType eDataType) {
return eDataType != null && isPrimitive(eDataType.getInstanceClass());
@@ -252,15 +285,16 @@ public class EcoreDataTypes {
}
/**
- * @return Returns an immutable list of the Ecore EDataType for java primitive wrapper classes.
+ * @return Returns an immutable list of the Ecore EDataType for java
+ * primitive wrapper classes.
*/
public List<EDataType> getEWrappers() {
return WRAPPERS_ETYPES_LIST;
}
/**
- * @return Returns true if and only if the the given eDataType is the Ecore EDataType for a
- * primitive wrapper class.
+ * @return Returns true if and only if the the given eDataType is the Ecore
+ * EDataType for a primitive wrapper class.
*/
public boolean isEWrapper(EDataType eDataType) {
return WRAPPERS_ETYPES_LIST.contains(eDataType);
@@ -297,29 +331,55 @@ public class EcoreDataTypes {
return true;
}
/*
- * There is some ambiguity around the Java Date class since it can also hold time - a
- * conflict with the DateTime class
+ * There is some ambiguity around the Java Date class since it can also
+ * hold time - a conflict with the DateTime class
*/
Class<?> ic = eDataType.getInstanceClass();
// do a string comparison to prevent another dependency for this teneo
// library.
- if (eDataType.getInstanceClassName() != null &&
- eDataType.getInstanceClassName().compareTo(po.getXSDDateClass()) == 0) {
+ if (eDataType.getInstanceClassName() != null
+ && eDataType.getInstanceClassName().compareTo(
+ po.getXSDDateClass()) == 0) {
return true;
}
- return java.util.Date.class == ic || java.util.Calendar.class == ic || java.sql.Date.class == ic;
+ return java.util.Date.class == ic || java.util.Calendar.class == ic
+ || java.sql.Date.class == ic;
}
/**
- * @return true if and only if the given dataType is a datetime/timestamp datatype.
+ * @return true if and only if the given dataType is a datetime/timestamp
+ * datatype.
+ */
+ public boolean isETime(EDataType eDataType) {
+ if (eDataType.equals(xmlTimeEDataType)) {
+ return true;
+ }
+ /*
+ * the InstanceClass for date type can be "Object" for XSD types. I'm
+ * not sure about ecore itself so I have kept the original check against
+ * the java classes.
+ */
+ Class<?> ic = eDataType.getInstanceClass();
+ // already handled through the first if
+ // if (ic == Object.class) {
+ // // could be an XML date type
+ // return eDataType.equals(xmlDateTimeEDataType);
+ // }
+ return java.sql.Timestamp.class == ic || Date.class == ic;
+ }
+
+ /**
+ * @return true if and only if the given dataType is a datetime/timestamp
+ * datatype.
*/
public boolean isEDateTime(EDataType eDataType) {
if (eDataType.equals(xmlDateTimeEDataType)) {
return true;
}
/*
- * the InstanceClass for date type can be "Object" for XSD types. I'm not sure about ecore
- * itself so I have kept the original check against the java classes.
+ * the InstanceClass for date type can be "Object" for XSD types. I'm
+ * not sure about ecore itself so I have kept the original check against
+ * the java classes.
*/
Class<?> ic = eDataType.getInstanceClass();
// already handled through the first if
@@ -331,12 +391,13 @@ public class EcoreDataTypes {
}
/**
- * @return Returns true if and only if the given type is either a primitive or a wrapper or
- * string or a date.
+ * @return Returns true if and only if the given type is either a primitive
+ * or a wrapper or string or a date.
*/
public boolean isSimpleType(EDataType eType, PersistenceOptions po) {
// TODO move elsewhere
- return isEPrimitive(eType) || isEWrapper(eType) || isEString(eType) || isEDate(eType, po) || isEDateTime(eType);
+ return isEPrimitive(eType) || isEWrapper(eType) || isEString(eType)
+ || isEDate(eType, po) || isEDateTime(eType);
}
/**
@@ -366,7 +427,8 @@ public class EcoreDataTypes {
public boolean isByteArray(EDataType eType) {
final Class<?> clazz = eType.getInstanceClass();
if (clazz != null) {
- return (clazz.isArray() && clazz.getComponentType().equals(Byte.TYPE));
+ return (clazz.isArray() && clazz.getComponentType().equals(
+ Byte.TYPE));
}
return false;
}

Back to the top