cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r605981 - in /incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript: XmlSchemaUtils.java service/ServiceJavascriptBuilder.java types/SchemaJavascriptBuilder.java
Date Thu, 20 Dec 2007 17:24:04 GMT
Author: bimargulies
Date: Thu Dec 20 09:23:59 2007
New Revision: 605981

URL: http://svn.apache.org/viewvc?rev=605981&view=rev
Log:
Add many more comments to the generated Javascript.

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

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java?rev=605981&r1=605980&r2=605981&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
Thu Dec 20 09:23:59 2007
@@ -220,7 +220,8 @@
 
         if (global) {
             return isElementNameQualified(element, elementSchema)
-                || !(element.getQName().getNamespaceURI().equals(localSchema.getTargetNamespace()));
+                || (localSchema != null 
+                    && !(element.getQName().getNamespaceURI().equals(localSchema.getTargetNamespace())));
         } else {
             return isElementNameQualified(element, elementSchema);
         }

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=605981&r1=605980&r2=605981&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
Thu Dec 20 09:23:59 2007
@@ -102,9 +102,7 @@
     private String opFunctionGlobalName;
 
     private boolean isInUnwrappedOperation;
-
     private boolean nonVoidOutput;
-
     private boolean isRPC;
 
     public ServiceJavascriptBuilder(ServiceInfo serviceInfo, NamespacePrefixAccumulator prefixAccumulator,
@@ -220,20 +218,63 @@
             inputParameterNames.add(ean.getElementJavascriptName());
         }
     }
+    
+    
 
     private void buildOperationFunction(StringBuilder parameterList) {
         String responseCallbackParams = "";
         if (!currentOperation.isOneWay()) {
             responseCallbackParams = "successCallback, errorCallback";
         }
-            
+        
+        MessageInfo inputMessage = currentOperation.getInput();
+
+        code.append("//\n");
+        code.append("// Operation " + currentOperation.getName() + "\n");
+        if (!isWrapped) {
+            code.append("// - bare operation. Parameters:\n");
+            for (ElementInfo ei : unwrappedElementsAndNames) {
+                code.append("// - " + getElementObjectName(ei) + "\n");
+            }
+        } else {
+            code.append("// Wrapped operation.\n");
+            XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(inputWrapperComplexType);
+
+            for (int i = 0; i < sequence.getItems().getCount(); i++) {
+                code.append("// parameter " + inputParameterNames.get(i) + "\n");
+                XmlSchemaElement sequenceElement = (XmlSchemaElement)sequence.getItems().getItem(i);
+                ElementInfo elementInfo = ElementInfo.forLocalElement(sequenceElement, 
+                                                                      "", 
+                                                                      null,
+                                                                      xmlSchemaCollection,

+                                                                      prefixAccumulator);

+                if (elementInfo.isArray()) {
+                    code.append("// - array\n");
+                }
+                XmlSchemaType elementType = elementInfo.getType();
+                if (elementType instanceof XmlSchemaComplexType) {
+                    QName baseName;
+                    if (elementType.getQName() != null) {
+                        baseName = elementType.getQName();
+                    } else {
+                        baseName = elementInfo.getElement().getQName();
+                    }
+                    code.append("// - Object constructor is " 
+                                    + nameManager.getJavascriptName(baseName) + "\n");
+                } else {
+                    code.append("// - simple type " + elementType.getQName());
+                }
+            }       
+        }
+        
+        code.append("//\n");
+        
         code.append("function " 
                     +  opFunctionGlobalName
                     + "("  + responseCallbackParams
                     + ((parameterList.length() > 0 && !currentOperation.isOneWay())

                         ? ", " + parameterList : "") + ") {\n");
         utils.appendLine("var xml = null;");
-        MessageInfo inputMessage = currentOperation.getInput();
         if (inputMessage != null) {
             utils.appendLine("var args = new Array(" + inputParameterNames.size() + ");");
             int px = 0;
@@ -424,6 +465,35 @@
         }
         code.append("}\n");
     }
