cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r611659 - in /incubator/cxf/trunk/rt/javascript/src: main/java/org/apache/cxf/javascript/ main/java/org/apache/cxf/javascript/service/ main/java/org/apache/cxf/javascript/types/ main/resources/org/apache/cxf/javascript/ test/java/org/apache...
Date Sun, 13 Jan 2008 21:51:47 GMT
Author: bimargulies
Date: Sun Jan 13 13:51:44 2008
New Revision: 611659

URL: http://svn.apache.org/viewvc?rev=611659&view=rev
Log:
More fun with anyType. Get better values.

Modified:
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
    incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java?rev=611659&r1=611658&r2=611659&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
Sun Jan 13 13:51:44 2008
@@ -203,7 +203,7 @@
         } else if (floatTypes.contains(name)) {
             return "parseFloat(" + value + ")";
         } else if ("boolean".equals(name)) {
-            return "(" + value + " == true)";
+            return "(" + value + " == 'true')";
         } else {
             return value;
         }

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java?rev=611659&r1=611658&r2=611659&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
Sun Jan 13 13:51:44 2008
@@ -183,8 +183,24 @@
                                  + "_deserialize;");
             }
             
+            globalElements = schemaInfo.getSchemaTypes();
+            namesIterator = globalElements.getNames();
+            while (namesIterator.hasNext()) {
+                QName name = (QName)namesIterator.next();
+                XmlSchemaType type = (XmlSchemaType) globalElements.getItem(name);
+                // For now, at least, don't handle simple types.
+                if (!(type instanceof XmlSchemaComplexType)) {
+                    continue;
+                }
+                // the names are misleading, but that's OK.
+                utils.appendLine("this.globalElementSerializers['" + name.toString() + "']
= "
+                                 + nameManager.getJavascriptName(name)
+                                 + "_serialize;");
+                utils.appendLine("this.globalElementDeserializers['" + name.toString() +
"'] = "
+                                 + nameManager.getJavascriptName(name)
+                                 + "_deserialize;");
+            }
         }
-
     }
 
     private String getFunctionGlobalName(QName itemName, String itemType) {

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java?rev=611659&r1=611658&r2=611659&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
Sun Jan 13 13:51:44 2008
@@ -592,9 +592,8 @@
         utils.appendLine("var value = null;");
         utils.startIf("!cxfjsutils.isElementNil(curElement)");
         if (itemInfo.isAnyType()) {
-            // All I can think of to do is deliver the DOM.
-            // unless we have xsi:type
-            utils.appendLine(valueTarget + " = curElement;");
+            // use our utility
+            utils.appendLine(valueTarget + " = org_apache_cxf_deserialize_anyType(cxfjsutils,
curElement);");
         } else if (simple) {
             utils.appendLine("value = cxfjsutils.getNodeText(curElement);");
             utils.appendLine(valueTarget 

Modified: incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js?rev=611659&r1=611658&r2=611659&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js
Sun Jan 13 13:51:44 2008
@@ -21,6 +21,9 @@
 // Alternative, it could be made 'static', but this allowed us to use this same object
 // to carry some state.
  
+const org_apache_cxf_XSI_namespace_uri = "http://www.w3.org/2001/XMLSchema-instance";
+const org_apache_cxf_XSD_namespace_uri = "http://www.w3.org/2001/XMLSchema";
+
 function cxf_apache_org_util_null_trace(message)
 {
 }
@@ -446,5 +449,63 @@
 	this.xml = xml;
 	this.raw = true;
 	this.xsiType = true;
+}
+
+function org_apache_cxf_get_xsi_type(elementNode)
+{
+    var attributes = elementNode.attributes;
+    if ((attributes!=null) && (attributes.length > 0)) {
+        for (var x=0; x<attributes.length; x++) {
+            var attributeNodeName = attributes.item(x).nodeName;
+            var attributeNamespacePrefix = org_apache_cxf_getPrefix(attributes.item(x).nodeName);
+            var attributeNamespaceSuffix = org_apache_cxf_getLocalName(attributes.item(x).nodeName);
+			if(attributeNamespaceSuffix == 'type') {
+				// perhaps this is ours
+				var ns = org_apache_cxf_getNamespaceURI(elementNode, attributeNamespacePrefix);
+				if(ns == org_apache_cxf_XSI_namespace_uri) {
+					return attributes.item(x).nodeValue;
+				}
+			}
+        }
+        return null;
+    }
+}
+
+// return the an object if we can deserialize an object, otherwise return the element itself.
+function org_apache_cxf_deserialize_anyType(cxfjsutils, element)
+{
+	var type = org_apache_cxf_get_xsi_type(element);
+	if(type != null) {
+		// type is a :-qualified name.
+		var namespacePrefix = org_apache_cxf_getPrefix(type);
+        var localName = org_apache_cxf_getLocalName(type);
+        var uri = org_apache_cxf_getNamespaceURI(element, namespacePrefix);
+        if(uri == org_apache_cxf_XSD_namespace_uri) {
+        	// we expect a Text node below
+        	var textNode = element.firstChild;
+        	if(textNode == null)
+        		return null;
+        	var text = textNode.nodeValue;
+        	if(text == null)
+        		return null;
+        	// For any of the basic types, assume that the nodeValue is what the doctor ordered,
+            //  converted to the appropriate type.
+        	// For some of the more interesting types this needs more work.
+        	if(localName == "int" || localName == "unsignedInt" || localName == "long" || localName
== "unsignedLong") {
+        		return parseInt(text);
+        	}
+        	if(localName == "float" || localName == "double")
+        		return parseFloat(text);
+        	if(localName == "boolean") 
+        		return text == 'true';
+        	return text;
+        }
+		var qname = "{" + uri + "}" + localName;
+		var deserializer = cxfjsutils.interfaceObject.globalElementDeserializers[qname];
+		if(deserializer != null) {
+			return deserializer(cxfjsutils, element);
+		}
+	}
+	return element;
 }
 	

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java?rev=611659&r1=611658&r2=611659&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java
Sun Jan 13 13:51:44 2008
@@ -93,7 +93,6 @@
         return null;
     }
     
-//    @org.junit.Ignore
     @Test
     public void callAcceptAnyTyped() {
         testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
@@ -120,7 +119,14 @@
         String beanString = (String)testUtilities.rhinoEvaluate("globalResponseObject._return._string");
         assertEquals("lima", beanString);
         Object o1 = testUtilities.rhinoEvaluate("globalResponseObject._return._objects._anyType[0]");
-        assertTrue(o1 instanceof JsSimpleDomNode);
+        assertNotNull(o1);
+        String marker = 
+            testUtilities.rhinoEvaluateConvert("globalResponseObject._return._objects._anyType[0].typeMarker",
+                                               String.class);
+        assertEquals("aegis_fortest_javascript_cxf_apache_org_Mammal", marker);
+        Object intValue = 
+            testUtilities.rhinoEvaluate("globalResponseObject._return._objects._anyType[1]");
+        assertEquals(new Integer(42), intValue);
         return null;
     }
     



Mime
View raw message