cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r601452 - in /incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript: ElementInfo.java JavascriptUtils.java service/ServiceJavascriptBuilder.java types/SchemaJavascriptBuilder.java
Date Wed, 05 Dec 2007 18:03:40 GMT
Author: bimargulies
Date: Wed Dec  5 10:03:40 2007
New Revision: 601452

URL: http://svn.apache.org/viewvc?rev=601452&view=rev
Log:
A week has seven days (max) and a CXF Java method has seven parameters (max). Doesn't anyone
in here read 
Terry Prachet? Remodularize to introduce a bean with, yes, eight items in it to allow dealing
with top-level
parts that are arrays.

Added:
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
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

Added: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java?rev=601452&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
(added)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
Wed Dec  5 10:03:40 2007
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.javascript;
+
+import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * All the information needed to create the JavaScript for an Xml Schema element. 
+ */
+public class ElementInfo {
+    private String utilsVarName;
+    private XmlSchemaElement element; 
+    private String elementJavascriptName;
+    private String elementXmlName;
+    private SchemaCollection xmlSchemaCollection;
+    private String referencingURI;
+    private XmlSchemaType containingType;
+    private boolean partElement;
+    
+    public String getUtilsVarName() {
+        return utilsVarName;
+    }
+    public void setUtilsVarName(String utilsVarName) {
+        this.utilsVarName = utilsVarName;
+    }
+    public XmlSchemaElement getElement() {
+        return element;
+    }
+    public void setElement(XmlSchemaElement element) {
+        this.element = element;
+    }
+    public String getElementJavascriptName() {
+        return elementJavascriptName;
+    }
+    public void setElementJavascriptName(String elementJavascriptName) {
+        this.elementJavascriptName = elementJavascriptName;
+    }
+    public String getElementXmlName() {
+        return elementXmlName;
+    }
+    public void setElementXmlName(String elementXmlName) {
+        this.elementXmlName = elementXmlName;
+    }
+    public SchemaCollection getXmlSchemaCollection() {
+        return xmlSchemaCollection;
+    }
+    public void setXmlSchemaCollection(SchemaCollection xmlSchemaCollection) {
+        this.xmlSchemaCollection = xmlSchemaCollection;
+    }
+    public String getReferencingURI() {
+        return referencingURI;
+    }
+    public void setReferencingURI(String referencingURI) {
+        this.referencingURI = referencingURI;
+    }
+    public XmlSchemaType getContainingType() {
+        return containingType;
+    }
+    public void setContainingType(XmlSchemaType containingType) {
+        this.containingType = containingType;
+    }
+    public boolean isPartElement() {
+        return partElement;
+    }
+    public void setPartElement(boolean partElement) {
+        this.partElement = partElement;
+    }
+
+}

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=601452&r1=601451&r2=601452&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
Wed Dec  5 10:03:40 2007
@@ -27,10 +27,8 @@
 
 import javax.xml.namespace.QName;
 
-import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 import org.apache.ws.commons.schema.XmlSchemaType;
 
@@ -192,44 +190,42 @@
         return token;
     }
     
