cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r606597 - 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/ test/java/org/apache/cxf/javascript/fortest/ test/resources/ t...
Date Sun, 23 Dec 2007 19:29:01 GMT
Author: bimargulies
Date: Sun Dec 23 11:29:00 2007
New Revision: 606597

URL: http://svn.apache.org/viewvc?rev=606597&view=rev
Log:
In the process of working on xs:any, discover some truly warped modularity, and clean it up.

Added:
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java
      - copied, changed from r605925, incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
Removed:
    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/types/SequenceItemInfo.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/Messages.properties
    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/fortest/SimpleDocLitBareImpl.java
    incubator/cxf/trunk/rt/javascript/src/test/resources/deserializationTests.js
    incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties
    incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/AnyTests.js

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=606597&r1=606596&r2=606597&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 Dec 23 11:29:00 2007
@@ -28,7 +28,6 @@
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.javascript.types.SequenceItemInfo;
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
@@ -212,43 +211,46 @@
     
     /**
      * Given an element, generate the serialization code.
-     * @param elementInfo
-     * @param schemaCollection
+     * @param elementInfo      description of the element we are serializing
+     * @param referencePrefix  prefix to the Javascript variable. Nothing for args,
+     * this._ for members.
+     * @param schemaCollection caller's schema collection.
      */
