You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2007/11/13 13:12:09 UTC

svn commit: r594504 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/xmlschema/ rt/core/src/main/java/org/apache/cxf/service/ rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/

Author: bimargulies
Date: Tue Nov 13 04:12:06 2007
New Revision: 594504

URL: http://svn.apache.org/viewvc?rev=594504&view=rev
Log:

Fix some cases in RSFB where it added global XmlSchema items to the
schema collection's 'table of all items' but not to the specific lists
of elements or types. Add utility functions to make this harder to
mess up. PMD comes when I can think it through. Add a visitor to
validate all the cross-references in the service model and the end of
the construction process. This overlapa a dkulp thing that I noticed
belatedly, we'll have to sort out whose to keep. This one logs all its
complaints, of which it sadly has a number.


Added:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/InvalidXmlSchemaReferenceException.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/ServiceModelSchemaValidator.java
Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java

Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/InvalidXmlSchemaReferenceException.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/InvalidXmlSchemaReferenceException.java?rev=594504&view=auto
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/InvalidXmlSchemaReferenceException.java (added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/InvalidXmlSchemaReferenceException.java Tue Nov 13 04:12:06 2007
@@ -0,0 +1,54 @@
+/**
+ * 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;
+
+/**
+ * Exception thrown when we detect an attempt to set an impossible XML Schema reference. 
+ */
+public class InvalidXmlSchemaReferenceException extends RuntimeException {
+
+    /**
+     * 
+     */
+    public InvalidXmlSchemaReferenceException() {
+    }
+
+    /**
+     * @param message
+     */
+    public InvalidXmlSchemaReferenceException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param cause
+     */
+    public InvalidXmlSchemaReferenceException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public InvalidXmlSchemaReferenceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java?rev=594504&r1=594503&r2=594504&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java Tue Nov 13 04:12:06 2007
@@ -157,4 +157,47 @@
         StringReader reader = new StringReader(tinyXmlSchemaDocument.toString());
         return schemaCollection.read(reader, new ValidationEventHandler() { });
     }
+
+    /**
+     * Validate that a qualified name points to some namespace in the schema.
+     * @param qname
+     */
+    public void validateQNameNamespace(QName qname) {
+        // astonishingly, xmlSchemaCollection has no accessor by target URL.
+        for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
+            if (schema.getTargetNamespace().equals(qname.getNamespaceURI())) {
+                return;
+            }
+        }
+        throw new InvalidXmlSchemaReferenceException(qname + " refers to unknown namespace.");
+    }
+
+    public void validateElementName(QName referrer, QName elementQName) {
+        XmlSchemaElement element = schemaCollection.getElementByQName(elementQName);
+        if (element == null) {
+            throw new InvalidXmlSchemaReferenceException(referrer 
+                                                         + " references "
+                                                         + elementQName);
+        }
+    }
+
+    public void validateTypeName(QName referrer, QName typeQName) {
+        XmlSchemaType type = schemaCollection.getTypeByQName(typeQName);
+        if (type == null) {
+            throw new InvalidXmlSchemaReferenceException(referrer 
+                                                         + " references "
+                                                         + typeQName);
+        }
+    }
+    
+    public static void addGlobalElementToSchema(XmlSchema schema, XmlSchemaElement element) {
+        schema.getItems().add(element);
+        // believe it or not, it is up to us to do both of these adds!
+        schema.getElements().add(element.getQName(), element);
+    }
+    
+    public static void addGlobalTypeToSchema(XmlSchema schema, XmlSchemaType type) {
+        schema.getItems().add(type);
+        schema.addType(type);
+    }
 }

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/ServiceModelSchemaValidator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/ServiceModelSchemaValidator.java?rev=594504&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/ServiceModelSchemaValidator.java (added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/ServiceModelSchemaValidator.java Tue Nov 13 04:12:06 2007
@@ -0,0 +1,137 @@
+/**
+ * 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.service;
+
+import org.apache.cxf.common.xmlschema.InvalidXmlSchemaReferenceException;
+import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.cxf.service.model.FaultInfo;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.service.model.UnwrappedOperationInfo;
+
+/**
+ * 
+ */
+public class ServiceModelSchemaValidator extends ServiceModelVisitor {
+    
+    private SchemaCollection schemaCollection;
+    private StringBuilder complaints;
+
+    public ServiceModelSchemaValidator(ServiceInfo serviceInfo) {
+        super(serviceInfo);
+        schemaCollection = serviceInfo.getXmlSchemaCollection();
+        complaints = new StringBuilder();
+    }
+    
+    public String getComplaints() {
+        return complaints.toString();
+    }
+
+    @Override
+    public void begin(FaultInfo fault) {
+        try {
+            schemaCollection.validateQNameNamespace(fault.getFaultName());
+            schemaCollection.validateQNameNamespace(fault.getName());
+        } catch (InvalidXmlSchemaReferenceException ixsre) {
+            complaints.append(fault.getName() + " fault name " + ixsre.getMessage() + "\n");
+        }
+    }
+
+    @Override
+    public void begin(InterfaceInfo intf) {
+        try {
+            schemaCollection.validateQNameNamespace(intf.getName());
+        } catch (InvalidXmlSchemaReferenceException ixsre) {
+            complaints.append(intf.getName() + " interface name " + ixsre.getMessage() + "\n");
+        }
+    }
+
+    @Override
+    public void begin(MessageInfo msg) {
+        try {
+            schemaCollection.validateQNameNamespace(msg.getName());
+        } catch (InvalidXmlSchemaReferenceException ixsre) {
+            complaints.append(msg.getName() + " message name " + ixsre.getMessage() + "\n");
+        }
+    }
+
+    @Override
+    public void begin(MessagePartInfo part) {
+        try {
+            schemaCollection.validateQNameNamespace(part.getConcreteName());
+        } catch (InvalidXmlSchemaReferenceException ixsre) {
+            complaints.append(part.getName() + " part concrete name " + ixsre.getMessage() + "\n");
+        }
+
+        try {
+            schemaCollection.validateQNameNamespace(part.getName());
+        } catch (InvalidXmlSchemaReferenceException ixsre) {
+            complaints.append(part.getName() + " part name " + ixsre.getMessage() + "\n");
+        }
+
+        if (part.isElement()) {
+            try {
+                schemaCollection.validateElementName(part.getName(), part.getElementQName());
+            } catch (InvalidXmlSchemaReferenceException ixsre) {
+                complaints.append(part.getName() + " element name " + ixsre.getMessage() + "\n");
+            }
+        } else {
+            if (part.getTypeQName() == null) {
+                complaints.append(part.getName() + " part type QName null.\n");
+            } else {
+                try {
+                    schemaCollection.validateTypeName(part.getName(), part.getTypeQName());
+                } catch (InvalidXmlSchemaReferenceException ixsre) {
+                    complaints.append(part.getName() + " type name " + ixsre.getMessage() + "\n");
+                }
+            }
+        }
+    }
+
+    @Override
+    public void begin(OperationInfo op) {
+        try {
+            schemaCollection.validateQNameNamespace(op.getName());
+        } catch (InvalidXmlSchemaReferenceException ixsre) {
+            complaints.append(op.getName() + " operation " + ixsre.getMessage() + "\n");
+        }
+    }
+
+    @Override
+    public void begin(ServiceInfo service) {
+        try {
+            schemaCollection.validateQNameNamespace(service.getName());
+        } catch (InvalidXmlSchemaReferenceException ixsre) {
+            complaints.append(service.getName() + " service " + ixsre.getMessage() + "\n");
+        }
+    }
+
+    @Override
+    public void begin(UnwrappedOperationInfo op) {
+        try {
+            schemaCollection.validateQNameNamespace(op.getName());
+        } catch (InvalidXmlSchemaReferenceException ixsre) {
+            complaints.append(op.getName() + " unwrapped operation " + ixsre.getMessage() + "\n");
+        }
+    }
+}

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=594504&r1=594503&r2=594504&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 Tue Nov 13 04:12:06 2007
@@ -64,6 +64,7 @@
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.ServiceImpl;
+import org.apache.cxf.service.ServiceModelSchemaValidator;
 import org.apache.cxf.service.invoker.ApplicationScopePolicy;
 import org.apache.cxf.service.invoker.FactoryInvoker;
 import org.apache.cxf.service.invoker.Invoker;
@@ -333,6 +334,12 @@
                 }
             }
         }
