Author: rfeng
Date: Thu Sep 21 15:33:45 2006
New Revision: 448720
URL: http://svn.apache.org/viewvc?view=rev&rev=448720
Log:
Test more data with simple types
Modified:
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtension.java
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/util/XSDDataTypeConverter.java
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtensionTestCase.java
Modified:
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtension.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtension.java?view=diff&rev=448720&r1=448719&r2=448720
==============================================================================
---
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtension.java
(original)
+++
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtension.java
Thu Sep 21 15:33:45 2006
@@ -67,8 +67,6 @@
public class SimpleTypeMapperExtension extends XSDDataTypeConverter implements
SimpleTypeMapper {
private DatatypeFactory factory;
- protected NamespaceContext namespaceContext;
-
public static final String URI_2001_SCHEMA_XSD =
"http://www.w3.org/2001/XMLSchema";
private static final String[] typeNames =
@@ -78,18 +76,20 @@
"unsignedByte", "positiveInteger", "negativeInteger",
"nonNegativeInteger", "nonPositiveInteger",
"gYearMonth", "gMonthDay", "gYear", "gMonth", "gDay",
"duration", "Name", "NCName", "NMTOKEN",
"NMTOKENS", "NOTATION", "ENTITY", "ENTITIES", "IDREF",
"IDREFS", "anyURI", "language", "ID" };
-
- public static final Map<String, XmlSchemaSimpleType> XSD_SIMPLE_TYPES= new
HashMap<String, XmlSchemaSimpleType>();
-
+
+ public static final Map<String, XmlSchemaSimpleType> XSD_SIMPLE_TYPES =
new HashMap<String, XmlSchemaSimpleType>();
+
static {
XmlSchemaCollection collection = new XmlSchemaCollection();
for (String type : typeNames) {
XmlSchemaSimpleType simpleType =
(XmlSchemaSimpleType) collection.getTypeByQName(new
QName(URI_2001_SCHEMA_XSD, type));
- XSD_SIMPLE_TYPES.put(type, simpleType);
+ if (simpleType != null) {
+ XSD_SIMPLE_TYPES.put(type, simpleType);
+ }
}
}
-
+
public SimpleTypeMapperExtension() {
super();
try {
@@ -100,6 +100,8 @@
}
public Object toJavaObject(XmlSchemaSimpleType simpleType, String value,
TransformationContext context) {
+ NamespaceContext namespaceContext =
+ (NamespaceContext) ((context != null) ?
context.getMetadata().get(NamespaceContext.class) : null);
/**
* <ul>
@@ -246,20 +248,6 @@
new GregorianCalendar(date.getYear(), date.getMonth(),
date.getDate(), date.getHours(), date
.getMinutes(), date.getSeconds());
return factory.newXMLGregorianCalendar(c);
- }
-
- /**
- * @return the namespaceContext
- */
- public NamespaceContext getNamespaceContext() {
- return namespaceContext;
- }
-
- /**
- * @param namespaceContext the namespaceContext to set
- */
- public void setNamespaceContext(NamespaceContext namespaceContext) {
- this.namespaceContext = namespaceContext;
}
}
Modified:
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/util/XSDDataTypeConverter.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/util/XSDDataTypeConverter.java?view=diff&rev=448720&r1=448719&r2=448720
==============================================================================
---
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/util/XSDDataTypeConverter.java
(original)
+++
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/util/XSDDataTypeConverter.java
Thu Sep 21 15:33:45 2006
@@ -66,11 +66,27 @@
}
public float parseFloat(String value) {
- return Float.parseFloat(value);
+ if (value.equals("INF")) {
+ return Float.POSITIVE_INFINITY;
+ } else if (value.equals("-INF")) {
+ return Float.NEGATIVE_INFINITY;
+ } else if (value.equals("NaN")) {
+ return Float.NaN;
+ } else {
+ return Float.parseFloat(value);
+ }
}
public double parseDouble(String value) {
- return Double.parseDouble(value);
+ if (value.equals("INF")) {
+ return Double.POSITIVE_INFINITY;
+ } else if (value.equals("-INF")) {
+ return Double.NEGATIVE_INFINITY;
+ } else if (value.equals("NaN")) {
+ return Double.NaN;
+ } else {
+ return Double.parseDouble(value);
+ }
}
public boolean parseBoolean(String value) {
Modified:
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtensionTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtensionTestCase.java?view=diff&rev=448720&r1=448719&r2=448720
==============================================================================
---
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtensionTestCase.java
(original)
+++
incubator/tuscany/java/sca/services/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/extension/SimpleTypeMapperExtensionTestCase.java
Thu Sep 21 15:33:45 2006
@@ -19,15 +19,59 @@
package org.apache.tuscany.databinding.extension;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+
import junit.framework.TestCase;
+import org.apache.tuscany.databinding.TransformationContext;
+import org.apache.tuscany.databinding.impl.TransformationContextImpl;
import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.easymock.EasyMock;
/**
*
*/
public class SimpleTypeMapperExtensionTestCase extends TestCase {
+ private static final Map<String, Object> sampleValues = new
HashMap<String, Object>();
+
+ static {
+ sampleValues.put("anyURI", "http://www.w3.com");
+ sampleValues.put("boolean", new String[] { "true", "false", "1", "0"
});
+ sampleValues.put("byte", new String[] { "-128", "127" });
+ sampleValues.put("date", new String[] { "2004-03-15",
"2002-09-24-06:00" });
+ sampleValues.put("dateTime", "2003-12-25T08:30:00");
+ sampleValues.put("decimal", "3.1415292");
+ sampleValues.put("double", new String[] { "3.1415292", "INF", "NaN" });
+ sampleValues.put("duration", new String[] { "P8M3DT7H33M2S",
"P5Y2M10DT15H" });
+ sampleValues.put("float", new String[] { "3.1415292", "INF", "NaN" });
+ sampleValues.put("gDay", "---11");
+ sampleValues.put("gMonth", "--02--");
+ sampleValues.put("gMonthDay", "--02-14");
+ sampleValues.put("gYear", "1999");
+ sampleValues.put("gYearMonth", "1972-08");
+ sampleValues.put("ID", "id-102");
+ sampleValues.put("IDREF", "id-102");
+ sampleValues.put("IDREFS", "id-102 id-103 id-100");
+ sampleValues.put("int", "77");
+ sampleValues.put("integer", "77");
+ sampleValues.put("long", "214");
+ sampleValues.put("negativeInteger", "-123");
+ sampleValues.put("nonNegativeInteger", "2");
+ sampleValues.put("nonPositiveInteger", "0");
+ sampleValues.put("positiveInteger", "500");
+ sampleValues.put("short", "476");
+ sampleValues.put("string", "Joeseph");
+ sampleValues.put("time", "13:02:00");
+ sampleValues.put("base64Binary", "TWFu");
+ sampleValues.put("hexBinary", "2CDB5F");
+ sampleValues.put("QName", "f:foo");
+ sampleValues.put("NOTATION", "f:bar");
+ }
+
/**
* @see junit.framework.TestCase#setUp()
*/
@@ -37,40 +81,24 @@
public void testMap() throws Exception {
SimpleTypeMapperExtension extension = new SimpleTypeMapperExtension();
+ TransformationContext context = new TransformationContextImpl();
+ NamespaceContext namespaceContext =
EasyMock.createMock(NamespaceContext.class);
+
EasyMock.expect(namespaceContext.getNamespaceURI(EasyMock.eq("f"))).andReturn("http://foo").anyTimes();
+ EasyMock.replay(namespaceContext);
+ context.getMetadata().put(NamespaceContext.class, namespaceContext);
for (XmlSchemaSimpleType simpleType :
SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.values()) {
- if (simpleType != null) {
- String name = simpleType.getName();
- String value = "12";
- if (name.equals("boolean")) {
- value = "true";
- } else if (name.equals("QName") || name.endsWith("NOTATION")) {
- value = "f:foo";
- continue;
- } else if (name.equals("base64Binary")) {
- value = "TWFu";
- } else if (name.equals("date")) {
- value = "2002-09-24-06:00";
- } else if (name.equals("time")) {
- value = "09:30:10+06:00";
- } else if (name.equals("dateTime")) {
- value = "2002-05-30T09:30:10+06:00";
- } else if (name.equals("gYear")) {
- value = "2001+00:00";
- } else if (name.equals("gYearMonth")) {
- value = "2001-10+02:00";
- } else if (name.equals("gMonthDay")) {
- value = "--11-01+02:00";
- } else if (name.equals("gMonth")) {
- value = "--11--";
- } else if (name.equals("gDay")) {
- value = "---01+02:00";
- } else if (name.equals("duration")) {
- value = "P5Y2M10DT15H";
+ String name = simpleType.getName();
+ Object value = sampleValues.get(name);
+ if (value instanceof String[]) {
+ for (String s : (String[]) value) {
+ Object obj = extension.toJavaObject(simpleType, s,
context);
+ extension.toXMLLiteral(simpleType, obj, context);
}
- Object obj = extension.toJavaObject(simpleType, value, null);
- extension.toXMLLiteral(simpleType, obj, null);
- // assertTrue("[" + type + "] " + str + " " + value,
str.contains(value));
+ } else if (value instanceof String) {
+ Object obj = extension.toJavaObject(simpleType, (String)
value, context);
+ extension.toXMLLiteral(simpleType, obj, context);
}
+ // assertTrue("[" + type + "] " + str + " " + value,
str.contains(value));
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]