You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by am...@apache.org on 2007/06/27 06:14:05 UTC
svn commit: r551030 -
/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java
Author: amilas
Date: Tue Jun 26 21:14:03 2007
New Revision: 551030
URL: http://svn.apache.org/viewvc?view=rev&rev=551030
Log:
fixed the issue Axis2-2701
Modified:
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java?view=diff&rev=551030&r1=551029&r2=551030
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java Tue Jun 26 21:14:03 2007
@@ -21,6 +21,7 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMText;
+import org.apache.axis2.databinding.utils.ConverterUtil;
import javax.activation.DataHandler;
import javax.xml.namespace.QName;
@@ -109,9 +110,9 @@
} else if (name.equals(W_CHAR)) {
return new Character(text.toCharArray()[0]);
} else if (name.equals(W_CALENDAR)) {
- return makeCalendar(text, false);
+ return makeCalendar(text);
} else if (name.equals(W_DATE)) {
- return makeCalendar(text, true);
+ return makeDate(text);
}/*
* return the correpsonding object for adding data type
*/
@@ -293,109 +294,12 @@
return obj.toString();
}
- public static Object makeCalendar(String source, boolean returnDate) {
- Calendar calendar = Calendar.getInstance();
- Date date;
- boolean bc = false;
-
- // validate fixed portion of format
- if (source == null || source.length() == 0) {
- throw new NumberFormatException("Calendar cannot be null");
- }
- if (source.charAt(0) == '+') {
- source = source.substring(1);
- }
- if (source.charAt(0) == '-') {
- source = source.substring(1);
- bc = true;
- }
- if (source.length() < 19) {
- throw new NumberFormatException("Calendar string too short");
- }
- if (source.charAt(4) != '-' || source.charAt(7) != '-' ||
- source.charAt(10) != 'T') {
- throw new NumberFormatException("Invalid date format");
- }
- if (source.charAt(13) != ':' || source.charAt(16) != ':') {
- throw new NumberFormatException("Invalid time format");
- }
- // convert what we have validated so far
- try {
- SimpleDateFormat zulu = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
- zulu.setTimeZone(TimeZone.getTimeZone("GMT"));
- date = zulu.parse(source.substring(0, 19) + ".000Z");
- } catch (Exception e) {
- throw new NumberFormatException(e.toString());
- }
- int pos = 19;
-
- // parse optional milliseconds
- if (pos < source.length() && source.charAt(pos) == '.') {
- int milliseconds;
- int start = ++pos;
- while (pos < source.length() &&
- Character.isDigit(source.charAt(pos))) {
- pos++;
- }
- String decimal = source.substring(start, pos);
- if (decimal.length() == 3) {
- milliseconds = Integer.parseInt(decimal);
- } else if (decimal.length() < 3) {
- milliseconds = Integer.parseInt((decimal + "000")
- .substring(0, 3));
- } else {
- milliseconds = Integer.parseInt(decimal.substring(0, 3));
- if (decimal.charAt(3) >= '5') {
- ++milliseconds;
- }
- }
-
- // add milliseconds to the current date
- date.setTime(date.getTime() + milliseconds);
- }
-
- // parse optional timezone
- if (pos + 5 < source.length() &&
- (source.charAt(pos) == '+' || (source.charAt(pos) == '-'))) {
- if (!Character.isDigit(source.charAt(pos + 1)) ||
- !Character.isDigit(source.charAt(pos + 2)) ||
- source.charAt(pos + 3) != ':' ||
- !Character.isDigit(source.charAt(pos + 4)) ||
- !Character.isDigit(source.charAt(pos + 5))) {
- throw new NumberFormatException("Invalid timezone");
- }
- int hours = (source.charAt(pos + 1) - '0') * 10
- + source.charAt(pos + 2) - '0';
- int mins = (source.charAt(pos + 4) - '0') * 10
- + source.charAt(pos + 5) - '0';
- int milliseconds = (hours * 60 + mins) * 60 * 1000;
-
- // subtract milliseconds from current date to obtain GMT
- if (source.charAt(pos) == '+') {
- milliseconds = -milliseconds;
- }
- date.setTime(date.getTime() + milliseconds);
- pos += 6;
- }
- if (pos < source.length() && source.charAt(pos) == 'Z') {
- pos++;
- calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
- }
- if (pos < source.length()) {
- throw new NumberFormatException("Unknown chars after calendar string");
- }
- calendar.setTime(date);
-
- // support dates before the Christian era
- if (bc) {
- calendar.set(Calendar.ERA, GregorianCalendar.BC);
- }
+ public static Object makeCalendar(String source) {
+ return ConverterUtil.convertToDateTime(source);
+ }
- if (returnDate) {
- return date;
- } else {
- return calendar;
- }
+ public static Object makeDate(String source) {
+ return ConverterUtil.convertToDate(source);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org