-    public void generateCodeToSerializeElement(ElementInfo elementInfo,
+    public void generateCodeToSerializeElement(ParticleInfo elementInfo,
+                                               String referencePrefix,
                                                SchemaCollection schemaCollection) {
         XmlSchemaType type = elementInfo.getType();
-        boolean nillable = elementInfo.getElement() != null 
-            && elementInfo.getElement().isNillable();
+        boolean nillable = elementInfo.isNillable();
         boolean optional = elementInfo.isOptional();
         boolean array = elementInfo.isArray();
+        String jsVar = referencePrefix + elementInfo.getJavascriptName();
         
         // first question: optional?
         if (optional) {
-            startIf(elementInfo.getElementJavascriptName() + " != null");
+            startIf(jsVar + " != null");
         } 
         
         // nillable and optional would be very strange together.
         // and nillable in the array case applies to the elements.
         if (nillable && !array) {
-            startIf(elementInfo.getElementJavascriptName() + " == null");
-            appendString("<" + elementInfo.getElementXmlName() + " " + XmlSchemaUtils.NIL_ATTRIBUTES + "/>");
+            startIf(jsVar + " == null");
+            appendString("<" + elementInfo.getXmlName() + " " + XmlSchemaUtils.NIL_ATTRIBUTES + "/>");
             appendElse();
         }
         
         if (array) {
             // protected against null in arrays.
-            startIf(elementInfo.getElementJavascriptName() + " != null");
-            startFor("var ax = 0", "ax < " +  elementInfo.getElementJavascriptName() + ".length", "ax ++");
-            elementInfo.setElementJavascriptName(elementInfo.getElementJavascriptName() + "[ax]");
+            startIf(jsVar + " != null");
+            startFor("var ax = 0", "ax < " +  jsVar + ".length", "ax ++");
+            jsVar = jsVar + "[ax]";
             // we need an extra level of 'nil' testing here. Or do we, depending on the type structure?
             // Recode and fiddle appropriately.
-            startIf(elementInfo.getElementJavascriptName() + " == null");
+            startIf(jsVar + " == null");
             if (nillable) {
-                appendString("<" + elementInfo.getElementXmlName() 
+                appendString("<" + elementInfo.getXmlName() 
                              + " " + XmlSchemaUtils.NIL_ATTRIBUTES + "/>");
             } else {
-                appendString("<" + elementInfo.getElementXmlName() + "/>");                    
+                appendString("<" + elementInfo.getXmlName() + "/>");                    
             }
             appendElse();
         }
@@ -256,22 +258,19 @@
         // now for the thing itself.
         if (type instanceof XmlSchemaComplexType) {
             // it has a value
-            appendExpression(elementInfo.getElementJavascriptName() + ".serialize(" 
-                             + elementInfo.getUtilsVarName() + ", '" 
-                             + elementInfo.getElementXmlName() + "')");
+            appendExpression(jsVar + ".serialize(cxfjsutils, '" 
+                             + elementInfo.getXmlName() + "')");
         } else { // simple type
             QName typeName = type.getQName();
-            appendString("<" + elementInfo.getElementXmlName() + ">");
+            appendString("<" + elementInfo.getXmlName() + ">");
             // warning: this assumes that ordinary Javascript serialization is all we need.
             // except for &gt; ad all of that.
             if (isStringSimpleType(typeName)) {
-                appendExpression(elementInfo.getUtilsVarName() 
-                                 + ".escapeXmlEntities(" 
-                                 + elementInfo.getElementJavascriptName() + ")");
+                appendExpression("cxfjsutils.escapeXmlEntities(" + jsVar + ")");
             } else {
-                appendExpression(elementInfo.getElementJavascriptName());
+                appendExpression(jsVar);
             }
-            appendString("</" + elementInfo.getElementXmlName() + ">");
+            appendString("</" + elementInfo.getXmlName() + ">");
         }
         
         if (array) {
@@ -295,13 +294,13 @@
      * @param elementInfo
      * @param schemaCollection
      */
-    public void generateCodeToSerializeAny(SequenceItemInfo itemInfo, 
+    public void generateCodeToSerializeAny(ParticleInfo itemInfo, 
                                            String prefix,
                                            SchemaCollection schemaCollection) {
         boolean optional = XmlSchemaUtils.isParticleOptional(itemInfo.getParticle());
         boolean array = XmlSchemaUtils.isParticleArray(itemInfo.getParticle());
         
-        appendLine("var anyHolder = this._" + itemInfo.getElementJavascriptVariable() + ";");
+        appendLine("var anyHolder = this._" + itemInfo.getJavascriptName() + ";");
         appendLine("var anySerializer = null;");
         appendLine("var anyXmlTag = null;");
         appendLine("var anyXmlNsDef = null;");

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=606597&r1=606596&r2=606597&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 Sun Dec 23 11:29:00 2007
@@ -26,4 +26,5 @@
 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.
+IMPOSSIBLE_GLOBAL_ITEM= JavaScript limitation: Element or xs:any at {0} used in a context that requires a global name, but it, and its type, are anonymous.
 

Copied: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java (from r605925, 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/ParticleInfo.java?p2=incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java&p1=incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java&r1=605925&r2=606597&rev=606597&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/ParticleInfo.java Sun Dec 23 11:29:00 2007
@@ -21,21 +21,24 @@
 
 import java.util.logging.Logger;
 
+import javax.xml.namespace.QName;
+
 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.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
 import org.apache.ws.commons.schema.XmlSchemaType;
 
 /**
  * All the information needed to create the JavaScript for an Xml Schema
- * element.
+ * element or xs:any.
  */
-public final class ElementInfo {
-    private static final Logger LOG = LogUtils.getL7dLogger(ElementInfo.class);
-    private String utilsVarName;
-    private XmlSchemaElement element;
+public final class ParticleInfo {
+    private static final Logger LOG = LogUtils.getL7dLogger(ParticleInfo.class);
+    private XmlSchemaParticle particle;
     private String javascriptName;
     private String xmlName;
     private XmlSchemaType containingType;
@@ -43,24 +46,37 @@
     private XmlSchemaType type;
     private boolean empty;
     // These are exactly the same values as we find in the XmlSchemaElement.
-    // there is no rationalization.
+    // there is no rationalization. But the accessors take care of business.
     private long minOccurs;
     private long maxOccurs;
+    private boolean nillable;
+    private boolean any;
+    private String defaultValue;
+    private boolean global;
 
-    private ElementInfo() {
+    private ParticleInfo() {
     }
 
-    public static ElementInfo forGlobalElement(XmlSchemaElement element, String javascriptPrefix,
-                                               XmlSchema currentSchema, SchemaCollection schemaCollection,
+    /**
+     * Create an elementInfo that stores information about a global, named, element.
+     * @param element the element   
+     * @param currentSchema the schema it came from.
+     * @param schemaCollection the collection of all schemas.
+     * @param prefixAccumulator the accumulator that assigns prefixes.
+     * @return
+     */
+    public static ParticleInfo forGlobalElement(XmlSchemaElement element, 
+                                               XmlSchema currentSchema, 
+                                               SchemaCollection schemaCollection,
                                                NamespacePrefixAccumulator prefixAccumulator) {
-        ElementInfo elementInfo = new ElementInfo();
-        elementInfo.element = element;
+        ParticleInfo elementInfo = new ParticleInfo();
+        elementInfo.particle = element;
         elementInfo.minOccurs = element.getMinOccurs();
         elementInfo.maxOccurs = element.getMaxOccurs();
+        elementInfo.nillable = element.isNillable();
+        elementInfo.global = true;
 
         factoryCommon(element, 
-                     true,
-                     javascriptPrefix,
                      currentSchema, 
                      schemaCollection, 
                      prefixAccumulator, 
@@ -69,102 +85,134 @@
     }
     
     /**
-     * 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. 
+     * 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.
+     * Note that in some cases the code in ServiceJavascriptBuilder uses a local
+     * element (or xa:any) from inside the part element, instead of the part
+     * element itself.  
      * @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,
+    public static ParticleInfo forPartElement(XmlSchemaElement element,
                                              SchemaCollection schemaCollection,
                                              String javascriptName,
                                              String xmlElementName) {
-        ElementInfo elementInfo = new ElementInfo();
-        elementInfo.element = element;
+        ParticleInfo elementInfo = new ParticleInfo();
+        elementInfo.particle = element;
         if (element == null) {
             elementInfo.minOccurs = 1;
             elementInfo.maxOccurs = 1;
         } else {
             elementInfo.minOccurs = element.getMinOccurs();
             elementInfo.maxOccurs = element.getMaxOccurs();
+            elementInfo.nillable = element.isNillable();
             factorySetupType(element, schemaCollection, elementInfo);
         }
         elementInfo.javascriptName = javascriptName;
         elementInfo.xmlName = xmlElementName;
+        elementInfo.global = true;
         
         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;
+    /**
+     * Fill in an ElementInfo for an element or xs:any from a sequence.
+     * @param sequenceElement
+     * @param currentSchema
+     * @param schemaCollection
+     * @param prefixAccumulator
+     * @return
+     */
+    public static ParticleInfo forLocalItem(XmlSchemaObject sequenceObject, 
+                                            XmlSchema currentSchema, 
+                                            SchemaCollection schemaCollection,
+                                            NamespacePrefixAccumulator prefixAccumulator,
+                                            QName contextName) {
+        XmlSchemaParticle sequenceParticle = 
+            XmlSchemaUtils.getObjectParticle(sequenceObject, contextName);
+        ParticleInfo elementInfo = new ParticleInfo();
+        XmlSchemaParticle realParticle = sequenceParticle;
+        
+        if (sequenceParticle instanceof XmlSchemaElement) {
+            XmlSchemaElement sequenceElement = (XmlSchemaElement) sequenceParticle;
 
+            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());
+                }
+                realParticle = refElement;
+                elementInfo.global = true;
+            }
+            elementInfo.nillable = ((XmlSchemaElement)realParticle).isNillable();
         }
-        elementInfo.minOccurs = sequenceElement.getMinOccurs();
-        elementInfo.maxOccurs = sequenceElement.getMaxOccurs();
-        
-        factoryCommon(realElement, 
-                     global, 
-                     javascriptPrefix,
+            
+        elementInfo.minOccurs = sequenceParticle.getMinOccurs();
+        elementInfo.maxOccurs = sequenceParticle.getMaxOccurs();
+
+        factoryCommon(realParticle, 
                      currentSchema, 
                      schemaCollection, 
                      prefixAccumulator, 
                      elementInfo);
         
-        elementInfo.element = realElement;
+        elementInfo.particle = realParticle;
 
         return elementInfo;
     }
 
-    private static void factoryCommon(XmlSchemaElement element, 
-                                      boolean global,
-                                      String javascriptPrefix,
+    private static void factoryCommon(XmlSchemaParticle particle, 
                                       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);
+                                      ParticleInfo elementInfo) {
+        
+        if (particle instanceof XmlSchemaElement) {
+            XmlSchemaElement element = (XmlSchemaElement) particle;
+            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();
+            boolean qualified = !elementNoNamespace
+                                && XmlSchemaUtils.isElementQualified(element, 
+                                                                     true, 
+                                                                     currentSchema, 
+                                                                     elementSchema);
+            elementInfo.xmlName = prefixAccumulator.xmlElementString(element, qualified);
+            // we are assuming here that we are not dealing, in close proximity,
+            // with elements with identical local names and different namespaces.
+            elementInfo.javascriptName = element.getQName().getLocalPart();
+            elementInfo.defaultValue = element.getDefaultValue();
+            factorySetupType(element, schemaCollection, elementInfo);
+        } else { // any
+            elementInfo.any = true;
+            elementInfo.xmlName = null; // unknown until runtime.
+            // TODO: multiple 'any'
+            elementInfo.javascriptName = "any";
+            elementInfo.type = null; // runtime for any.
+
+        }
     }
 
-    private static void factorySetupType(XmlSchemaElement element, SchemaCollection schemaCollection,
-                                         ElementInfo elementInfo) {
+    private static void factorySetupType(XmlSchemaElement element, 
+                                         SchemaCollection schemaCollection,
+                                         ParticleInfo elementInfo) {
         elementInfo.type = element.getSchemaType();
         if (elementInfo.type == null) {
             elementInfo.type = schemaCollection.getTypeByQName(element.getSchemaTypeName());
@@ -173,32 +221,47 @@
             }
         }
     }
-
-    public String getUtilsVarName() {
-        return utilsVarName;
-    }
-
-    public void setUtilsVarName(String utilsVarName) {
-        this.utilsVarName = utilsVarName;
+    
+    /**
+     * As a general rule, the JavaScript code is organized by types. The exception
+     * is global elements that have anonymous types. In those cases, the JavaScript code
+     * has its functions named according to the element. This method returns the QName 
+     * for the type or element, accordingly. If a schema has a local element with an
+     * anonymous, complex, type, this will throw. This will need to be fixed.
+     * @return the qname.
+     */
+    public QName getControllingName() {
+        if (type != null && type.getQName() != null) {
+            return type.getQName();
+        } else if (particle instanceof XmlSchemaElement) {
+            XmlSchemaElement element = (XmlSchemaElement) particle;
+            if (element.getQName() != null) {
+                return element.getQName();
+            } 
+        }
+        Message message = new Message("IMPOSSIBLE_GLOBAL_ITEM", LOG, 
+                                      XmlSchemaUtils.cleanedUpSchemaSource(particle));
+        LOG.severe(message.toString());
+        throw new UnsupportedConstruct(message);
     }
 
-    public XmlSchemaElement getElement() {
-        return element;
+    public XmlSchemaParticle getParticle() {
+        return particle;
     }
 
-    public String getElementJavascriptName() {
+    public String getJavascriptName() {
         return javascriptName;
     }
     
-    public void setElementJavascriptName(String name) {
+    public void setJavascriptName(String name) {
         javascriptName = name;
     }
 
-    public String getElementXmlName() {
+    public String getXmlName() {
         return xmlName;
     }
 
-    public void setElementXmlName(String elementXmlName) {
+    public void setXmlName(String elementXmlName) {
         this.xmlName = elementXmlName;
     }
 
@@ -241,5 +304,41 @@
     public boolean isOptional() {
         return minOccurs == 0 && maxOccurs == 1;
     }
+    
+    /** 
+     * @return Returns the nillable flag for the element. False for 'xs:any'
+     */
+    public boolean isNillable() {
+        return nillable;
+    }
+    
+    public boolean isAny() {
+        return any;
+    }
 
+    /** * @return Returns the defaultValue.
+     */
+    public String getDefaultValue() {
+        if (isOptional()) {
+            return "null";
+        } else {
+            return defaultValue;
+        }
+    }
+
+    /**
+     * @param defaultValue The defaultValue to set.
+     */
+    public void setDefaultValue(String defaultValue) {
+        this.defaultValue = defaultValue;
+    }
+    
+    /**
+     * True if this describes a global, named, element.
+     * @return
+     */
+    public boolean isGlobal() {
+        return global;
+    }
 }
+

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=606597&r1=606596&r2=606597&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 Sun Dec 23 11:29:00 2007
@@ -56,7 +56,7 @@
     private XmlSchemaUtils() {
     }
     
-    private static String cleanedUpSchemaSource(XmlSchemaType subject) {
+    static String cleanedUpSchemaSource(XmlSchemaObject subject) {
         if (subject.getSourceURI() == null) {
             return "";
         } else {
@@ -71,10 +71,13 @@
         throw new UnsupportedConstruct(message);
     }
     
-    public static void unsupportedConstruct(String messageKey, String what, XmlSchemaType subject) {
-        Message message = new Message(messageKey, LOG, what, subject.getQName(),
-                                      subject == null ? "(global)" 
-                                          : cleanedUpSchemaSource(subject));
+    public static void unsupportedConstruct(String messageKey, 
+                                            String what, 
+                                            QName subjectName,
+                                            XmlSchemaObject subject) {
+        Message message = new Message(messageKey, LOG, what, 
+                                      subjectName == null ? "anonymous" : subjectName,
+                                      cleanedUpSchemaSource(subject));
         LOG.severe(message.toString());
         throw new UnsupportedConstruct(message);
         
@@ -167,7 +170,9 @@
             element = nextElement;
         }
         if (element.getSchemaType() == null) {
-            XmlSchemaUtils.unsupportedConstruct("ELEMENT_HAS_NO_TYPE", originalElement.getName(), 
+            XmlSchemaUtils.unsupportedConstruct("ELEMENT_HAS_NO_TYPE", 
+                                                originalElement.getName(), 
+                                                containingType.getQName(),
                                                 containingType);
         }
         return element.getSchemaType();
@@ -192,7 +197,7 @@
     
     /**
      * 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'
+     * to just check the form 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,
@@ -235,16 +240,18 @@
      * @param object
      * @return
      */
-    public static XmlSchemaParticle getObjectParticle(XmlSchemaObject object, XmlSchemaType type) {
+    public static XmlSchemaParticle getObjectParticle(XmlSchemaObject object, QName contextName) {
         
         if (!(object instanceof XmlSchemaParticle)) {
             XmlSchemaUtils.unsupportedConstruct("NON_PARTICLE_CHILD", 
-                                                object.getClass().getSimpleName(), type);
+                                                object.getClass().getSimpleName(), 
+                                                contextName, object);
         }
         if (!(object instanceof XmlSchemaElement)
             && !(object instanceof XmlSchemaAny)) {
             XmlSchemaUtils.unsupportedConstruct("GROUP_CHILD", 
-                                                object.getClass().getSimpleName(), type);
+                                                object.getClass().getSimpleName(), contextName,
+                                                object);
         }
         
         return (XmlSchemaParticle) object;

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=606597&r1=606596&r2=606597&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 Dec 23 11:29:00 2007
@@ -38,10 +38,10 @@
 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;
+import org.apache.cxf.javascript.ParticleInfo;
 import org.apache.cxf.javascript.UnsupportedConstruct;
 import org.apache.cxf.javascript.XmlSchemaUtils;
 import org.apache.cxf.service.ServiceModelVisitor;
@@ -55,11 +55,13 @@
 import org.apache.cxf.transport.local.LocalTransportFactory;
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAny;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
 import org.apache.ws.commons.schema.XmlSchemaObjectTable;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 import org.apache.ws.commons.schema.XmlSchemaType;
@@ -93,7 +95,7 @@
     // derived from the parts.
     private List<String> inputParameterNames = new ArrayList<String>();
     // when not wrapped, we use this to keep track of the bits.
-    private List<ElementInfo> unwrappedElementsAndNames;
+    private List<ParticleInfo> unwrappedElementsAndNames;
     
     private NamespacePrefixAccumulator prefixAccumulator;
     private BindingInfo xmlBindingInfo;
@@ -246,13 +248,13 @@
      * visit the input message parts and collect relevant data.
      */
     private void collectUnwrappedInputInfo() {
-        unwrappedElementsAndNames = new ArrayList<ElementInfo>();
+        unwrappedElementsAndNames = new ArrayList<ParticleInfo>();
         if (currentOperation.getInput() != null) {
             getElementsForParts(currentOperation.getInput(), unwrappedElementsAndNames);
         }
         
-        for (ElementInfo ean : unwrappedElementsAndNames) {
-            inputParameterNames.add(ean.getElementJavascriptName());
+        for (ParticleInfo ean : unwrappedElementsAndNames) {
+            inputParameterNames.add(ean.getJavascriptName());
         }
     }
     
@@ -270,36 +272,43 @@
         code.append("// Operation " + currentOperation.getName() + "\n");
         if (!isWrapped) {
             code.append("// - bare operation. Parameters:\n");
-            for (ElementInfo ei : unwrappedElementsAndNames) {
+            for (ParticleInfo ei : unwrappedElementsAndNames) {
                 code.append("// - " + getElementObjectName(ei) + "\n");
             }
         } else {
             code.append("// Wrapped operation.\n");
+            QName contextQName = inputWrapperComplexType.getQName();
+            if (contextQName == null) {
+                contextQName = inputWrapperElement.getQName();
+            }
             XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(inputWrapperComplexType);
+            XmlSchema wrapperSchema = 
+                xmlSchemaCollection.getSchemaByTargetNamespace(contextQName.getNamespaceURI());
 
             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()) {
+                XmlSchemaObject sequenceItem = sequence.getItems().getItem(i);
+                ParticleInfo itemInfo = ParticleInfo.forLocalItem(sequenceItem,
+                                                                  wrapperSchema,
+                                                                  xmlSchemaCollection,
+                                                                  prefixAccumulator,
+                                                                  contextQName); 
+                if (itemInfo.isArray()) {
                     code.append("// - array\n");
                 }
-                XmlSchemaType elementType = elementInfo.getType();
-                if (elementType instanceof XmlSchemaComplexType) {
+                
+                XmlSchemaType type = itemInfo.getType(); // null for an any.
+                if (type instanceof XmlSchemaComplexType) {
                     QName baseName;
-                    if (elementType.getQName() != null) {
-                        baseName = elementType.getQName();
+                    if (type.getQName() != null) {
+                        baseName = type.getQName();
                     } else {
-                        baseName = elementInfo.getElement().getQName();
+                        baseName = ((XmlSchemaElement)sequenceItem).getQName();
                     }
                     code.append("// - Object constructor is " 
                                     + nameManager.getJavascriptName(baseName) + "\n");
-                } else {
-                    code.append("// - simple type " + elementType.getQName());
+                } else if (type != null) {
+                    code.append("// - simple type " + type.getQName());
                 }
             }       
         }
@@ -388,8 +397,7 @@
     // not the root element.
     private void buildSuccessFunction(MessageInfo outputMessage) {
         // Here are the success and error callbacks. They have the job of
-        // calling
-        // the callbacks provided to the operation function with appropriate
+        // calling callbacks provided to the operation function with appropriate
         // parameters.
         String successFunctionGlobalName = opFunctionGlobalName + "_onsuccess"; 
         String successFunctionPropertyName = opFunctionPropertyName + "_onsuccess"; 
@@ -456,12 +464,12 @@
         if (parts.size() != 1) {
             unsupportedConstruct("MULTIPLE_OUTPUTS", outputMessage.getName().toString());
         }
-        List<ElementInfo> elements = new ArrayList<ElementInfo>();
+        List<ParticleInfo> elements = new ArrayList<ParticleInfo>();
         String functionName = outputDeserializerFunctionName(outputMessage);
         code.append("function " + functionName + "(cxfjsutils, partElement) {\n");
         getElementsForParts(outputMessage, elements);
-        ElementInfo element = elements.get(0);
-        XmlSchemaType type;
+        ParticleInfo element = elements.get(0);
+        XmlSchemaType type = null;
         
         if (isRPC) {
             utils.appendLine("cxfjsutils.trace('rpc element: ' + cxfjsutils.traceElementName(partElement));");
@@ -469,25 +477,11 @@
             utils.appendLine("cxfjsutils.trace('rpc element: ' + cxfjsutils.traceElementName(partElement));");
         }
         
-        if (element.getType() != null) {
-            type = element.getType();
-        } else {
-            type = element.getElement().getSchemaType();
-        }
+        type = element.getType();
         
         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();
-                }
-                
-                String typeObjectName = nameManager.getJavascriptName(nameToDeserialize);
-                
+                String typeObjectName = nameManager.getJavascriptName(element.getControllingName());
                 utils
                     .appendLine("var returnObject = " 
                                 + typeObjectName 
@@ -503,27 +497,12 @@
         code.append("}\n");
     }
     
-    private String getElementObjectName(ElementInfo element) {
-        
-        XmlSchemaType type;
-        
-        if (element.getType() != null) {
-            type = element.getType();
-        } else {
-            type = element.getElement().getSchemaType();
-        }
+    private String getElementObjectName(ParticleInfo element) {
+        XmlSchemaType type = element.getType();
 
         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);
+                return nameManager.getJavascriptName(element.getControllingName());
             } else {
                 return "type " + type.getQName(); // could it be anonymous?
             } 
@@ -543,7 +522,7 @@
             getFunctionPropertyName(inputMessagesWithNameConflicts, message, message.getName())
             + "_serializeInput";
 
-        code.append("function " + serializerFunctionGlobalName + "(cxfutils, args) {\n");
+        code.append("function " + serializerFunctionGlobalName + "(cxfjsutils, args) {\n");
 
         String wrapperXmlElementName = null; 
         // for the wrapped case, we can name the object for Javascript after whatever we like.
@@ -564,7 +543,7 @@
             SoapVersion soapVersion = soapBindingInfo.getSoapVersion();
             assert soapVersion.getVersion() == 1.1;
             utils.appendLine("var xml;");
-            utils.appendLine("xml = cxfutils.beginSoap11Message(\"" + prefixAccumulator.getAttributes()
+            utils.appendLine("xml = cxfjsutils.beginSoap11Message(\"" + prefixAccumulator.getAttributes()
                              + "\");");
         } else {
             // other alternative is XML, which isn't really all here yet.
@@ -574,14 +553,13 @@
         utils.setXmlStringAccumulator("xml");
         
         if (isWrapped) {
-            ElementInfo elementInfo = ElementInfo.forPartElement(inputWrapperElement,
+            ParticleInfo elementInfo = ParticleInfo.forPartElement(inputWrapperElement,
                                                                  xmlSchemaCollection,
                                                                  "wrapperObj",
                                                                  wrapperXmlElementName);
 
             elementInfo.setContainingType(null);
-            elementInfo.setUtilsVarName("cxfutils");
-            utils.generateCodeToSerializeElement(elementInfo, xmlSchemaCollection);
+            utils.generateCodeToSerializeElement(elementInfo, "", xmlSchemaCollection);
         } else {
             String operationXmlElement = null;
             if (isRPC) {
@@ -594,7 +572,7 @@
                 utils.appendString("<" + operationXmlElement + ">");                
             }
             int px = 0;
-            // Multiple parts for doc/lit violates WS-I, but we can still do them.
+            // Multiple parts for document violates WS-I, but we can still do them.
             // They are normal for RPC.
             // 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
@@ -602,23 +580,23 @@
             // 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 (ElementInfo ean : unwrappedElementsAndNames) {
-                ElementInfo elementInfo = ElementInfo.forPartElement(ean.getElement(),
-                                                                     xmlSchemaCollection,
-                                                                     "args[" + px + "]",
-                                                                     ean.getElementXmlName());
-                elementInfo.setContainingType(null);
-                elementInfo.setType(ean.getType());
-                elementInfo.setUtilsVarName("cxfutils");
-                utils.generateCodeToSerializeElement(elementInfo, xmlSchemaCollection);
-                px++;
+            for (ParticleInfo ean : unwrappedElementsAndNames) {
+                String savedjsName = ean.getJavascriptName();
+                try {
+                    ean.setJavascriptName("args[" + px + "]");
+                    utils.generateCodeToSerializeElement(ean, "", xmlSchemaCollection);
+                    px++;
+                } finally {
+                    ean.setJavascriptName(savedjsName);
+                    
+                }
             }
             if (isRPC) {
                 utils.appendString("</" + operationXmlElement + ">");                
             }
         }
 
-        utils.appendLine("xml = xml + cxfutils.endSoap11Message();");
+        utils.appendLine("xml = xml + cxfjsutils.endSoap11Message();");
         utils.appendLine("return xml;");
         code.append("}\n\n");
         code.append(currentInterfaceClassName + ".prototype."
@@ -652,14 +630,14 @@
         return false;
     }
     
-    private XmlSchemaElement getBuriedElement(XmlSchemaComplexType type, 
+    private XmlSchemaParticle getBuriedElement(XmlSchemaComplexType type, 
                                               QName parentName) {
         XmlSchemaSequence sequence = getTypeSequence(type, parentName);
         XmlSchemaObjectCollection insides = sequence.getItems();
         if (insides.getCount() == 1) {
             XmlSchemaObject item = insides.getItem(0);
-            if (item instanceof XmlSchemaElement) {
-                return (XmlSchemaElement) item;
+            if (item instanceof XmlSchemaElement || item instanceof XmlSchemaAny) {
+                return (XmlSchemaParticle) item;
             }
         }
         return null;
@@ -670,7 +648,7 @@
      * @param parts 
      * @param elements
      */
-    private void getElementsForParts(MessageInfo message, List<ElementInfo> elements) {
+    private void getElementsForParts(MessageInfo message, List<ParticleInfo> elements) {
         for (MessagePartInfo mpi : message.getMessageParts()) {
             XmlSchemaElement element = null;
             XmlSchemaType type = null; 
@@ -700,12 +678,18 @@
             }
             
             boolean empty = isEmptyType(type, diagnosticName);
-            // In the bare case, if the type is nameless but contains but one element, concentrate on that.
-            if (!empty && type instanceof XmlSchemaComplexType && type.getName() == null && !isWrapped) {
-                XmlSchemaElement betterElement = getBuriedElement((XmlSchemaComplexType) type,
+            // There's something funny about doc/bare. Since it's doc, there is no
+            // element in the part. There is a type. However, for some reason,
+            // it tends to be an anonymous complex type containing an element, and that
+            // element corresponds to the type of the parameter. So, we refocus on that.
+            if (!empty 
+                && type instanceof XmlSchemaComplexType 
+                && type.getName() == null 
+                && !isWrapped) {
+                XmlSchemaParticle betterElement = getBuriedElement((XmlSchemaComplexType) type,
                                                                   diagnosticName);
-                if (betterElement != null) {
-                    element = betterElement;
+                if (betterElement instanceof XmlSchemaElement) {
+                    element = (XmlSchemaElement)betterElement;
                     if (element.getSchemaType() == null) {
                         element.setSchemaType(xmlSchemaCollection
                                                   .getTypeByQName(element.getSchemaTypeName()));
@@ -717,7 +701,7 @@
             String partJavascriptVar = 
                 JavascriptUtils.javaScriptNameToken(mpi.getConcreteName().getLocalPart());
             String elementXmlRef = prefixAccumulator.xmlElementString(mpi.getConcreteName());
-            ElementInfo elementInfo = ElementInfo.forPartElement(element,
+            ParticleInfo elementInfo = ParticleInfo.forPartElement(element,
                                                                  xmlSchemaCollection,
                                                                  partJavascriptVar, 
                                                                  elementXmlRef);        

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=606597&r1=606596&r2=606597&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 Dec 23 11:29:00 2007
@@ -30,10 +30,10 @@
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.common.xmlschema.XmlSchemaTools;
-import org.apache.cxf.javascript.ElementInfo;
 import org.apache.cxf.javascript.JavascriptUtils;
 import org.apache.cxf.javascript.NameManager;
 import org.apache.cxf.javascript.NamespacePrefixAccumulator;
+import org.apache.cxf.javascript.ParticleInfo;
 import org.apache.cxf.javascript.UnsupportedConstruct;
 import org.apache.cxf.javascript.XmlSchemaUtils;
 import org.apache.cxf.service.model.SchemaInfo;
@@ -197,33 +197,32 @@
         code.append(accessors.toString());
     }
 
-    private void constructOneElement(XmlSchemaComplexType type, XmlSchemaSequence sequence,
+    private void constructOneElement(XmlSchemaComplexType type, 
+                                     XmlSchemaSequence sequence,
                                      final String elementPrefix, 
                                      String typeObjectName, 
                                      XmlSchemaObject thing) {
 
-        SequenceItemInfo itemInfo = new SequenceItemInfo(xmlSchemaCollection, type, thing);
-
-        if (itemInfo.isAny()) {
-            itemInfo.setElementJavascriptVariable(itemInfo.getElementJavascriptVariable());
-        }
-
-        itemInfo.setElementJavascriptVariable(elementPrefix + itemInfo.getElementJavascriptVariable());
-
-        String accessorSuffix = StringUtils.capitalize(itemInfo.getElementName());
+        ParticleInfo itemInfo = ParticleInfo.forLocalItem(thing, 
+                                                          schemaInfo.getSchema(),
+                                                          xmlSchemaCollection, 
+                                                          prefixAccumulator, 
+                                                          type.getQName()); 
+            
+        String accessorSuffix = StringUtils.capitalize(itemInfo.getJavascriptName());
 
         String accessorName = typeObjectName + "_get" + accessorSuffix;
         String getFunctionProperty = typeObjectName + ".prototype.get" + accessorSuffix;
         String setFunctionProperty = typeObjectName + ".prototype.set" + accessorSuffix;
         accessors.append("//\n");
         accessors.append("// accessor is " + getFunctionProperty + "\n");
-        accessors.append("// element get for " + itemInfo.getElementName() + "\n");
+        accessors.append("// element get for " + itemInfo.getJavascriptName() + "\n");
         if (itemInfo.isAny()) {
             accessors.append("// - xs:any\n");
         } else {
-            // can we get an anonymous type on an element in the middle of a
-            // type?
-            accessors.append("// - element type is " + itemInfo.getElementType().getQName() + "\n");
+            if (itemInfo.getType() != null) {
+                accessors.append("// - element type is " + itemInfo.getType().getQName() + "\n");
+            }
         }
 
         if (XmlSchemaUtils.isParticleOptional(itemInfo.getParticle())) {
@@ -243,33 +242,34 @@
         }
 
         accessors.append("//\n");
-        accessors.append("// element set for " + itemInfo.getElementName() + "\n");
+        accessors.append("// element set for " + itemInfo.getJavascriptName() + "\n");
         accessors.append("// setter function is is " + setFunctionProperty + "\n");
         accessors.append("//\n");
-        accessors.append("function " + accessorName + "() { return "
-                         + itemInfo.getElementJavascriptVariable() + ";}\n");
-        accessors.append(getFunctionProperty + " = " + accessorName + ";\n");
+        accessors.append("function " + accessorName + "() { return this._"
+                         + itemInfo.getJavascriptName() + ";}\n\n");
+        accessors.append(getFunctionProperty + " = " + accessorName + ";\n\n");
         accessorName = typeObjectName + "_set" + accessorSuffix;
-        accessors.append("function " + accessorName + "(value) {" + itemInfo.getElementJavascriptVariable()
-                         + " = value;}\n");
+        accessors.append("function " + accessorName + "(value) { this._" 
+                         + itemInfo.getJavascriptName()
+                         + " = value;}\n\n");
         accessors.append(setFunctionProperty + " = " + accessorName + ";\n");
 
         if (XmlSchemaUtils.isParticleOptional(itemInfo.getParticle())
             || (itemInfo.isNillable() && !XmlSchemaUtils.isParticleArray(itemInfo.getParticle()))) {
-            utils.appendLine(itemInfo.getElementJavascriptVariable() + " = null;");
+            utils.appendLine("this._" + itemInfo.getJavascriptName() + " = null;");
         } else if (XmlSchemaUtils.isParticleArray(itemInfo.getParticle())) {
-            utils.appendLine(itemInfo.getElementJavascriptVariable() + " = [];");
-        } else if (itemInfo.isAny() || itemInfo.getElementType() instanceof XmlSchemaComplexType) {
+            utils.appendLine("this._" + itemInfo.getJavascriptName() + " = [];");
+        } else if (itemInfo.isAny() || itemInfo.getType() instanceof XmlSchemaComplexType) {
             // even for required complex elements, we leave them null.
             // otherwise, we could end up in a cycle or otherwise miserable. The
             // application code is responsible for this.
-            utils.appendLine(itemInfo.getElementJavascriptVariable() + " = null;");
+            utils.appendLine("this._" + itemInfo.getJavascriptName() + " = null;");
         } else {
-            if (itemInfo.getDefaultValueString() == null) {
-                itemInfo.setDefaultValueString(utils.getDefaultValueForSimpleType(itemInfo.getElementType()));
+            if (itemInfo.getDefaultValue() == null) {
+                itemInfo.setDefaultValue(utils.getDefaultValueForSimpleType(itemInfo.getType()));
             }
-            utils.appendLine(itemInfo.getElementJavascriptVariable() + " = "
-                             + itemInfo.getDefaultValueString() + ";");
+            utils.appendLine("this._" + itemInfo.getJavascriptName() + " = "
+                             + itemInfo.getDefaultValue() + ";");
         }
     }
 
@@ -338,23 +338,22 @@
 
         for (int i = 0; i < sequence.getItems().getCount(); i++) {
             XmlSchemaObject sequenceItem = (XmlSchemaObject)sequence.getItems().getItem(i);
-            SequenceItemInfo itemInfo = new SequenceItemInfo(xmlSchemaCollection, type, sequenceItem);
+            ParticleInfo itemInfo = ParticleInfo.forLocalItem(sequenceItem, 
+                                                              schemaInfo.getSchema(), 
+                                                              xmlSchemaCollection, 
+                                                              prefixAccumulator, 
+                                                              type.getQName()); 
+                
             // If the item is 'any', it could be ANY of our top-level elements.
             if (itemInfo.isAny()) {
                 serializeAny(itemInfo, bodyUtils);
             } else {
-                XmlSchemaElement sequenceElement = (XmlSchemaElement)sequenceItem;
-                ElementInfo elementInfo = ElementInfo.forLocalElement(sequenceElement, elementPrefix,
-                                                                      schemaInfo.getSchema(),
-                                                                      xmlSchemaCollection, prefixAccumulator);
-                elementInfo.setContainingType(type);
-                elementInfo.setUtilsVarName("cxfjsutils");
-                bodyUtils.generateCodeToSerializeElement(elementInfo, xmlSchemaCollection);
+                bodyUtils.generateCodeToSerializeElement(itemInfo, "this._", xmlSchemaCollection);
             }
         }
     }
 
-    private void serializeAny(SequenceItemInfo itemInfo, JavascriptUtils bodyUtils) {
+    private void serializeAny(ParticleInfo itemInfo, JavascriptUtils bodyUtils) {
         String prefix = "cxfjsany" + anyPrefixCounter;
         anyPrefixCounter++;
         bodyUtils.generateCodeToSerializeAny(itemInfo, prefix, xmlSchemaCollection);
@@ -385,12 +384,20 @@
         for (int i = 0; i < sequence.getItems().getCount(); i++) {
             utils.appendLine("cxfjsutils.trace('curElement: ' + cxfjsutils.traceElementName(curElement));");
             XmlSchemaObject thing = sequence.getItems().getItem(i);
-            SequenceItemInfo itemInfo = new SequenceItemInfo(xmlSchemaCollection, type, thing);
+            ParticleInfo itemInfo = ParticleInfo.forLocalItem(thing,
+                                                              schemaInfo.getSchema(),
+                                                              xmlSchemaCollection, 
+                                                              prefixAccumulator, 
+                                                              type.getQName()); 
             if (itemInfo.isAny()) {
-                SequenceItemInfo nextItem = null;
+                ParticleInfo nextItem = null;
                 if (i != sequence.getItems().getCount() - 1) {
                     XmlSchemaObject nextThing = sequence.getItems().getItem(i + 1);
-                    nextItem = new SequenceItemInfo(xmlSchemaCollection, type, nextThing);
+                    nextItem = ParticleInfo.forLocalItem(nextThing, 
+                                                         schemaInfo.getSchema(), 
+                                                         xmlSchemaCollection, 
+                                                         prefixAccumulator, 
+                                                         type.getQName()); 
                     // theoretically, you could have two anys with different
                     // namespaces.
                     if (nextItem.isAny()) {
@@ -430,8 +437,8 @@
     }
 
     private void deserializeAny(XmlSchemaComplexType type, 
-                                SequenceItemInfo itemInfo, 
-                                SequenceItemInfo nextItem) {
+                                ParticleInfo itemInfo, 
+                                ParticleInfo nextItem) {
         XmlSchemaAny any = (XmlSchemaAny)itemInfo.getParticle();
         
         boolean array = XmlSchemaUtils.isParticleArray(any);
@@ -521,43 +528,43 @@
         utils.endBlock(); // while
 
         utils.appendLine("var anyHolder = new org_apache_cxf_any_holder(anyURI, anyObject);");
-        utils.appendLine("this._" + itemInfo.getElementJavascriptVariable() + " = anyHolder;");
+        utils.appendLine("this._" + itemInfo.getJavascriptName() + " = anyHolder;");
     }
 
     private void deserializeElement(XmlSchemaComplexType type, XmlSchemaObject thing) {
-        XmlSchemaElement sequenceElement = (XmlSchemaElement)thing;
-        XmlSchemaElement realElement = XmlSchemaUtils
-            .getReferredElement(sequenceElement, xmlSchemaCollection);
-        boolean global = realElement != null;
-        if (!global) {
-            realElement = sequenceElement;
-        }
-        XmlSchemaType elType = XmlSchemaUtils.getElementType(xmlSchemaCollection, null, realElement, type);
-        boolean simple = elType instanceof XmlSchemaSimpleType;
-        String accessorName = "set" + StringUtils.capitalize(realElement.getName());
-        String elementName = realElement.getName();
-        utils.appendLine("cxfjsutils.trace('processing " + elementName + "');");
-        String elementNamespaceURI = realElement.getQName().getNamespaceURI();
+        ParticleInfo itemInfo = ParticleInfo.forLocalItem(thing, 
+                                                          schemaInfo.getSchema(),
+                                                          xmlSchemaCollection, 
+                                                          prefixAccumulator, 
+                                                          type.getQName());
+        XmlSchemaType itemType = itemInfo.getType();
+        boolean simple = itemType instanceof XmlSchemaSimpleType;
+        String accessorName = "set" + StringUtils.capitalize(itemInfo.getJavascriptName());
+        utils.appendLine("cxfjsutils.trace('processing " + itemInfo.getJavascriptName() + "');");
+        XmlSchemaElement element = (XmlSchemaElement) itemInfo.getParticle();
+        String elementNamespaceURI = element.getQName().getNamespaceURI();
         boolean elementNoNamespace = "".equals(elementNamespaceURI);
         XmlSchema elementSchema = null;
         if (!elementNoNamespace) {
             elementSchema = xmlSchemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
         }
         boolean qualified = !elementNoNamespace
-                            && XmlSchemaUtils.isElementQualified(realElement, global, schemaInfo.getSchema(),
+                            && XmlSchemaUtils.isElementQualified(element, 
+                                                                 itemInfo.isGlobal(), 
+                                                                 schemaInfo.getSchema(),
                                                                  elementSchema);
 
         if (!qualified) {
             elementNamespaceURI = "";
         }
-
+        
+        String localName = element.getQName().getLocalPart();
         String valueTarget = "item";
 
-        if (XmlSchemaUtils.isParticleOptional(sequenceElement)
-            || XmlSchemaUtils.isParticleArray(sequenceElement)) {
+        if (itemInfo.isOptional() || itemInfo.isArray()) {
             utils.startIf("curElement != null && cxfjsutils.isNodeNamedNS(curElement, '"
-                          + elementNamespaceURI + "', '" + elementName + "')");
-            if (XmlSchemaUtils.isParticleArray(sequenceElement)) {
+                          + elementNamespaceURI + "', '" + localName + "')");
+            if (itemInfo.isArray()) {
                 utils.appendLine("item = [];");
                 utils.startDo();
                 valueTarget = "arrayItem";
@@ -569,34 +576,39 @@
         utils.startIf("!cxfjsutils.isElementNil(curElement)");
         if (simple) {
             utils.appendLine("value = cxfjsutils.getNodeText(curElement);");
-            utils.appendLine(valueTarget + " = " + utils.javascriptParseExpression(elType, "value") + ";");
+            utils.appendLine(valueTarget 
+                             + " = " 
+                             + utils.javascriptParseExpression(itemType, "value") + ";");
         } else {
-            XmlSchemaComplexType complexType = (XmlSchemaComplexType)elType;
+            XmlSchemaComplexType complexType = (XmlSchemaComplexType)itemType;
             QName baseQName = complexType.getQName();
             if (baseQName == null) {
-                baseQName = realElement.getQName();
+                baseQName = element.getQName();
             }
 
             String elTypeJsName = nameManager.getJavascriptName(baseQName);
-            utils.appendLine(valueTarget + " = " + elTypeJsName + "_deserialize(cxfjsutils, curElement);");
+            utils.appendLine(valueTarget 
+                             + " = " 
+                             + elTypeJsName 
+                             + "_deserialize(cxfjsutils, curElement);");
         }
 
         utils.endBlock(); // the if for the nil.
-        if (XmlSchemaUtils.isParticleArray(sequenceElement)) {
+        if (itemInfo.isArray()) {
             utils.appendLine("item.push(arrayItem);");
             utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
             utils.endBlock();
             utils.appendLine("  while(curElement != null && cxfjsutils.isNodeNamedNS(curElement, '"
-                             + elementNamespaceURI + "', '" + sequenceElement.getName() + "'));");
+                             + elementNamespaceURI + "', '" 
+                             + localName + "'));");
         }
         utils.appendLine("newobject." + accessorName + "(item);");
-        if (!XmlSchemaUtils.isParticleArray(sequenceElement)) {
+        if (!itemInfo.isArray()) {
             utils.startIf("curElement != null");
             utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
             utils.endBlock();
         }
-        if (XmlSchemaUtils.isParticleOptional(sequenceElement)
-            || XmlSchemaUtils.isParticleArray(sequenceElement)) {
+        if (itemInfo.isOptional() || itemInfo.isArray()) {
             utils.endBlock();
         }
     }

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitBareImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitBareImpl.java?rev=606597&r1=606596&r2=606597&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitBareImpl.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitBareImpl.java Sun Dec 23 11:29:00 2007
@@ -24,7 +24,7 @@
 /**
  * 
  */
-//@org.apache.cxf.feature.Features(features = "org.apache.cxf.feature.LoggingFeature")   
+@org.apache.cxf.feature.Features(features = "org.apache.cxf.feature.LoggingFeature")   
 @WebService(endpointInterface = "org.apache.cxf.javascript.fortest.SimpleDocLitBare",
             targetNamespace = "uri:org.apache.cxf.javascript.fortest")
 public class SimpleDocLitBareImpl implements SimpleDocLitBare {

Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/deserializationTests.js
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/deserializationTests.js?rev=606597&r1=606596&r2=606597&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/deserializationTests.js (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/deserializationTests.js Sun Dec 23 11:29:00 2007
@@ -43,7 +43,7 @@
 	if(bean.getOptionalIntItem() != 0)
 		assertionFailed("deserializeTestBean3_1 optionalIntItem " + bean.getOptionalIntItem());
 	if(bean.getOptionalStringItem() != null)
-		assertionFailed("deserializeTestBean3_1 optionalStringItem " + bean.getOptionalStringItem());
+		assertionFailed("deserializeTestBean3_1 optionalStringItem '" + bean.getOptionalStringItem() + "'");
 	if(bean.getOptionalIntArrayItem() == null)
 		assertionFailed("deserializeTestBean3_1 optionalIntArrayItem null");
 	if(bean.getOptionalIntArrayItem().length != 0)

Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties?rev=606597&r1=606596&r2=606597&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties Sun Dec 23 11:29:00 2007
@@ -23,7 +23,7 @@
 .level= INFO
 java.util.logging.ConsoleHandler.level = FINEST
 java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
-org.apache.cxf.javascript.JavascriptTestUtilities.level=FINEST
+#org.apache.cxf.javascript.JavascriptTestUtilities.level=FINEST
 
 
 

Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/AnyTests.js
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/AnyTests.js?rev=606597&r1=606596&r2=606597&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/AnyTests.js (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/AnyTests.js Sun Dec 23 11:29:00 2007
@@ -34,4 +34,7 @@
 	globalResponseObject = null;
 }
 
-// nothing yet.
+function testAny1ToServerChalk(url)
+{
+}
+



Mime
View raw message