cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r603120 - in /incubator/cxf/trunk: rt/javascript/src/main/java/org/apache/cxf/javascript/ rt/javascript/src/main/java/org/apache/cxf/javascript/service/ rt/javascript/src/main/java/org/apache/cxf/javascript/types/ rt/javascript/src/test/jav...
Date Tue, 11 Dec 2007 02:15:33 GMT
Author: bimargulies
Date: Mon Dec 10 18:15:31 2007
New Revision: 603120

URL: http://svn.apache.org/viewvc?rev=603120&view=rev
Log:
OK, now RPC works and all the stuff that worked before works, too.

Modified:
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
    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/Messages.properties
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java
    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
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitBareClientTest.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/QueryHandlerTest.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
    incubator/cxf/trunk/tools/wsdlto/frontend/javascript/src/main/java/org/apache/cxf/tools/wsdlto/javascript/WSDLToJavaScriptProcessor.java

Modified: 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=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
Mon Dec 10 18:15:31 2007
@@ -19,89 +19,227 @@
 
 package org.apache.cxf.javascript;
 
+import java.util.logging.Logger;
+
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.ws.commons.schema.XmlSchema;
 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. 
+ * All the information needed to create the JavaScript for an Xml Schema
+ * element.
  */
-public class ElementInfo {
+public final class ElementInfo {
+    private static final Logger LOG = LogUtils.getL7dLogger(ElementInfo.class);
     private String utilsVarName;
-    private XmlSchemaElement element; 
-    private String elementJavascriptName;
-    private String elementXmlName;
-    private SchemaCollection xmlSchemaCollection;
-    private String referencingURI;
+    private XmlSchemaElement element;
+    private String javascriptName;
+    private String xmlName;
     private XmlSchemaType containingType;
     // in the RPC case, we can have a type and no element.
     private XmlSchemaType type;
     private boolean empty;
-    
-    public ElementInfo(XmlSchemaElement element, XmlSchemaType type, String partJavascriptVar,
-                       String elementXmlRef, boolean empty) {
-        this.element = element;
-        this.type = type;
-        this.elementJavascriptName = partJavascriptVar;
-        this.elementXmlName = elementXmlRef;
-        this.empty = empty;
+    // These are exactly the same values as we find in the XmlSchemaElement.
+    // there is no rationalization.
+    private long minOccurs;
+    private long maxOccurs;
+
+    private ElementInfo() {
+    }
+
+    public static ElementInfo forGlobalElement(XmlSchemaElement element, String javascriptPrefix,
+                                               XmlSchema currentSchema, SchemaCollection
schemaCollection,
+                                               NamespacePrefixAccumulator prefixAccumulator)
{
+        ElementInfo elementInfo = new ElementInfo();
+        elementInfo.element = element;
+        elementInfo.minOccurs = element.getMinOccurs();
+        elementInfo.maxOccurs = element.getMaxOccurs();
+
+        factoryCommon(element, 
+                     true,
+                     javascriptPrefix,
+                     currentSchema, 
+                     schemaCollection, 
+                     prefixAccumulator, 
+                     elementInfo);
+        return elementInfo;
     }
     
-    public ElementInfo() {
+    /**
+     * Create element information for a part element. For a part, the JavaScript and Element
names are 
+     * calculated in advance, and the element itself might be null! In that case, the minOccurs
+     * and maxOccurs are conventional. 
+     * @param element the element, or null
+     * @param schemaCollection the schema collection, for resolving types.
+     * @param javascriptName javascript variable name
+     * @param xmlElementName xml element string
+     * @return
+     */
+    public static ElementInfo forPartElement(XmlSchemaElement element,
+                                             SchemaCollection schemaCollection,
+                                             String javascriptName,
+                                             String xmlElementName) {
+        ElementInfo elementInfo = new ElementInfo();
+        elementInfo.element = element;
+        if (element == null) {
+            elementInfo.minOccurs = 1;
+            elementInfo.maxOccurs = 1;
+        } else {
+            elementInfo.minOccurs = element.getMinOccurs();
+            elementInfo.maxOccurs = element.getMaxOccurs();
+            factorySetupType(element, schemaCollection, elementInfo);
+        }
+        elementInfo.javascriptName = javascriptName;
+        elementInfo.xmlName = xmlElementName;
+        
+        return elementInfo;
+    }
+
+    public static ElementInfo forLocalElement(XmlSchemaElement sequenceElement, 
+                                              String javascriptPrefix,
+                                              XmlSchema currentSchema, 
+                                              SchemaCollection schemaCollection,
+                                              NamespacePrefixAccumulator prefixAccumulator)
{
+        ElementInfo elementInfo = new ElementInfo();
+        XmlSchemaElement realElement = sequenceElement;
+        boolean global = false;
+
+        if (sequenceElement.getRefName() != null) {
+            XmlSchemaElement refElement = schemaCollection.getElementByQName(sequenceElement.getRefName());
+            if (refElement == null) {
+                Message message = new Message("ELEMENT_DANGLING_REFERENCE", LOG, sequenceElement.getQName(),
+                                              sequenceElement.getRefName());
+                throw new UnsupportedConstruct(message.toString());
+            }
+
+            realElement = refElement;
+
+        }
+        elementInfo.minOccurs = sequenceElement.getMinOccurs();
+        elementInfo.maxOccurs = sequenceElement.getMaxOccurs();
+        
+        factoryCommon(realElement, 
+                     global, 
+                     javascriptPrefix,
+                     currentSchema, 
+                     schemaCollection, 
+                     prefixAccumulator, 
+                     elementInfo);
+        
+        elementInfo.element = realElement;
+
+        return elementInfo;
+    }
+
+    private static void factoryCommon(XmlSchemaElement element, 
+                                      boolean global,
+                                      String javascriptPrefix,
+                                      XmlSchema currentSchema,
+                                      SchemaCollection schemaCollection,
+                                      NamespacePrefixAccumulator prefixAccumulator, 
+                                      ElementInfo elementInfo) {
+        String elementNamespaceURI = element.getQName().getNamespaceURI();
+        boolean elementNoNamespace = "".equals(elementNamespaceURI);
+
+        XmlSchema elementSchema = null;
+        if (!elementNoNamespace) {
+            elementSchema = schemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
+            if (elementSchema == null) {
+                throw new RuntimeException("Missing schema " + elementNamespaceURI);
+            }
+        }
+
+        boolean qualified = !elementNoNamespace
+                            && XmlSchemaUtils.isElementQualified(element, true, currentSchema,
elementSchema);
+        elementInfo.xmlName = prefixAccumulator.xmlElementString(element, qualified);
+        
+        factorySetupType(element, schemaCollection, elementInfo);
+        
+        // we are assuming here that we are not dealing, in close proximity,
+        // with elements with identical local names and different namespaces.
+        elementInfo.javascriptName = javascriptPrefix + element.getQName().getLocalPart();
+    }
+
+    private static void factorySetupType(XmlSchemaElement element, SchemaCollection schemaCollection,
+                                         ElementInfo elementInfo) {
+        elementInfo.type = element.getSchemaType();
+        if (elementInfo.type == null) {
+            elementInfo.type = schemaCollection.getTypeByQName(element.getSchemaTypeName());
+            if (elementInfo.type == null) {
+                throw new RuntimeException("null type");
+            }
+        }
     }
 
     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;
+        return javascriptName;
     }
-    public void setElementJavascriptName(String elementJavascriptName) {
-        this.elementJavascriptName = elementJavascriptName;
+    
+    public void setElementJavascriptName(String name) {
+        javascriptName = name;
     }
+
     public String getElementXmlName() {
-        return elementXmlName;
+        return xmlName;
     }
+
     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;
+        this.xmlName = elementXmlName;
     }
+
     public XmlSchemaType getContainingType() {
         return containingType;
     }
+
     public void setContainingType(XmlSchemaType containingType) {
         this.containingType = containingType;
     }
+
     public XmlSchemaType getType() {
         return type;
     }
+
     public void setType(XmlSchemaType type) {
         this.type = type;
     }
+
     public boolean isEmpty() {
         return empty;
     }
+
     public void setEmpty(boolean empty) {
         this.empty = empty;
     }
+
+    public long getMinOccurs() {
+        return minOccurs;
+    }
+
+    public long getMaxOccurs() {
+        return maxOccurs;
+    }
+
+    public boolean isArray() {
+        return maxOccurs > 1;
+    }
+    
+    public boolean isOptional() {
+        return minOccurs == 0 && maxOccurs == 1;
+    }
+
 }

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java?rev=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
Mon Dec 10 18:15:31 2007
@@ -132,7 +132,7 @@
             try {
                 for (SchemaInfo schema : schemata) {
                     SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
-                        .getXmlSchemaCollection(), prefixManager, nameManager, schema);
+                        .getXmlSchemaCollection(), prefixManager, nameManager);
                     String allThatJavascript = builder.generateCodeForSchema(schema);
                     writer.append(allThatJavascript);
                 }

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=603120&r1=603119&r2=603120&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
Mon Dec 10 18:15:31 2007
@@ -27,14 +27,15 @@
 
 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;
 
 /**
- * 
+ * A set of functions that assist in JavaScript generation. This includes functions
+ * for appending strings of JavaScript to a buffer as well as some type utilities.
  */
 public class JavascriptUtils {
     private static final String NL = "\n";
@@ -191,25 +192,14 @@
         return token;
     }
     
-    public void generateCodeToSerializeElement(ElementInfo elementInfo) {
-        XmlSchemaElement element = elementInfo.getElement();
+    public void generateCodeToSerializeElement(ElementInfo elementInfo,
+                                               SchemaCollection schemaCollection) {
         XmlSchemaType type = elementInfo.getType();
-        boolean nillable = element == null || elementInfo.getElement().isNillable();
-        boolean optional = element == null || XmlSchemaUtils.isParticleOptional(elementInfo.getElement());
-        boolean array = element != null && XmlSchemaUtils.isParticleArray(elementInfo.getElement());
-        
-        XmlSchemaType elType = type;
-        // perhaps push this up into the callers.
-        if (elType == null) {
-            XmlSchemaUtils.getElementType(elementInfo.getXmlSchemaCollection(),
-                                          elementInfo.getReferencingURI(),
-                                          elementInfo.getElement(), 
-                                          elementInfo.getContainingType());
-            if (elType == null) {
-                throw new UnsupportedConstruct("Null type");
-            }
-        }
-
+        boolean nillable = elementInfo.getElement() != null 
+            && elementInfo.getElement().isNillable();
+        boolean optional = elementInfo.isOptional();
+        boolean array = elementInfo.isArray();
+        
         // first question: optional?
         if (optional) {
             startIf(elementInfo.getElementJavascriptName() + " != null");
@@ -241,13 +231,13 @@
         }
         
         // now for the thing itself.
-        if (elType instanceof XmlSchemaComplexType) {
+        if (type instanceof XmlSchemaComplexType) {
             // it has a value
             appendExpression(elementInfo.getElementJavascriptName() + ".serialize(" 
                              + elementInfo.getUtilsVarName() + ", '" 
                              + elementInfo.getElementXmlName() + "')");
         } else { // simple type
-            QName typeName = elType.getQName();
+            QName typeName = type.getQName();
             appendString("<" + elementInfo.getElementXmlName() + ">");
             // warning: this assumes that ordinary Javascript serialization is all we need.
             // except for &gt; ad all of that.

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/Messages.properties?rev=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/Messages.properties
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/Messages.properties
Mon Dec 10 18:15:31 2007
@@ -22,7 +22,7 @@
 NULL_PARTICLE=JavaScript limitation: Type {0} has no particle. {1} 
 NON_ELEMENT_CHILD=JavaScript limitation: Non-Element sequence member {0} of {1}. {2}
 ABSTRACT_ELEMENT=JavaScript limitation: Abstract element {0} of {1}. {2}
-ELEMENT_HAS_NO_TYPE= Element {0} has no type in the schema. {1}
-ELEMENT_TYPE_MISSING= Element {0} references type {1} which is not defined.
-
+ELEMENT_HAS_NO_TYPE=Element {0} has no type in the schema. {1}
+ELEMENT_TYPE_MISSING=Element {0} references type {1} which is not defined.
+ELEMENT_SCHEMA_MISSING=Element {0} contained in missing schema.
 

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java?rev=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java
Mon Dec 10 18:15:31 2007
@@ -27,7 +27,6 @@
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 
 public class NamespacePrefixAccumulator {
@@ -76,24 +75,19 @@
     
     /**
      * This function obtains a name, perhaps namespace-qualified, for an element.
-     * It also maintains a Map that records all the prefixes used in the course
-     * of working on a single serializer function (and thus a single complex-type-element
-     * XML element) which is used for namespace prefix management.
-     * @param element
-     * @param namespaceMap
+     * @param element the element.
+     * @param qualified whether to qualify.
      * @return
      */
-    public String xmlElementString(SchemaInfo schemaInfo, XmlSchemaElement element) {
-        String namespaceURI = XmlSchemaUtils.getElementQualifier(schemaInfo, element);
-        if ("".equals(namespaceURI)) {
-            return element.getName(); // use the non-qualified name.
-        } else {
+    public String xmlElementString(XmlSchemaElement element, boolean qualified) {
+        if (qualified) {
             // What if there were a prefix in the element's qname? This is not apparently

             // something that happens in this environment.
-            String prefix = getPrefix(namespaceURI);
-            collect(prefix, namespaceURI);
+            String prefix = getPrefix(element.getQName().getNamespaceURI());
+            collect(prefix, element.getQName().getNamespaceURI());
             return prefix + ":" + element.getName();
         }
+        return element.getName(); // use the non-qualified name.
     }
     
     public String xmlElementString(QName name) { // used with part concrete names

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=603120&r1=603119&r2=603120&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
Mon Dec 10 18:15:31 2007
@@ -26,8 +26,8 @@
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.wsdl.WSDLConstants;
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaForm;
@@ -167,40 +167,54 @@
         return type instanceof XmlSchemaComplexType;
     }
     
-    public static boolean isElementNameQualified(XmlSchemaElement element, SchemaInfo schemaInfo)
{
+    public static boolean isElementNameQualified(XmlSchemaElement element, XmlSchema schema)
{
+        if (element.getRefName() != null) {
+            throw new RuntimeException("isElementNameQualified on element with ref=");
+        }
         if (element.getForm().equals(QUALIFIED)) {
             return true;
         }
         if (element.getForm().equals(UNQUALIFIED)) {
             return false;
         }
-        return schemaInfo.getSchema().getElementFormDefault().equals(QUALIFIED);
+        return schema.getElementFormDefault().equals(QUALIFIED);
     }
     
     /**
-     * Return an empty string if this element should be unqualified in XML
-     * or the namespace URI if it should be qualified. 
-     * @param element
-     * @return
+     * due to a bug, feature, or just plain oddity of JAXB, it isn't good enough to just
check the 
+     * for of an element and of its schema. If schema 'a' (default unqualified) has a complex
type
+     * with an element with a ref= to schema (b) (default unqualified), JAXB seems to expect
to
+     * see a qualifier, anyway.
+     * <br/>
+     * So, if the element is local to a complex type, all we care about is the default element
form of the
+     * schema and the local form of the element.
+     * <br/>
+     * If, on the other hand, the element is global, we might need to compare namespaces.

+     * <br/>
+     * @param element the element.
+     * @param global if this element is a global element (complex type ref= to it, or in
a part)
+     * @param localSchema the schema of the complex type containing the reference, 
+     * only used for the 'odd case'.
+     * @param elementSchema the schema for the element.
+     * @return if the element needs to be qualified.
      */
-    public static String getElementQualifier(SchemaInfo schemaInfo, XmlSchemaElement element)
{
-        QName qname;
-        boolean forceQualification = false;
-        // JAXB ends up with no form='qualified', but we qualify anyway if the namespace
don't
-        // match.
+    public static boolean isElementQualified(XmlSchemaElement element,
+                                             boolean global,
+                                             XmlSchema localSchema,
+                                             XmlSchema elementSchema) {
+        if (element.getQName() == null) {
+            throw new RuntimeException("getSchemaQualifier on anonymous element.");
+        }
         if (element.getRefName() != null) {
-            qname = element.getRefName();
-            forceQualification = !qname.getNamespaceURI().equals(schemaInfo.getNamespaceURI());
-        } else {
-            qname = element.getQName();
+            throw new RuntimeException("getSchemaQualified on the 'from' side of ref=.");
         }
-        // some elements don't have qnames, only local names.
-        // one hopes that we aren't called upon to produce a qualified form for such an element,
though
-        // perhaps we're supposed to pull the TNS out of a hat.
-        if (forceQualification || isElementNameQualified(element, schemaInfo)) {
-            return qname.getNamespaceURI();
+            
+
+        if (global) {
+            return isElementNameQualified(element, elementSchema)
+                || !(element.getQName().getNamespaceURI().equals(localSchema.getTargetNamespace()));
         } else {
-            return "";
+            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=603120&r1=603119&r2=603120&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
Mon Dec 10 18:15:31 2007
@@ -74,7 +74,6 @@
     private Set<MessageInfo> inputMessagesWithNameConflicts;
     private Set<MessageInfo> outputMessagesWithNameConflicts;
     private SchemaCollection xmlSchemaCollection;
-    private String serviceTargetNamespace;
     
     private boolean isWrapped;
     // facts about the wrapper when there is one.
@@ -149,8 +148,6 @@
         utils.appendLine("this._onsuccess = null;");
         utils.appendLine("this._onerror = null;");
         code.append("}\n\n");
-
-        serviceTargetNamespace = serviceInfo.getTargetNamespace();
     }
 
     private String getFunctionGlobalName(QName itemName, String itemType) {
@@ -439,8 +436,8 @@
             + "_serializeInput";
 
         code.append("function " + serializerFunctionGlobalName + "(cxfutils, args) {\n");
-        String wrapperXmlElementName = null; 
 
+        String wrapperXmlElementName = null; 
         // for the wrapped case, we can name the object for Javascript after whatever we
like.
         // we could use the wrapped part, or we could use a conventional name.
         if (isWrapped) {
@@ -469,17 +466,14 @@
         utils.setXmlStringAccumulator("xml");
         
         if (isWrapped) {
-            ElementInfo elementInfo = new ElementInfo();
+            ElementInfo elementInfo = ElementInfo.forPartElement(inputWrapperElement,
+                                                                 xmlSchemaCollection,
+                                                                 "wrapperObj",
+                                                                 wrapperXmlElementName);
+
             elementInfo.setContainingType(null);
-            elementInfo.setElement(inputWrapperElement);
-            elementInfo.setType(inputWrapperElement.getSchemaType());
-            elementInfo.setElementJavascriptName("wrapperObj");
-            elementInfo.setElementXmlName(wrapperXmlElementName);
-            elementInfo.setReferencingURI(serviceTargetNamespace);
             elementInfo.setUtilsVarName("cxfutils");
-            elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
-
-            utils.generateCodeToSerializeElement(elementInfo);
+            utils.generateCodeToSerializeElement(elementInfo, xmlSchemaCollection);
         } else {
             String operationXmlElement = null;
             if (isRPC) {
@@ -501,16 +495,14 @@
             // (though if the same sort of thing happens elsewhere due to an XmlRootElement,
             // the JavaScript programmer is stuck with the situation). 
             for (ElementInfo ean : unwrappedElementsAndNames) {
-                ElementInfo elementInfo = new ElementInfo();
+                ElementInfo elementInfo = ElementInfo.forPartElement(ean.getElement(),
+                                                                     xmlSchemaCollection,
+                                                                     "args[" + px + "]",
+                                                                     ean.getElementXmlName());
                 elementInfo.setContainingType(null);
-                elementInfo.setElement(ean.getElement());
                 elementInfo.setType(ean.getType());
-                elementInfo.setElementJavascriptName("args[" + px + "]");
-                elementInfo.setElementXmlName(ean.getElementXmlName());
-                elementInfo.setReferencingURI(serviceTargetNamespace);
                 elementInfo.setUtilsVarName("cxfutils");
-                elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
-                utils.generateCodeToSerializeElement(elementInfo);
+                utils.generateCodeToSerializeElement(elementInfo, xmlSchemaCollection);
                 px++;
             }
             if (isRPC) {
@@ -609,14 +601,21 @@
                         element.setSchemaType(xmlSchemaCollection
                                                   .getTypeByQName(element.getSchemaTypeName()));
                     }
+                    type = element.getSchemaType();
                 }
             }
             
             String partJavascriptVar = 
                 JavascriptUtils.javaScriptNameToken(mpi.getConcreteName().getLocalPart());
             String elementXmlRef = prefixAccumulator.xmlElementString(mpi.getConcreteName());
-
-            elements.add(new ElementInfo(element, type, partJavascriptVar, elementXmlRef,
empty));
+            ElementInfo elementInfo = ElementInfo.forPartElement(element,
+                                                                 xmlSchemaCollection,
+                                                                 partJavascriptVar, 
+                                                                 elementXmlRef);        
+            // the type may have been recalculated above.
+            elementInfo.setType(type);
+            elementInfo.setEmpty(empty);
+            elements.add(elementInfo);
         }
     }
     

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=603120&r1=603119&r2=603120&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
Mon Dec 10 18:15:31 2007
@@ -35,6 +35,7 @@
 import org.apache.cxf.javascript.UnsupportedConstruct;
 import org.apache.cxf.javascript.XmlSchemaUtils;
 import org.apache.cxf.service.model.SchemaInfo;
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaObject;
@@ -55,20 +56,19 @@
     
     private SchemaCollection xmlSchemaCollection;
     private NameManager nameManager;
-    private SchemaInfo schemaInfo;
     private NamespacePrefixAccumulator prefixAccumulator;
+    private SchemaInfo schemaInfo;
     
     public SchemaJavascriptBuilder(SchemaCollection schemaCollection,
                                    NamespacePrefixAccumulator prefixAccumulator,
-                                   NameManager nameManager, 
-                                   SchemaInfo schemaInfo) {
+                                   NameManager nameManager) {
         this.xmlSchemaCollection = schemaCollection;
         this.nameManager = nameManager;
-        this.schemaInfo = schemaInfo;
         this.prefixAccumulator = prefixAccumulator;
     }
     
     public String generateCodeForSchema(SchemaInfo schema) {
+        schemaInfo = schema;
         StringBuffer code = new StringBuffer();
         code.append("//\n");
         code.append("// Definitions for schema: " + schema.getNamespaceURI());
@@ -273,36 +273,19 @@
 
         // XML Schema, please meet Iterable (not).
         for (int i = 0; i < sequence.getItems().getCount(); i++) {
-            XmlSchemaElement elChild = (XmlSchemaElement)sequence.getItems().getItem(i);
-            if (elChild.isAbstract()) {
-                XmlSchemaUtils.unsupportedConstruct("ABSTRACT_ELEMENT", elChild.getName(),
type);
+            XmlSchemaElement sequenceElement = (XmlSchemaElement)sequence.getItems().getItem(i);
+            if (sequenceElement.isAbstract()) {
+                XmlSchemaUtils.unsupportedConstruct("ABSTRACT_ELEMENT", sequenceElement.getName(),
type);
             }
             
-            // assume that no lunatic has created multiple elements that differ only by namespace.
-            // or, perhaps, detect that when generating the parser?
-            if (elChild.getRefName() != null) {
-                XmlSchemaElement refElement = xmlSchemaCollection.getElementByQName(elChild.getRefName());
-                if (refElement == null) {
-                    Message message = new Message("ELEMENT_DANGLING_REFERENCE", LOG,
-                                                  elChild.getQName(),
-                                                  elChild.getRefName());
-                    throw new UnsupportedConstruct(message.toString());
-                }
-                elChild = refElement;
-            }
-            String elementName = elementPrefix + elChild.getName();
-            String elementXmlRef = prefixAccumulator.xmlElementString(schemaInfo, elChild);
-            
-            ElementInfo elementInfo = new ElementInfo();
+            ElementInfo elementInfo = ElementInfo.forLocalElement(sequenceElement, 
+                                                                  elementPrefix, 
+                                                                  schemaInfo.getSchema(),
+                                                                  xmlSchemaCollection, 
+                                                                  prefixAccumulator);
             elementInfo.setContainingType(type);
-            elementInfo.setElement(elChild);
-            elementInfo.setElementJavascriptName(elementName);
-            elementInfo.setElementXmlName(elementXmlRef);
-            elementInfo.setReferencingURI(null);
             elementInfo.setUtilsVarName("cxfjsutils");
-            elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
-            elementInfo.setType(elChild.getSchemaType());
-            utils.generateCodeToSerializeElement(elementInfo);
+            utils.generateCodeToSerializeElement(elementInfo, xmlSchemaCollection);
         }
     }
     /**
@@ -344,27 +327,56 @@
                                                     thing.getClass().getSimpleName(), type);
             }
             
-            XmlSchemaElement elChild = (XmlSchemaElement)thing;
-            XmlSchemaType elType = XmlSchemaUtils.getElementType(xmlSchemaCollection, null,
elChild, type);
+            boolean global = false;
+            XmlSchemaElement sequenceElement = (XmlSchemaElement)thing;
+            XmlSchemaElement realElement = sequenceElement;
+            
+            if (sequenceElement.getRefName() != null) {
+                XmlSchemaElement refElement = 
+                    xmlSchemaCollection.getElementByQName(sequenceElement.getRefName());
+                if (refElement == null) {
+                    throw new RuntimeException("Dangling reference");
+                }
+                realElement = refElement;
+                global = true;
+            }
+            
+            XmlSchemaType elType = XmlSchemaUtils.getElementType(xmlSchemaCollection, 
+                                                                 null, realElement, type);
             boolean simple = elType instanceof XmlSchemaSimpleType;
 
-            String accessorName = "set" + StringUtils.capitalize(elChild.getName()); 
+            String accessorName = "set" + StringUtils.capitalize(realElement.getName());

             // For optional or an array, we need to check if the element is the 
             // one we want.
             
-            String elementName = elChild.getName();
+            String elementName = realElement.getName();
             utils.appendLine("cxfjsutils.trace('processing " + elementName + "');");
-            String elementNamespaceURI = XmlSchemaUtils.getElementQualifier(schemaInfo, elChild);
+            String elementNamespaceURI = realElement.getQName().getNamespaceURI();
+            boolean elementNoNamespace = "".equals(elementNamespaceURI);
+            XmlSchema elementSchema = null;
+            if (!elementNoNamespace) {
+                elementSchema = xmlSchemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
+            }
+            boolean qualified = !elementNoNamespace
+                && XmlSchemaUtils.isElementQualified(realElement, 
+                                                  global, 
+                                                  schemaInfo.getSchema(),
+                                                  elementSchema);
             
+            if (!qualified) {
+                elementNamespaceURI = "";
+            }
+                
             String valueTarget = "item";
 
-            if (XmlSchemaUtils.isParticleOptional(elChild) || XmlSchemaUtils.isParticleArray(elChild))
{
+            if (XmlSchemaUtils.isParticleOptional(sequenceElement) 
+                || XmlSchemaUtils.isParticleArray(sequenceElement)) {
                 utils.startIf("curElement != null && cxfjsutils.isNodeNamedNS(curElement,
'" 
                               + elementNamespaceURI 
                               + "', '" 
                               + elementName
                               + "')");
-                if (XmlSchemaUtils.isParticleArray(elChild)) {
+                if (XmlSchemaUtils.isParticleArray(sequenceElement)) {
                     utils.appendLine("item = [];");
                     utils.startDo();
                     valueTarget = "arrayItem";
@@ -387,21 +399,22 @@
             }
              
             utils.endBlock(); // the if for the nil.
-            if (XmlSchemaUtils.isParticleArray(elChild)) {
+            if (XmlSchemaUtils.isParticleArray(sequenceElement)) {
                 utils.appendLine("item.push(arrayItem);");
                 utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
                 utils.endBlock();
                 utils.appendLine("  while(curElement != null && cxfjsutils.isNodeNamedNS(curElement,
'" 
                                   + elementNamespaceURI + "', '" 
-                                  + elChild.getName() + "'));");
+                                  + sequenceElement.getName() + "'));");
             }
             utils.appendLine("newobject." + accessorName + "(item);");
-            if (!XmlSchemaUtils.isParticleArray(elChild)) {
+            if (!XmlSchemaUtils.isParticleArray(sequenceElement)) {
                 utils.startIf("curElement != null");
                 utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
                 utils.endBlock();
             }
-            if (XmlSchemaUtils.isParticleOptional(elChild) || XmlSchemaUtils.isParticleArray(elChild))
{
+            if (XmlSchemaUtils.isParticleOptional(sequenceElement) 
+                || XmlSchemaUtils.isParticleArray(sequenceElement)) {
                 utils.endBlock();
             }
         }

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitBareClientTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitBareClientTest.java?rev=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitBareClientTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitBareClientTest.java
Mon Dec 10 18:15:31 2007
@@ -215,7 +215,6 @@
         return null;
     }
     
-    @org.junit.Ignore
     @Test
     public void callFunctionWithBeans() {
         LOG.info("about to call beanFunctionTest");
@@ -226,7 +225,6 @@
         });
     }
 
-    @org.junit.Ignore
     @Test
     public void callCompliant() {
         LOG.info("about to call compliant");

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java?rev=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
Mon Dec 10 18:15:31 2007
@@ -354,7 +354,7 @@
             .getXmlSchemaCollection());
         for (SchemaInfo schema : schemata) {
             SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
-                .getXmlSchemaCollection(), prefixManager, nameManager, schema);
+                .getXmlSchemaCollection(), prefixManager, nameManager);
             String allThatJavascript = builder.generateCodeForSchema(schema);
             readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
         }

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/QueryHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/QueryHandlerTest.java?rev=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/QueryHandlerTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/QueryHandlerTest.java
Mon Dec 10 18:15:31 2007
@@ -94,7 +94,6 @@
         return js.toString();
     }
     
-    @org.junit.Ignore
     @Test
     public void hwQueryTest() throws Exception {
         URL endpointURL = new URL(hwEndpoint.getAddress()  + "?js");

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java?rev=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
Mon Dec 10 18:15:31 2007
@@ -120,7 +120,6 @@
     }
 
     @Test
-    @org.junit.Ignore
     public void testSerialization() throws Exception {
         setupClientAndRhino("simple-dlwu-proxy-factory");
 
@@ -202,7 +201,7 @@
             new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
         for (SchemaInfo schema : schemata) {
             SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
-                .getXmlSchemaCollection(), prefixAccumulator, nameManager, schema);
+                .getXmlSchemaCollection(), prefixAccumulator, nameManager);
             String allThatJavascript = builder.generateCodeForSchema(schema);
             assertNotNull(allThatJavascript);
             testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");

Modified: incubator/cxf/trunk/tools/wsdlto/frontend/javascript/src/main/java/org/apache/cxf/tools/wsdlto/javascript/WSDLToJavaScriptProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/javascript/src/main/java/org/apache/cxf/tools/wsdlto/javascript/WSDLToJavaScriptProcessor.java?rev=603120&r1=603119&r2=603120&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/frontend/javascript/src/main/java/org/apache/cxf/tools/wsdlto/javascript/WSDLToJavaScriptProcessor.java
(original)
+++ incubator/cxf/trunk/tools/wsdlto/frontend/javascript/src/main/java/org/apache/cxf/tools/wsdlto/javascript/WSDLToJavaScriptProcessor.java
Mon Dec 10 18:15:31 2007
@@ -66,8 +66,9 @@
             BufferedWriter writer = new BufferedWriter(outputStreamWriter);
                 
             for (SchemaInfo schema : schemata) {
-                SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo
-                    .getXmlSchemaCollection(), prefixManager, nameManager, schema);
+                SchemaJavascriptBuilder jsBuilder = 
+                    new SchemaJavascriptBuilder(serviceInfo
+                    .getXmlSchemaCollection(), prefixManager, nameManager);
                 String allThatJavascript = jsBuilder.generateCodeForSchema(schema);
                 writer.append(allThatJavascript);
             }



Mime
View raw message