+        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
+        validator.walk();
+        String validationComplaints = validator.getComplaints();
+        if (!"".equals(validationComplaints)) {
+            LOG.info(validationComplaints);
+        }
     }
 
 
@@ -645,7 +652,7 @@
         el.setQName(mpi.getElementQName());
         el.setName(mpi.getElementQName().getLocalPart());
         if (!isExistSchemaElement(schema, mpi.getElementQName())) {
-            schema.getItems().add(el);
+            SchemaCollection.addGlobalElementToSchema(schema, el);
         }
         el.setMinOccurs(1);
         el.setMaxOccurs(0);
@@ -754,8 +761,7 @@
             el.setNillable(true);
             
             if (!isExistSchemaElement(schema, qname)) {
-                schema.getItems().add(el);
-                schema.getElements().add(qname, el);
+                SchemaCollection.addGlobalElementToSchema(schema, el);
             } else {
                 el = getExistingSchemaElement(schema, qname);    
             }
@@ -842,7 +848,7 @@
         XmlSchemaElement el = new XmlSchemaElement();
         el.setQName(wrapperName);
         el.setName(wrapperName.getLocalPart());
-        schema.getItems().add(el);
+        SchemaCollection.addGlobalElementToSchema(schema, el);
 
         wrappedMessage.getMessageParts().get(0).setXmlSchema(el);
 
@@ -850,9 +856,8 @@
         
         if (!isAnonymousWrapperTypes()) {
             ct.setName(wrapperName.getLocalPart());
-            el.setSchemaTypeName(wrapperName);            
-            schema.addType(ct);
-            schema.getItems().add(ct);
+            el.setSchemaTypeName(wrapperName);
+            SchemaCollection.addGlobalTypeToSchema(schema, ct);
         }
         el.setSchemaType(ct);
 
@@ -1123,6 +1128,7 @@
         }
         if (part.getElementQName() == null) {
             part.setElementQName(inMsg.getName());
+//Benson            checkForElement(op.getInterface().getService(), part);
         } else if (!part.getElementQName().equals(op.getInput().getName())) {
             op.getInput().setName(part.getElementQName());
         }