svn commit: r1176281 - /axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java

2011-09-27 Thread sagara
Author: sagara
Date: Tue Sep 27 08:45:05 2011
New Revision: 1176281

URL: http://svn.apache.org/viewvc?rev=1176281&view=rev
Log:
Since org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl is not an 
instantiable class this method return null, changed to use Class names.   

Modified:

axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java

Modified: 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java?rev=1176281&r1=1176280&r2=1176281&view=diff
==
--- 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java
 Tue Sep 27 08:45:05 2011
@@ -330,25 +330,18 @@ public class TypeTable {
  *the name
  * @return the schema type name by class
  */
-private QName getSchemaTypeNameByClass(String name) {   
-Object dataClass;
-try {
-dataClass = Class.forName(name).newInstance();
-/*
- * XMLGregorianCalendar can be found as following classes.
- * 
1.)com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl
- * 2.)org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl
- */
-if (dataClass instanceof XMLGregorianCalendar) {
-return (QName) simpleTypetoxsd.get(XMLGregorianCalendar.class
-.getName());
-}
-} catch (InstantiationException e) {
-e.printStackTrace();
-} catch (IllegalAccessException e) {
-e.printStackTrace();
-} catch (ClassNotFoundException e) {
-e.printStackTrace();
+private QName getSchemaTypeNameByClass(String name) {
+/*
+ * XMLGregorianCalendar can be found as following classes.
+ * 
1.)com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl
+ * 2.)org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl
+ */
+if 
("com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl"
+.equals(name)
+|| "org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl"
+.equals(name)) {
+return (QName) simpleTypetoxsd.get(XMLGregorianCalendar.class
+.getName());
 }
 return null;
 }




svn commit: r1176349 - in /axis/axis2/java/core/trunk/modules/adb: src/org/apache/axis2/databinding/utils/ConverterUtil.java test/org/apache/axis2/databinding/utils/ConverterUtilTest.java

2011-09-27 Thread sagara
Author: sagara
Date: Tue Sep 27 12:15:27 2011
New Revision: 1176349

URL: http://svn.apache.org/viewvc?rev=1176349&view=rev
Log:
Added new method to convert lexical string of a date to Java.util.Date based on 
javax.xml.datatype package.

Modified:

axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java

axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java

Modified: 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java?rev=1176349&r1=1176348&r2=1176349&view=diff
==
--- 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java
 Tue Sep 27 12:15:27 2011
@@ -63,6 +63,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.activation.DataHandler;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
@@ -617,6 +620,30 @@ public class ConverterUtil {
 
 return calendar.getTime();
 
+}
+
+/**
+ * Convert lexical representation of date to java.util.Date.
+ * 
+ * @param source
+ *the source
+ * @return the date
+ * 
+ * This method used to parse the lexical string representation
+ * defined in XML Schema 1.0 Part 2, Section 3.2.[7-14].1 to a
+ * java.util.Date based on XMLGregorianCalendar. This replaced the
+ * behavior of convertToDate() method that copied from Axis1 .
+ */
+public static Date convertXmlToDate(String source) {
+try {
+XMLGregorianCalendar cal = DatatypeFactory.newInstance()
+.newXMLGregorianCalendar(source);
+return cal.toGregorianCalendar().getTime();
+} catch (DatatypeConfigurationException e) {
+e.printStackTrace();
+}
+return null;
+
 }
 
 public static Time convertToTime(String s) {
@@ -1567,7 +1594,7 @@ public class ConverterUtil {
 throw new XMLStreamException("Invalid 
URI");
 }
 } else if ("date".equals(attributeType)) {
-returnObject = 
ConverterUtil.convertToDate(attribValue);
+returnObject = 
ConverterUtil.convertXmlToDate(attribValue);
 } else if ("dateTime".equals(attributeType)) {
 returnObject = 
ConverterUtil.convertToDateTime(attribValue);
 } else if ("time".equals(attributeType)) {

Modified: 
axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java?rev=1176349&r1=1176348&r2=1176349&view=diff
==
--- 
axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java
 Tue Sep 27 12:15:27 2011
@@ -168,5 +168,44 @@ public class ConverterUtilTest extends T
 
TestCase.assertTrue(ConverterUtil.convertToString(c).endsWith("+09:00"));
 
 }
+
+public void testconvertToDateXML() {
+
+Date date = null;
+String dateStr = null;
+
+dateStr = "2007-02-15";
+date = ConverterUtil.convertXmlToDate(dateStr);
+assertNotNull(date);
+
+dateStr = "2007-02-15Z";
+date = ConverterUtil.convertXmlToDate(dateStr);
+assertNotNull(date);
+
+dateStr = "2007-02-15+05:30";
+date = ConverterUtil.convertXmlToDate(dateStr);
+assertNotNull(date);
+
+dateStr = "2007-02-15-12:30";
+date = ConverterUtil.convertXmlToDate(dateStr);
+assertNotNull(date);
+
+dateStr = "1997-07-16T19:20:30.45+01:00";
+date = ConverterUtil.convertXmlToDate(dateStr);
+assertNotNull(date);
+
+dateStr = "2011-09-27T14:43:55.162+05:30";
+date = ConverterUtil.convertXmlToDate(dateStr);
+assertNotNull(date);
+
+dateStr = "1997-07-16T19:20:30+01:00";
+date = ConverterUtil.convertXmlToDate(dateStr);
+assertNotNull(date);
+
+dateStr = "1994-1