You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/02/25 18:54:36 UTC
svn commit: r747871 [1/3] - in /cxf/branches/2.1.x-fixes:
api/src/main/java/org/apache/cxf/wsdl/ rt/databinding/aegis/
rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/
rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/
rt/data...
Author: dkulp
Date: Wed Feb 25 17:54:34 2009
New Revision: 747871
URL: http://svn.apache.org/viewvc?rev=747871&view=rev
Log:
Back out binary incompatible changes
Added:
cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java (with props)
Removed:
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java
Modified:
cxf/branches/2.1.x-fixes/rt/databinding/aegis/pom.xml
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/XMLBeanTypeInfo.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapRefType.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/ParameterMappingTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/WrappedTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/ArrayService.aegis.xml
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/QualificationTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfoTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/SoapArrayTypeTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/StructTypeTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/EnumTypeTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/JaxbTypeTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/XFireTypeTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/streams/XMLStreamReaderMappingTest.java
cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/type/aegisOptionsTestBeans.xml
cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/WeatherService2Test.java
cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/XMLBeansServiceTest.java
cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/rpc/WeatherServiceRPCLitTest.java
cxf/branches/2.1.x-fixes/systests/pom.xml
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/aegis/AegisClientServerTest.java
Added: cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java?rev=747871&view=auto
==============================================================================
--- cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java (added)
+++ cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java Wed Feb 25 17:54:34 2009
@@ -0,0 +1,146 @@
+/**
+ * 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.wsdl;
+
+import javax.xml.namespace.QName;
+
+public final class WSDLConstants {
+
+ public static final String WSDL_PREFIX = "wsdl";
+ public static final String NS_WSDL11 = "http://schemas.xmlsoap.org/wsdl/";
+
+
+ public static final String NP_XMLNS = "xmlns";
+ public static final String NS_XMLNS = "http://www.w3.org/2000/xmlns/";
+
+ // XML Schema (CR) datatypes + structures
+ public static final String NP_SCHEMA_XSD = "xsd";
+ public static final String NS_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
+
+ public static final QName QNAME_SCHEMA = new QName(NS_SCHEMA_XSD, "schema");
+
+ // XML Schema instance
+ public static final String NP_SCHEMA_XSI = "xsi";
+ public static final String NS_SCHEMA_XSI = "http://www.w3.org/2001/XMLSchema-instance";
+
+ public static final String A_XSI_TYPE = "type";
+ public static final String A_XSI_NIL = "nil";
+
+ // XML Schema attribute names
+ public static final QName NA_XSI_TYPE = new QName(NP_SCHEMA_XSI, A_XSI_TYPE, NS_SCHEMA_XSI);
+ public static final QName NA_XSI_NIL = new QName(NP_SCHEMA_XSI, A_XSI_NIL, NS_SCHEMA_XSI);
+
+
+
+ public static final String NS_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/";
+ public static final String NS_SOAP11 = NS_SOAP;
+ public static final String NS_SOAP12 = "http://schemas.xmlsoap.org/wsdl/soap12/";
+ public static final String SOAP11_PREFIX = "soap";
+ public static final String SOAP12_PREFIX = "soap12";
+
+ public static final String NS_SOAP11_HTTP_TRANSPORT = "http://schemas.xmlsoap.org/soap/http";
+
+ public static final QName QNAME_SOAP_BINDING = new QName(NS_SOAP, "binding");
+ public static final QName QNAME_SOAP_OPERATION = new QName(NS_SOAP, "operation");
+ public static final QName QNAME_SOAP_BODY = new QName(NS_SOAP, "body");
+ public static final QName QNAME_SOAP_FAULT = new QName(NS_SOAP, "fault");
+ public static final QName QNAME_SOAP_BINDING_ADDRESS = new QName(NS_SOAP, "address");
+
+
+ public static final String NS_SOAP12_HTTP_TRANSPORT = "http://www.w3.org/2003/05/soap/bindings/HTTP/";
+
+ public static final QName QNAME_SOAP12_BINDING = new QName(NS_SOAP12, "binding");
+ public static final QName QNAME_SOAP12_BINDING_ADDRESS = new QName(NS_SOAP12, "address");
+
+
+ public static final String DOCUMENT = "document";
+ public static final String RPC = "rpc";
+ public static final String LITERAL = "literal";
+ public static final String REPLACE_WITH_ACTUAL_URL = "REPLACE_WITH_ACTUAL_URL";
+
+ public static final String JMS_PREFIX = "jms";
+ public static final String TNS_PREFIX = "tns";
+
+ // WSDL 1.1 definitions
+ public static final QName QNAME_BINDING = new QName(NS_WSDL11, "binding");
+ public static final QName QNAME_DEFINITIONS = new QName(NS_WSDL11, "definitions");
+ public static final QName QNAME_DOCUMENTATION = new QName(NS_WSDL11, "documentation");
+ public static final QName QNAME_IMPORT = new QName(NS_WSDL11, "import");
+ public static final QName QNAME_MESSAGE = new QName(NS_WSDL11, "message");
+ public static final QName QNAME_PART = new QName(NS_WSDL11, "part");
+ public static final QName QNAME_OPERATION = new QName(NS_WSDL11, "operation");
+ public static final QName QNAME_INPUT = new QName(NS_WSDL11, "input");
+ public static final QName QNAME_OUTPUT = new QName(NS_WSDL11, "output");
+
+ public static final QName QNAME_PORT = new QName(NS_WSDL11, "port");
+ public static final QName QNAME_ADDRESS = new QName(NS_WSDL11, "address");
+ public static final QName QNAME_PORT_TYPE = new QName(NS_WSDL11, "portType");
+ public static final QName QNAME_FAULT = new QName(NS_WSDL11, "fault");
+ public static final QName QNAME_SERVICE = new QName(NS_WSDL11, "service");
+ public static final QName QNAME_TYPES = new QName(NS_WSDL11, "types");
+
+ // WSDL Validation
+ public static final String ATTR_PART_ELEMENT = "element";
+ public static final String ATTR_PART_TYPE = "type";
+ public static final String ATTR_TYPE = "type";
+
+ //For Stax2DOM getUserData(location)
+ public static final String NODE_LOCATION = "location";
+
+ public static final int DOC_WRAPPED = 1;
+ public static final int DOC_BARE = 2;
+ public static final int RPC_WRAPPED = 3;
+ public static final int ERORR_STYLE_USE = -1;
+
+ public static final String NS_BINDING_XML = "http://cxf.apache.org/bindings/xformat";
+ public static final QName QNAME_XMLHTTP_BINDING_ADDRESS =
+ new QName("http://schemas.xmlsoap.org/wsdl/http/", "address");
+
+ public static final String ATTR_TRANSPORT = "transport";
+ public static final String ATTR_LOCATION = "location";
+ public static final String ATTR_NAME = "name";
+ public static final String ATTR_NAMESPACE = "namespace";
+ public static final String ATTR_TNS = "targetNamespace";
+ // usual prefix for the targetNamespace.
+ public static final String CONVENTIONAL_TNS_PREFIX = "tns";
+
+ public static final String WSDL11 = "1.1";
+ public static final String WSDL20 = "2.0";
+
+ public enum WSDLVersion {
+ WSDL11,
+ WSDL20,
+ UNKNOWN
+ };
+
+ private WSDLConstants() {
+ }
+
+ public static WSDLVersion getVersion(String version) {
+ if (WSDL11.equals(version)) {
+ return WSDLVersion.WSDL11;
+ }
+ if (WSDL20.equals(version)) {
+ return WSDLVersion.WSDL20;
+ }
+ return WSDLVersion.UNKNOWN;
+ }
+
+}
Propchange: cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/pom.xml?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/pom.xml (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/pom.xml Wed Feb 25 17:54:34 2009
@@ -82,9 +82,13 @@
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>${jdom.version}</version>
- <scope>provided</scope>
</dependency>
<dependency>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java Wed Feb 25 17:54:34 2009
@@ -46,10 +46,11 @@
import org.apache.cxf.aegis.type.java5.Java5TypeCreator;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.util.SOAPConstants;
-import org.apache.cxf.common.xmlschema.XmlSchemaUtils;
-import org.apache.cxf.helpers.XMLUtils;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.cxf.helpers.DOMUtils;
+import org.jaxen.JaxenException;
+import org.jaxen.jdom.JDOMXPath;
+import org.jdom.Element;
+import org.jdom.Namespace;
/**
* The Aegis Databinding context object. This object coordinates the data binding process: reading and writing
@@ -73,11 +74,19 @@
public class AegisContext {
/**
- * Namespace used for the miscellaneous Aegis type schema.
+ * Namespace used for miscellaneous Aegis types.
*/
- public static final String UTILITY_TYPES_SCHEMA_NS = "http://cxf.apache.org/aegisTypes";
- private Document aegisTypesSchemaDocument;
- private Document xmimeSchemaDocument;
+ public static final String SCHEMA_NS = "http://cxf.apache.org/aegisTypes";
+ private static JDOMXPath importTypesXpath;
+
+ static {
+ try {
+ importTypesXpath = new JDOMXPath("xsd:import[@namespace='" + SCHEMA_NS + "']");
+ importTypesXpath.addNamespace(SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ } catch (JaxenException e) {
+ throw new RuntimeException(e);
+ }
+ }
private boolean writeXsiTypes;
private boolean readXsiTypes = true;
@@ -92,9 +101,9 @@
private TypeCreationOptions configuration;
private boolean mtomEnabled;
private boolean mtomUseXmime;
- private boolean enableJDOMMappings;
// this URI goes into the type map.
private String mappingNamespaceURI;
+ private Document typesSchemaDocument;
/**
* Construct a context.
@@ -141,9 +150,7 @@
}
if (typeMapping == null) {
boolean defaultNillable = configuration.isDefaultNillable();
- TypeMapping baseTM = DefaultTypeMapping.createDefaultTypeMapping(defaultNillable,
- mtomUseXmime,
- enableJDOMMappings);
+ TypeMapping baseTM = DefaultTypeMapping.createDefaultTypeMapping(defaultNillable, mtomUseXmime);
// The use of the XSD URI in the mapping is, MAGIC.
if (mappingNamespaceURI == null) {
mappingNamespaceURI = SOAPConstants.XSD;
@@ -241,47 +248,43 @@
}
}
- public static boolean schemaImportsUtilityTypes(XmlSchema schema) {
- return XmlSchemaUtils.schemaImportsNamespace(schema, UTILITY_TYPES_SCHEMA_NS);
- }
-
- private Document getSchemaDocument(String resourcePath) {
+ public static boolean schemaImportsUtilityTypes(Element schemaElement) {
try {
- return XMLUtils.parse(getClass().getResourceAsStream(resourcePath));
- } catch (ParserConfigurationException e) {
+ return importTypesXpath.selectSingleNode(schemaElement) != null;
+ } catch (JaxenException e) {
throw new RuntimeException(e);
+ }
+ }
+
+ public Document getTypesSchemaDocument() {
+ ensureTypesSchemaDocument();
+ return typesSchemaDocument;
+ }
+
+ private void ensureTypesSchemaDocument() {
+ if (typesSchemaDocument != null) {
+ return;
+ }
+ try {
+ typesSchemaDocument = DOMUtils.readXml(getClass()
+ .getResourceAsStream("/META-INF/cxf/aegisTypes.xsd"));
} catch (SAXException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
}
}
-
- // could we make these documents static? What would we synchronize on?
- private Document getAegisTypesSchemaDocument() {
- if (aegisTypesSchemaDocument == null) {
- aegisTypesSchemaDocument = getSchemaDocument("/META-INF/cxf/aegisTypes.xsd");
- }
- return aegisTypesSchemaDocument;
- }
-
- private Document getXmimeSchemaDocument() {
- if (xmimeSchemaDocument == null) {
- xmimeSchemaDocument = getSchemaDocument("/schemas/wsdl/xmime.xsd");
- }
- return xmimeSchemaDocument;
- }
-
- public XmlSchema addTypesSchemaDocument(XmlSchemaCollection collection) {
- return collection.read(getAegisTypesSchemaDocument(), null);
- }
-
- public XmlSchema addXmimeSchemaDocument(XmlSchemaCollection collection) {
- return collection.read(getXmimeSchemaDocument(), null);
- }
- public static void addUtilityTypesToSchema(XmlSchema root) {
- XmlSchemaUtils.addImportIfNeeded(root, UTILITY_TYPES_SCHEMA_NS);
+ public static void addUtilityTypesToSchema(Element root) {
+ if (schemaImportsUtilityTypes(root)) {
+ return;
+ }
+ Element element = new Element("import", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ root.addContent(0, element);
+ element.setAttribute("namespace", SCHEMA_NS);
+ root.addNamespaceDeclaration(Namespace.getNamespace("aegisTypes", SCHEMA_NS));
}
/**
@@ -464,16 +467,4 @@
public void setMappingNamespaceURI(String mappingNamespaceURI) {
this.mappingNamespaceURI = mappingNamespaceURI;
}
-
- public boolean isEnableJDOMMappings() {
- return enableJDOMMappings;
- }
-
- /**
- * Whether to enable JDOM as a mapping for xsd:anyType if JDOM is in the classpath.
- * @param enableJDOMMappings
- */
- public void setEnableJDOMMappings(boolean enableJDOMMappings) {
- this.enableJDOMMappings = enableJDOMMappings;
- }
}
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java Wed Feb 25 17:54:34 2009
@@ -18,6 +18,7 @@
*/
package org.apache.cxf.aegis.databinding;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
@@ -28,43 +29,53 @@
import java.util.logging.Logger;
import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
import org.apache.cxf.aegis.AegisContext;
import org.apache.cxf.aegis.DatabindingException;
-import org.apache.cxf.aegis.type.AbstractTypeCreator;
+import org.apache.cxf.aegis.type.AbstractTypeCreator.TypeClassInfo;
import org.apache.cxf.aegis.type.Type;
import org.apache.cxf.aegis.type.TypeCreationOptions;
import org.apache.cxf.aegis.type.TypeCreator;
import org.apache.cxf.aegis.type.TypeMapping;
import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
-import org.apache.cxf.common.WSDLConstants;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SOAPConstants;
import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
-import org.apache.cxf.common.xmlschema.XmlSchemaUtils;
import org.apache.cxf.databinding.AbstractDataBinding;
import org.apache.cxf.databinding.DataReader;
import org.apache.cxf.databinding.DataWriter;
import org.apache.cxf.frontend.MethodDispatcher;
import org.apache.cxf.frontend.SimpleMethodDispatcher;
import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.service.Service;
+import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.model.AbstractMessageContainer;
import org.apache.cxf.service.model.FaultInfo;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.cxf.service.model.OperationInfo;
-import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.wsdl.WSDLConstants;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaAnnotated;
-import org.apache.ws.commons.schema.XmlSchemaForm;
import org.apache.ws.commons.schema.utils.NamespaceMap;
+import org.jaxen.JaxenException;
+import org.jaxen.jdom.JDOMXPath;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.output.DOMOutputter;
/**
* CXF databinding object for Aegis. By default, this creates an AegisContext object. To customize
@@ -99,6 +110,7 @@
protected static final int FAULT_PARAM = 2;
private static final Logger LOG = LogUtils.getL7dLogger(AegisDatabinding.class);
+ private static org.w3c.dom.Document xmimeSchemaDocument;
private AegisContext aegisContext;
private Map<MessagePartInfo, Type> part2Type;
@@ -108,10 +120,36 @@
private TypeCreationOptions configuration;
private boolean mtomEnabled;
private boolean mtomUseXmime;
+ private JDOMXPath importXmimeXpath;
public AegisDatabinding() {
super();
part2Type = new HashMap<MessagePartInfo, Type>();
+ // we have this also in AbstractXOPType. There has to be a better way.
+ importXmimeXpath = AbstractXOPType.getXmimeXpathImport();
+ }
+
+ private boolean schemaImportsXmime(Element schemaElement) {
+ try {
+ return importXmimeXpath.selectSingleNode(schemaElement) != null;
+ } catch (JaxenException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void ensureXmimeSchemaDocument() {
+ if (xmimeSchemaDocument != null) {
+ return;
+ }
+ try {
+ xmimeSchemaDocument = DOMUtils.readXml(getClass().getResourceAsStream("/schemas/wsdl/xmime.xsd"));
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ }
}
/**
@@ -421,90 +459,106 @@
}
Map<String, String> namespaceMap = getDeclaredNamespaceMappings();
+ boolean needXmimeSchema = false;
+ // utility types.
+ boolean needTypesSchema = false;
- for (ServiceInfo si : s.getServiceInfos()) {
- // these two must be recalculated per-service-info!
- boolean needXmimeSchema = false;
- boolean needTypesSchema = false;
-
- for (Map.Entry<String, Set<Type>> entry : tns2Type.entrySet()) {
-
- String schemaNamespaceUri = entry.getKey();
-
- if (XmlSchemaConstants.XSD_NAMESPACE_URI.equals(schemaNamespaceUri)) {
- continue;
- }
-
- if (AegisContext.UTILITY_TYPES_SCHEMA_NS.equals(schemaNamespaceUri)) {
- continue; // we handle this separately.
- }
-
- if (AbstractXOPType.XML_MIME_NS.equals(schemaNamespaceUri)) {
- continue; // similiarly.
- }
-
- SchemaInfo schemaInfo = si.addNewSchema(entry.getKey());
- XmlSchema schema = schemaInfo.getSchema();
- NamespaceMap xmlsNamespaceMap = new NamespaceMap();
-
- // user-requested prefix mappings.
- if (namespaceMap != null) {
- for (Map.Entry<String, String> e : namespaceMap.entrySet()) {
- xmlsNamespaceMap.add(e.getValue(), e.getKey());
- }
- }
-
- // tns: is conventional, and besides we have unit tests that are hardcoded to it.
- if (!xmlsNamespaceMap.containsKey(WSDLConstants.CONVENTIONAL_TNS_PREFIX)
- // if some wants something other than TNS, they get it.
- && !xmlsNamespaceMap.containsValue(entry.getKey())) {
- xmlsNamespaceMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, entry.getKey());
- }
-
- // ditto for xsd: instead of just namespace= for the schema schema.
- if (!xmlsNamespaceMap.containsKey("xsd")
- && !xmlsNamespaceMap.containsValue(XmlSchemaConstants.XSD_NAMESPACE_URI)) {
- xmlsNamespaceMap.add("xsd", XmlSchemaConstants.XSD_NAMESPACE_URI);
- }
-
- schema.setNamespaceContext(xmlsNamespaceMap);
- schema.setTargetNamespace(entry.getKey());
- schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
- schema.setAttributeFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
+ for (Map.Entry<String, Set<Type>> entry : tns2Type.entrySet()) {
+ String xsdPrefix = SOAPConstants.XSD_PREFIX;
+ if (namespaceMap != null && namespaceMap.containsKey(SOAPConstants.XSD)) {
+ xsdPrefix = namespaceMap.get(SOAPConstants.XSD);
+ }
+
+ Element e = new Element("schema", xsdPrefix, SOAPConstants.XSD);
- for (Type t : entry.getValue()) {
- t.writeSchema(schema);
+ e.setAttribute(new Attribute(WSDLConstants.ATTR_TNS, entry.getKey()));
+
+ if (null != namespaceMap) { // did application hand us some
+ // additional namespaces?
+ for (Map.Entry<String, String> mapping : namespaceMap.entrySet()) {
+ // user gives us namespace->prefix mapping.
+ e.addNamespaceDeclaration(Namespace.getNamespace(mapping.getValue(), mapping.getKey()));
}
+ }
+
+ // if the user didn't pick something else, assign 'tns' as the
+ // prefix.
+ if (namespaceMap == null || !namespaceMap.containsKey(entry.getKey())) {
+ // Schemas are more readable if there is a specific prefix for
+ // the TNS.
+ e.addNamespaceDeclaration(Namespace.getNamespace(WSDLConstants.CONVENTIONAL_TNS_PREFIX, entry
+ .getKey()));
+ }
+ e.setAttribute(new Attribute("elementFormDefault", "qualified"));
+ e.setAttribute(new Attribute("attributeFormDefault", "qualified"));
- if (schemaImportsXmime(schema)) {
- needXmimeSchema = true;
+ for (Type t : entry.getValue()) {
+ t.writeSchema(e);
+ }
+
+ if (e.getChildren().size() == 0) {
+ continue;
+ }
+
+ if (schemaImportsXmime(e)) {
+ needXmimeSchema = true;
+ }
+ if (AegisContext.schemaImportsUtilityTypes(e)) {
+ needTypesSchema = true;
+ }
+
+ try {
+ NamespaceMap nsMap = new NamespaceMap();
+
+ nsMap.add(xsdPrefix, SOAPConstants.XSD);
+
+ // We prefer explicit prefixes over those generated in the
+ // types.
+ // This loop may have intended to support prefixes from
+ // individual aegis files,
+ // but that isn't a good idea.
+ for (Iterator itr = e.getAdditionalNamespaces().iterator(); itr.hasNext();) {
+ Namespace n = (Namespace)itr.next();
+ if (!nsMap.containsValue(n.getURI())) {
+ nsMap.add(n.getPrefix(), n.getURI());
+ }
}
-
- if (AegisContext.schemaImportsUtilityTypes(schema)) {
- needTypesSchema = true;
+
+ org.w3c.dom.Document schema = new DOMOutputter().output(new Document(e));
+
+ for (ServiceInfo si : s.getServiceInfos()) {
+ SchemaCollection col = si.getXmlSchemaCollection();
+ col.setNamespaceContext(nsMap);
+ XmlSchema xmlSchema = addSchemaDocument(si, col, schema, entry.getKey());
+ // Work around bug in JDOM DOMOutputter which fails to
+ // correctly
+ // assign namespaces to attributes. If JDOM worked right,
+ // the collection object would get the prefixes for itself.
+ xmlSchema.setNamespaceContext(nsMap);
}
+ } catch (JDOMException e1) {
+ throw new ServiceConstructionException(e1);
}
- if (needXmimeSchema) {
- XmlSchema schema =
- aegisContext.addXmimeSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
- SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
- schemaInfo.setSchema(schema);
- si.addSchema(schemaInfo);
+ }
+
+ if (needXmimeSchema) {
+ ensureXmimeSchemaDocument();
+ for (ServiceInfo si : s.getServiceInfos()) {
+ SchemaCollection col = si.getXmlSchemaCollection();
+ // invented systemId.
+ addSchemaDocument(si, col, xmimeSchemaDocument, AbstractXOPType.XML_MIME_NS);
}
-
- if (needTypesSchema) {
- XmlSchema schema =
- aegisContext.addTypesSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
- SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
- schemaInfo.setSchema(schema);
- si.addSchema(schemaInfo);
+ }
+
+ if (needTypesSchema) {
+ org.w3c.dom.Document schema = aegisContext.getTypesSchemaDocument();
+ for (ServiceInfo si : s.getServiceInfos()) {
+ SchemaCollection col = si.getXmlSchemaCollection();
+ addSchemaDocument(si, col, schema, AegisContext.SCHEMA_NS);
}
}
- }
-
- private boolean schemaImportsXmime(XmlSchema schema) {
- return XmlSchemaUtils.schemaImportsNamespace(schema, AbstractXOPType.XML_MIME_NS);
+
}
public QName getSuggestedName(Service s, TypeMapping tm, OperationInfo op, int param) {
@@ -546,7 +600,7 @@
OperationInfo op = param.getMessageInfo().getOperation();
Method m = getMethod(s, op);
- AbstractTypeCreator.TypeClassInfo info;
+ TypeClassInfo info;
if (paramtype != FAULT_PARAM && m != null) {
info = typeCreator.createClassInfo(m, param.getIndex() - offset);
} else {
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java Wed Feb 25 17:54:34 2009
@@ -34,15 +34,13 @@
import org.apache.cxf.aegis.type.collection.MapType;
import org.apache.cxf.aegis.util.NamespaceHelper;
import org.apache.cxf.aegis.util.ServiceUtils;
-import org.apache.cxf.common.WSDLConstants;
import org.apache.cxf.common.util.XMLSchemaQNames;
+import org.apache.cxf.wsdl.WSDLConstants;
/**
* @author Hani Suleiman Date: Jun 14, 2005 Time: 11:59:57 PM
*/
public abstract class AbstractTypeCreator implements TypeCreator {
- public static final String HTTP_CXF_APACHE_ORG_ARRAYS = "http://cxf.apache.org/arrays";
-
protected TypeMapping tm;
protected AbstractTypeCreator nextCreator;
@@ -310,7 +308,7 @@
ns = tm.getMappingIdentifierURI();
}
if (WSDLConstants.NS_SCHEMA_XSD.equals(ns)) {
- ns = HTTP_CXF_APACHE_ORG_ARRAYS;
+ ns = "http://cxf.apache.org/arrays";
}
String first = type.getSchemaType().getLocalPart().substring(0, 1);
@@ -318,13 +316,13 @@
String localName = "ArrayOf" + first.toUpperCase() + last;
if (info.nonDefaultAttributes()) {
localName += "-";
- if (info.getMinOccurs() >= 0) {
- localName += info.minOccurs;
- }
- localName += "-";
if (info.getMaxOccurs() >= 0) {
localName += info.maxOccurs;
}
+ localName += "-";
+ if (info.getMinOccurs() >= 0) {
+ localName += info.minOccurs;
+ }
if (info.isFlat()) {
localName += "Flat";
}
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java Wed Feb 25 17:54:34 2009
@@ -68,9 +68,9 @@
import org.apache.cxf.aegis.type.xml.SourceType;
import org.apache.cxf.aegis.type.xml.XMLStreamReaderType;
import org.apache.cxf.binding.soap.Soap11;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.util.SOAPConstants;
import org.apache.cxf.common.util.XMLSchemaQNames;
+import org.jdom.Element;
/**
* Contains type mappings for java/qname pairs.
@@ -224,7 +224,7 @@
}
private static void fillStandardMappings(TypeMapping tm, boolean defaultNillable,
- boolean enableMtomXmime, boolean enableJDOM) {
+ boolean enableMtomXmime) {
defaultRegister(tm, defaultNillable, BigDecimal.class, XMLSchemaQNames.XSD_DECIMAL,
new BigDecimalType());
defaultRegister(tm, defaultNillable, BigInteger.class, XMLSchemaQNames.XSD_INTEGER,
@@ -234,6 +234,9 @@
defaultRegister(tm, defaultNillable, Calendar.class, XMLSchemaQNames.XSD_DATETIME,
new CalendarType());
defaultRegister(tm, defaultNillable, Date.class, XMLSchemaQNames.XSD_DATETIME, new DateTimeType());
+ defaultRegister(tm, defaultNillable, Document.class, XMLSchemaQNames.XSD_ANY, new DocumentType());
+ defaultRegister(tm, defaultNillable, Element.class, XMLSchemaQNames.XSD_ANY,
+ new JDOMElementType());
defaultRegister(tm, defaultNillable, Float.class, XMLSchemaQNames.XSD_FLOAT, new FloatType());
defaultRegister(tm, defaultNillable, Double.class, XMLSchemaQNames.XSD_DOUBLE, new DoubleType());
defaultRegister(tm, defaultNillable, Integer.class, XMLSchemaQNames.XSD_INT, new IntType());
@@ -262,6 +265,8 @@
defaultRegister(tm, defaultNillable, java.sql.Date.class, XMLSchemaQNames.XSD_DATETIME,
new SqlDateType());
+ defaultRegister(tm, defaultNillable, org.jdom.Document.class, XMLSchemaQNames.XSD_ANY,
+ new JDOMDocumentType());
QName mtomBase64 = XMLSchemaQNames.XSD_BASE64;
if (enableMtomXmime) {
@@ -272,56 +277,13 @@
new DataSourceType(enableMtomXmime, null));
defaultRegister(tm, defaultNillable, DataHandler.class, mtomBase64,
new DataHandlerType(enableMtomXmime, null));
-
-
- defaultRegister(tm, defaultNillable, Document.class, XMLSchemaQNames.XSD_ANY, new DocumentType());
- if (enableJDOM) {
- registerJDOMTypes(tm, defaultNillable);
- }
-
- }
-
- private static void registerJDOMTypes(TypeMapping tm, boolean defaultNillable) {
- try {
- Class<?> jdomDocClass = ClassLoaderUtils.loadClass("org.jdom.Document", DefaultTypeMapping.class);
- defaultRegister(tm, defaultNillable, jdomDocClass, XMLSchemaQNames.XSD_ANY,
- new JDOMDocumentType());
-
- } catch (ClassNotFoundException e) {
- // not available.
- }
-
- try {
- Class<?> jdomElementClass =
- ClassLoaderUtils.loadClass("org.jdom.Element", DefaultTypeMapping.class);
- defaultRegister(tm, defaultNillable, jdomElementClass, XMLSchemaQNames.XSD_ANY,
- new JDOMElementType());
- } catch (ClassNotFoundException e) {
- // not available.
- }
- }
-
- public static DefaultTypeMapping createSoap11TypeMapping(boolean defaultNillable,
- boolean enableMtomXmime) {
- return createSoap11TypeMapping(
- defaultNillable,
- enableMtomXmime,
- false);
}
- /**
- * Create a type mapping object with a stock set of mappings, including the SOAP 1.1 'encoded'
- * types.
- * @param defaultNillable whether elements are nillable by default.
- * @param enableMtomXmime whether to enable XMIME annotations with MTOM.
- * @param enableJDOM whether to add mappings for JDOM.
- * @return
- */
public static DefaultTypeMapping createSoap11TypeMapping(boolean defaultNillable,
- boolean enableMtomXmime, boolean enableJDOM) {
+ boolean enableMtomXmime) {
// Create a Type Mapping for SOAP 1.1 Encoding
DefaultTypeMapping soapTM = new DefaultTypeMapping(Soap11.SOAP_ENCODING_URI);
- fillStandardMappings(soapTM, defaultNillable, enableMtomXmime, enableJDOM);
+ fillStandardMappings(soapTM, defaultNillable, enableMtomXmime);
defaultRegister(soapTM, defaultNillable, boolean.class, Soap11.ENCODED_BOOLEAN, new BooleanType());
defaultRegister(soapTM, defaultNillable, char.class, Soap11.ENCODED_CHAR, new CharacterType());
@@ -353,26 +315,10 @@
}
public static DefaultTypeMapping createDefaultTypeMapping(boolean defaultNillable,
- boolean enableMtomXmime) {
- return createDefaultTypeMapping(
- defaultNillable,
- enableMtomXmime,
- false);
- }
-
- /**
- * Create a set of default type mappings.
- * @param defaultNillable whether elements are nillable by default.
- * @param enableMtomXmime whether to enable XMIME annotations on MTOM.
- * @param enableJDOM whether to map JDOM types.
- * @return
- */
- public static DefaultTypeMapping createDefaultTypeMapping(boolean defaultNillable,
- boolean enableMtomXmime,
- boolean enableJDOM) {
+ boolean enableMtomXmime) {
// by convention, the default mapping is against the XML schema URI.
DefaultTypeMapping tm = new DefaultTypeMapping(SOAPConstants.XSD);
- fillStandardMappings(tm, defaultNillable, enableMtomXmime, enableJDOM);
+ fillStandardMappings(tm, defaultNillable, enableMtomXmime);
defaultRegister(tm, defaultNillable, Character.class,
CharacterAsStringType.CHARACTER_AS_STRING_TYPE_QNAME,
new CharacterAsStringType());
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java Wed Feb 25 17:54:34 2009
@@ -26,8 +26,7 @@
import org.apache.cxf.aegis.DatabindingException;
import org.apache.cxf.aegis.xml.MessageReader;
import org.apache.cxf.aegis.xml.MessageWriter;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.jdom.Element;
/**
* A Type reads and writes XML fragments to create and write objects.
@@ -77,7 +76,7 @@
* type object adds it to the schema.
* @param root root of the XSD document.
*/
- public void writeSchema(XmlSchema root) {
+ public void writeSchema(Element root) {
}
/**
@@ -85,7 +84,7 @@
* xsd:element element, it can implement this.
* @param schemaElement
*/
- public void addToSchemaElement(XmlSchemaElement schemaElement) {
+ public void addToSchemaElement(Element schemaElement) {
}
/**
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java Wed Feb 25 17:54:34 2009
@@ -18,6 +18,8 @@
*/
package org.apache.cxf.aegis.type;
+import java.util.List;
+
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
import org.apache.commons.logging.Log;
@@ -25,9 +27,10 @@
import org.apache.cxf.aegis.AegisContext;
import org.apache.cxf.aegis.util.NamespaceHelper;
import org.apache.cxf.common.util.SOAPConstants;
-import org.apache.cxf.common.xmlschema.XmlSchemaUtils;
-import org.apache.ws.commons.schema.XmlSchema;
-
+import org.apache.cxf.helpers.CastUtils;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Namespace;
/**
* Static methods/constants for Aegis.
@@ -156,9 +159,26 @@
return type;
}
-
- public static void setAttributeAttributes(QName name, Type type, XmlSchema root) {
+ public static Attribute createTypeAttribute(String prefix, Type type, Element root) {
String ns = type.getSchemaType().getNamespaceURI();
- XmlSchemaUtils.addImportIfNeeded(root, ns);
+ if (!ns.equals(root.getAttributeValue("targetNamespace"))
+ && !ns.equals(SOAPConstants.XSD)) {
+ //find import statement
+ List<Element> l = CastUtils.cast(root.getChildren("import",
+ Namespace.getNamespace(SOAPConstants.XSD)));
+ boolean found = false;
+ for (Element e : l) {
+ if (ns.equals(e.getAttributeValue("namespace"))) {
+ found = true;
+ }
+ }
+ if (!found) {
+ Element element = new Element("import", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ root.addContent(0, element);
+ element.setAttribute("namespace", ns);
+ }
+ }
+ return new Attribute("type", prefix + ':' + type.getSchemaType().getLocalPart());
}
+
}
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java Wed Feb 25 17:54:34 2009
@@ -38,12 +38,6 @@
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
-import javax.xml.xpath.XPathConstants;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
@@ -56,8 +50,12 @@
import org.apache.cxf.aegis.type.basic.XMLBeanTypeInfo;
import org.apache.cxf.aegis.util.NamespaceHelper;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.helpers.XPathUtils;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.DOMBuilder;
+import org.jdom.xpath.XPath;
/**
* Deduce mapping information from an xml file. The xml file should be in the
@@ -115,7 +113,7 @@
if (is != null) {
try {
aegisDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
- aegisDocumentBuilderFactory.setNamespaceAware(true);
+
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
aegisSchema = schemaFactory.newSchema(new StreamSource(is));
@@ -134,8 +132,6 @@
}
}
}
-
- private XPathUtils xpathUtils = new XPathUtils();
private Document readAegisFile(InputStream is, final String path) throws IOException {
DocumentBuilder documentBuilder;
@@ -188,7 +184,7 @@
// above.
return null;
}
- return doc;
+ return new DOMBuilder().build(doc);
}
protected Document getDocument(Class clazz) {
@@ -325,17 +321,17 @@
if (mapping != null || mappings.size() > 0) {
String typeNameAtt = null;
if (mapping != null) {
- typeNameAtt = DOMUtils.getAttributeValueEmptyNull(mapping, "name");
+ typeNameAtt = mapping.getAttributeValue("name");
}
String extensibleElements = null;
if (mapping != null) {
- extensibleElements = mapping.getAttribute("extensibleElements");
+ extensibleElements = mapping.getAttributeValue("extensibleElements");
}
String extensibleAttributes = null;
if (mapping != null) {
- extensibleAttributes = mapping.getAttribute("extensibleAttributes");
+ extensibleAttributes = mapping.getAttributeValue("extensibleAttributes");
}
String defaultNS = NamespaceHelper.makeNamespaceFromClassName(info.getTypeClass().getName(),
@@ -440,7 +436,7 @@
}
info.setTypeClass(m.getReturnType());
// info.setAnnotations(m.getAnnotations());
- Element rtElement = DOMUtils.getFirstChildWithName(bestMatch, "", "return-type");
+ Element rtElement = bestMatch.getChild("return-type");
readMetadata(info, mapping, rtElement);
}
@@ -448,25 +444,24 @@
}
protected void readMetadata(TypeClassInfo info, Element mapping, Element parameter) {
- info.setTypeName(createQName(parameter, DOMUtils.getAttributeValueEmptyNull(parameter, "typeName")));
- info.setMappedName(createQName(parameter,
- DOMUtils.getAttributeValueEmptyNull(parameter, "mappedName")));
+ info.setTypeName(createQName(parameter, parameter.getAttributeValue("typeName")));
+ info.setMappedName(createQName(parameter, parameter.getAttributeValue("mappedName")));
setComponentType(info, mapping, parameter);
setKeyType(info, mapping, parameter);
setValueType(info, mapping, parameter);
setType(info, parameter);
- String min = DOMUtils.getAttributeValueEmptyNull(parameter, "minOccurs");
+ String min = parameter.getAttributeValue("minOccurs");
if (min != null) {
info.setMinOccurs(Long.parseLong(min));
}
- String max = DOMUtils.getAttributeValueEmptyNull(parameter, "maxOccurs");
+ String max = parameter.getAttributeValue("maxOccurs");
if (max != null) {
info.setMaxOccurs(Long.parseLong(max));
}
- String flat = DOMUtils.getAttributeValueEmptyNull(parameter, "flat");
+ String flat = parameter.getAttributeValue("flat");
if (flat != null) {
info.setFlat(Boolean.valueOf(flat.toLowerCase()).booleanValue());
}
@@ -525,7 +520,7 @@
}
protected void setComponentType(TypeClassInfo info, Element mapping, Element parameter) {
- String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "componentType");
+ String componentType = parameter.getAttributeValue("componentType");
if (componentType != null) {
info.setGenericType(loadGeneric(info, mapping, componentType));
}
@@ -543,7 +538,7 @@
TypeClassInfo componentInfo = new TypeClassInfo();
componentInfo.setDescription("generic component " + componentInfo.getDescription());
readMetadata(componentInfo, mapping, propertyEl);
- String className = DOMUtils.getAttributeValueEmptyNull(propertyEl, "class");
+ String className = propertyEl.getAttributeValue("class");
if (className == null) {
throw new DatabindingException("A 'class' attribute must be specified for <component> "
+ name);
@@ -566,7 +561,7 @@
}
protected void setType(TypeClassInfo info, Element parameter) {
- String type = DOMUtils.getAttributeValueEmptyNull(parameter, "type");
+ String type = parameter.getAttributeValue("type");
if (type != null) {
try {
info.setType(ClassLoaderUtils.loadClass(type, getClass()));
@@ -577,14 +572,14 @@
}
protected void setKeyType(TypeClassInfo info, Element mapping, Element parameter) {
- String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "keyType");
+ String componentType = parameter.getAttributeValue("keyType");
if (componentType != null) {
info.setKeyType(loadGeneric(info, mapping, componentType));
}
}
private void setValueType(TypeClassInfo info, Element mapping, Element parameter) {
- String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "valueType");
+ String componentType = parameter.getAttributeValue("valueType");
if (componentType != null) {
info.setValueType(loadGeneric(info, mapping, componentType));
}
@@ -617,10 +612,10 @@
Element match = getMatch(element, "parameter[@index='" + i + "']");
if (match != null
// we check if the type is specified and matches
- && DOMUtils.getAttributeValueEmptyNull(match, "class") != null
+ && match.getAttributeValue("class") != null
// if it doesn't match, then we can definitely rule out
// this result
- && !DOMUtils.getAttributeValueEmptyNull(match, "class").equals(parameterType.getName())) {
+ && !match.getAttributeValue("class").equals(parameterType.getName())) {
iterator.remove();
}
@@ -637,9 +632,7 @@
int highestSpecified = 0;
for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
Element element = (Element)iterator.next();
-
- List<Element> params = DOMUtils.getChildrenWithName(element, "", "parameter");
- int availableParameters = params.size();
+ int availableParameters = element.getChildren("parameter").size();
if (availableParameters > highestSpecified) {
bestCandidate = element;
highestSpecified = availableParameters;
@@ -648,17 +641,23 @@
return bestCandidate;
}
- private Element getMatch(Node doc, String xpath) {
- return (Element)xpathUtils.getValue(xpath, doc, XPathConstants.NODE);
+ private Element getMatch(Object doc, String xpath) {
+ try {
+ XPath path = XPath.newInstance(xpath);
+ return (Element)path.selectSingleNode(doc);
+ } catch (JDOMException e) {
+ throw new DatabindingException("Error evaluating xpath " + xpath, e);
+ }
}
- private List<Element> getMatches(Node doc, String xpath) {
- NodeList nl = (NodeList)xpathUtils.getValue(xpath, doc, XPathConstants.NODESET);
- List<Element> r = new ArrayList<Element>();
- for (int x = 0; x < nl.getLength(); x++) {
- r.add((Element)nl.item(x));
+ @SuppressWarnings("unchecked")
+ private List<Element> getMatches(Object doc, String xpath) {
+ try {
+ XPath path = XPath.newInstance(xpath);
+ return path.selectNodes(doc);
+ } catch (JDOMException e) {
+ throw new DatabindingException("Error evaluating xpath " + xpath, e);
}
- return r;
}
/**
@@ -677,12 +676,12 @@
String prefix = value.substring(0, index);
String localName = value.substring(index + 1);
- String ns = DOMUtils.getNamespace(e, prefix);
+ Namespace ns = e.getNamespace(prefix);
if (ns == null || localName == null) {
throw new DatabindingException("Invalid QName in mapping: " + value);
}
- return new QName(ns, localName, prefix);
+ return new QName(ns.getURI(), localName, prefix);
}
}
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java Wed Feb 25 17:54:34 2009
@@ -22,6 +22,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import javax.xml.namespace.QName;
@@ -32,13 +34,14 @@
import org.apache.cxf.aegis.DatabindingException;
import org.apache.cxf.aegis.type.Type;
import org.apache.cxf.aegis.type.TypeUtil;
+import org.apache.cxf.aegis.util.NamespaceHelper;
import org.apache.cxf.aegis.xml.MessageReader;
import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.common.util.SOAPConstants;
import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Namespace;
/**
* An ArrayType.
@@ -162,8 +165,8 @@
}
@Override
- public void writeObject(Object values, MessageWriter writer,
- Context context) throws DatabindingException {
+ public void writeObject(Object values, MessageWriter writer, Context context)
+ throws DatabindingException {
boolean forceXsiWrite = false;
if (values == null) {
return;
@@ -186,6 +189,7 @@
String name = type.getSchemaType().getLocalPart();
+
Class arrayType = type.getTypeClass();
boolean oldXsiWrite = context.getGlobalContext().isWriteXsiTypes();
@@ -262,51 +266,70 @@
} else {
type.writeObject(value, cwriter, context);
}
-
+
if (type.isWriteOuter()) {
cwriter.close();
}
}
@Override
- public void writeSchema(XmlSchema root) {
- if (hasDefinedArray(root)) {
- return;
- }
+ public void writeSchema(Element root) {
+ try {
+ if (hasDefinedArray(root)) {
+ return;
+ }
- XmlSchemaComplexType complex = new XmlSchemaComplexType(root);
- complex.setName(getSchemaType().getLocalPart());
- root.addType(complex);
- root.getItems().add(complex);
-
- XmlSchemaSequence seq = new XmlSchemaSequence();
- complex.setParticle(seq);
-
- Type componentType = getComponentType();
- XmlSchemaElement element = new XmlSchemaElement();
- element.setName(componentType.getSchemaType().getLocalPart());
- element.setSchemaTypeName(componentType.getSchemaType());
-
- seq.getItems().add(element);
+ Element complex = new Element("complexType", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ complex.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
+ root.addContent(complex);
- if (componentType.isNillable()) {
- element.setNillable(true);
- }
+ Element seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ complex.addContent(seq);
+
+ Element element = new Element("element", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ seq.addContent(element);
+
+ Type componentType = getComponentType();
+ String prefix = NamespaceHelper.getUniquePrefix(root, componentType.getSchemaType()
+ .getNamespaceURI());
+
+ element.setAttribute(new Attribute("name", componentType.getSchemaType().getLocalPart()));
+ element.setAttribute(TypeUtil.createTypeAttribute(prefix, componentType, root));
+
+ if (componentType.isNillable()) {
+ element.setAttribute(new Attribute("nillable", "true"));
+ }
+
+ element.setAttribute(new Attribute("minOccurs", Long.valueOf(getMinOccurs()).toString()));
- element.setMinOccurs(getMinOccurs());
- element.setMaxOccurs(getMaxOccurs());
+ if (maxOccurs == Long.MAX_VALUE) {
+ element.setAttribute(new Attribute("maxOccurs", "unbounded"));
+ } else {
+ element.setAttribute(new Attribute("maxOccurs", Long.valueOf(getMaxOccurs()).toString()));
+ }
+ } catch (IllegalArgumentException e) {
+ throw new DatabindingException("Illegal argument.", e);
+ }
}
/**
- * Since both an Array and a List can have the same type definition, double check that there isn't already
- * a defined type already.
+ * Since both an Array and a List can have the same type definition, double
+ * check that there isn't already a defined type already.
*
* @param root
* @return
*/
- private boolean hasDefinedArray(XmlSchema root) {
- return root.getTypeByName(getSchemaType().getLocalPart()) != null;
+ private boolean hasDefinedArray(Element root) {
+ List children = root.getChildren("complexType", Namespace.getNamespace(SOAPConstants.XSD));
+ for (Iterator itr = children.iterator(); itr.hasNext();) {
+ Element e = (Element)itr.next();
+
+ if (e.getAttributeValue("name").equals(getSchemaType().getLocalPart())) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -393,7 +416,7 @@
setWriteOuter(!flat);
this.flat = flat;
}
-
+
@Override
public boolean hasMaxOccurs() {
return true;
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java?rev=747871&r1=747870&r2=747871&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java Wed Feb 25 17:54:34 2009
@@ -26,36 +26,31 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
-
import javax.xml.namespace.QName;
import org.apache.cxf.aegis.AegisContext;
import org.apache.cxf.aegis.Context;
import org.apache.cxf.aegis.DatabindingException;
-import org.apache.cxf.aegis.type.AbstractTypeCreator;
import org.apache.cxf.aegis.type.Type;
import org.apache.cxf.aegis.type.TypeMapping;
import org.apache.cxf.aegis.type.TypeUtil;
import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
+import org.apache.cxf.aegis.util.NamespaceHelper;
import org.apache.cxf.aegis.xml.MessageReader;
import org.apache.cxf.aegis.xml.MessageWriter;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.xmlschema.XmlSchemaUtils;
+import org.apache.cxf.common.util.SOAPConstants;
import org.apache.cxf.interceptor.Fault;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaAny;
-import org.apache.ws.commons.schema.XmlSchemaAnyAttribute;
-import org.apache.ws.commons.schema.XmlSchemaAttribute;
-import org.apache.ws.commons.schema.XmlSchemaComplexContent;
-import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.jaxen.JaxenException;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Namespace;
/**
* Serializes JavaBeans.
- *
+ *
* There's a really dangerous coding convention in this class, maintainers beware.
* There are two constructor. The no-args constructor defers, until later,
* the construction of a BeanTypeInfo. The one-arg constructor gets the BeanTypeInfo passed as a parameter.
@@ -110,7 +105,7 @@
if (impl == null) {
InvocationHandler handler = new InterfaceInvocationHandler();
- object = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] {
+ object = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] {
clazz
}, handler);
target = handler;
@@ -163,7 +158,7 @@
writeProperty(name, target, writeObj, clazz, propertyTypeInfo);
} else {
if (!propertyTypeInfo.isNillable(name)) {
- throw new DatabindingException(name.getLocalPart()
+ throw new DatabindingException(name.getLocalPart()
+ " is nil, but not nillable.");
}
@@ -188,9 +183,11 @@
}
}
- protected Type getElementType(QName name, BeanTypeInfo beanTypeInfo,
- MessageReader reader, Context context) {
-
+ protected Type getElementType(QName name,
+ BeanTypeInfo beanTypeInfo,
+ MessageReader reader,
+ Context context) {
+
Type type = beanTypeInfo.getType(name);
// Type can be overriden with a xsi:type attribute
@@ -199,10 +196,11 @@
}
/**
- * If the class is an exception, this will try and instantiate it with information from the XFireFault (if
- * it exists).
+ * If the class is an exception, this will try and instantiate it with
+ * information from the XFireFault (if it exists).
*/
- protected Object createFromFault(Context context) throws SecurityException, InstantiationException,
+ protected Object createFromFault(Context context)
+ throws SecurityException, InstantiationException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Class<?> clazz = getTypeClass();
Constructor ctr;
@@ -211,28 +209,16 @@
Fault fault = context.getFault();
try {
- ctr = clazz.getConstructor(new Class[] {
- String.class, Throwable.class
- });
- o = ctr.newInstance(new Object[] {
- fault.getMessage(), fault
- });
+ ctr = clazz.getConstructor(new Class[] {String.class, Throwable.class});
+ o = ctr.newInstance(new Object[] {fault.getMessage(), fault});
} catch (NoSuchMethodException e) {
try {
- ctr = clazz.getConstructor(new Class[] {
- String.class, Exception.class
- });
- o = ctr.newInstance(new Object[] {
- fault.getMessage(), fault
- });
+ ctr = clazz.getConstructor(new Class[] {String.class, Exception.class});
+ o = ctr.newInstance(new Object[] {fault.getMessage(), fault});
} catch (NoSuchMethodException e1) {
try {
- ctr = clazz.getConstructor(new Class[] {
- String.class
- });
- o = ctr.newInstance(new Object[] {
- fault.getMessage()
- });
+ ctr = clazz.getConstructor(new Class[] {String.class});
+ o = ctr.newInstance(new Object[] {fault.getMessage()});
} catch (NoSuchMethodException e2) {
return clazz.newInstance();
}
@@ -249,7 +235,7 @@
throws DatabindingException {
if (object instanceof InterfaceInvocationHandler) {
- InterfaceInvocationHandler delegate = (InterfaceInvocationHandler)object;
+ InterfaceInvocationHandler delegate = (InterfaceInvocationHandler) object;
delegate.writeProperty(name.getLocalPart(), property);
return;
}
@@ -272,9 +258,7 @@
Class propertyType = desc.getPropertyType();
if ((property == null && !propertyType.isPrimitive()) || (property != null)) {
- m.invoke(object, new Object[] {
- property
- });
+ m.invoke(object, new Object[] {property});
}
} catch (Exception e) {
if (e instanceof DatabindingException) {
@@ -287,20 +271,18 @@
}
/**
- * This is a hack to get the write method from the implementation class for an interface.
+ * This is a hack to get the write method from the implementation class for
+ * an interface.
*/
private Method getWriteMethodFromImplClass(Class<?> impl, PropertyDescriptor pd) throws Exception {
String name = pd.getName();
name = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
- return impl.getMethod(name, new Class[] {
- pd.getPropertyType()
- });
+ return impl.getMethod(name, new Class[] {pd.getPropertyType()});
}
-
+
/**
* To avoid double-writing xsi:type attributes, ObjectType uses this special entrypoint.
- *
* @param object
* @param writer
* @param context
@@ -310,33 +292,38 @@
Context context, boolean wroteXsiType) {
writeObjectInternal(object, writer, context, wroteXsiType);
}
-
+
/**
* {@inheritDoc}
*/
@Override
- public void writeObject(Object object, MessageWriter writer,
- Context context) throws DatabindingException {
+ public void writeObject(Object object, MessageWriter writer, Context context)
+ throws DatabindingException {
writeObjectInternal(object, writer, context, false);
}
- private void writeObjectInternal(Object object, MessageWriter writer, Context context,
- boolean wroteXsiType) throws DatabindingException {
+ private void writeObjectInternal(Object object, MessageWriter writer, Context context,
+ boolean wroteXsiType)
+ throws DatabindingException {
if (object == null) {
return;
}
BeanTypeInfo inf = getTypeInfo();
- if (!wroteXsiType && object.getClass() == getTypeClass() && context.isWriteXsiTypes()) {
+ if (!wroteXsiType
+ && object.getClass() == getTypeClass()
+ && context.isWriteXsiTypes()) {
writer.writeXsiType(getSchemaType());
}
/*
- * TODO: Replace this method with one split into two pieces so that we can front-load the attributes
- * and traverse down the list of super classes.
+ * TODO: Replace this method with one split into two pieces so that we
+ * can front-load the attributes and traverse down the list of super
+ * classes.
*/
- for (QName name : inf.getAttributes()) {
+ for (Iterator itr = inf.getAttributes(); itr.hasNext();) {
+ QName name = (QName)itr.next();
Object value = readProperty(object, name);
if (value != null) {
@@ -355,7 +342,8 @@
}
}
- for (QName name : inf.getElements()) {
+ for (Iterator itr = inf.getElements(); itr.hasNext();) {
+ QName name = (QName)itr.next();
if (inf.isExtension()
&& inf.getPropertyDescriptorFromMappedName(name).getReadMethod().getDeclaringClass() != inf
@@ -427,6 +415,163 @@
}
}
+ /**
+ * @see org.apache.cxf.aegis.type.Type#writeSchema(org.jdom.Element)
+ */
+ @Override
+ public void writeSchema(Element root) {
+ BeanTypeInfo inf = getTypeInfo();
+ Element complex = new Element("complexType", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ complex.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
+ root.addContent(complex);
+
+ Type sooperType = getSuperType();
+
+ /*
+ * See Java Virtual Machine specification:
+ * http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
+ */
+ if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0)
+ && !inf.getTypeClass().isInterface()) {
+ complex.setAttribute(new Attribute("abstract", "true"));
+ }
+
+ if (inf.isExtension() && sooperType != null) {
+ Element complexContent = new Element("complexContent",
+ SOAPConstants.XSD_PREFIX,
+ SOAPConstants.XSD);
+ complex.addContent(complexContent);
+ complex = complexContent;
+ }
+
+ /*
+ * Decide if we're going to extend another type. If we are going to
+ * defer, then make sure that we extend the type for our superclass.
+ */
+ boolean isExtension = inf.isExtension();
+
+ Element dummy = complex;
+
+ if (isExtension && sooperType != null) {
+
+ Element extension = new Element("extension", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ complex.addContent(extension);
+ QName baseType = sooperType.getSchemaType();
+ extension.setAttribute(new Attribute("base", getNameWithPrefix2(root, baseType
+ .getNamespaceURI(), baseType.getLocalPart())));
+
+ dummy = extension;
+ }
+
+ Element seq = null;
+ boolean needXmime = false;
+ boolean needUtilityTypes = false;
+
+ // Write out schema for elements
+ for (Iterator itr = inf.getElements(); itr.hasNext();) {
+
+ QName name = (QName)itr.next();
+
+ if (isExtension) {
+ PropertyDescriptor pd = inf.getPropertyDescriptorFromMappedName(name);
+
+ assert pd.getReadMethod() != null && pd.getWriteMethod() != null;
+ if (pd.getReadMethod().getDeclaringClass() != inf.getTypeClass()) {
+ continue;
+ }
+ }
+
+ if (seq == null) {
+ seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ dummy.addContent(seq);
+ }
+
+ Element element = new Element("element", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ seq.addContent(element);
+
+ Type type = getType(inf, name);
+
+ String nameNS = name.getNamespaceURI();
+ String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());
+
+ String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());
+
+ writeTypeReference(name, nameWithPrefix, element, type, prefix, root);
+ needXmime |= type.usesXmime();
+ needUtilityTypes |= type.usesUtilityTypes();
+ }
+
+ if (needXmime) {
+ addXmimeToSchema(root);
+ }
+
+ if (needUtilityTypes) {
+ AegisContext.addUtilityTypesToSchema(root);
+ }
+
+ /**
+ * if future proof then add <xsd:any/> element
+ */
+ if (inf.isExtensibleElements()) {
+ if (seq == null) {
+ seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ dummy.addContent(seq);
+ }
+ seq.addContent(createAnyElement());
+ }
+
+ // Write out schema for attributes
+ for (Iterator itr = inf.getAttributes(); itr.hasNext();) {
+ QName name = (QName)itr.next();
+
+ Element element = new Element("attribute", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ dummy.addContent(element);
+
+ Type type = getType(inf, name);
+
+ String nameNS = name.getNamespaceURI();
+ String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());
+
+ String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());
+ element.setAttribute(new Attribute("name", nameWithPrefix));
+ element.setAttribute(TypeUtil.createTypeAttribute(prefix, type, root));
+ }
+
+ /**
+ * If extensible attributes then add <xsd:anyAttribute/>
+ */
+ if (inf.isExtensibleAttributes()) {
+ dummy.addContent(createAnyAttribute());
+ }
+ }
+
+ private String getNameWithPrefix(Element root, String nameNS, String localName) {
+ if (!"".equals(nameNS) && !nameNS.equals(getSchemaType().getNamespaceURI())) {
+ Element rootElement = (Element)root.getParent();
+ String prefix = null;
+ if (rootElement != null) { // can happen with doc/lit/bare
+ prefix = NamespaceHelper.getUniquePrefix(rootElement, nameNS);
+ }
+
+ if (prefix == null || prefix.length() == 0) {
+ prefix = NamespaceHelper.getUniquePrefix(root, nameNS);
+ }
+
+ return prefix + ":" + localName;
+ }
+ return localName;
+ }
+
+ private String getNameWithPrefix2(Element root, String nameNS, String localName) {
+ String prefix = NamespaceHelper.getUniquePrefix(root, nameNS);
+
+ if (prefix == null || prefix.length() == 0) {
+ prefix = NamespaceHelper.getUniquePrefix(root, nameNS);
+ }
+
+ return prefix + ":" + localName;
+ }
+
private Type getType(BeanTypeInfo inf, QName name) {
Type type = inf.getType(name);
@@ -438,22 +583,23 @@
return type;
}
- private void writeTypeReference(QName name, XmlSchemaElement element, Type type) {
+ private void writeTypeReference(QName name, String nameWithPrefix,
+ Element element, Type type, String prefix,
+ Element root) {
if (type.isAbstract()) {
- element.setName(name.getLocalPart());
- element.setSchemaTypeName(type.getSchemaType());
+ element.setAttribute(new Attribute("name", nameWithPrefix));
+ element.setAttribute(TypeUtil.createTypeAttribute(prefix, type, root));
int minOccurs = getTypeInfo().getMinOccurs(name);
- /*
- * Old code had ridiculous '!=0' here, which cannot have been right.
- */
- if (minOccurs != -1) {
- element.setMinOccurs(minOccurs);
+ if (minOccurs == 0) {
+ element.setAttribute(new Attribute("minOccurs", Integer.valueOf(minOccurs).toString()));
}
- element.setNillable(getTypeInfo().isNillable(name));
+ if (getTypeInfo().isNillable(name)) {
+ element.setAttribute(new Attribute("nillable", "true"));
+ }
} else {
- element.setRefName(type.getSchemaType());
+ element.setAttribute(new Attribute("ref", prefix + ':' + type.getSchemaType().getLocalPart()));
}
}
@@ -469,7 +615,7 @@
/**
* We need to write a complex type schema for Beans, so return true.
- *
+ *
* @see org.apache.cxf.aegis.type.Type#isComplex()
*/
@Override
@@ -486,11 +632,13 @@
BeanTypeInfo inf = getTypeInfo();
- for (QName name : inf.getAttributes()) {
+ for (Iterator itr = inf.getAttributes(); itr.hasNext();) {
+ QName name = (QName)itr.next();
deps.add(inf.getType(name));
}
- for (QName name : inf.getElements()) {
+ for (Iterator itr = inf.getElements(); itr.hasNext();) {
+ QName name = (QName)itr.next();
if (inf.isExtension()
&& inf.getPropertyDescriptorFromMappedName(name).getReadMethod().getDeclaringClass() != inf
.getTypeClass()) {
@@ -500,7 +648,7 @@
}
/*
- * Automagically add chain of superclassesif this is an an extension.
+ * Automagically add chain of superclasses *if* this is an an extension.
*/
if (inf.isExtension()) {
Type sooperType = getSuperType();
@@ -520,12 +668,11 @@
type = beanType.getTypeInfo().getType(name);
if (type == null) {
- Type superType = beanType.getSuperType(); /*
- * The class might inherit from, say, 'Integer'. In
- * which case we've got no BeanType to work with.
- */
+ Type superType = beanType.getSuperType(); /* The class might inherit from, say, 'Integer'.
+ In which case we've got no BeanType
+ to work with. */
if (superType instanceof BeanType) {
- beanType = (BeanType)superType;
+ beanType = (BeanType) superType;
} else {
break; // give up.
}
@@ -597,6 +744,19 @@
}
/**
+ * Create an element to represent any future elements that might get added
+ * to the schema <xsd:any minOccurs="0" maxOccurs="unbounded"/>
+ *
+ * @return
+ */
+ private Element createAnyElement() {
+ Element result = new Element("any", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ result.setAttribute(new Attribute("minOccurs", "0"));
+ result.setAttribute(new Attribute("maxOccurs", "unbounded"));
+ return result;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -615,8 +775,29 @@
return sb.toString();
}
- private void addXmimeToSchema(XmlSchema root) {
- XmlSchemaUtils.addImportIfNeeded(root, AbstractXOPType.XML_MIME_NS);
+ /**
+ * Create an element to represent any future attributes that might get added
+ * to the schema <xsd:anyAttribute/>
+ *
+ * @return
+ */
+ private Element createAnyAttribute() {
+ return new Element("anyAttribute", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ }
+
+ private void addXmimeToSchema(Element root) {
+ try {
+ Object node = AbstractXOPType.getXmimeXpathImport().selectSingleNode(root);
+ if (node != null) {
+ return;
+ }
+ } catch (JaxenException e) {
+ throw new RuntimeException(e);
+ }
+ Element element = new Element("import", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+ root.addContent(0, element);
+ element.setAttribute("namespace", AbstractXOPType.XML_MIME_NS);
+ root.addNamespaceDeclaration(Namespace.getNamespace("xmime", AbstractXOPType.XML_MIME_NS));
}
/**
@@ -640,113 +821,4 @@
info.setTypeMapping(typeMapping);
}
}
-
- @Override
- public void writeSchema(XmlSchema root) {
- BeanTypeInfo inf = getTypeInfo();
- XmlSchemaComplexType complex = new XmlSchemaComplexType(root);
- complex.setName(getSchemaType().getLocalPart());
- root.addType(complex);
- root.getItems().add(complex);
-
- Type sooperType = getSuperType();
-
- /*
- * See Java Virtual Machine specification:
- * http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
- */
- if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0)
- && !inf.getTypeClass().isInterface()) {
- complex.setAbstract(true);
- }
-
- XmlSchemaSequence sequence = new XmlSchemaSequence();
- /*
- * Decide if we're going to extend another type. If we are going to defer, then make sure that we
- * extend the type for our superclass.
- */
- boolean isExtension = inf.isExtension();
-
- if (isExtension && sooperType != null) {
- // if sooperType is null, things are confused.
- XmlSchemaComplexContent content = new XmlSchemaComplexContent();
- complex.setContentModel(content);
- XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
- content.setContent(extension);
- extension.setBaseTypeName(sooperType.getSchemaType());
- extension.setParticle(sequence);
- } else {
- complex.setParticle(sequence);
- }
-
- boolean needXmime = false;
- boolean needUtilityTypes = false;
-
- // Write out schema for elements
- for (QName name : inf.getElements()) {
-
- if (isExtension) {
- PropertyDescriptor pd = inf.getPropertyDescriptorFromMappedName(name);
-
- // assert pd.getReadMethod() != null && pd.getWriteMethod() != null;
-
- if (pd.getReadMethod().getDeclaringClass() != inf.getTypeClass()) {
- continue;
- }
- }
-
- XmlSchemaElement element = new XmlSchemaElement();
- element.setName(name.getLocalPart());
- sequence.getItems().add(element);
-
- Type type = getType(inf, name);
- if (AbstractTypeCreator.
- HTTP_CXF_APACHE_ORG_ARRAYS.equals(type.getSchemaType().getNamespaceURI())) {
- XmlSchemaUtils.addImportIfNeeded(root, AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS);
- }
-
- writeTypeReference(name, element, type);
- needXmime |= type.usesXmime();
- needUtilityTypes |= type.usesUtilityTypes();
- }
-
- if (needXmime) {
- addXmimeToSchema(root);
- }
-
- if (needUtilityTypes) {
- AegisContext.addUtilityTypesToSchema(root);
- }
-
- /**
- * if future proof then add <xsd:any/> element
- */
- if (inf.isExtensibleElements()) {
- XmlSchemaAny any = new XmlSchemaAny();
- any.setMinOccurs(0);
- any.setMaxOccurs(Long.MAX_VALUE);
- sequence.getItems().add(any);
- }
-
- // Write out schema for attributes
- for (QName name : inf.getAttributes()) {
- XmlSchemaAttribute attribute = new XmlSchemaAttribute();
- complex.getAttributes().add(attribute);
- attribute.setName(name.getLocalPart());
- Type type = getType(inf, name);
- attribute.setSchemaTypeName(type.getSchemaType());
- String ns = name.getNamespaceURI();
- if (!ns.equals(root.getTargetNamespace())) {
- XmlSchemaUtils.addImportIfNeeded(root, ns);
- }
- }
-
- /**
- * If extensible attributes then add <xsd:anyAttribute/>
- */
- if (inf.isExtensibleAttributes()) {
- sequence.getItems().add(new XmlSchemaAnyAttribute());
- }
- }
-
}