cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r606243 - in /incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types: SchemaJavascriptBuilder.java SequenceItemInfo.java
Date Fri, 21 Dec 2007 16:53:27 GMT
Author: bimargulies
Date: Fri Dec 21 08:53:27 2007
New Revision: 606243

URL: http://svn.apache.org/viewvc?rev=606243&view=rev
Log:
Continue to sneak up on xs:any.

Added:
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SequenceItemInfo.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/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=606243&r1=606242&r2=606243&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
Fri Dec 21 08:53:27 2007
@@ -38,12 +38,10 @@
 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.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.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;
@@ -195,97 +193,82 @@
                                      final String elementPrefix, 
                                      String typeObjectName, 
                                      XmlSchemaObject thing) {
-
-        XmlSchemaParticle particle = XmlSchemaUtils.getObjectParticle(thing, type);
-        XmlSchemaElement sequenceElement = null;
-        XmlSchemaType elType = null;
-        boolean nillable = false;
-        String elementName = null;
-        String elementJavascriptVariable = null;
-        String defaultValueString = null;
-        boolean any = false;
-        
-        if (particle instanceof XmlSchemaAny) {
-            any = true;
-            // TODO: what about a collision here?
-            elementName = "any" + anyCounter;
-            elementJavascriptVariable = elementPrefix + elementName;
+        
+        SequenceItemInfo itemInfo = new SequenceItemInfo(xmlSchemaCollection, type, thing);
+        
+        if (itemInfo.isAny()) {
+            itemInfo.setElementJavascriptVariable(itemInfo.getElementJavascriptVariable()
+                                                          + anyCounter);
             anyCounter++;
-        } else {
-            sequenceElement = (XmlSchemaElement)thing;
-            elType = XmlSchemaUtils.getElementType(xmlSchemaCollection, null, sequenceElement,
type);
-            nillable = sequenceElement.isNillable();
-            if (sequenceElement.isAbstract()) { 
-                XmlSchemaUtils.unsupportedConstruct("ABSTRACT_ELEMENT", sequenceElement.getName(),
type);
-            }
-            elementName = sequenceElement.getName();
-            elementJavascriptVariable = elementPrefix + sequenceElement.getName();
-            defaultValueString = sequenceElement.getDefaultValue();
         }
-
         
-        String accessorSuffix = StringUtils.capitalize(elementName);
+        itemInfo.setElementJavascriptVariable(elementPrefix 
+                                                      + itemInfo.getElementJavascriptVariable());

+
+        String accessorSuffix = StringUtils.capitalize(itemInfo.getElementName());
 
         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 " + elementName + "\n");
-        if (any) {
+        accessors.append("// element get for " + itemInfo.getElementName() + "\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 " + elType.getQName() + "\n");
+            accessors.append("// - element type is " 
+                             + itemInfo.getElementType().getQName() + "\n");
         }
         
-        if (XmlSchemaUtils.isParticleOptional(particle)) {
+        if (XmlSchemaUtils.isParticleOptional(itemInfo.getParticle())) {
             accessors.append("// - optional element\n");
         } else {
             accessors.append("// - required element\n");
             
         }
         
-        if (XmlSchemaUtils.isParticleArray(particle)) {
+        if (XmlSchemaUtils.isParticleArray(itemInfo.getParticle())) {
             accessors.append("// - array\n");
             
         }
         
-        if (nillable) {
+        if (itemInfo.isNillable()) {
             accessors.append("// - nillable\n");
         }
         
         accessors.append("//\n");
-        accessors.append("// element set for " + elementName + "\n");
+        accessors.append("// element set for " + itemInfo.getElementName() + "\n");
         accessors.append("// setter function is is " + setFunctionProperty + "\n");
         accessors.append("//\n");
         accessors.append("function " + accessorName + "() { return " 
-                         + elementJavascriptVariable 
+                         + itemInfo.getElementJavascriptVariable() 
                          + ";}\n");
         accessors.append(getFunctionProperty + " = " + accessorName + ";\n");
         accessorName = typeObjectName + "_set" + accessorSuffix;
         accessors.append("function " 
                          + accessorName + "(value) {" 
-                         + elementJavascriptVariable
+                         + itemInfo.getElementJavascriptVariable()
                          + " = value;}\n");
         accessors.append(setFunctionProperty + " = " + accessorName + ";\n");
         
-        if (XmlSchemaUtils.isParticleOptional(particle) 
-            || (nillable && !XmlSchemaUtils.isParticleArray(particle))) {
-            utils.appendLine(elementJavascriptVariable + " = null;");
-        } else if (XmlSchemaUtils.isParticleArray(particle)) {
-            utils.appendLine(elementJavascriptVariable + " = [];");
-        } else if (elType instanceof XmlSchemaComplexType) {
+        if (XmlSchemaUtils.isParticleOptional(itemInfo.getParticle()) 
+            || (itemInfo.isNillable() && !XmlSchemaUtils.isParticleArray(itemInfo.getParticle())))
{
+            utils.appendLine(itemInfo.getElementJavascriptVariable() + " = null;");
+        } else if (XmlSchemaUtils.isParticleArray(itemInfo.getParticle())) {
+            utils.appendLine(itemInfo.getElementJavascriptVariable() + " = [];");
+        } else if (itemInfo.getElementType() 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(elementJavascriptVariable + " = null;");
+            utils.appendLine(itemInfo.getElementJavascriptVariable() + " = null;");
         } else {
-            if (defaultValueString == null) {
-                defaultValueString = 
-                    utils.getDefaultValueForSimpleType(elType);
+            if (itemInfo.getDefaultValueString() == null) {
+                itemInfo.setDefaultValueString(utils.getDefaultValueForSimpleType(itemInfo.getElementType()));
             }
-            utils.appendLine(elementJavascriptVariable + " = " + defaultValueString + ";");
+            utils.appendLine(itemInfo.getElementJavascriptVariable()
+                             + " = " 
+                             + itemInfo.getDefaultValueString() + ";");
         }
     }
     

Added: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SequenceItemInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SequenceItemInfo.java?rev=606243&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SequenceItemInfo.java
(added)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SequenceItemInfo.java
Fri Dec 21 08:53:27 2007
@@ -0,0 +1,182 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.javascript.types;
+
+import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.cxf.javascript.XmlSchemaUtils;
+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.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * Information about a sequence 'element'
+ * For now, only handles elements and 'any'. 
+ */
+public class SequenceItemInfo {
+    private XmlSchemaParticle particle;
+    private XmlSchemaElement sequenceElement;
+    private XmlSchemaType elementType;
+    private boolean nillable;
+    private String elementName;
+    private String elementJavascriptVariable;
+    private String defaultValueString;
+    private boolean any;
+    
+    /**
+     * Gather information about a member of a sequence.
+     * @param xmlSchemaCollection
+     * @param containingType
+     * @param sequenceMember
+     */
+    public SequenceItemInfo(SchemaCollection xmlSchemaCollection,
+                            XmlSchemaComplexType containingType, 
+                            XmlSchemaObject sequenceMember) {
+        particle = XmlSchemaUtils.getObjectParticle(sequenceMember, containingType);
+        if (particle instanceof XmlSchemaAny) {
+            any = true;
+            elementName = "any";
+            elementJavascriptVariable = elementName;
+        } else {
+            sequenceElement = (XmlSchemaElement)sequenceMember;
+            elementType = XmlSchemaUtils.getElementType(xmlSchemaCollection, 
+                                                   null, sequenceElement, containingType);
+            nillable = sequenceElement.isNillable();
+            if (sequenceElement.isAbstract()) { 
+                XmlSchemaUtils.unsupportedConstruct("ABSTRACT_ELEMENT", 
+                                                    sequenceElement.getName(), containingType);
+            }
+            elementName = sequenceElement.getName();
+            elementJavascriptVariable = sequenceElement.getName();
+            defaultValueString = sequenceElement.getDefaultValue();
+        }
+
+        
+    }
+    
+    
+    /** 
+     * @return Returns the particle.
+     */
+    public XmlSchemaParticle getParticle() {
+        return particle;
+    }
+    /** * @return Returns the sequenceElement.
+     */
+    public XmlSchemaElement getSequenceElement() {
+        return sequenceElement;
+    }
+    /** * @return Returns the elType.
+     */
+    public XmlSchemaType getElementType() {
+        return elementType;
+    }
+    /** * @return Returns the nillable.
+     */
+    public boolean isNillable() {
+        return nillable;
+    }
+    /** * @return Returns the elementName.
+     */
+    public String getElementName() {
+        return elementName;
+    }
+    /** * @return Returns the elementJavascriptVariable.
+     */
+    public String getElementJavascriptVariable() {
+        return elementJavascriptVariable;
+    }
+    /** * @return Returns the defaultValueString.
+     */
+    public String getDefaultValueString() {
+        return defaultValueString;
+    }
+    /** * @return Returns the any.
+     */
+    public boolean isAny() {
+        return any;
+    }
+
+
+    /**
+     * @param particle The particle to set.
+     */
+    public void setParticle(XmlSchemaParticle particle) {
+        this.particle = particle;
+    }
+
+
+    /**
+     * @param sequenceElement The sequenceElement to set.
+     */
+    public void setSequenceElement(XmlSchemaElement sequenceElement) {
+        this.sequenceElement = sequenceElement;
+    }
+
+
+    /**
+     * @param elementType The elementType to set.
+     */
+    public void setElementType(XmlSchemaType elementType) {
+        this.elementType = elementType;
+    }
+
+
+    /**
+     * @param nillable The nillable to set.
+     */
+    public void setNillable(boolean nillable) {
+        this.nillable = nillable;
+    }
+
+
+    /**
+     * @param elementName The elementName to set.
+     */
+    public void setElementName(String elementName) {
+        this.elementName = elementName;
+    }
+
+
+    /**
+     * @param elementJavascriptVariable The elementJavascriptVariable to set.
+     */
+    public void setElementJavascriptVariable(String elementJavascriptVariable) {
+        this.elementJavascriptVariable = elementJavascriptVariable;
+    }
+
+
+    /**
+     * @param defaultValueString The defaultValueString to set.
+     */
+    public void setDefaultValueString(String defaultValueString) {
+        this.defaultValueString = defaultValueString;
+    }
+
+
+    /**
+     * @param any The any to set.
+     */
+    public void setAny(boolean any) {
+        this.any = any;
+    }
+}

Propchange: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SequenceItemInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SequenceItemInfo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message