+    
+    private String getElementObjectName(ElementInfo element) {
+        
+        XmlSchemaType type;
+        
+        if (element.getType() != null) {
+            type = element.getType();
+        } else {
+            type = element.getElement().getSchemaType();
+        }
+
+        if (!element.isEmpty()) {
+            if (type instanceof XmlSchemaComplexType) {
+                // if there are no response items, the type is likely to have no name and
no particle.
+                XmlSchemaComplexType complexType = (XmlSchemaComplexType)type;
+                QName nameToDeserialize = null; 
+                if (null == complexType.getName()) {
+                    nameToDeserialize = element.getElement().getQName();
+                } else {
+                    nameToDeserialize = complexType.getQName();
+                }
+                return nameManager.getJavascriptName(nameToDeserialize);
+            } else {
+                return "type " + type.getQName(); // could it be anonymous?
+            } 
+        } else {
+            return "empty element?";
+        }
+    }
 
     private void createInputSerializer() {
         
@@ -631,7 +701,8 @@
                 currentOperation.getUnwrappedOperation().getInput().getMessageParts();
 
             for (MessagePartInfo mpi : unwrappedParts) {
-                inputParameterNames.add(mpi.getName().getLocalPart());
+                String jsParamName = JavascriptUtils.javaScriptNameToken(mpi.getName().getLocalPart());
+                inputParameterNames.add(jsParamName);
             }
 
             inputWrapperPartInfo = currentOperation.getInput().getMessagePart(0);
@@ -673,6 +744,7 @@
             } else {
                 inputWrapperClassName = nameManager.getJavascriptName(inputWrapperComplexType.getQName());
             }
+            
         }
 
         if (currentOperation.getOutput() != null) {

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=605981&r1=605980&r2=605981&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
Thu Dec 20 09:23:59 2007
@@ -151,6 +151,9 @@
         final String elementPrefix = "this._";
         
         String typeObjectName = nameManager.getJavascriptName(name);
+        code.append("//\n");
+        code.append("// Constructor for XML Schema item " + name.toString() + "\n");
+        code.append("//\n");
         code.append("function " + typeObjectName + " () {\n");
         
         for (int i = 0; i < sequence.getItems().getCount(); i++) {
@@ -174,15 +177,42 @@
             String accessorSuffix = StringUtils.capitalize(elChild.getName());
 
             String accessorName = typeObjectName + "_get" + accessorSuffix;
-            accessors.append("function " + accessorName + "() { return " + elementName +
";}\n");
-            accessors.append(typeObjectName + ".prototype.get" 
-                             + accessorSuffix + " = " + accessorName + ";\n");
+            String getFunctionProperty = typeObjectName + ".prototype.get" + accessorSuffix;

+            String setFunctionProperty = typeObjectName + ".prototype.set" + accessorSuffix;

+            code.append("//\n");
+            code.append("// accessor is " + getFunctionProperty + "\n");
+            code.append("// element get for " + elChild.getName() + "\n");
+            // can we get an anonymous type on an element in the middle of a type?
+            code.append("// - element type is " + elType.getQName() + "\n");
+            
+            if (XmlSchemaUtils.isParticleOptional(elChild)) {
+                code.append("// - optional element\n");
+            } else {
+                code.append("// - required element\n");
+                
+            }
+            
+            if (XmlSchemaUtils.isParticleArray(elChild)) {
+                code.append("// - array\n");
+                
+            }
             
+            if (nillable) {
+                code.append("// - nillable\n");
+                
+            }
+            code.append("//\n");
+            code.append("// element set for " + elChild.getName() + "\n");
+            code.append("// setter function is is " + setFunctionProperty + "\n");
+            code.append("//\n");
+
+            code.append("//\n");
+            accessors.append("function " + accessorName + "() { return " + elementName +
";}\n");
+            accessors.append(getFunctionProperty + " = " + accessorName + ";\n");
             accessorName = typeObjectName + "_set" + accessorSuffix;
             accessors.append("function " 
                              + accessorName + "(value) {" + elementName + " = value;}\n");
-            accessors.append(typeObjectName 
-                             + ".prototype.set" + accessorSuffix + " = " + accessorName +
";\n");
+            accessors.append(setFunctionProperty + " = " + accessorName + ";\n");
             
             if (XmlSchemaUtils.isParticleOptional(elChild) 
                 || (nillable && !XmlSchemaUtils.isParticleArray(elChild))) {
@@ -287,7 +317,8 @@
             utils.generateCodeToSerializeElement(elementInfo, xmlSchemaCollection);
         }
     }
-    /**
+
+       /**
      * Generate a JavaScript function that takes an element for a complex type and walks
through
      * its children using them to fill in the values for a JavaScript object.
      * @param type schema type for the process



Mime
View raw message