Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Use J2SE spec API for XML datatypes (work with IBM JDK)
[Teneo] Use J2SE spec API for XML datatypes (work with IBM JDK) [message #612992] Sun, 23 December 2007 16:14
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 135
Registered: March 2010
Senior Member
This is a multi-part message in MIME format.
--------------080908030601030202060106
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

Teneo uses the internal Xerces API to construct XML Gregorian calendar
objects, by calling the constructor of:

com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregoria nCalendarImpl

The standard J2SE API does not include this implementation class as part
of the platform. Therefore, using it may cause incompatibility with
other JDK implementations that implement XMLGregorianCalendar differently.

I've just come across one such case while using IBM's JDK. Although IBM
does the same thing as Sun (i.e. distribute Xerces with its JDK), it
uses the original namespace for the classes, whereas Sun has renamed it
from "org.apace.xerces..." to "com.sun.org.apache.xerces..."

This patch removes references to the internal class implementation and
uses the DatatypeFactory to construct XMLGregorianCalendar objects, as
instructed by Sun's API docs at:

http://java.sun.com/javase/6/docs/api/javax/xml/datatype/XML GregorianCalendar.html#XMLGregorianCalendar()

It will sadly be slower than calling the constructor directly, but I
don't see any other nice way around this.

--------------080908030601030202060106
Content-Type: text/x-patch;
name="std_jaxp.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="std_jaxp.patch"

### Eclipse Workspace Patch 1.0
#P org.eclipse.emf.teneo
Index: src/org/eclipse/emf/teneo/util/EcoreDataTypes.java
============================================================ =======
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.teneo/plug ins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/Eco reDataTypes.java,v
retrieving revision 1.6
diff -u -r1.6 EcoreDataTypes.java
--- src/org/eclipse/emf/teneo/util/EcoreDataTypes.java 4 Jul 2007 19:27:26 -0000 1.6
+++ src/org/eclipse/emf/teneo/util/EcoreDataTypes.java 23 Dec 2007 15:59:35 -0000
@@ -24,6 +24,8 @@
import java.util.Date;
import java.util.List;

+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import org.eclipse.emf.ecore.EClassifier;
@@ -31,8 +33,7 @@
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
-
-import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregoria nCalendarImpl;
+import org.eclipse.emf.teneo.TeneoException;

/**
* Utility class to classify Ecore datatypes.
@@ -46,6 +47,9 @@
private static EDataType xmlDateEDataType = xmlTypePackage.getDate();
private static EDataType xmlDateTimeEDataType = xmlTypePackage.getDateTime();

+ // 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(),
@@ -63,13 +67,18 @@
public static EcoreDataTypes INSTANCE = new EcoreDataTypes();

private EcoreDataTypes() {
+ try {
+ dataTypeFactory = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e) {
+ throw new TeneoException("Exception ", e);
+ }
}

// TODO: Make all utility methods static.

/** Return a XMLGregorianCalendar on the basis of the date */
public XMLGregorianCalendar getXMLGregorianCalendar(Date date) {
- final XMLGregorianCalendar gregCalendar = new XMLGregorianCalendarImpl();
+ final XMLGregorianCalendar gregCalendar = dataTypeFactory.newXMLGregorianCalendar();
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
gregCalendar.setYear(calendar.get(Calendar.YEAR));
@@ -80,7 +89,7 @@

/** Return a XMLGregorianCalendar on datetime level (milliseconds) */
public XMLGregorianCalendar getXMLGregorianCalendarDateTime(Date date) {
- final XMLGregorianCalendar gregCalendar = new XMLGregorianCalendarImpl();
+ final XMLGregorianCalendar gregCalendar = dataTypeFactory.newXMLGregorianCalendar();
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
gregCalendar.setYear(calendar.get(Calendar.YEAR));
#P org.eclipse.emf.teneo.hibernate
Index: src/org/eclipse/emf/teneo/hibernate/mapping/XSDDateTime.java
============================================================ =======
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.teneo/plug ins/org.eclipse.emf.teneo.hibernate/src/org/eclipse/emf/tene o/hibernate/mapping/XSDDateTime.java,v
retrieving revision 1.2
diff -u -r1.2 XSDDateTime.java
--- src/org/eclipse/emf/teneo/hibernate/mapping/XSDDateTime.java 4 Jul 2007 19:27:28 -0000 1.2
+++ src/org/eclipse/emf/teneo/hibernate/mapping/XSDDateTime.java 23 Dec 2007 15:59:37 -0000
@@ -31,8 +31,6 @@
import org.hibernate.HibernateException;
import org.hibernate.type.MutableType;

-import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregoria nCalendarImpl;
-
/**
* Implements the hibernate UserType for EMF's XMLGregorianCalendar ("datetime" type in XSD).
*
@@ -71,7 +69,7 @@
*/
@Override
public Object deepCopyNotNull(Object value) {
- return new XMLGregorianCalendarImpl(((XMLGregorianCalendar) value).toGregorianCalendar());
+ return dataTypeFactory.newXMLGregorianCalendar(((XMLGregorianCalend ar) value).toGregorianCalendar());
}

/*

--------------080908030601030202060106--
Previous Topic:[Ecore Tools] Upper Bound = -2
Next Topic:[Teneo] Use J2SE spec API for XML datatypes (work with IBM JDK)
Goto Forum:
  


Current Time: Sun Sep 20 04:49:57 GMT 2020

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

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

Back to the top