Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 74421 invoked from network); 17 Oct 2010 02:27:19 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 17 Oct 2010 02:27:19 -0000 Received: (qmail 66977 invoked by uid 500); 17 Oct 2010 02:27:19 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 66927 invoked by uid 500); 17 Oct 2010 02:27:19 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 66920 invoked by uid 99); 17 Oct 2010 02:27:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 17 Oct 2010 02:27:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 17 Oct 2010 02:27:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 163892388A6E; Sun, 17 Oct 2010 02:26:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1023402 [4/9] - in /cxf/trunk: api/src/main/java/org/apache/cxf/databinding/ api/src/main/java/org/apache/cxf/service/model/ common/common/src/main/java/org/apache/cxf/common/xmlschema/ common/common/src/test/java/org/apache/cxf/common/xml... Date: Sun, 17 Oct 2010 02:26:08 -0000 To: commits@cxf.apache.org From: bimargulies@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101017022610.163892388A6E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/AttributeInfo.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/AttributeInfo.java?rev=1023402&r1=1023401&r2=1023402&view=diff ============================================================================== --- cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/AttributeInfo.java (original) +++ cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/AttributeInfo.java Sun Oct 17 02:26:06 2010 @@ -34,7 +34,6 @@ import org.apache.ws.commons.schema.XmlS import org.apache.ws.commons.schema.XmlSchemaObject; import org.apache.ws.commons.schema.XmlSchemaType; import org.apache.ws.commons.schema.XmlSchemaUse; -import org.apache.ws.commons.schema.constants.Constants.BlockConstants; /** * All the information needed to create the JavaScript for an Xml Schema attribute @@ -60,7 +59,7 @@ public final class AttributeInfo impleme /** * Create an elementInfo that stores information about a global, named, * element. - * + * * @param attribute the element * @param currentSchema the schema it came from. * @param schemaCollection the collection of all schemas. @@ -80,14 +79,14 @@ public final class AttributeInfo impleme /** * Fill in an AttributeInfo for an attribute or anyAttribute from a sequence. - * + * * @param sequenceElement * @param currentSchema * @param schemaCollection * @param prefixAccumulator * @return */ - public static AttributeInfo forLocalItem(XmlSchemaObject sequenceObject, + public static AttributeInfo forLocalItem(XmlSchemaObject sequenceObject, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, QName contextName) { @@ -98,15 +97,9 @@ public final class AttributeInfo impleme if (annotated instanceof XmlSchemaAttribute) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)annotated; attributeInfo.use = attribute.getUse(); - - if (attribute.getRefName() != null) { - XmlSchemaAttribute refAttribute = schemaCollection - .getAttributeByQName(attribute.getRefName()); - if (refAttribute == null) { - throw new UnsupportedConstruct(LOG, "ATTRIBUTE_DANGLING_REFERENCE", attribute - .getQName(), attribute.getRefName()); - } - realAnnotated = refAttribute; + + if (attribute.getRef().getTarget() != null) { + realAnnotated = attribute.getRef().getTarget(); attributeInfo.global = true; } } else if (annotated instanceof XmlSchemaAnyAttribute) { @@ -114,7 +107,7 @@ public final class AttributeInfo impleme attributeInfo.xmlName = null; // unknown until runtime. attributeInfo.javascriptName = "any"; attributeInfo.type = null; // runtime for any. - attributeInfo.use = new XmlSchemaUse(BlockConstants.OPTIONAL); + attributeInfo.use = XmlSchemaUse.OPTIONAL; } else { throw new UnsupportedConstruct(LOG, "UNSUPPORTED_ATTRIBUTE_ITEM", annotated, contextName); } @@ -128,7 +121,7 @@ public final class AttributeInfo impleme private static void factoryCommon(XmlSchemaAnnotated annotated, XmlSchema currentSchema, SchemaCollection schemaCollection, - NamespacePrefixAccumulator prefixAccumulator, + NamespacePrefixAccumulator prefixAccumulator, AttributeInfo attributeInfo) { if (annotated instanceof XmlSchemaAttribute) { @@ -161,7 +154,7 @@ public final class AttributeInfo impleme attributeInfo.xmlName = null; // unknown until runtime. attributeInfo.javascriptName = "any"; attributeInfo.type = null; // runtime for any. - attributeInfo.use = new XmlSchemaUse(BlockConstants.OPTIONAL); + attributeInfo.use = XmlSchemaUse.OPTIONAL; } } @@ -173,7 +166,7 @@ public final class AttributeInfo impleme attributeInfo.anyType = true; } else { attributeInfo.type = schemaCollection.getTypeByQName(element.getSchemaTypeName()); - if (attributeInfo.type == null + if (attributeInfo.type == null && !element.getSchemaTypeName() .getNamespaceURI().equals(XmlSchemaConstants.XSD_NAMESPACE_URI)) { XmlSchemaUtils.unsupportedConstruct("MISSING_TYPE", element.getSchemaTypeName() @@ -236,7 +229,7 @@ public final class AttributeInfo impleme /** * * - * + * * @return Returns the defaultValue. */ public String getDefaultValue() { @@ -248,7 +241,7 @@ public final class AttributeInfo impleme /** * True if this describes a global, named, attribute. - * + * * @return */ public boolean isGlobal() { @@ -272,7 +265,7 @@ public final class AttributeInfo impleme } public boolean isOptional() { - return !use.equals(new XmlSchemaUse(BlockConstants.REQUIRED)); + return !use.equals(XmlSchemaUse.REQUIRED); } public void setDefaultValue(String value) { Modified: cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java?rev=1023402&r1=1023401&r2=1023402&view=diff ============================================================================== --- cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java (original) +++ cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java Sun Oct 17 02:26:06 2010 @@ -63,7 +63,7 @@ public final class ParticleInfo implemen /** * 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. @@ -91,7 +91,7 @@ public final class ParticleInfo implemen * 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 @@ -120,7 +120,7 @@ public final class ParticleInfo implemen /** * Fill in an ElementInfo for an element or xs:any from a sequence. - * + * * @param sequenceElement * @param currentSchema * @param schemaCollection @@ -130,19 +130,19 @@ public final class ParticleInfo implemen public static ParticleInfo forLocalItem(XmlSchemaObject sequenceObject, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, QName contextName) { - XmlSchemaParticle sequenceParticle = XmlSchemaUtils.getObjectParticle(sequenceObject, contextName); + XmlSchemaParticle sequenceParticle = + XmlSchemaUtils.getObjectParticle((XmlSchemaObject)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 (sequenceElement.getRef().getTargetQName() != null) { + XmlSchemaElement refElement = sequenceElement.getRef().getTarget(); if (refElement == null) { Message message = new Message("ELEMENT_DANGLING_REFERENCE", LOG, sequenceElement - .getQName(), sequenceElement.getRefName()); + .getQName(), sequenceElement.getRef().getTargetQName()); throw new UnsupportedConstruct(message.toString()); } realParticle = refElement; @@ -163,14 +163,14 @@ public final class ParticleInfo implemen private static void factoryCommon(XmlSchemaParticle particle, XmlSchema currentSchema, SchemaCollection schemaCollection, - NamespacePrefixAccumulator prefixAccumulator, + NamespacePrefixAccumulator prefixAccumulator, ParticleInfo elementInfo) { if (particle instanceof XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement)particle; QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, currentSchema); - String elementNamespaceURI = elementQName.getNamespaceURI(); - + String elementNamespaceURI = elementQName.getNamespaceURI(); + boolean elementNoNamespace = "".equals(elementNamespaceURI); XmlSchema elementSchema = null; @@ -191,7 +191,7 @@ public final class ParticleInfo implemen elementInfo.javascriptName = elementQName.getLocalPart(); String schemaDefaultValue = element.getDefaultValue(); /* - * Schema default values are carried as strings. + * Schema default values are carried as strings. * In javascript, for actual strings, we need quotes, but not for * numbers. The following is a trick. */ @@ -238,7 +238,7 @@ public final class ParticleInfo implemen } } builder.append('\''); - schemaDefaultValue = builder.toString(); + schemaDefaultValue = builder.toString(); } return schemaDefaultValue; } @@ -252,7 +252,7 @@ public final class ParticleInfo implemen elementInfo.anyType = true; } else { elementInfo.type = schemaCollection.getTypeByQName(element.getSchemaTypeName()); - if (elementInfo.type == null + if (elementInfo.type == null && !element.getSchemaTypeName() .getNamespaceURI().equals(XmlSchemaConstants.XSD_NAMESPACE_URI)) { XmlSchemaUtils.unsupportedConstruct("MISSING_TYPE", element.getSchemaTypeName() @@ -272,7 +272,7 @@ public final class ParticleInfo implemen * 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() { @@ -367,7 +367,7 @@ public final class ParticleInfo implemen /** * * - * + * * @return Returns the defaultValue. */ public String getDefaultValue() { @@ -387,7 +387,7 @@ public final class ParticleInfo implemen /** * True if this describes a global, named, element. - * + * * @return */ public boolean isGlobal() { Modified: cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java?rev=1023402&r1=1023401&r2=1023402&view=diff ============================================================================== --- cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java (original) +++ cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java Sun Oct 17 02:26:06 2010 @@ -22,7 +22,6 @@ package org.apache.cxf.javascript.servic import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -60,10 +59,9 @@ import org.apache.ws.commons.schema.XmlS 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.XmlSchemaSequenceMember; import org.apache.ws.commons.schema.XmlSchemaSimpleType; import org.apache.ws.commons.schema.XmlSchemaType; @@ -85,7 +83,7 @@ public class ServiceJavascriptBuilder ex private SchemaCollection xmlSchemaCollection; // When generating from a tool or ?js, we know the endpoint addr and can build it into the javascript. private String endpointAddress; - + private boolean isWrapped; // facts about the wrapper when there is one. private MessagePartInfo inputWrapperPartInfo; @@ -102,7 +100,7 @@ public class ServiceJavascriptBuilder ex private List inputParameterNames = new ArrayList(); // when not wrapped, we use this to keep track of the bits. private List unwrappedElementsAndNames; - + private NamespacePrefixAccumulator prefixAccumulator; private BindingInfo xmlBindingInfo; private Map localOperationsNameMap; @@ -170,17 +168,15 @@ public class ServiceJavascriptBuilder ex generateGlobalElementDictionary(); code.append("}\n\n"); } - + private void generateGlobalElementDictionary() { // to handle 'any', we need a dictionary of all the global elements of all the schemas. utils.appendLine("this.globalElementSerializers = [];"); utils.appendLine("this.globalElementDeserializers = [];"); for (XmlSchema schemaInfo : xmlSchemaCollection.getXmlSchemas()) { - XmlSchemaObjectTable globalElements = schemaInfo.getElements(); - Iterator namesIterator = globalElements.getNames(); - while (namesIterator.hasNext()) { - QName name = (QName)namesIterator.next(); - XmlSchemaElement element = (XmlSchemaElement) globalElements.getItem(name); + for (Map.Entry e : schemaInfo.getElements().entrySet()) { + QName name = e.getKey(); + XmlSchemaElement element = e.getValue(); // For now, at least, don't handle elements with simple types. // That comes later to improve deserialization. if (JavascriptUtils.notVeryComplexType(element.getSchemaType())) { @@ -198,12 +194,10 @@ public class ServiceJavascriptBuilder ex + nameManager.getJavascriptName(name) + "_deserialize;"); } - - globalElements = schemaInfo.getSchemaTypes(); - namesIterator = globalElements.getNames(); - while (namesIterator.hasNext()) { - QName name = (QName)namesIterator.next(); - XmlSchemaType type = (XmlSchemaType) globalElements.getItem(name); + + for (Map.Entry e : schemaInfo.getSchemaTypes().entrySet()) { + QName name = e.getKey(); + XmlSchemaType type = e.getValue(); // For now, at least, don't handle simple types. if (JavascriptUtils.notVeryComplexType(type)) { continue; @@ -220,10 +214,10 @@ public class ServiceJavascriptBuilder ex } private String getFunctionGlobalName(QName itemName, String itemType) { - return nameManager.getJavascriptName(itemName) + "_" + itemType; + return nameManager.getJavascriptName(itemName) + "_" + itemType; } - - + + private String getFunctionPropertyName(Set conflictMap, T object, QName fullName) { boolean needsLongName = conflictMap.contains(object); String functionName; @@ -233,7 +227,7 @@ public class ServiceJavascriptBuilder ex functionName = JavascriptUtils.javaScriptNameToken(fullName.getLocalPart()); } return functionName; - + } // we do this at the end so we can inventory name conflicts sooner. @@ -246,11 +240,11 @@ public class ServiceJavascriptBuilder ex } isWrapped = op.isUnwrappedCapable(); - + StringBuilder parameterList = new StringBuilder(); inputParameterNames = new ArrayList(); - + if (isWrapped) { collectWrapperElementInfo(); } else { @@ -260,7 +254,7 @@ public class ServiceJavascriptBuilder ex buildParameterList(parameterList); MessageInfo outputMessage = op.getOutput(); - nonVoidOutput = outputMessage != null && outputMessage.getMessageParts().size() != 0; + nonVoidOutput = outputMessage != null && outputMessage.getMessageParts().size() != 0; if (!op.isOneWay()) { buildSuccessFunction(outputMessage); @@ -273,7 +267,7 @@ public class ServiceJavascriptBuilder ex if (nonVoidOutput) { createResponseDeserializer(outputMessage); - } + } } /** @@ -284,20 +278,20 @@ public class ServiceJavascriptBuilder ex if (currentOperation.getInput() != null) { getElementsForParts(currentOperation.getInput(), unwrappedElementsAndNames); } - + for (ParticleInfo ean : unwrappedElementsAndNames) { inputParameterNames.add(ean.getJavascriptName()); } } - - + + private void buildOperationFunction(StringBuilder parameterList) { String responseCallbackParams = ""; if (!currentOperation.isOneWay()) { responseCallbackParams = "successCallback, errorCallback"; } - + MessageInfo inputMessage = currentOperation.getInput(); code.append("//\n"); @@ -314,21 +308,21 @@ public class ServiceJavascriptBuilder ex contextQName = inputWrapperElement.getQName(); } XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(inputWrapperComplexType); - XmlSchema wrapperSchema = + XmlSchema wrapperSchema = xmlSchemaCollection.getSchemaByTargetNamespace(contextQName.getNamespaceURI()); - for (int i = 0; i < sequence.getItems().getCount(); i++) { + for (int i = 0; i < sequence.getItems().size(); i++) { code.append("// parameter " + inputParameterNames.get(i) + "\n"); - XmlSchemaObject sequenceItem = sequence.getItems().getItem(i); - ParticleInfo itemInfo = ParticleInfo.forLocalItem(sequenceItem, + XmlSchemaSequenceMember sequenceItem = sequence.getItems().get(i); + ParticleInfo itemInfo = ParticleInfo.forLocalItem((XmlSchemaObject)sequenceItem, wrapperSchema, xmlSchemaCollection, prefixAccumulator, - contextQName); + contextQName); if (itemInfo.isArray()) { code.append("// - array\n"); } - + XmlSchemaType type = itemInfo.getType(); // null for an any. if (type instanceof XmlSchemaComplexType) { QName baseName; @@ -337,20 +331,20 @@ public class ServiceJavascriptBuilder ex } else { baseName = ((XmlSchemaElement)sequenceItem).getQName(); } - code.append("// - Object constructor is " + code.append("// - Object constructor is " + nameManager.getJavascriptName(baseName) + "\n"); } else if (type != null) { code.append("// - simple type " + type.getQName()); } - } + } } - + code.append("//\n"); - - code.append("function " + + code.append("function " + opFunctionGlobalName + "(" + responseCallbackParams - + ((parameterList.length() > 0 && !currentOperation.isOneWay()) + + ((parameterList.length() > 0 && !currentOperation.isOneWay()) ? ", " : "") + parameterList + ") {\n"); utils.appendLine("this.client = new CxfApacheOrgClient(this.jsutils);"); utils.appendLine("var xml = null;"); @@ -363,7 +357,7 @@ public class ServiceJavascriptBuilder ex } utils.appendLine("xml = this." + getFunctionPropertyName(inputMessagesWithNameConflicts, - inputMessage, + inputMessage, inputMessage.getName()) + "_serializeInput" + "(this.jsutils, args);"); @@ -376,7 +370,7 @@ public class ServiceJavascriptBuilder ex utils.appendLine("this.client.user_onerror = errorCallback;"); utils.appendLine("var closureThis = this;"); // client will pass itself and the response XML. - utils.appendLine("this.client.onsuccess = function(client, responseXml) { closureThis." + utils.appendLine("this.client.onsuccess = function(client, responseXml) { closureThis." + opFunctionPropertyName + "_onsuccess(client, responseXml); };"); // client will pass itself. @@ -405,9 +399,9 @@ public class ServiceJavascriptBuilder ex + syncAsyncFlag + ", requestHeaders);"); code.append("}\n\n"); - code.append(currentInterfaceClassName + ".prototype." - + opFunctionPropertyName - + " = " + code.append(currentInterfaceClassName + ".prototype." + + opFunctionPropertyName + + " = " + opFunctionGlobalName + ";\n\n"); } @@ -415,7 +409,7 @@ public class ServiceJavascriptBuilder ex private void buildErrorFunction() { String errorFunctionPropertyName = opFunctionPropertyName + "_onerror"; String errorFunctionGlobalName = opFunctionGlobalName + "_onerror"; - + code.append("function " + errorFunctionGlobalName + "(client) {\n"); utils.startIf("client.user_onerror"); // Is this a good set of parameters for the error function? @@ -432,10 +426,10 @@ public class ServiceJavascriptBuilder ex utils.appendLine("client.user_onerror(httpStatus, httpStatusText);"); utils.endBlock(); code.append("}\n\n"); - code.append(currentInterfaceClassName + ".prototype." - + errorFunctionPropertyName + code.append(currentInterfaceClassName + ".prototype." + + errorFunctionPropertyName + " = " - + errorFunctionGlobalName + + errorFunctionGlobalName + ";\n\n"); } @@ -445,13 +439,13 @@ public class ServiceJavascriptBuilder ex // Here are the success and error callbacks. They have the job of // calling callbacks provided to the operation function with appropriate // parameters. - String successFunctionGlobalName = opFunctionGlobalName + "_onsuccess"; - String successFunctionPropertyName = opFunctionPropertyName + "_onsuccess"; + String successFunctionGlobalName = opFunctionGlobalName + "_onsuccess"; + String successFunctionPropertyName = opFunctionPropertyName + "_onsuccess"; String arglist = "(client)"; if (nonVoidOutput) { arglist = "(client, responseXml)"; } - + code.append("function " + successFunctionGlobalName + arglist + " {\n"); utils.startIf("client.user_onsuccess"); utils.appendLine("var responseObject = null;"); @@ -480,7 +474,7 @@ public class ServiceJavascriptBuilder ex utils.appendLine("element = this.jsutils.getFirstElementChild(element);"); utils.appendLine("this.jsutils.trace('part element: ' " + "+ this.jsutils.traceElementName(element));"); - } + } String deserializerFunctionName = outputDeserializerFunctionName(outputMessage); utils.appendLine("this.jsutils.trace('calling " + deserializerFunctionName + "');"); utils.appendLine("responseObject = " + deserializerFunctionName + "(this.jsutils, element);"); @@ -488,8 +482,8 @@ public class ServiceJavascriptBuilder ex utils.appendLine("client.user_onsuccess(responseObject);"); utils.endBlock(); code.append("}\n\n"); - code.append(currentInterfaceClassName + ".prototype." - + successFunctionPropertyName + code.append(currentInterfaceClassName + ".prototype." + + successFunctionPropertyName + " = " + successFunctionGlobalName + ";\n\n"); } @@ -509,7 +503,7 @@ public class ServiceJavascriptBuilder ex return getFunctionGlobalName(message.getName(), "deserializeResponse"); } - // This ignores 'wrapped', because it assumes one part that we can use one way or + // This ignores 'wrapped', because it assumes one part that we can use one way or // the other. For simple cases, this is certainly OK. private void createResponseDeserializer(MessageInfo outputMessage) { List parts = outputMessage.getMessageParts(); @@ -522,33 +516,33 @@ public class ServiceJavascriptBuilder ex getElementsForParts(outputMessage, elements); ParticleInfo element = elements.get(0); XmlSchemaType type = null; - + if (isRPC) { utils.appendLine("cxfjsutils.trace('rpc element: ' + cxfjsutils.traceElementName(partElement));"); utils.appendLine("partElement = cxfjsutils.getFirstElementChild(partElement);"); utils.appendLine("cxfjsutils.trace('rpc element: ' + cxfjsutils.traceElementName(partElement));"); } - + type = element.getType(); - + if (!element.isEmpty()) { if (type instanceof XmlSchemaComplexType) { String typeObjectName = nameManager.getJavascriptName(element.getControllingName()); utils - .appendLine("var returnObject = " - + typeObjectName + .appendLine("var returnObject = " + + typeObjectName + "_deserialize (cxfjsutils, partElement);\n"); } else if (type instanceof XmlSchemaSimpleType) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)type; utils.appendLine("var returnText = cxfjsutils.getNodeText(partElement);"); - utils.appendLine("var returnObject = " + utils.appendLine("var returnObject = " + utils.javascriptParseExpression(simpleType, "returnText") + ";"); - } + } utils.appendLine("return returnObject;"); } code.append("}\n"); } - + private String getElementObjectName(ParticleInfo element) { XmlSchemaType type = element.getType(); @@ -557,30 +551,30 @@ public class ServiceJavascriptBuilder ex return nameManager.getJavascriptName(element.getControllingName()); } else { return "type " + type.getQName(); // could it be anonymous? - } + } } else { return "empty element?"; } } private void createInputSerializer() { - + // If are working on a wrapped method, then we use the wrapper element. // If we are working on an unwrapped method, we will have to work from the unwrapped parts. - + MessageInfo message = currentOperation.getInput(); String serializerFunctionGlobalName = getFunctionGlobalName(message.getName(), "serializeInput"); - String serializerFunctionPropertyName = + String serializerFunctionPropertyName = getFunctionPropertyName(inputMessagesWithNameConflicts, message, message.getName()) + "_serializeInput"; code.append("function " + serializerFunctionGlobalName + "(cxfjsutils, 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) { - wrapperXmlElementName = + wrapperXmlElementName = prefixAccumulator.xmlElementString(inputWrapperPartInfo.getConcreteName()); utils.appendLine("var wrapperObj = new " + inputWrapperClassName + "();"); int px = 0; @@ -603,7 +597,7 @@ public class ServiceJavascriptBuilder ex } utils.setXmlStringAccumulator("xml"); - + if (isWrapped) { ParticleInfo elementInfo = ParticleInfo.forPartElement(inputWrapperElement, xmlSchemaCollection, @@ -615,23 +609,23 @@ public class ServiceJavascriptBuilder ex } else { String operationXmlElement = null; if (isRPC) { - operationXmlElement = + operationXmlElement = prefixAccumulator.xmlElementString(currentOperation.getName()); // RPC has a level of element for the entire operation. // we might have some schema to model this, but the following seems // sufficient. - utils.appendString("<" + operationXmlElement + ">"); + utils.appendString("<" + operationXmlElement + ">"); } int px = 0; // 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 - // with a complex type consisting of an element with array bounds. We don't + // with a complex type consisting of an element with array bounds. We don't // want the JavasSript programmer to have to concoct an extra level of object // (though if the same sort of thing happens elsewhere due to an XmlRootElement, - // the JavaScript programmer is stuck with the situation). + // the JavaScript programmer is stuck with the situation). for (ParticleInfo ean : unwrappedElementsAndNames) { String savedjsName = ean.getJavascriptName(); try { @@ -640,11 +634,11 @@ public class ServiceJavascriptBuilder ex px++; } finally { ean.setJavascriptName(savedjsName); - + } } if (isRPC) { - utils.appendString(""); + utils.appendString(""); } } @@ -652,42 +646,42 @@ public class ServiceJavascriptBuilder ex utils.appendLine("return xml;"); code.append("}\n\n"); code.append(currentInterfaceClassName + ".prototype." - + serializerFunctionPropertyName + + serializerFunctionPropertyName + " = " + serializerFunctionGlobalName + ";\n\n"); } - - private XmlSchemaSequence getTypeSequence(XmlSchemaComplexType type, + + private XmlSchemaSequence getTypeSequence(XmlSchemaComplexType type, QName parentName) { if (!(type.getParticle() instanceof XmlSchemaSequence)) { - unsupportedConstruct("NON_SEQUENCE_PARTICLE", - type.getQName() != null ? type.getQName() + unsupportedConstruct("NON_SEQUENCE_PARTICLE", + type.getQName() != null ? type.getQName() : parentName); } return (XmlSchemaSequence)type.getParticle(); } - + private boolean isEmptyType(XmlSchemaType type, QName parentName) { if (type instanceof XmlSchemaComplexType) { XmlSchemaComplexType complexType = (XmlSchemaComplexType)type; if (complexType.getParticle() == null) { return true; - } + } XmlSchemaSequence sequence = getTypeSequence(complexType, parentName); - if (sequence.getItems().getCount() == 0) { + if (sequence.getItems().size() == 0) { return true; } } return false; } - - private XmlSchemaParticle 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); + List insides = sequence.getItems(); + if (insides.size() == 1) { + XmlSchemaSequenceMember item = insides.get(0); if (item instanceof XmlSchemaElement || item instanceof XmlSchemaAny) { return (XmlSchemaParticle) item; } @@ -697,13 +691,13 @@ public class ServiceJavascriptBuilder ex /** * Collect information about the parts of an unwrapped message. - * @param parts + * @param parts * @param elements */ private void getElementsForParts(MessageInfo message, List elements) { for (MessagePartInfo mpi : message.getMessageParts()) { XmlSchemaElement element = null; - XmlSchemaType type = null; + XmlSchemaType type = null; QName diagnosticName = mpi.getName(); if (mpi.isElement()) { element = (XmlSchemaElement)mpi.getXmlSchema(); @@ -714,9 +708,9 @@ public class ServiceJavascriptBuilder ex diagnosticName = element.getQName(); type = element.getSchemaType(); if (type == null) { - type = XmlSchemaUtils.getElementType(xmlSchemaCollection, - null, - element, + type = XmlSchemaUtils.getElementType(xmlSchemaCollection, + null, + element, null); } } else { @@ -726,17 +720,17 @@ public class ServiceJavascriptBuilder ex type = xmlSchemaCollection.getTypeByQName(mpi.getTypeQName()); diagnosticName = type.getQName(); } - + } - + boolean empty = isEmptyType(type, diagnosticName); // 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 + if (!empty + && type instanceof XmlSchemaComplexType + && type.getName() == null && !isWrapped) { XmlSchemaParticle betterElement = getBuriedElement((XmlSchemaComplexType) type, diagnosticName); @@ -746,8 +740,8 @@ public class ServiceJavascriptBuilder ex if (element.getSchemaTypeName() != null) { element.setSchemaType(xmlSchemaCollection .getTypeByQName(element.getSchemaTypeName())); - } else if (element.getRefName() != null) { - element = xmlSchemaCollection.getElementByQName(element.getRefName()); + } else if (element.getRef().getTargetQName() != null) { + element = element.getRef().getTarget(); element.setSchemaType(xmlSchemaCollection .getTypeByQName(element.getSchemaTypeName())); } @@ -755,28 +749,28 @@ public class ServiceJavascriptBuilder ex type = element.getSchemaType(); } } - - String partJavascriptVar = + + String partJavascriptVar = JavascriptUtils.javaScriptNameToken(mpi.getConcreteName().getLocalPart()); String elementXmlRef = prefixAccumulator.xmlElementString(mpi.getConcreteName()); ParticleInfo elementInfo = ParticleInfo.forPartElement(element, xmlSchemaCollection, - partJavascriptVar, - elementXmlRef); + partJavascriptVar, + elementXmlRef); // the type may have been recalculated above. elementInfo.setType(type); elementInfo.setEmpty(empty); elements.add(elementInfo); } } - + // This function finds all the information for the wrapper. private void collectWrapperElementInfo() { - + if (currentOperation.getInput() != null) { inputWrapperPartInfo = currentOperation.getInput().getMessagePart(0); - List unwrappedParts = + List unwrappedParts = currentOperation.getUnwrappedOperation().getInput().getMessageParts(); for (MessagePartInfo mpi : unwrappedParts) { @@ -789,8 +783,8 @@ public class ServiceJavascriptBuilder ex inputWrapperElement = (XmlSchemaElement)inputWrapperPartInfo.getXmlSchema(); if (inputWrapperElement == null) { - inputWrapperElement = - XmlSchemaUtils.findElementByRefName(xmlSchemaCollection, + inputWrapperElement = + XmlSchemaUtils.findElementByRefName(xmlSchemaCollection, inputWrapperPartInfo.getElementQName(), serviceInfo.getTargetNamespace()); } @@ -798,32 +792,32 @@ public class ServiceJavascriptBuilder ex // the null name is probably something awful in RFSB. if (inputWrapperComplexType == null) { inputWrapperComplexType = (XmlSchemaComplexType) - XmlSchemaUtils.getElementType(xmlSchemaCollection, - serviceInfo.getTargetNamespace(), - inputWrapperElement, + XmlSchemaUtils.getElementType(xmlSchemaCollection, + serviceInfo.getTargetNamespace(), + inputWrapperElement, null); } if (inputWrapperComplexType == null) { unsupportedConstruct("MISSING_WRAPPER_TYPE", currentOperation.getInterface().getName(), - currentOperation.getName(), + currentOperation.getName(), inputWrapperPartInfo.getName()); } - + if (inputWrapperComplexType.getQName() == null) { // we should be ignoring this for zero-argument wrappers. if (inputWrapperPartInfo.isElement()) { inputWrapperClassName = nameManager. getJavascriptName(inputWrapperPartInfo.getElementQName()); } else { - unsupportedConstruct("NON_ELEMENT_ANON_TYPE_PART", + unsupportedConstruct("NON_ELEMENT_ANON_TYPE_PART", inputWrapperPartInfo.getMessageInfo().getName(), inputWrapperPartInfo.getName()); } } else { inputWrapperClassName = nameManager.getJavascriptName(inputWrapperComplexType.getQName()); } - + } if (currentOperation.getOutput() != null) { @@ -832,17 +826,17 @@ public class ServiceJavascriptBuilder ex outputWrapperElement = (XmlSchemaElement)outputWrapperPartInfo.getXmlSchema(); if (outputWrapperElement == null) { - outputWrapperElement = - XmlSchemaUtils.findElementByRefName(xmlSchemaCollection, + outputWrapperElement = + XmlSchemaUtils.findElementByRefName(xmlSchemaCollection, outputWrapperPartInfo.getElementQName(), serviceInfo.getTargetNamespace()); } outputWrapperComplexType = (XmlSchemaComplexType)outputWrapperElement.getSchemaType(); if (outputWrapperComplexType == null) { outputWrapperComplexType = (XmlSchemaComplexType) - XmlSchemaUtils.getElementType(xmlSchemaCollection, - serviceInfo.getTargetNamespace(), - outputWrapperElement, + XmlSchemaUtils.getElementType(xmlSchemaCollection, + serviceInfo.getTargetNamespace(), + outputWrapperElement, null); } } @@ -850,7 +844,7 @@ public class ServiceJavascriptBuilder ex @Override public void begin(ServiceInfo service) { - + code.append("//\n"); code.append("// Definitions for service: " + service.getName().toString() + "\n"); code.append("//\n"); @@ -934,7 +928,7 @@ public class ServiceJavascriptBuilder ex opFunctionPropertyName = getFunctionPropertyName(operationsWithNameConflicts, op, op.getName()); opFunctionGlobalName = getFunctionGlobalName(op.getName(), "op"); } - + @Override public void begin(MessageInfo msg) { if (isInUnwrappedOperation) { @@ -962,7 +956,7 @@ public class ServiceJavascriptBuilder ex @Override public void begin(EndpointInfo endpointInfo) { String address = endpointInfo.getAddress(); - String portClassName = currentInterfaceClassName + "_" + String portClassName = currentInterfaceClassName + "_" + nameManager.getJavascriptName(endpointInfo.getName()); code.append("function " + portClassName + " () {\n"); code.append(" this.url = '" + address + "';\n"); Modified: cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java?rev=1023402&r1=1023401&r2=1023402&view=diff ============================================================================== --- cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java (original) +++ cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java Sun Oct 17 02:26:06 2010 @@ -19,8 +19,8 @@ package org.apache.cxf.javascript.types; -import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import javax.xml.namespace.QName; @@ -41,20 +41,17 @@ import org.apache.cxf.javascript.Unsuppo import org.apache.ws.commons.schema.XmlSchema; import org.apache.ws.commons.schema.XmlSchemaAnnotated; import org.apache.ws.commons.schema.XmlSchemaAny; -import org.apache.ws.commons.schema.XmlSchemaAttribute; +import org.apache.ws.commons.schema.XmlSchemaAttributeOrGroupRef; import org.apache.ws.commons.schema.XmlSchemaCollection; 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.XmlSchemaSimpleType; import org.apache.ws.commons.schema.XmlSchemaType; /** - * Generate Javascript for a schema, and provide information needed for the - * service builder. As of this pass, there is no support for non-sequence types - * or for attribute mappings. + * Generate Javascript for a schema, and provide information needed for the service builder. As of this pass, + * there is no support for non-sequence types or for attribute mappings. */ public class SchemaJavascriptBuilder { @@ -63,7 +60,7 @@ public class SchemaJavascriptBuilder { private SchemaCollection xmlSchemaCollection; private NameManager nameManager; private NamespacePrefixAccumulator prefixAccumulator; - //private SchemaInfo schemaInfo; + // private SchemaInfo schemaInfo; // In general, I (bimargulies) hate fields that are temporary communications // between members of a class. However, given the style restrictions on the @@ -79,7 +76,7 @@ public class SchemaJavascriptBuilder { this.nameManager = nameManager; this.prefixAccumulator = prefixAccumulator; } - + public String generateCodeForSchemaCollection(XmlSchemaCollection collection) { StringBuilder accumulatedCode = new StringBuilder(); for (XmlSchema schema : collection.getXmlSchemas()) { @@ -100,16 +97,13 @@ public class SchemaJavascriptBuilder { } code.append("\n//\n"); - XmlSchemaObjectTable schemaTypes = schema.getSchemaTypes(); - Iterator namesIterator = schemaTypes.getNames(); - while (namesIterator.hasNext()) { - QName name = (QName)namesIterator.next(); - XmlSchemaObject xmlSchemaObject = (XmlSchemaObject)schemaTypes.getItem(name); - if (xmlSchemaObject instanceof XmlSchemaComplexType) { + Map schemaTypes = schema.getSchemaTypes(); + for (Map.Entry e : schemaTypes.entrySet()) { + XmlSchemaType type = e.getValue(); + if (type instanceof XmlSchemaComplexType) { try { - XmlSchemaComplexType complexType = (XmlSchemaComplexType)xmlSchemaObject; - if (!JavascriptUtils.notVeryComplexType(complexType) - && complexType.getName() != null) { + XmlSchemaComplexType complexType = (XmlSchemaComplexType)type; + if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() != null) { complexTypeConstructorAndAccessors(complexType.getQName(), complexType); complexTypeSerializerFunction(complexType.getQName(), complexType); domDeserializerFunction(complexType.getQName(), complexType); @@ -119,8 +113,8 @@ public class SchemaJavascriptBuilder { continue; // it could be empty, but the style checker // would complain. } - } else if (xmlSchemaObject instanceof XmlSchemaSimpleType) { - XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)xmlSchemaObject; + } else if (type instanceof XmlSchemaSimpleType) { + XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)type; if (XmlSchemaUtils.isEumeration(simpleType)) { List values = XmlSchemaUtils.enumeratorValues(simpleType); code.append("//\n"); @@ -133,50 +127,37 @@ public class SchemaJavascriptBuilder { } } - // now add in global elements with anonymous types. - schemaTypes = schema.getElements(); - namesIterator = schemaTypes.getNames(); - while (namesIterator.hasNext()) { - QName name = (QName)namesIterator.next(); - XmlSchemaObject xmlSchemaObject = (XmlSchemaObject)schemaTypes.getItem(name); - if (xmlSchemaObject instanceof XmlSchemaElement) { // the - // alternative - // is too wierd - // to - // contemplate. - try { - XmlSchemaElement element = (XmlSchemaElement)xmlSchemaObject; - if (element.getSchemaTypeName() == null && element.getSchemaType() == null) { - Message message = new Message("ELEMENT_MISSING_TYPE", LOG, element.getQName(), - element.getSchemaTypeName(), - schema.getTargetNamespace()); - LOG.warning(message.toString()); - continue; - } - XmlSchemaType type; - if (element.getSchemaType() != null) { - type = element.getSchemaType(); - } else { - type = schema.getTypeByName(element.getSchemaTypeName()); - } - if (!(type instanceof XmlSchemaComplexType)) { - // we never make classes for simple type. - continue; - } + for (Map.Entry e : schema.getElements().entrySet()) { + XmlSchemaElement element = e.getValue(); + try { + if (element.getSchemaTypeName() == null && element.getSchemaType() == null) { + Message message = new Message("ELEMENT_MISSING_TYPE", LOG, element.getQName(), + element.getSchemaTypeName(), schema.getTargetNamespace()); + LOG.warning(message.toString()); + continue; + } + XmlSchemaType type; + if (element.getSchemaType() != null) { + type = element.getSchemaType(); + } else { + type = schema.getTypeByName(element.getSchemaTypeName()); + } + if (!(type instanceof XmlSchemaComplexType)) { + // we never make classes for simple type. + continue; + } - XmlSchemaComplexType complexType = (XmlSchemaComplexType)type; - // for named types we don't bother to generate for the - // element. - if (!JavascriptUtils.notVeryComplexType(complexType) - && complexType.getName() == null) { - complexTypeConstructorAndAccessors(element.getQName(), complexType); - complexTypeSerializerFunction(element.getQName(), complexType); - domDeserializerFunction(element.getQName(), complexType); - } - } catch (UnsupportedConstruct usc) { - continue; // it could be empty, but the style checker - // would complain. + XmlSchemaComplexType complexType = (XmlSchemaComplexType)type; + // for named types we don't bother to generate for the + // element. + if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() == null) { + complexTypeConstructorAndAccessors(element.getQName(), complexType); + complexTypeSerializerFunction(element.getQName(), complexType); + domDeserializerFunction(element.getQName(), complexType); } + } catch (UnsupportedConstruct usc) { + continue; // it could be empty, but the style checker + // would complain. } } @@ -206,31 +187,24 @@ public class SchemaJavascriptBuilder { // to assist in debugging we put a type property into every object. utils.appendLine("this.typeMarker = '" + typeObjectName + "';"); for (XmlSchemaObject thing : items) { - ParticleInfo itemInfo = ParticleInfo.forLocalItem(thing, - xmlSchema, - xmlSchemaCollection, - prefixAccumulator, - type.getQName()); + ParticleInfo itemInfo = ParticleInfo.forLocalItem(thing, xmlSchema, xmlSchemaCollection, + prefixAccumulator, type.getQName()); constructOneItem(type, elementPrefix, typeObjectName, itemInfo); } - + for (XmlSchemaAnnotated thing : attrs) { - AttributeInfo itemInfo = AttributeInfo.forLocalItem(thing, xmlSchema, - xmlSchemaCollection, - prefixAccumulator, - type.getQName()); + AttributeInfo itemInfo = AttributeInfo.forLocalItem(thing, xmlSchema, xmlSchemaCollection, + prefixAccumulator, type.getQName()); constructOneItem(type, elementPrefix, typeObjectName, itemInfo); } - + code.append("}\n\n"); code.append(accessors.toString()); } - private void constructOneItem(XmlSchemaComplexType type, - final String elementPrefix, - String typeObjectName, - ItemInfo itemInfo) { - + private void constructOneItem(XmlSchemaComplexType type, final String elementPrefix, + String typeObjectName, ItemInfo itemInfo) { + String accessorSuffix = StringUtils.capitalize(itemInfo.getJavascriptName()); String accessorName = typeObjectName + "_get" + accessorSuffix; @@ -267,12 +241,11 @@ public class SchemaJavascriptBuilder { accessors.append("// element set for " + itemInfo.getJavascriptName() + "\n"); accessors.append("// setter function is is " + setFunctionProperty + "\n"); accessors.append("//\n"); - accessors.append("function " + accessorName + "() { return this._" - + itemInfo.getJavascriptName() + ";}\n\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) { this._" - + itemInfo.getJavascriptName() + accessors.append("function " + accessorName + "(value) { this._" + itemInfo.getJavascriptName() + " = value;}\n\n"); accessors.append(setFunctionProperty + " = " + accessorName + ";\n"); @@ -290,18 +263,16 @@ public class SchemaJavascriptBuilder { if (itemInfo.getDefaultValue() == null) { itemInfo.setDefaultValue(utils.getDefaultValueForSimpleType(itemInfo.getType())); } - utils.appendLine("this._" + itemInfo.getJavascriptName() + " = " - + itemInfo.getDefaultValue() + ";"); + utils.appendLine("this._" + itemInfo.getJavascriptName() + " = " + itemInfo.getDefaultValue() + + ";"); } } /** - * Produce a serializer function for a type. These functions emit the - * surrounding element XML if the caller supplies an XML element name. It's - * not quite as simple as that, though. The element name may need namespace - * qualification, and this function will add more namespace prefixes as - * needed. - * + * Produce a serializer function for a type. These functions emit the surrounding element XML if the + * caller supplies an XML element name. It's not quite as simple as that, though. The element name may + * need namespace qualification, and this function will add more namespace prefixes as needed. + * * @param type * @return */ @@ -348,19 +319,16 @@ public class SchemaJavascriptBuilder { } private void complexTypeSerializeAttributes(XmlSchemaComplexType type, String string) { - XmlSchemaObjectCollection attributes = type.getAttributes(); - for (int ax = 0; ax < attributes.getCount(); ax++) { - @SuppressWarnings("unused") // work in progress. - XmlSchemaAttribute attribute = (XmlSchemaAttribute)attributes.getItem(ax); - } + @SuppressWarnings("unused") + List attributes = type.getAttributes(); + // work in progress. } /** - * Build the serialization code for a complex type. At the top level, this - * operates on single items, so it does not pay attention to minOccurs and - * maxOccurs. However, as it works through the sequence, it manages optional - * elements and arrays. - * + * Build the serialization code for a complex type. At the top level, this operates on single items, so it + * does not pay attention to minOccurs and maxOccurs. However, as it works through the sequence, it + * manages optional elements and arrays. + * * @param type * @param elementPrefix * @param bodyNamespaceURIs @@ -370,12 +338,9 @@ public class SchemaJavascriptBuilder { JavascriptUtils bodyUtils) { List items = XmlSchemaUtils.getContentElements(type, xmlSchemaCollection); for (XmlSchemaObject sequenceItem : items) { - ParticleInfo itemInfo = ParticleInfo.forLocalItem(sequenceItem, - xmlSchema, - xmlSchemaCollection, - prefixAccumulator, - type.getQName()); - + ParticleInfo itemInfo = ParticleInfo.forLocalItem(sequenceItem, xmlSchema, xmlSchemaCollection, + prefixAccumulator, type.getQName()); + // If the item is 'any', it could be ANY of our top-level elements. if (itemInfo.isAny()) { serializeAny(itemInfo, bodyUtils); @@ -392,16 +357,15 @@ public class SchemaJavascriptBuilder { } /** - * Generate a JavaScript function that takes an element for a complex type - * and walks through its children using them to fill in the values for a - * JavaScript object. - * + * Generate a JavaScript function that takes an element for a complex type and walks through its children + * using them to fill in the values for a JavaScript object. + * * @param type schema type for the process * @return the string contents of the JavaScript. */ public void domDeserializerFunction(QName name, XmlSchemaComplexType type) { utils = new JavascriptUtils(code); - + List contentElements = XmlSchemaUtils.getContentElements(type, xmlSchemaCollection); String typeObjectName = nameManager.getJavascriptName(name); code.append("function " + typeObjectName + "_deserialize (cxfjsutils, element) {\n"); @@ -416,20 +380,14 @@ public class SchemaJavascriptBuilder { for (int i = 0; i < contentElements.size(); i++) { XmlSchemaObject contentElement = contentElements.get(i); utils.appendLine("cxfjsutils.trace('curElement: ' + cxfjsutils.traceElementName(curElement));"); - ParticleInfo itemInfo = ParticleInfo.forLocalItem(contentElement, - xmlSchema, - xmlSchemaCollection, - prefixAccumulator, - type.getQName()); + ParticleInfo itemInfo = ParticleInfo.forLocalItem(contentElement, xmlSchema, xmlSchemaCollection, + prefixAccumulator, type.getQName()); if (itemInfo.isAny()) { ParticleInfo nextItem = null; if (i != nContentElements - 1) { XmlSchemaObject nextThing = contentElements.get(i + 1); - nextItem = ParticleInfo.forLocalItem(nextThing, - xmlSchema, - xmlSchemaCollection, - prefixAccumulator, - type.getQName()); + nextItem = ParticleInfo.forLocalItem(nextThing, xmlSchema, xmlSchemaCollection, + prefixAccumulator, type.getQName()); // theoretically, you could have two anys with different // namespaces. if (nextItem.isAny()) { @@ -444,7 +402,7 @@ public class SchemaJavascriptBuilder { utils.appendLine("return newobject;"); code.append("}\n\n"); } - + private String buildNamespaceList(String anyNamespaceSpec) { StringBuilder nslist = new StringBuilder(); String[] namespaces = anyNamespaceSpec.split("\\s"); @@ -468,14 +426,12 @@ public class SchemaJavascriptBuilder { return nslist.toString(); } - private void deserializeAny(XmlSchemaComplexType type, - ParticleInfo itemInfo, - ParticleInfo nextItem) { + private void deserializeAny(XmlSchemaComplexType type, ParticleInfo itemInfo, ParticleInfo nextItem) { XmlSchemaAny any = (XmlSchemaAny)itemInfo.getParticle(); - + boolean array = XmlSchemaUtils.isParticleArray(any); boolean optional = XmlSchemaUtils.isParticleOptional(any); - + if (array) { utils.appendLine("var anyObject = [];"); } else { @@ -491,10 +447,8 @@ public class SchemaJavascriptBuilder { } String matchType; String namespaceList = "[]"; - - if (anyNamespaceSpec == null - || "##any".equals(anyNamespaceSpec) - || "".equals(anyNamespaceSpec)) { + + if (anyNamespaceSpec == null || "##any".equals(anyNamespaceSpec) || "".equals(anyNamespaceSpec)) { matchType = "org_apache_cxf_any_ns_matcher.ANY"; } else if ("##other".equals(anyNamespaceSpec)) { matchType = "org_apache_cxf_any_ns_matcher.OTHER"; @@ -504,19 +458,16 @@ public class SchemaJavascriptBuilder { matchType = "org_apache_cxf_any_ns_matcher.LISTED"; namespaceList = buildNamespaceList(anyNamespaceSpec); } - + String nextLocalPartConstant = "null"; if (nextElement != null) { nextLocalPartConstant = "'" + nextElement.getQName().getLocalPart() + "'"; } - - utils.appendLine("var matcher = new org_apache_cxf_any_ns_matcher(" - + matchType - + ", '" + xmlSchema.getTargetNamespace() + "'" - + ", " + namespaceList - + ", " + nextLocalPartConstant - + ");"); - + + utils.appendLine("var matcher = new org_apache_cxf_any_ns_matcher(" + matchType + ", '" + + xmlSchema.getTargetNamespace() + "'" + ", " + namespaceList + ", " + + nextLocalPartConstant + ");"); + if (array) { utils.appendLine("var anyNeeded = " + any.getMinOccurs() + ";"); utils.appendLine("var anyAllowed = " + any.getMaxOccurs() + ";"); @@ -527,23 +478,23 @@ public class SchemaJavascriptBuilder { utils.appendLine("var anyNeeded = 1;"); utils.appendLine("var anyAllowed = 1;"); } - + utils.startWhile("anyNeeded > 0 || anyAllowed > 0"); utils.appendLine("var anyURI;"); utils.appendLine("var anyLocalPart;"); utils.appendLine("var anyMatched = false;"); utils.startIf("curElement"); - + utils.appendLine("anyURI = cxfjsutils.getElementNamespaceURI(curElement);"); utils.appendLine("anyLocalPart = cxfjsutils.getNodeLocalName(curElement);"); utils.appendLine("var anyQName = '{' + anyURI + '}' + anyLocalPart;"); - utils.appendLine("cxfjsutils.trace('any match: ' + anyQName);"); + utils.appendLine("cxfjsutils.trace('any match: ' + anyQName);"); utils.appendLine("anyMatched = matcher.match(anyURI, anyLocalPart)"); - utils.appendLine("cxfjsutils.trace(' --> ' + anyMatched);"); + utils.appendLine("cxfjsutils.trace(' --> ' + anyMatched);"); utils.endBlock(); // curElement != null - + utils.startIf("anyMatched"); // if match utils.appendLine("anyDeserializer = " + "cxfjsutils.interfaceObject.globalElementDeserializers[anyQName];"); @@ -560,10 +511,10 @@ public class SchemaJavascriptBuilder { } else { utils.appendLine("anyObject = anyValue;"); } - + utils.appendLine("anyNeeded--;"); utils.appendLine("anyAllowed--;"); - // if we consumed the element, we advance. + // if we consumed the element, we advance. utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);"); utils.appendElse(); // match // non-matching case @@ -578,19 +529,16 @@ public class SchemaJavascriptBuilder { } private void deserializeElement(XmlSchemaComplexType type, XmlSchemaObject thing) { - ParticleInfo itemInfo = ParticleInfo.forLocalItem(thing, - xmlSchema, - xmlSchemaCollection, - prefixAccumulator, - type.getQName()); + ParticleInfo itemInfo = ParticleInfo.forLocalItem(thing, xmlSchema, xmlSchemaCollection, + prefixAccumulator, type.getQName()); XmlSchemaType itemType = itemInfo.getType(); boolean simple = itemType instanceof XmlSchemaSimpleType - || JavascriptUtils.notVeryComplexType(itemType); + || JavascriptUtils.notVeryComplexType(itemType); boolean mtomCandidate = JavascriptUtils.mtomCandidateType(itemType); String accessorName = "set" + StringUtils.capitalize(itemInfo.getJavascriptName()); utils.appendLine("cxfjsutils.trace('processing " + itemInfo.getJavascriptName() + "');"); - XmlSchemaElement element = (XmlSchemaElement) itemInfo.getParticle(); - QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, xmlSchema); + XmlSchemaElement element = (XmlSchemaElement)itemInfo.getParticle(); + QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, xmlSchema); String elementNamespaceURI = elementQName.getNamespaceURI(); boolean elementNoNamespace = "".equals(elementNamespaceURI); XmlSchema elementSchema = null; @@ -598,15 +546,13 @@ public class SchemaJavascriptBuilder { elementSchema = xmlSchemaCollection.getSchemaByTargetNamespace(elementNamespaceURI); } boolean qualified = !elementNoNamespace - && XmlSchemaUtils.isElementQualified(element, - itemInfo.isGlobal(), - xmlSchema, + && XmlSchemaUtils.isElementQualified(element, itemInfo.isGlobal(), xmlSchema, elementSchema); if (!qualified) { elementNamespaceURI = ""; } - + String localName = elementQName.getLocalPart(); String valueTarget = "item"; @@ -631,9 +577,8 @@ public class SchemaJavascriptBuilder { utils.appendLine(valueTarget + " = cxfjsutils.deserializeBase64orMom(curElement);"); } else { utils.appendLine("value = cxfjsutils.getNodeText(curElement);"); - utils.appendLine(valueTarget - + " = " - + utils.javascriptParseExpression(itemType, "value") + ";"); + utils.appendLine(valueTarget + " = " + utils.javascriptParseExpression(itemType, "value") + + ";"); } } else { XmlSchemaComplexType complexType = (XmlSchemaComplexType)itemType; @@ -643,10 +588,7 @@ public class SchemaJavascriptBuilder { } 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. @@ -655,8 +597,7 @@ public class SchemaJavascriptBuilder { utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);"); utils.endBlock(); utils.appendLine(" while(curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" - + elementNamespaceURI + "', '" - + localName + "'));"); + + elementNamespaceURI + "', '" + localName + "'));"); } utils.appendLine("newobject." + accessorName + "(item);"); utils.appendLine("var item = null;"); Modified: cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/common/WSDLUtils.java URL: http://svn.apache.org/viewvc/cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/common/WSDLUtils.java?rev=1023402&r1=1023401&r2=1023402&view=diff ============================================================================== --- cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/common/WSDLUtils.java (original) +++ cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/common/WSDLUtils.java Sun Oct 17 02:26:06 2010 @@ -22,8 +22,6 @@ package org.apache.cxf.tools.corba.commo import java.io.IOException; import java.io.Writer; -import java.util.Iterator; - import javax.wsdl.Definition; import javax.wsdl.WSDLException; import javax.wsdl.xml.WSDLWriter; @@ -44,24 +42,22 @@ public final class WSDLUtils { } public static boolean isElementFormQualified(SchemaCollection schemas, QName type) { - if (type != null) { + if (type != null) { XmlSchema sch = schemas.getSchemaByTargetNamespace(type.getNamespaceURI()); if (sch != null) { - return sch.getElementFormDefault().getValue().equals(XmlSchemaForm.QUALIFIED); + return sch.getElementFormDefault() == XmlSchemaForm.QUALIFIED; } } return false; } public static boolean isElementFormQualified(XmlSchema schema, QName type) { - if (type != null) { + if (type != null) { String uri = type.getNamespaceURI(); if (uri.equals(schema.getTargetNamespace())) { - return schema.getElementFormDefault().getValue().equals(XmlSchemaForm.QUALIFIED); + return schema.getElementFormDefault() == XmlSchemaForm.QUALIFIED; } - Iterator it = schema.getIncludes().getIterator(); - while (it.hasNext()) { - XmlSchemaExternal extSchema = (XmlSchemaExternal) it.next(); + for (XmlSchemaExternal extSchema : schema.getExternals()) { return isElementFormQualified(extSchema.getSchema(), type); } } @@ -69,25 +65,25 @@ public final class WSDLUtils { } public static void writeWSDL(Definition def, String outputdir, String wsdlOutput) - throws WSDLException, IOException { + throws WSDLException, IOException { FileWriterUtil fw = new FileWriterUtil(outputdir); Writer outputWriter = fw.getWriter("", wsdlOutput); - writeWSDL(def, outputWriter); + writeWSDL(def, outputWriter); } public static void writeWSDL(Definition def, Writer outputWriter) - throws WSDLException, IOException { + throws WSDLException, IOException { WSDLCorbaFactory wsdlfactory = WSDLCorbaFactory .newInstance("org.apache.cxf.tools.corba.common.WSDLCorbaFactoryImpl"); - WSDLWriter writer = wsdlfactory.newWSDLWriter(); + WSDLWriter writer = wsdlfactory.newWSDLWriter(); writer.writeWSDL(def, outputWriter); - + outputWriter.flush(); outputWriter.close(); } - + public static void writeSchema(Definition def, Writer outputWriter) throws WSDLException, IOException { SchemaFactory sfactory = SchemaFactory .newInstance("org.apache.cxf.tools.corba.common.SchemaFactoryImpl"); Modified: cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ArrayVisitor.java URL: http://svn.apache.org/viewvc/cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ArrayVisitor.java?rev=1023402&r1=1023401&r2=1023402&view=diff ============================================================================== --- cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ArrayVisitor.java (original) +++ cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ArrayVisitor.java Sun Oct 17 02:26:06 2010 @@ -39,7 +39,7 @@ public class ArrayVisitor extends Visito private static final String ELEMENT_NAME = "item"; private AST identifierNode; - + public ArrayVisitor(Scope scope, Definition defn, XmlSchema schemaRef, @@ -81,7 +81,7 @@ public class ArrayVisitor extends Visito AST firstSizeNode = node.getFirstChild(); AST nextSizeNode = firstSizeNode.getNextSibling(); Types result = null; - + // process all anonarrays, skip first array as it might not be anonymous if (nextSizeNode != null) { result = doAnonarray(nextSizeNode, getSchemaType(), getCorbaType()); @@ -91,26 +91,26 @@ public class ArrayVisitor extends Visito result.setCorbaType(getCorbaType()); result.setFullyQualifiedName(getFullyQualifiedName()); } - + // process first array Long size = new Long(firstSizeNode.toString()); XmlSchemaType stype = null; CorbaTypeImpl ctype = null; if (identifierNode != null) { - Scope scopedName = getScope(); + Scope scopedName = getScope(); if (result.getSchemaType() != null) { - stype = generateSchemaArray(scopedName, size, - result.getSchemaType(), + stype = generateSchemaArray(scopedName, size, + result.getSchemaType(), result.getFullyQualifiedName()); } else { - stype = generateSchemaArray(scopedName, size, + stype = generateSchemaArray(scopedName, size, null, result.getFullyQualifiedName()); } if (result.getCorbaType() != null) { ctype = generateCorbaArray(scopedName, size, result.getCorbaType(), stype, getFullyQualifiedName()); } else { - ctype = generateCorbaArray(scopedName, size, null, stype, + ctype = generateCorbaArray(scopedName, size, null, stype, getFullyQualifiedName()); } } else { @@ -136,29 +136,29 @@ public class ArrayVisitor extends Visito size, null, stype, getFullyQualifiedName()); } } - + // add schemaType schema.getItems().add(stype); schema.addType(stype); // add corbaType typeMap.getStructOrExceptionOrUnion().add(ctype); - + setSchemaType(stype); setCorbaType(ctype); } private Types doAnonarray(AST node, XmlSchemaType stype, CorbaTypeImpl ctype) { Types result = new Types(); - + if (node != null) { - + AST next = node.getNextSibling(); result = doAnonarray(next, stype, ctype); Scope scopedName = TypesUtils.generateAnonymousScopedName(getScope(), schema); Long size = new Long(node.toString()); - + if (result.getSchemaType() == null) { result.setSchemaType(generateSchemaArray(scopedName, size, @@ -170,7 +170,7 @@ public class ArrayVisitor extends Visito result.getSchemaType(), getFullyQualifiedName())); } - + if (result.getCorbaType() == null) { result.setCorbaType(generateCorbaAnonarray(scopedName.toString(), size, @@ -184,7 +184,7 @@ public class ArrayVisitor extends Visito result.getSchemaType(), getFullyQualifiedName())); } - + // add schemaType schema.getItems().add(result.getSchemaType()); @@ -193,18 +193,18 @@ public class ArrayVisitor extends Visito // add corbaType typeMap.getStructOrExceptionOrUnion().add(result.getCorbaType()); } - + return result; } - - private XmlSchemaComplexType generateSchemaArray(Scope scopedName, Long size, + + private XmlSchemaComplexType generateSchemaArray(Scope scopedName, Long size, XmlSchemaType type, Scope fQName) { - XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema); + XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, false); complexType.setName(mapper.mapToQName(scopedName)); XmlSchemaSequence sequence = new XmlSchemaSequence(); - XmlSchemaElement element = new XmlSchemaElement(); + XmlSchemaElement element = new XmlSchemaElement(schema, false); element.setMinOccurs(size); element.setMaxOccurs(size); element.setName(ELEMENT_NAME); @@ -214,11 +214,11 @@ public class ArrayVisitor extends Visito element.setNillable(true); } } else { - ArrayDeferredAction arrayAction = + ArrayDeferredAction arrayAction = new ArrayDeferredAction(element); wsdlVisitor.getDeferredActions().add(fQName, arrayAction); } - + sequence.getItems().add(element); complexType.setParticle(sequence); @@ -226,7 +226,7 @@ public class ArrayVisitor extends Visito return complexType; } - private Array generateCorbaArray(Scope scopedName, Long size, + private Array generateCorbaArray(Scope scopedName, Long size, CorbaTypeImpl type, XmlSchemaType stype, Scope fQName) { Array array = new Array(); array.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString())); @@ -238,14 +238,14 @@ public class ArrayVisitor extends Visito if (type != null) { array.setElemtype(type.getQName()); } else { - ArrayDeferredAction arrayAction = + ArrayDeferredAction arrayAction = new ArrayDeferredAction(array); wsdlVisitor.getDeferredActions().add(fQName, arrayAction); } return array; } - private Anonarray generateCorbaAnonarray(String name, Long size, + private Anonarray generateCorbaAnonarray(String name, Long size, CorbaTypeImpl type, XmlSchemaType stype, Scope fQName) { Anonarray anonarray = new Anonarray(); anonarray.setQName(new QName(typeMap.getTargetNamespace(), name)); @@ -256,50 +256,50 @@ public class ArrayVisitor extends Visito if (type != null) { anonarray.setElemtype(type.getQName()); } else { - ArrayDeferredAction anonarrayAction = + ArrayDeferredAction anonarrayAction = new ArrayDeferredAction(anonarray); wsdlVisitor.getDeferredActions().add(fQName, anonarrayAction); } return anonarray; } - + class Types { private XmlSchemaType schemaType; private CorbaTypeImpl corbaType; private Scope fullyQualifiedName; - + public Types() { schemaType = null; corbaType = null; } - + public Types(XmlSchemaType stype, CorbaTypeImpl ctype, Scope fqName) { schemaType = stype; corbaType = ctype; fullyQualifiedName = fqName; } - + public void setSchemaType(XmlSchemaType stype) { schemaType = stype; } - + public void setCorbaType(CorbaTypeImpl ctype) { corbaType = ctype; } - + public XmlSchemaType getSchemaType() { return schemaType; } - + public CorbaTypeImpl getCorbaType() { return corbaType; } - + public void setFullyQualifiedName(Scope fqName) { fullyQualifiedName = fqName; } - + public Scope getFullyQualifiedName() { return fullyQualifiedName; }