Return-Path: Delivered-To: apmail-incubator-cxf-commits-archive@locus.apache.org Received: (qmail 28177 invoked from network); 19 Mar 2008 16:32:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Mar 2008 16:32:45 -0000 Received: (qmail 73292 invoked by uid 500); 19 Mar 2008 16:32:43 -0000 Delivered-To: apmail-incubator-cxf-commits-archive@incubator.apache.org Received: (qmail 73248 invoked by uid 500); 19 Mar 2008 16:32:43 -0000 Mailing-List: contact cxf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-commits@incubator.apache.org Received: (qmail 73222 invoked by uid 99); 19 Mar 2008 16:32:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Mar 2008 09:32:43 -0700 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.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Mar 2008 16:32:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 46A5E1A9832; Wed, 19 Mar 2008 09:32:18 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r638927 - in /incubator/cxf/branches/2.0.x-fixes: ./ api/src/main/java/org/apache/cxf/service/model/ api/src/main/java/org/apache/cxf/wsdl/ common/common/src/main/java/org/apache/cxf/common/util/ common/common/src/main/java/org/apache/cxf/c... Date: Wed, 19 Mar 2008 16:32:07 -0000 To: cxf-commits@incubator.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080319163218.46A5E1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Wed Mar 19 09:31:56 2008 New Revision: 638927 URL: http://svn.apache.org/viewvc?rev=638927&view=rev Log: Merged revisions 638828 via svnmerge from https://svn.apache.org/repos/asf/incubator/cxf/trunk ........ r638828 | bimargulies | 2008-03-19 09:35:16 -0400 (Wed, 19 Mar 2008) | 3 lines Speed up repeated endpoint creation by a very large amount by caching the schemas, both in DOM and XmlSchema forms. ........ Added: incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/service/model/ServiceSchemaInfo.java - copied unchanged from r638828, incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/ServiceSchemaInfo.java Modified: incubator/cxf/branches/2.0.x-fixes/ (props changed) incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/service/model/ServiceInfo.java incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLManager.java incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java incubator/cxf/branches/2.0.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java Propchange: incubator/cxf/branches/2.0.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/service/model/ServiceInfo.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/service/model/ServiceInfo.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/service/model/ServiceInfo.java (original) +++ incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/service/model/ServiceInfo.java Wed Mar 19 09:31:56 2008 @@ -138,11 +138,16 @@ return null; } - public Collection getSchemas() { - return Collections.unmodifiableCollection(schemas); + public List getSchemas() { + return Collections.unmodifiableList(schemas); } public SchemaCollection getXmlSchemaCollection() { return xmlSchemaCollection; + } + + public void setServiceSchemaInfo(ServiceSchemaInfo serviceSchemaInfo) { + xmlSchemaCollection = serviceSchemaInfo.getSchemaCollection(); + schemas = serviceSchemaInfo.getSchemaInfoList(); } } Modified: incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLManager.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLManager.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLManager.java (original) +++ incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLManager.java Wed Mar 19 09:31:56 2008 @@ -26,8 +26,9 @@ import javax.wsdl.WSDLException; import javax.wsdl.extensions.ExtensionRegistry; import javax.wsdl.factory.WSDLFactory; - import org.w3c.dom.Element; +import org.apache.cxf.service.model.ServiceSchemaInfo; + /** * WSDLManager @@ -41,7 +42,7 @@ * this to register their own extensors. * @return the ExtensionRegistry */ - ExtensionRegistry getExtenstionRegistry(); + ExtensionRegistry getExtensionRegistry(); /** * Returns the WSDLFactory that is used to read/write WSDL definitions @@ -90,5 +91,19 @@ * @return all Definitions in the map */ Map getDefinitions(); + + /** + * This object will cache the schemas for a WSDL. + * @param wsdl + * @return + */ + ServiceSchemaInfo getSchemasForDefinition(Definition wsdl); + + /** + * Register a collection of schemas for a WSDL. + * @param wsdl + * @param schemas + */ + void putSchemasForDefinition(Definition wsdl, ServiceSchemaInfo schemas); } Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java (original) +++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java Wed Mar 19 09:31:56 2008 @@ -25,8 +25,8 @@ /** - * Implements a useful caching map. It weakly references the keys, - * but strongly references the data. It works a log like the WeakHashMap, + * Implements a useful caching map. It weakly references the keys, + * but strongly references the data. It works much like the WeakHashMap, * in that when the keys are garbage collected, the data is removed from * the map. * Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java (original) +++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java Wed Mar 19 09:31:56 2008 @@ -1,273 +1,280 @@ -/** - * 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.io.Reader; -import java.io.StringReader; -import java.lang.reflect.Method; - -import javax.xml.namespace.QName; -import javax.xml.transform.Source; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; - -import org.apache.ws.commons.schema.ValidationEventHandler; -import org.apache.ws.commons.schema.XmlSchema; -import org.apache.ws.commons.schema.XmlSchemaCollection; -import org.apache.ws.commons.schema.XmlSchemaElement; -import org.apache.ws.commons.schema.XmlSchemaType; -import org.apache.ws.commons.schema.extensions.ExtensionRegistry; -import org.apache.ws.commons.schema.resolver.URIResolver; -import org.apache.ws.commons.schema.utils.NamespaceMap; -import org.apache.ws.commons.schema.utils.NamespacePrefixList; -import org.apache.ws.commons.schema.utils.TargetNamespaceValidator; - -/** - * Wrapper class for XmlSchemaCollection that deals with various quirks and bugs. - * One bug is WSCOMMONS-272. - */ -public class SchemaCollection { - private static final Method GET_ELEMENT_BY_NAME_METHOD; - static { - Method m = null; - try { - m = XmlSchema.class.getMethod("getElementByName", - new Class[] {String.class}); - } catch (Exception ex) { - //ignore - } - GET_ELEMENT_BY_NAME_METHOD = m; - } - - private XmlSchemaCollection schemaCollection; - - public SchemaCollection() { - this(new XmlSchemaCollection()); - } - - public SchemaCollection(XmlSchemaCollection col) { - schemaCollection = col; - col.getExtReg().setDefaultExtensionDeserializer(new FixedExtensionDeserializer()); - if (schemaCollection.getNamespaceContext() == null) { - // an empty prefix map avoids extra checks for null. - schemaCollection.setNamespaceContext(new NamespaceMap()); - } - } - - public boolean equals(Object obj) { - return schemaCollection.equals(obj); - } - - public XmlSchemaElement getElementByQName(QName qname) { - return schemaCollection.getElementByQName(qname); - } - - public ExtensionRegistry getExtReg() { - return schemaCollection.getExtReg(); - } - - public NamespacePrefixList getNamespaceContext() { - return schemaCollection.getNamespaceContext(); - } - - public XmlSchemaType getTypeByQName(QName schemaTypeName) { - return schemaCollection.getTypeByQName(schemaTypeName); - } - - public XmlSchema[] getXmlSchema(String systemId) { - return schemaCollection.getXmlSchema(systemId); - } - - public XmlSchema[] getXmlSchemas() { - return schemaCollection.getXmlSchemas(); - } - - public int hashCode() { - return schemaCollection.hashCode(); - } - - public void init() { - schemaCollection.init(); - } - - public XmlSchema read(Document doc, String uri, ValidationEventHandler veh, - TargetNamespaceValidator validator) { - return schemaCollection.read(doc, uri, veh, validator); - } - - public XmlSchema read(Document doc, String uri, ValidationEventHandler veh) { - return schemaCollection.read(doc, uri, veh); - } - - public XmlSchema read(Document doc, ValidationEventHandler veh) { - return schemaCollection.read(doc, veh); - } - - public XmlSchema read(Element elem, String uri) { - return schemaCollection.read(elem, uri); - } - - public XmlSchema read(Element elem) { - return schemaCollection.read(elem); - } - - public XmlSchema read(InputSource inputSource, ValidationEventHandler veh) { - return schemaCollection.read(inputSource, veh); - } - - public XmlSchema read(Reader r, ValidationEventHandler veh) { - return schemaCollection.read(r, veh); - } - - public XmlSchema read(Source source, ValidationEventHandler veh) { - return schemaCollection.read(source, veh); - } - - public void setBaseUri(String baseUri) { - schemaCollection.setBaseUri(baseUri); - } - - public void setExtReg(ExtensionRegistry extReg) { - schemaCollection.setExtReg(extReg); - } - - public void setNamespaceContext(NamespacePrefixList namespaceContext) { - schemaCollection.setNamespaceContext(namespaceContext); - } - - public void setSchemaResolver(URIResolver schemaResolver) { - schemaCollection.setSchemaResolver(schemaResolver); - } - - /** - * This function is not part of the XmlSchema API. Who knows why? - * @param namespaceURI targetNamespace - * @return schema, or null. - */ - public XmlSchema getSchemaByTargetNamespace(String namespaceURI) { - for (XmlSchema schema : schemaCollection.getXmlSchemas()) { - if (schema.getTargetNamespace().equals(namespaceURI)) { - return schema; - } - } - return null; - } - - public XmlSchema getSchemaForElement(QName name) { - for (XmlSchema schema : schemaCollection.getXmlSchemas()) { - if (name.getNamespaceURI().equals(schema.getTargetNamespace())) { - - //for XmlSchema 1.4, we should use: - //schema.getElementByName(name.getLocalPart()) != null - //but that doesn't exist in 1.3 so for now, use reflection - try { - if (GET_ELEMENT_BY_NAME_METHOD != null) { - if (GET_ELEMENT_BY_NAME_METHOD.invoke(schema, - new Object[] {name.getLocalPart()}) != null) { - return schema; - } - } else if (schema.getElementByName(name) != null) { - return schema; - } - - } catch (java.lang.reflect.InvocationTargetException ex) { - //ignore - } catch (IllegalAccessException ex) { - //ignore - } - } - } - return null; - } - - /** - * This is a really ugly trick to get around a bug or oversight in XmlSchema, which is that - * there is no way to programmatically construct an XmlSchema instance that ends up cataloged - * in a collection. If there is a fix to WSCOMMONS-272, this can go away. - * @param namespaceURI TNS for new schema. - * @return new schema - */ - - public XmlSchema newXmlSchemaInCollection(String namespaceURI) { - StringBuffer tinyXmlSchemaDocument = new StringBuffer(); - tinyXmlSchemaDocument.append(""); - 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. - if ("".equals(qname.getNamespaceURI())) { - return; // references to the 'unqualified' namespace are OK even if there is no schema for it. - } - 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 element " - + elementQName); - } - } - - public void validateTypeName(QName referrer, QName typeQName) { - XmlSchemaType type = schemaCollection.getTypeByQName(typeQName); - if (type == null) { - throw new InvalidXmlSchemaReferenceException(referrer - + " references type " - + typeQName); - } - } - - public void addGlobalElementToSchema(XmlSchemaElement element) { - XmlSchema schema = getSchemaByTargetNamespace(element.getQName().getNamespaceURI()); - if (schema == null) { - schema = newXmlSchemaInCollection(element.getQName().getNamespaceURI()); - } - 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 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); - } +/** + * 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.io.Reader; +import java.io.StringReader; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; +import javax.xml.transform.Source; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; + +import org.apache.ws.commons.schema.ValidationEventHandler; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaType; +import org.apache.ws.commons.schema.extensions.ExtensionRegistry; +import org.apache.ws.commons.schema.resolver.URIResolver; +import org.apache.ws.commons.schema.utils.NamespaceMap; +import org.apache.ws.commons.schema.utils.NamespacePrefixList; +import org.apache.ws.commons.schema.utils.TargetNamespaceValidator; + +/** + * Wrapper class for XmlSchemaCollection that deals with various quirks and bugs. + * One bug is WSCOMMONS-272. + */ +public class SchemaCollection { + private static final Method GET_ELEMENT_BY_NAME_METHOD; + static { + Method m = null; + try { + m = XmlSchema.class.getMethod("getElementByName", + new Class[] {String.class}); + } catch (Exception ex) { + //ignore + } + GET_ELEMENT_BY_NAME_METHOD = m; + } + + private XmlSchemaCollection schemaCollection; + + public SchemaCollection() { + this(new XmlSchemaCollection()); + } + + public SchemaCollection(XmlSchemaCollection col) { + schemaCollection = col; + col.getExtReg().setDefaultExtensionDeserializer(new FixedExtensionDeserializer()); + if (schemaCollection.getNamespaceContext() == null) { + // an empty prefix map avoids extra checks for null. + schemaCollection.setNamespaceContext(new NamespaceMap()); + } + } + + public boolean equals(Object obj) { + return schemaCollection.equals(obj); + } + + public XmlSchemaElement getElementByQName(QName qname) { + return schemaCollection.getElementByQName(qname); + } + + public ExtensionRegistry getExtReg() { + return schemaCollection.getExtReg(); + } + + public NamespacePrefixList getNamespaceContext() { + return schemaCollection.getNamespaceContext(); + } + + public XmlSchemaType getTypeByQName(QName schemaTypeName) { + return schemaCollection.getTypeByQName(schemaTypeName); + } + + public XmlSchema[] getXmlSchema(String systemId) { + return schemaCollection.getXmlSchema(systemId); + } + + public XmlSchema[] getXmlSchemas() { + return schemaCollection.getXmlSchemas(); + } + + public int hashCode() { + return schemaCollection.hashCode(); + } + + public void init() { + schemaCollection.init(); + } + + public XmlSchema read(Document doc, String uri, ValidationEventHandler veh, + TargetNamespaceValidator validator) { + return schemaCollection.read(doc, uri, veh, validator); + } + + public XmlSchema read(Document doc, String uri, ValidationEventHandler veh) { + return schemaCollection.read(doc, uri, veh); + } + + public XmlSchema read(Document doc, ValidationEventHandler veh) { + return schemaCollection.read(doc, veh); + } + + public XmlSchema read(Element elem, String uri) { + return schemaCollection.read(elem, uri); + } + + public XmlSchema read(Element elem) { + return schemaCollection.read(elem); + } + + public XmlSchema read(InputSource inputSource, ValidationEventHandler veh) { + return schemaCollection.read(inputSource, veh); + } + + public XmlSchema read(Reader r, ValidationEventHandler veh) { + return schemaCollection.read(r, veh); + } + + public XmlSchema read(Source source, ValidationEventHandler veh) { + return schemaCollection.read(source, veh); + } + + public void setBaseUri(String baseUri) { + schemaCollection.setBaseUri(baseUri); + } + + public void setExtReg(ExtensionRegistry extReg) { + schemaCollection.setExtReg(extReg); + } + + public void setNamespaceContext(NamespacePrefixList namespaceContext) { + schemaCollection.setNamespaceContext(namespaceContext); + } + + public void setSchemaResolver(URIResolver schemaResolver) { + schemaCollection.setSchemaResolver(schemaResolver); + } + + /** + * This function is not part of the XmlSchema API. Who knows why? + * @param namespaceURI targetNamespace + * @return schema, or null. + */ + public XmlSchema getSchemaByTargetNamespace(String namespaceURI) { + for (XmlSchema schema : schemaCollection.getXmlSchemas()) { + if (schema.getTargetNamespace().equals(namespaceURI)) { + return schema; + } + } + return null; + } + + public XmlSchema getSchemaForElement(QName name) { + for (XmlSchema schema : schemaCollection.getXmlSchemas()) { + if (name.getNamespaceURI().equals(schema.getTargetNamespace())) { + + //for XmlSchema 1.4, we should use: + //schema.getElementByName(name.getLocalPart()) != null + //but that doesn't exist in 1.3 so for now, use reflection + try { + if (GET_ELEMENT_BY_NAME_METHOD != null) { + if (GET_ELEMENT_BY_NAME_METHOD.invoke(schema, + new Object[] {name.getLocalPart()}) != null) { + return schema; + } + } else if (schema.getElementByName(name) != null) { + return schema; + } + + } catch (java.lang.reflect.InvocationTargetException ex) { + //ignore + } catch (IllegalAccessException ex) { + //ignore + } + } + } + return null; + } + + /** + * This is a really ugly trick to get around a bug or oversight in XmlSchema, which is that + * there is no way to programmatically construct an XmlSchema instance that ends up cataloged + * in a collection. If there is a fix to WSCOMMONS-272, this can go away. + * @param namespaceURI TNS for new schema. + * @return new schema + */ + + public XmlSchema newXmlSchemaInCollection(String namespaceURI) { + StringBuffer tinyXmlSchemaDocument = new StringBuffer(); + tinyXmlSchemaDocument.append(""); + 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. + if ("".equals(qname.getNamespaceURI())) { + return; // references to the 'unqualified' namespace are OK even if there is no schema for it. + } + 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 element " + + elementQName); + } + } + + public void validateTypeName(QName referrer, QName typeQName) { + XmlSchemaType type = schemaCollection.getTypeByQName(typeQName); + if (type == null) { + throw new InvalidXmlSchemaReferenceException(referrer + + " references type " + + typeQName); + } + } + + public void addGlobalElementToSchema(XmlSchemaElement element) { + synchronized (this) { + XmlSchema schema = getSchemaByTargetNamespace(element.getQName().getNamespaceURI()); + if (schema == null) { + schema = newXmlSchemaInCollection(element.getQName().getNamespaceURI()); + } + 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 addGlobalElementToSchema(XmlSchema schema, XmlSchemaElement element) { + synchronized (schema) { + 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) { + synchronized (schema) { + schema.getItems().add(type); + schema.addType(type); + } + } } + Modified: incubator/cxf/branches/2.0.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java (original) +++ incubator/cxf/branches/2.0.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java Wed Mar 19 09:31:56 2008 @@ -180,7 +180,7 @@ private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException { boolean isSoap12 = bi.getSoapVersion() instanceof Soap12; ExtensionRegistry extensionRegistry = getBus().getExtension(WSDLManager.class) - .getExtenstionRegistry(); + .getExtensionRegistry(); SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12); soapBinding.setStyle(bi.getStyle()); Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java (original) +++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java Wed Mar 19 09:31:56 2008 @@ -161,7 +161,7 @@ WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class) .getWSDLFactory().newWSDLWriter(); - def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtenstionRegistry()); + def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry()); doc = wsdlWriter.getDocument(def); } else { SchemaReference si = smp.get(xsd); Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java (original) +++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java Wed Mar 19 09:31:56 2008 @@ -201,7 +201,7 @@ private Definition newDefinition(final QName name, String targetNamespace) { Definition d = bus.getExtension(WSDLManager.class).getWSDLFactory().newDefinition(); - d.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtenstionRegistry()); + d.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry()); d.setQName(name); d.setTargetNamespace(targetNamespace); addNamespace(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NU_SCHEMA_XSD, d); Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java (original) +++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java Wed Mar 19 09:31:56 2008 @@ -53,6 +53,7 @@ import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.CacheMap; import org.apache.cxf.common.util.PropertiesLoaderUtils; +import org.apache.cxf.service.model.ServiceSchemaInfo; import org.apache.cxf.wsdl.JAXBExtensionHelper; import org.apache.cxf.wsdl.WSDLConstants; import org.apache.cxf.wsdl.WSDLManager; @@ -71,6 +72,9 @@ final ExtensionRegistry registry; final WSDLFactory factory; final Map definitionsMap; + final Map schemaCacheMap; + private boolean disableSchemaCache; + private Bus bus; public WSDLManagerImpl() throws BusException { @@ -93,6 +97,7 @@ throw new BusException(e); } definitionsMap = new CacheMap(); + schemaCacheMap = new CacheMap(); registerInitialExtensions(); } @@ -127,7 +132,7 @@ * * @see org.apache.cxf.wsdl.WSDLManager#getExtenstionRegistry() */ - public ExtensionRegistry getExtenstionRegistry() { + public ExtensionRegistry getExtensionRegistry() { return registry; } @@ -230,6 +235,37 @@ LOG.log(Level.WARNING, "EXTENSION_ADD_FAILED_MSG", ex); } } + } + + public ServiceSchemaInfo getSchemasForDefinition(Definition wsdl) { + if (disableSchemaCache) { + return null; + } + synchronized (schemaCacheMap) { + return schemaCacheMap.get(wsdl); + } + + } + + public void putSchemasForDefinition(Definition wsdl, ServiceSchemaInfo schemas) { + if (!disableSchemaCache) { + synchronized (schemaCacheMap) { + schemaCacheMap.put(wsdl, schemas); + } + } + + } + + public boolean isDisableSchemaCache() { + return disableSchemaCache; + } + + /** + * There's a test that 'fails' by succeeding if the cache is operational. + * @param disableSchemaCache + */ + public void setDisableSchemaCache(boolean disableSchemaCache) { + this.disableSchemaCache = disableSchemaCache; } } Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java (original) +++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java Wed Mar 19 09:31:56 2008 @@ -70,9 +70,11 @@ 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.ServiceSchemaInfo; import org.apache.cxf.service.model.UnwrappedOperationInfo; import org.apache.cxf.transport.DestinationFactory; import org.apache.cxf.transport.DestinationFactoryManager; +import org.apache.cxf.wsdl.WSDLManager; import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension; import org.apache.ws.commons.schema.XmlSchemaComplexType; import org.apache.ws.commons.schema.XmlSchemaElement; @@ -235,8 +237,24 @@ description.getDescribed().add(service); service.setProperty(WSDL_DEFINITION, def); service.setProperty(WSDL_SERVICE, serv); + WSDLManager wsdlManager = bus.getExtension(WSDLManager.class); + ServiceSchemaInfo serviceSchemaInfo = null; + if (wsdlManager != null) { + serviceSchemaInfo = wsdlManager.getSchemasForDefinition(def); + } + + if (serviceSchemaInfo != null) { + service.setServiceSchemaInfo(serviceSchemaInfo); + } else { + getSchemas(def, service); + if (wsdlManager != null) { + serviceSchemaInfo = new ServiceSchemaInfo(); + serviceSchemaInfo.setSchemaCollection(service.getXmlSchemaCollection()); + serviceSchemaInfo.setSchemaInfoList(service.getSchemas()); + wsdlManager.putSchemasForDefinition(def, serviceSchemaInfo); + } + } - getSchemas(def, service); service.setProperty(WSDL_SCHEMA_ELEMENT_LIST, this.schemaList); service.setTargetNamespace(def.getTargetNamespace()); service.setName(serv.getQName()); Modified: incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java (original) +++ incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java Wed Mar 19 09:31:56 2008 @@ -107,7 +107,7 @@ Definition def = new ServiceWSDLBuilder(bus, service).build(); WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter(); - def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtenstionRegistry()); + def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry()); Document doc = wsdlWriter.getDocument(def); Map ns = new HashMap(); @@ -142,7 +142,7 @@ Definition def = new ServiceWSDLBuilder(bus, service).build(); WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter(); - def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtenstionRegistry()); + def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry()); Document doc = wsdlWriter.getDocument(def); Map ns = new HashMap(); Modified: incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java?rev=638927&r1=638926&r2=638927&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java (original) +++ incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java Wed Mar 19 09:31:56 2008 @@ -34,6 +34,8 @@ import org.apache.cxf.catalog.CatalogWSDLLocator; import org.apache.cxf.catalog.OASISCatalogManager; import org.apache.cxf.helpers.IOUtils; +import org.apache.cxf.wsdl.WSDLManager; +import org.apache.cxf.wsdl11.WSDLManagerImpl; import org.apache.hello_world.Greeter; import org.apache.hello_world.GreeterImpl; @@ -97,6 +99,9 @@ Bus bus = BusFactory.getDefaultBus(); OASISCatalogManager catalog = new OASISCatalogManager(); bus.setExtension(catalog, OASISCatalogManager.class); + // prevent cache from papering over the lack of a schema. + WSDLManagerImpl mgr = (WSDLManagerImpl)bus.getExtension(WSDLManager.class); + mgr.setDisableSchemaCache(true); try { SOAPService service = new SOAPService(wsdl, serviceName);