cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r597906 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/xmlschema/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ rt/javascript/src/main/j...
Date Sat, 24 Nov 2007 19:37:50 GMT
Author: bimargulies
Date: Sat Nov 24 11:37:49 2007
New Revision: 597906

URL: http://svn.apache.org/viewvc?rev=597906&view=rev
Log:
Impose some structure on the use of the QName and refName attributes of XmlSchemaElements.
Fix case in JAXB where they were both set (bad) inconsistently (worse).

Added:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaInvalidOperation.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
Modified:
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/Messages.properties
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java

Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaInvalidOperation.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaInvalidOperation.java?rev=597906&view=auto
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaInvalidOperation.java
(added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaInvalidOperation.java
Sat Nov 24 11:37:49 2007
@@ -0,0 +1,31 @@
+/**
+ * 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.common.xmlschema;
+
+/**
+ * Very simple exception class used to detect internal errors.
+ */
+public class XmlSchemaInvalidOperation extends RuntimeException {
+
+    public XmlSchemaInvalidOperation(String message) {
+        super(message);
+    }
+
+}

Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java?rev=597906&view=auto
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
(added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
Sat Nov 24 11:37:49 2007
@@ -0,0 +1,102 @@
+/**
+ * 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.common.xmlschema;
+
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+
+/**
+ * Some functions that avoid problems with Commons XML Schema.  
+ */
+public final class XmlSchemaTools {
+    private static final Logger LOG = LogUtils.getL7dLogger(XmlSchemaTools.class);
+    
+    private XmlSchemaTools() {
+    }
+    
+    private static void setNameFromQName(XmlSchemaElement element, QName name) {
+        if (name == null) {
+            element.setName(null);
+        } else {
+            element.setName(name.getLocalPart());
+        }
+    }
+    
+    /**
+     * Wrapper around XmlSchemaElement.setQName that checks for inconsistency with 
+     * refName.
+     * @param element
+     * @param name
+     */
+    public static void setElementQName(XmlSchemaElement element, QName name) {
+        if (name != null && element.getRefName() != null && !element.getRefName().equals(name))
{
+            LOG.severe("Attempt to set the QName of an element with a reference name");
+            throw new 
+                XmlSchemaInvalidOperation("Attempt to set the QName of an element "
+                                          + "with a reference name.");
+        }
+        element.setQName(name);
+        // in CXF, we want them to be consistent.
+        setNameFromQName(element, name);
+    }
+
+    /**
+     * Wrapper around XmlSchemaElement.setName that checks for inconsistency with 
+     * refName.
+     * @param element
+     * @param name
+     */
+    public static void setElementName(XmlSchemaElement element, String name) {
+        if (name != null 
+            && element.getRefName() != null 
+            && !element.getRefName().getLocalPart().equals(name)
+            && (element.getQName() == null || element.getQName().getLocalPart().equals(name)))
{
+            LOG.severe("Attempt to set the name of an element with a reference name.");
+            throw new 
+                XmlSchemaInvalidOperation("Attempt to set the name of an element "
+                                          + "with a reference name.");
+        }
+        element.setName(name);
+    }
+
+    /**
+     * Wrapper around XmlSchemaElement.setRefName that checks for inconsistency with 
+     * name and QName.
+     * @param element
+     * @param name
+     */
+    public static void setElementRefName(XmlSchemaElement element, QName name) {
+        if (name != null
+            && ((element.getQName() != null && !element.getQName().equals(name))

+            || (element.getName() != null && !element.getName().equals(name.getLocalPart()))))
{
+            LOG.severe("Attempt to set the refName of an element with a name or QName");
+            throw new 
+                XmlSchemaInvalidOperation("Attempt to set the refName of an element "
+                                          + "with a name or QName.");
+        }
+        element.setRefName(name);
+        // cxf conventionally keeps something in the name slot.
+        setNameFromQName(element, name);
+    }
+}

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=597906&r1=597905&r2=597906&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Sat Nov 24 11:37:49 2007
@@ -34,6 +34,7 @@
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.cxf.common.xmlschema.XmlSchemaTools;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.service.ServiceModelVisitor;
 import org.apache.cxf.service.model.FaultInfo;
@@ -190,8 +191,7 @@
 
     private XmlSchemaElement createXsElement(MessagePartInfo part, QName typeName, SchemaInfo
schemaInfo) {
         XmlSchemaElement el = new XmlSchemaElement();
-        el.setQName(part.getElementQName());
-        el.setName(part.getElementQName().getLocalPart());
+        XmlSchemaTools.setElementQName(el, part.getElementQName());
         el.setNillable(true);
         el.setSchemaTypeName(typeName);
         part.setXmlSchema(el);
@@ -214,8 +214,7 @@
                 && !isExistSchemaElement(schemaInfo.getSchema(), part.getElementQName()))
{
                     
                 XmlSchemaElement el = new XmlSchemaElement();
-                el.setQName(part.getElementQName());
-                el.setName(part.getElementQName().getLocalPart());
+                XmlSchemaTools.setElementQName(el, part.getElementQName());
                 el.setNillable(true);
                 
                 schemaInfo.getSchema().getItems().add(el);
@@ -248,8 +247,7 @@
             }
                 
             XmlSchemaElement el = new XmlSchemaElement();
-            el.setQName(part.getElementQName());
-            el.setName(part.getElementQName().getLocalPart());
+            XmlSchemaTools.setElementQName(el, part.getElementQName());
             
             schemaInfo.getSchema().getItems().add(el);
             schemaInfo.getSchema().getElements().add(el.getQName(), el);
@@ -278,8 +276,8 @@
                             String ns = schemaInfo.getSchema().getElementFormDefault()
                                 .getValue().equals(XmlSchemaForm.UNQUALIFIED) 
                                 ? "" : part.getElementQName().getLocalPart();
-                            el.setQName(new QName(ns, m.getName().substring(beginIdx)));
-                            
+                            XmlSchemaTools.setElementQName(el, 
+                                                           new QName(ns, m.getName().substring(beginIdx)));
                             Iterator<QName> itr = beanInfo.getTypeNames().iterator();
                             if (!itr.hasNext()) {
                                 return;
@@ -334,8 +332,7 @@
         }
         
         XmlSchemaElement el = new XmlSchemaElement();
-        el.setQName(part.getElementQName());
-        el.setName(part.getElementQName().getLocalPart());
+        XmlSchemaTools.setElementQName(el, part.getElementQName());
         schema.getItems().add(el);
         schema.getElements().add(el.getQName(), el);
         part.setXmlSchema(el);
@@ -382,7 +379,7 @@
     public void addElement(XmlSchemaSequence seq, JaxBeanInfo<?> beanInfo, QName name)
{    
         XmlSchemaElement el = new XmlSchemaElement();
         el.setName(name.getLocalPart());
-        el.setQName(name);
+        XmlSchemaTools.setElementQName(el, name);
 
         el.setMinOccurs(1);
         el.setMaxOccurs(1);
@@ -392,7 +389,8 @@
             QName ename = new QName(beanInfo.getElementNamespaceURI(null), 
                                    beanInfo.getElementLocalName(null));
             XmlSchemaElement el2 = schemas.getElementByQName(ename);
-            el.setRefName(el2.getRefName());
+            XmlSchemaTools.setElementQName(el, null);
+            XmlSchemaTools.setElementRefName(el, el2.getRefName());
         } else {
             Iterator<QName> itr = beanInfo.getTypeNames().iterator();
             if (!itr.hasNext()) {

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=597906&r1=597905&r2=597906&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Sat Nov 24 11:37:49 2007
@@ -52,6 +52,7 @@
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.cxf.common.xmlschema.XmlSchemaTools;
 import org.apache.cxf.databinding.source.mime.MimeAttribute;
 import org.apache.cxf.databinding.source.mime.MimeSerializer;
 import org.apache.cxf.endpoint.Endpoint;
@@ -655,8 +656,7 @@
         XmlSchema schema = si.getSchema();
 
         XmlSchemaElement el = new XmlSchemaElement();
-        el.setQName(mpi.getElementQName());
-        el.setName(mpi.getElementQName().getLocalPart());
+        XmlSchemaTools.setElementQName(el, mpi.getElementQName());
         if (!isExistSchemaElement(schema, mpi.getElementQName())) {
             SchemaCollection.addGlobalElementToSchema(schema, el);
         }
@@ -760,8 +760,7 @@
             }
 
             XmlSchemaElement el = new XmlSchemaElement();
-            el.setQName(qname);
-            el.setName(qname.getLocalPart());
+            XmlSchemaTools.setElementQName(el, qname);
             el.setMinOccurs(1);
             el.setMaxOccurs(0);
             el.setNillable(true);
@@ -852,8 +851,7 @@
                                             QName wrapperName) {
         
         XmlSchemaElement el = new XmlSchemaElement();
-        el.setQName(wrapperName);
-        el.setName(wrapperName.getLocalPart());
+        XmlSchemaTools.setElementQName(el, wrapperName);
         SchemaCollection.addGlobalElementToSchema(schema, el);
 
         wrappedMessage.getMessageParts().get(0).setXmlSchema(el);
@@ -873,11 +871,11 @@
 
         for (MessagePartInfo mpi : unwrappedMessage.getMessageParts()) {
             el = new XmlSchemaElement();
-            el.setName(mpi.getName().getLocalPart());
-            el.setQName(mpi.getName());
+            XmlSchemaTools.setElementQName(el, mpi.getName());
             if (mpi.isElement()) {
                 addImport(schema, mpi.getElementQName().getNamespaceURI());
-                el.setRefName(mpi.getElementQName());
+                XmlSchemaTools.setElementQName(el, null);
+                XmlSchemaTools.setElementRefName(el, mpi.getElementQName());
             } else {
                 if (mpi.getTypeQName() != null && !existXmlListAnno(mpi)) {
                     el.setSchemaTypeName(mpi.getTypeQName());
@@ -946,8 +944,7 @@
             if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
                 QName qn = (QName)mpi.getProperty(ELEMENT_NAME);
 
-                el.setName(qn.getLocalPart());
-                el.setQName(qn);
+                XmlSchemaTools.setElementQName(el, qn);
 
                 SchemaInfo headerSchemaInfo = getOrCreateSchema(serviceInfo, 
                                                                 qn.getNamespaceURI(),

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=597906&r1=597905&r2=597906&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
Sat Nov 24 11:37:49 2007
@@ -36,7 +36,8 @@
 import org.apache.ws.commons.schema.XmlSchemaType;
 
 /**
- * 
+ * There are a number of pitfalls in Commons Xml Schema. This class contains some utilities
+ * that avoid some of the problems and centralizes some repetitive tasks. 
  */
 public final class XmlSchemaUtils {
     public static final XmlSchemaForm QUALIFIED = new XmlSchemaForm(XmlSchemaForm.QUALIFIED);
@@ -94,7 +95,8 @@
     }
     
     /**
-     * This copes with an observed phenomenon in the schema built by the ReflectionServiceFactoryBean.
It 
+     * This copes with an observed phenomenon in the schema built by the 
+     * ReflectionServiceFactoryBean. It 
      * is creating element such that: (a) the type is not set. (b) the refName is set. 
      * (c) the namespaceURI in the refName is set empty. This apparently indicates 
      * 'same Schema' to everyone else, so thus function implements

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/Messages.properties?rev=597906&r1=597905&r2=597906&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/Messages.properties
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/Messages.properties
Sat Nov 24 11:37:49 2007
@@ -21,4 +21,5 @@
 NO_USABLE_BINDING=Service {0} has no SOAP or XML binding.
 MULTIPLE_OUTPUTS=Operation {0} has more than one output part.
 RPC= Service {0} calls for unsupported RPC binding style.
-XML_BINDING= Service {0} calls for unsupported XML binding.
\ No newline at end of file
+XML_BINDING= Service {0} calls for unsupported XML binding.
+MISSING_PART_ELEMENT= Part {0} lacks an element in the XML Schema.
\ No newline at end of file

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=597906&r1=597905&r2=597906&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
Sat Nov 24 11:37:49 2007
@@ -193,7 +193,7 @@
         if (inputMessage != null) {
             parts = inputMessage.getMessageParts();
             if (isWrapped) {
-                wrapperClassName = setupWrapperElement(op, inputParameterNames, parts);
+                wrapperClassName = setupWrapperElement(inputParameterNames, parts);
             }
 
             buildParameterList(inputParameterNames, parameterList);
@@ -428,7 +428,7 @@
 
     private void getElementsForParts(List<ElementAndNames> elements, List<MessagePartInfo>
parts) {
         for (MessagePartInfo mpi : parts) {
-            XmlSchemaElement element;
+            XmlSchemaElement element = null;
             if (mpi.isElement()) {
                 element = (XmlSchemaElement)mpi.getXmlSchema();
                 if (element == null) {
@@ -442,15 +442,8 @@
                 // other work to do.
                 LOG.severe("Missing element " + mpi.getElementQName().toString() + " in "
                            + mpi.getName().toString());
-                // there is still an element in there, but it's not a very
-                // interesting element
-                element = new XmlSchemaElement();
-                XmlSchemaElement dummyElement = (XmlSchemaElement)mpi.getXmlSchema();
-                element.setMaxOccurs(dummyElement.getMaxOccurs());
-                element.setMinOccurs(dummyElement.getMinOccurs());
-                element.setNillable(dummyElement.isNillable());
-                element.setSchemaType(xmlSchemaCollection.getTypeByQName(mpi.getTypeQName()));
-                element.setQName(mpi.getName());
+                unsupportedConstruct("MISSING_PART_ELEMENT", mpi.getName().toString());
+               
             }
             assert element != null;
             assert element.getQName() != null;
@@ -461,8 +454,7 @@
         }
     }
 
-    private String setupWrapperElement(OperationInfo op, List<String> inputParameterNames,
-                                       List<MessagePartInfo> parts) {
+    private String setupWrapperElement(List<String> inputParameterNames, List<MessagePartInfo>
parts) {
         String wrapperClassName;
         // expect one input part.
         assert parts.size() == 1;
@@ -471,7 +463,8 @@
         assert wrapperPart.isElement();
         wrapperElement = (XmlSchemaElement)wrapperPart.getXmlSchema();
         XmlSchemaComplexType wrapperType = (XmlSchemaComplexType)XmlSchemaUtils
-            .getElementType(xmlSchemaCollection, op.getName().getNamespaceURI(), wrapperElement,
null);
+            .getElementType(xmlSchemaCollection, 
+                            currentOperation.getName().getNamespaceURI(), wrapperElement,
null);
         wrapperClassName = nameManager.getJavascriptName(wrapperType);
         XmlSchemaSequence wrapperTypeSequence = XmlSchemaUtils.getSequence(wrapperType);
         for (int i = 0; i < wrapperTypeSequence.getItems().getCount(); i++) {
@@ -482,7 +475,11 @@
             }
 
             XmlSchemaElement elChild = (XmlSchemaElement)thing;
-            inputParameterNames.add(elChild.getName());
+            if (elChild.getRefName() != null) {
+                inputParameterNames.add(elChild.getRefName().getLocalPart());
+            } else {
+                inputParameterNames.add(elChild.getQName().getLocalPart());
+            }
         }
         return wrapperClassName;
     }



Mime
View raw message