-    public void generateCodeToSerializeElement(String utilsVarName,
-                                               XmlSchemaElement element, 
-                                               String elementJavascriptName,
-                                               String elementXmlName,
-                                               SchemaCollection xmlSchemaCollection,
-                                               String referencingURI,
-                                               XmlSchemaType containingType) {
-        boolean nillable = element.isNillable();
-        boolean optional = XmlSchemaUtils.isParticleOptional(element);
+    public void generateCodeToSerializeElement(ElementInfo elementInfo) {
+        boolean nillable = elementInfo.getElement().isNillable();
+        boolean optional = XmlSchemaUtils.isParticleOptional(elementInfo.getElement());
         
         XmlSchemaType elType = 
-            XmlSchemaUtils.getElementType(xmlSchemaCollection, referencingURI, element, containingType);
+            XmlSchemaUtils.getElementType(elementInfo.getXmlSchemaCollection(),
+                                          elementInfo.getReferencingURI(),
+                                          elementInfo.getElement(), 
+                                          elementInfo.getContainingType());
         
         // first question: optional?
         if (optional) {
-            startIf(elementJavascriptName + " != null");
+            startIf(elementInfo.getElementJavascriptName() + " != null");
         }
         
         // nillable and optional would be very strange together.
         // and nillable in the array case applies to the elements.
-        if (nillable && !XmlSchemaUtils.isParticleArray(element)) {
-            startIf(elementJavascriptName + " == null");
-            appendString("<" + elementXmlName + " " + XmlSchemaUtils.NIL_ATTRIBUTES +
"/>");
+        if (nillable && !XmlSchemaUtils.isParticleArray(elementInfo.getElement()))
{
+            startIf(elementInfo.getElementJavascriptName() + " == null");
+            appendString("<" + elementInfo.getElementXmlName() + " " + XmlSchemaUtils.NIL_ATTRIBUTES
+ "/>");
             appendElse();
         }
 
-        if (XmlSchemaUtils.isParticleArray(element)) {
+        if (XmlSchemaUtils.isParticleArray(elementInfo.getElement())) {
             // protected against null in arrays.
-            startIf(elementJavascriptName + " != null");
-            startFor("var ax = 0", "ax < " +  elementJavascriptName + ".length", "ax ++");
-            elementJavascriptName = elementJavascriptName + "[ax]";
+            startIf(elementInfo.getElementJavascriptName() + " != null");
+            startFor("var ax = 0", "ax < " +  elementInfo.getElementJavascriptName() +
".length", "ax ++");
+            elementInfo.setElementJavascriptName(elementInfo.getElementJavascriptName() +
"[ax]");
             // we need an extra level of 'nil' testing here. Or do we, depending on the type
structure?
             // Recode and fiddle appropriately.
-            startIf(elementJavascriptName + " == null");
+            startIf(elementInfo.getElementJavascriptName() + " == null");
             if (nillable) {
-                appendString("<" + elementXmlName + " " + XmlSchemaUtils.NIL_ATTRIBUTES
+ "/>");
+                appendString("<" + elementInfo.getElementXmlName() 
+                             + " " + XmlSchemaUtils.NIL_ATTRIBUTES + "/>");
             } else {
-                appendString("<" + elementXmlName + "/>");                    
+                appendString("<" + elementInfo.getElementXmlName() + "/>");       
            
             }
             appendElse();
         }
@@ -237,33 +233,35 @@
         // now for the thing itself.
         if (elType instanceof XmlSchemaComplexType) {
             // it has a value
-            appendExpression(elementJavascriptName + ".serialize(" 
-                                     + utilsVarName + ", '" 
-                                     + elementXmlName + "')");
+            appendExpression(elementInfo.getElementJavascriptName() + ".serialize(" 
+                             + elementInfo.getUtilsVarName() + ", '" 
+                             + elementInfo.getElementXmlName() + "')");
         } else { // simple type
             QName typeName = elType.getQName();
-            appendString("<" + elementXmlName + ">");
+            appendString("<" + elementInfo.getElementXmlName() + ">");
             // warning: this assumes that ordinary Javascript serialization is all we need.
             // except for &gt; ad all of that.
             if (isStringSimpleType(typeName)) {
-                appendExpression(utilsVarName + ".escapeXmlEntities(" + elementJavascriptName
+ ")");
+                appendExpression(elementInfo.getUtilsVarName() 
+                                 + ".escapeXmlEntities(" 
+                                 + elementInfo.getElementJavascriptName() + ")");
             } else {
-                appendExpression(elementJavascriptName);
+                appendExpression(elementInfo.getElementJavascriptName());
             }
-            appendString("</" + elementXmlName + ">");
+            appendString("</" + elementInfo.getElementXmlName() + ">");
         }
         
-        if (XmlSchemaUtils.isParticleArray(element)) {
+        if (XmlSchemaUtils.isParticleArray(elementInfo.getElement())) {
             endBlock(); // for the extra level of nil checking, which might be wrong.
             endBlock(); // for the for loop.
             endBlock(); // the null protection.
         }
         
-        if (nillable && !XmlSchemaUtils.isParticleArray(element)) {
+        if (nillable && !XmlSchemaUtils.isParticleArray(elementInfo.getElement()))
{
             endBlock();
         }
         
-        if (XmlSchemaUtils.isParticleOptional(element)) {
+        if (XmlSchemaUtils.isParticleOptional(elementInfo.getElement())) {
             endBlock();
         }
 

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=601452&r1=601451&r2=601452&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
Wed Dec  5 10:03:40 2007
@@ -37,6 +37,7 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.cxf.javascript.ElementInfo;
 import org.apache.cxf.javascript.JavascriptUtils;
 import org.apache.cxf.javascript.NameManager;
 import org.apache.cxf.javascript.NamespacePrefixAccumulator;
@@ -478,24 +479,37 @@
         utils.setXmlStringAccumulator("xml");
         
         if (isWrapped) {
-            utils.generateCodeToSerializeElement("cxfutils", 
-                                                 inputWrapperElement, 
-                                                 "wrapperObj",
-                                                 wrapperXmlElementName,
-                                                 xmlSchemaCollection, 
-                                                 serviceTargetNamespace,
-                                                 null);
+            ElementInfo elementInfo = new ElementInfo();
+            elementInfo.setContainingType(null);
+            elementInfo.setElement(inputWrapperElement);
+            elementInfo.setElementJavascriptName("wrapperObj");
+            elementInfo.setElementXmlName(wrapperXmlElementName);
+            elementInfo.setReferencingURI(serviceTargetNamespace);
+            elementInfo.setUtilsVarName("cxfutils");
+            elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
+            elementInfo.setPartElement(true);
+
+            utils.generateCodeToSerializeElement(elementInfo);
         } else {
             int px = 0;
             // Multiple parts violates WS-I, but we can still do them.
+            // Parts are top-level elements. As such, they cannot, directly, be arrays.
+            // If a part is declared as an array type, the schema has a non-array element
+            // with a complex type consisting of an element with array bounds. We don't 
+            // want the JavasSript programmer to have to concoct an extra level of object
+            // (though if the same sort of thing happens elsewhere due to an XmlRootElement,
+            // the JavaScript programmer is stuck with the situation). 
             for (ElementAndNames ean : unwrappedElementsAndNames) {
-                utils.generateCodeToSerializeElement("cxfutils",
-                                                     ean.getElement(),
-                                                     "args[" + px + "]",
-                                                     ean.getXmlName(),
-                                                     xmlSchemaCollection,
-                                                     serviceTargetNamespace,
-                                                     null);
+                ElementInfo elementInfo = new ElementInfo();
+                elementInfo.setContainingType(null);
+                elementInfo.setElement(ean.getElement());
+                elementInfo.setElementJavascriptName("args[" + px + "]");
+                elementInfo.setElementXmlName(ean.getXmlName());
+                elementInfo.setReferencingURI(serviceTargetNamespace);
+                elementInfo.setUtilsVarName("cxfutils");
+                elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
+                elementInfo.setPartElement(true);
+                utils.generateCodeToSerializeElement(elementInfo);
                 px++;
             }
         }

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=601452&r1=601451&r2=601452&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
Wed Dec  5 10:03:40 2007
@@ -27,6 +27,7 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.cxf.javascript.ElementInfo;
 import org.apache.cxf.javascript.JavascriptUtils;
 import org.apache.cxf.javascript.NameManager;
 import org.apache.cxf.javascript.NamespacePrefixAccumulator;
@@ -239,8 +240,16 @@
             String elementName = elementPrefix + elChild.getName();
             String elementXmlRef = prefixAccumulator.xmlElementString(schemaInfo, elChild);
             
-            utils.generateCodeToSerializeElement("cxfjsutils", elChild, elementName, 
-                                                 elementXmlRef, xmlSchemaCollection, null,
type);
+            ElementInfo elementInfo = new ElementInfo();
+            elementInfo.setContainingType(type);
+            elementInfo.setElement(elChild);
+            elementInfo.setElementJavascriptName(elementName);
+            elementInfo.setElementXmlName(elementXmlRef);
+            elementInfo.setReferencingURI(null);
+            elementInfo.setUtilsVarName("cxfjsutils");
+            elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
+            elementInfo.setPartElement(false);
+            utils.generateCodeToSerializeElement(elementInfo);
         }
     }
     /**



Mime
View raw message