You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2006/09/10 21:01:38 UTC
svn commit: r441986 - in /incubator/tuscany/java:
samples/sca/echo.databinding/src/test/resources/META-INF/tuscany/
sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/
sca/idl/wsdl/ sca/idl/wsdl/src/main/java/org/...
Author: rfeng
Date: Sun Sep 10 12:01:37 2006
New Revision: 441986
URL: http://svn.apache.org/viewvc?view=rev&rev=441986
Log:
Add XML schema loading with Apache XmlSchema to WSDL IDL to introspect JAX-WS Wrapper Style operation
Added:
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperation.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java (with props)
incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd (with props)
incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl
Modified:
incubator/tuscany/java/samples/sca/echo.databinding/src/test/resources/META-INF/tuscany/test-interface-wsdl.scdl
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java
incubator/tuscany/java/sca/idl/wsdl/pom.xml
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java
incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java
incubator/tuscany/java/sca/idl/wsdl/src/main/resources/META-INF/tuscany/interface-wsdl.scdl
incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java
incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java
Modified: incubator/tuscany/java/samples/sca/echo.databinding/src/test/resources/META-INF/tuscany/test-interface-wsdl.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sca/echo.databinding/src/test/resources/META-INF/tuscany/test-interface-wsdl.scdl?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/samples/sca/echo.databinding/src/test/resources/META-INF/tuscany/test-interface-wsdl.scdl (original)
+++ incubator/tuscany/java/samples/sca/echo.databinding/src/test/resources/META-INF/tuscany/test-interface-wsdl.scdl Sun Sep 10 12:01:37 2006
@@ -33,6 +33,10 @@
<system:implementation.system class="org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl" initLevel="40" />
</component>
+ <component name="xmlSchema.registry">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.XMLSchemaRegistryImpl" initLevel="35" />
+ </component>
+
<component name="interface.wsdl.Introspector">
<system:implementation.system class="org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospectorImpl" initLevel="40" />
</component>
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java Sun Sep 10 12:01:37 2006
@@ -38,6 +38,7 @@
import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl;
import org.apache.tuscany.idl.wsdl.WSDLServiceContract;
+import org.apache.tuscany.idl.wsdl.XMLSchemaRegistryImpl;
public class RhinoScriptIntrospectorTestCase extends TestCase {
@@ -92,6 +93,7 @@
RhinoSCAConfig scaConfig = new RhinoSCAConfig(rs.getScriptScope());
WSDLDefinitionRegistryImpl wsdlReg = new WSDLDefinitionRegistryImpl();
+ wsdlReg.setSchemaRegistry(new XMLSchemaRegistryImpl());
wsdlReg.setMonitor(NULL_MONITOR);
URL wsdlURL =
getClass().getClassLoader().getResource("org/apache/tuscany/container/javascript/rhino/helloworld.wsdl");
Modified: incubator/tuscany/java/sca/idl/wsdl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/pom.xml?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/pom.xml (original)
+++ incubator/tuscany/java/sca/idl/wsdl/pom.xml Sun Sep 10 12:01:37 2006
@@ -50,6 +50,13 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.ws.commons</groupId>
+ <artifactId>XmlSchema</artifactId>
+ <version>SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
</dependency>
Modified: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java (original)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java Sun Sep 10 12:01:37 2006
@@ -34,6 +34,7 @@
import javax.wsdl.PortType;
import javax.xml.namespace.QName;
+import org.apache.tuscany.spi.annotation.Autowire;
import org.apache.tuscany.spi.idl.InvalidServiceContractException;
import org.apache.tuscany.spi.model.DataType;
import org.apache.tuscany.spi.model.InteractionScope;
@@ -44,10 +45,22 @@
*/
public class InterfaceWSDLIntrospectorImpl implements InterfaceWSDLIntrospector {
public static final String INPUT_PARTS = "idl:input";
+
public static final String IDL_WSDL_DOCUMENT_LITERAL_WRPPED = "idl.wsdl.documentLiteralWrpped";
+
+ private WSDLDefinitionRegistry wsdlDefinitionRegistry;
+
private String defaultDataBinding = "org.w3c.dom.Node"; // Default to DOM binding?
- @Property(name="defaultDataBinding")
+ /**
+ * @param wsdlDefinitionRegistry
+ */
+ public InterfaceWSDLIntrospectorImpl(@Autowire WSDLDefinitionRegistry wsdlDefinitionRegistry) {
+ super();
+ this.wsdlDefinitionRegistry = wsdlDefinitionRegistry;
+ }
+
+ @Property(name = "defaultDataBinding")
public void setDefaultDataBinding(String defaultDataBinding) {
this.defaultDataBinding = defaultDataBinding;
}
@@ -55,57 +68,68 @@
// FIXME: Do we want to deal with document-literal wrapped style based on the JAX-WS spec?
protected Map<String, org.apache.tuscany.spi.model.Operation<QName>> introspectOperations(PortType portType)
throws NotSupportedWSDLException {
- boolean oneway = false;
Map<String, org.apache.tuscany.spi.model.Operation<QName>> operations =
- new HashMap<String, org.apache.tuscany.spi.model.Operation<QName>>();
+ new HashMap<String, org.apache.tuscany.spi.model.Operation<QName>>();
for (Object op : portType.getOperations()) {
Operation wsdlOp = (Operation) op;
- String name = wsdlOp.getName();
+ operations.put(wsdlOp.getName(), introspectOperation(wsdlOp));
+ }
+ return operations;
+ }
- Input input = wsdlOp.getInput();
- Message inputMsg = (input == null) ? null : input.getMessage();
- DataType<List<DataType<QName>>> inputType = introspectType(inputMsg);
-
- Message outputMsg;
- Output output = wsdlOp.getOutput();
- if (output == null) {
- // TODO: [rfeng] Is this the correct way to determine if it's non-blocking?
- oneway = true;
- }
- outputMsg = (output == null) ? null : output.getMessage();
+ protected org.apache.tuscany.spi.model.Operation<QName> introspectOperation(Operation wsdlOp)
+ throws NotSupportedWSDLException {
+
+ Input input = wsdlOp.getInput();
+ Message inputMsg = (input == null) ? null : input.getMessage();
+ DataType<List<DataType<QName>>> inputType = introspectType(inputMsg);
+
+ Message outputMsg;
+ Output output = wsdlOp.getOutput();
+ boolean oneway = false;
+ if (output == null) {
+ // TODO: [rfeng] Is this the correct way to determine if it's non-blocking?
+ oneway = true;
+ }
+ outputMsg = (output == null) ? null : output.getMessage();
- List outputParts = (outputMsg == null) ? null : outputMsg.getOrderedParts(null);
- DataType<QName> outputType = null;
- if (outputParts != null || outputParts.size() > 0) {
- if (outputParts.size() > 1) {
- // We don't support output with multiple parts
- throw new NotSupportedWSDLException("Multi-part output is not supported");
- }
- Part part = (Part) outputParts.get(0);
- outputType = introspectType(part);
+ List outputParts = (outputMsg == null) ? null : outputMsg.getOrderedParts(null);
+ DataType<QName> outputType = null;
+ if (outputParts != null || outputParts.size() > 0) {
+ if (outputParts.size() > 1) {
+ // We don't support output with multiple parts
+ throw new NotSupportedWSDLException("Multi-part output is not supported");
}
+ Part part = (Part) outputParts.get(0);
+ outputType = introspectType(part);
+ }
- Collection faults = wsdlOp.getFaults().values();
- List<DataType<QName>> faultTypes = new ArrayList<DataType<QName>>();
- for (Object f : faults) {
- Fault fault = (Fault) f;
- Message faultMsg = fault.getMessage();
- List faultParts = faultMsg.getOrderedParts(null);
- if (faultParts.size() != 1) {
- throw new NotSupportedWSDLException("The fault message MUST have a single part");
- }
- Part part = (Part) faultParts.get(0);
- // A fault is typed by a message
- DataType<QName> dataType = introspectType(part);
- faultTypes.add(dataType);
+ Collection faults = wsdlOp.getFaults().values();
+ List<DataType<QName>> faultTypes = new ArrayList<DataType<QName>>();
+ for (Object f : faults) {
+ Fault fault = (Fault) f;
+ Message faultMsg = fault.getMessage();
+ List faultParts = faultMsg.getOrderedParts(null);
+ if (faultParts.size() != 1) {
+ throw new NotSupportedWSDLException("The fault message MUST have a single part");
}
+ Part part = (Part) faultParts.get(0);
+ // A fault is typed by a message
+ DataType<QName> dataType = introspectType(part);
+ faultTypes.add(dataType);
+ }
- // FIXME: [rfeng] How to figure the nonBlocking and dataBinding?
- org.apache.tuscany.spi.model.Operation<QName> operation =
- new org.apache.tuscany.spi.model.Operation<QName>(name, inputType, outputType, faultTypes, oneway, defaultDataBinding);
- operations.put(name, operation);
+ org.apache.tuscany.spi.model.Operation<QName> operation =
+ new org.apache.tuscany.spi.model.Operation<QName>(wsdlOp.getName(), inputType, outputType, faultTypes,
+ oneway, defaultDataBinding);
+
+ WrapperStyleOperation wrapperStyleOperation =
+ new WrapperStyleOperation(wsdlOp, wsdlDefinitionRegistry.getSchemaRegistry());
+ if (wrapperStyleOperation.isWrapperStyle()) {
+ operation.addMetaData(WrapperStyleOperation.class.getName(), wrapperStyleOperation);
}
- return operations;
+ return operation;
+
}
protected DataType<List<DataType<QName>>> introspectType(Message message) {
@@ -118,7 +142,8 @@
dataTypes.add(dataType);
}
}
- DataType<List<DataType<QName>>> msgType = new DataType<List<DataType<QName>>>(INPUT_PARTS, Object.class, dataTypes);
+ DataType<List<DataType<QName>>> msgType =
+ new DataType<List<DataType<QName>>>(INPUT_PARTS, Object.class, dataTypes);
msgType.setMetadata(IDL_WSDL_DOCUMENT_LITERAL_WRPPED, Boolean.FALSE);
return msgType;
}
@@ -151,7 +176,7 @@
*/
public WSDLServiceContract introspect(PortType portType, PortType callbackPortType)
throws InvalidServiceContractException {
- assert portType!=null: "PortType cannot be null";
+ assert portType != null : "PortType cannot be null";
WSDLServiceContract contract = new WSDLServiceContract();
// FIXME: set to Non-conversational for now
contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL);
@@ -165,6 +190,5 @@
}
return contract;
}
-
}
Modified: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java (original)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java Sun Sep 10 12:01:37 2006
@@ -41,21 +41,24 @@
/**
* Loads a WSDL interface definition from an XML-based assembly file
- *
+ *
* @version $Rev$ $Date$
*/
public class InterfaceWSDLLoader extends LoaderExtension {
public static final QName INTERFACE_WSDL = new QName(XML_NAMESPACE_1_0, "interface.wsdl");
+
private static final String WSDLI = "http://www.w3.org/2006/01/wsdl-instance";
+
private static final String WSDLI_LOCATION = "wsdlLocation";
private WSDLDefinitionRegistry wsdlRegistry;
+
private InterfaceWSDLIntrospector introspector;
- @Constructor( { "registry", "wsdlRegistry", "introspector" })
+ @Constructor ({ "registry", "wsdlRegistry", "introspector" })
public InterfaceWSDLLoader(@Autowire LoaderRegistry registry,
- @Autowire WSDLDefinitionRegistry wsdlRegistry,
- @Autowire InterfaceWSDLIntrospector introspector) {
+ @Autowire WSDLDefinitionRegistry wsdlRegistry,
+ @Autowire InterfaceWSDLIntrospector introspector) {
super(registry);
this.wsdlRegistry = wsdlRegistry;
this.introspector = introspector;
@@ -65,10 +68,10 @@
return INTERFACE_WSDL;
}
- public WSDLServiceContract load(CompositeComponent parent,
- XMLStreamReader reader,
- DeploymentContext deploymentContext)
- throws XMLStreamException, LoaderException {
+ public WSDLServiceContract load(
+ CompositeComponent parent,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
assert INTERFACE_WSDL.equals(reader.getName());
String interfaceURI = reader.getAttributeValue(null, "interface");
@@ -79,7 +82,7 @@
String callbackURI = reader.getAttributeValue(null, "callbackInterface");
String wsdlLocation = reader.getAttributeValue(WSDLI, WSDLI_LOCATION);
// FIXME set the interaction scope
-// serviceContract.setInteractionScope(StAXUtil.interactionScope(reader.getAttributeValue(null, "scope")));
+ // serviceContract.setInteractionScope(StAXUtil.interactionScope(reader.getAttributeValue(null, "scope")));
LoaderUtil.skipToEndElement(reader);
if (wsdlLocation != null) {
@@ -118,7 +121,7 @@
int index = uri.indexOf('#');
String namespace = uri.substring(0, index);
String name = uri.substring(index + 1);
- name = name.substring("wsdl.interface(".length(), name.length()-1);
+ name = name.substring("wsdl.interface(".length(), name.length() - 1);
QName qname = new QName(namespace, name);
return wsdlRegistry.getPortType(qname);
}
Modified: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java (original)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java Sun Sep 10 12:01:37 2006
@@ -79,4 +79,11 @@
* @return the ExtensionRegistry that is used when parsing WSDL documents.
*/
ExtensionRegistry getExtensionRegistry();
+
+ /**
+ * Get the XMLSchemaRegistry
+ *
+ * @return
+ */
+ XMLSchemaRegistry getSchemaRegistry();
}
Modified: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java (original)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java Sun Sep 10 12:01:37 2006
@@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import javax.wsdl.Definition;
+import javax.wsdl.Import;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.WSDLException;
@@ -35,25 +36,36 @@
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
+import org.apache.tuscany.spi.annotation.Autowire;
+
/**
* The default implementation of the runtime WSDL registry
- *
+ *
* @version $Rev$ $Date$
*/
public class WSDLDefinitionRegistryImpl implements WSDLDefinitionRegistry {
private final WSDLFactory wsdlFactory;
+
private final ExtensionRegistry registry;
private final Map<URL, Definition> definitionsByLocation = new HashMap<URL, Definition>();
+
private final Map<String, List<Definition>> definitionsByNamespace = new HashMap<String, List<Definition>>();
private Monitor monitor;
+ private XMLSchemaRegistry schemaRegistry;
+
public WSDLDefinitionRegistryImpl() throws WSDLException {
wsdlFactory = WSDLFactory.newInstance();
registry = wsdlFactory.newPopulatedExtensionRegistry();
}
+ @Autowire
+ public void setSchemaRegistry(XMLSchemaRegistry schemaRegistry) {
+ this.schemaRegistry = schemaRegistry;
+ }
+
@org.apache.tuscany.api.annotation.Monitor
public void setMonitor(Monitor monitor) {
this.monitor = monitor;
@@ -94,7 +106,9 @@
return definition;
}
- monitor.readingWSDL(namespace, location);
+ if (monitor != null) {
+ monitor.readingWSDL(namespace, location);
+ }
WSDLReader reader = wsdlFactory.newWSDLReader();
reader.setFeature("javax.wsdl.verbose", false);
reader.setExtensionRegistry(registry);
@@ -102,11 +116,23 @@
definition = reader.readWSDL(location.toString());
String definitionNamespace = definition.getTargetNamespace();
if (namespace != null && !namespace.equals(definitionNamespace)) {
- throw new WSDLException(WSDLException.CONFIGURATION_ERROR,
- namespace + " != " + definition.getTargetNamespace());
+ throw new WSDLException(WSDLException.CONFIGURATION_ERROR, namespace + " != "
+ + definition.getTargetNamespace());
}
- monitor.cachingDefinition(definitionNamespace, location);
+ // Load inline schemas
+ getSchemaRegistry().loadSchemas(definition);
+ for (Object i : definition.getImports().values()) {
+ Import imp = (Import) i;
+ Definition imported = imp.getDefinition();
+ if (imported != null) {
+ getSchemaRegistry().loadSchemas(imported);
+ }
+ }
+
+ if (monitor != null) {
+ monitor.cachingDefinition(definitionNamespace, location);
+ }
definitionsByLocation.put(location, definition);
List<Definition> definitions = definitionsByNamespace.get(definitionNamespace);
if (definitions == null) {
@@ -152,19 +178,27 @@
/**
* Monitor event emitted immediately before an attempt is made to read WSDL for the supplied namespace from the
* supplied location.
- *
+ *
* @param namespace the target namespace expected in the WSDL; may be null
- * @param location the location where we will attempt to read the WSDL definition from
+ * @param location the location where we will attempt to read the WSDL definition from
*/
void readingWSDL(String namespace, URL location);
/**
* Monitor event emitted immediately before registering a WSDL definition in the cache.
- *
+ *
* @param namespace the target namespace for the WSDL
- * @param location the location where the WSDL definition was read from
+ * @param location the location where the WSDL definition was read from
*/
void cachingDefinition(String namespace, URL location);
+ }
+
+ public XMLSchemaRegistry getSchemaRegistry() {
+ if (schemaRegistry == null) {
+ // Default
+ schemaRegistry = new XMLSchemaRegistryImpl();
+ }
+ return schemaRegistry;
}
}
Added: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperation.java?view=auto&rev=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperation.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperation.java Sun Sep 10 12:01:37 2006
@@ -0,0 +1,206 @@
+/*
+ * 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.tuscany.idl.wsdl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Output;
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * The "Wrapper Style" WSDL operation is defined by The Java API for XML-Based Web Services (JAX-WS) 2.0 specification,
+ * section 2.3.1.2 Wrapper Style.
+ * <p>
+ * A WSDL operation qualifies for wrapper style mapping only if the following criteria are met:
+ * <ul>
+ * <li>(i) The operations input and output messages (if present) each contain only a single part
+ * <li>(ii) The input message part refers to a global element declaration whose localname is equal to the operation
+ * name
+ * <li>(iii) The output message part refers to a global element declaration
+ * <li>(iv) The elements referred to by the input and output message parts (henceforth referred to as wrapper elements)
+ * are both complex types defined using the xsd:sequence compositor
+ * <li>(v) The wrapper elements only contain child elements, they must not contain other structures such as wildcards
+ * (element or attribute), xsd:choice, substitution groups (element references are not permitted) or attributes;
+ * furthermore, they must not be nillable.
+ * </ul>
+ */
+public class WrapperStyleOperation {
+ private XMLSchemaRegistry schemaRegistry;
+
+ private Operation operation;
+
+ private List<XmlSchemaElement> inputElements;
+
+ private List<XmlSchemaElement> outputElements;
+
+ /**
+ * @param operation
+ * @param schemaRegistry
+ */
+ public WrapperStyleOperation(Operation operation, XMLSchemaRegistry schemaRegistry) {
+ super();
+ this.operation = operation;
+ this.schemaRegistry = schemaRegistry;
+ }
+
+ /**
+ * Test if the operation qualifies wrapper style as defined by the JAX-WS 2.0 spec
+ *
+ * @return true if the operation qualifies wrapper style, otherwise false
+ */
+ public boolean isWrapperStyle() {
+ return getInputChildElements() != null && (operation.getOutput() == null || getOutputChildElements() != null);
+ }
+
+ private List<XmlSchemaElement> getChildElements(QName elementName) {
+ XmlSchemaElement element = schemaRegistry.getElement(elementName);
+ if (element == null) {
+ return null;
+ }
+ XmlSchemaType type = element.getSchemaType();
+ if (!(type instanceof XmlSchemaComplexType)) {
+ // Has to be a complexType
+ return null;
+ }
+ XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+ if (complexType.getAttributes().getCount() != 0 || complexType.getAnyAttribute() != null) {
+ // No attributes
+ return null;
+ }
+ XmlSchemaParticle particle = complexType.getParticle();
+ if (particle == null) {
+ // No particle
+ return Collections.emptyList();
+ }
+ if (!(particle instanceof XmlSchemaSequence)) {
+ return null;
+ }
+ XmlSchemaSequence sequence = (XmlSchemaSequence) complexType.getParticle();
+ XmlSchemaObjectCollection items = sequence.getItems();
+ List<XmlSchemaElement> childElements = new ArrayList<XmlSchemaElement>();
+ for (int i = 0; i < items.getCount(); i++) {
+ XmlSchemaObject schemaObject = items.getItem(i);
+ if (!(schemaObject instanceof XmlSchemaElement)) {
+ return null;
+ }
+ XmlSchemaElement childElement = (XmlSchemaElement) schemaObject;
+ if (childElement.getName() == null || childElement.getRefName() != null || childElement.isNillable()) {
+ return null;
+ }
+ // TODO: Do we support maxOccurs >1 ?
+ if (childElement.getMaxOccurs() > 1) {
+ return null;
+ }
+ childElements.add(childElement);
+ }
+ return childElements;
+ }
+
+ /**
+ * Return a list of child XSD elements under the wrapped request element
+ *
+ * @return a list of child XSD elements or null if if the request element is not wrapped
+ */
+ public List<XmlSchemaElement> getInputChildElements() {
+ if (inputElements != null) {
+ return inputElements;
+ }
+ Input input = operation.getInput();
+ if (input != null) {
+ Message inputMsg = input.getMessage();
+ Collection parts = inputMsg.getParts().values();
+ if (parts.size() != 1) {
+ return null;
+ }
+ Part part = (Part) parts.iterator().next();
+ QName elementName = part.getElementName();
+ if (elementName == null) {
+ return null;
+ }
+ if (!operation.getName().equals(elementName.getLocalPart())) {
+ return null;
+ }
+ inputElements = getChildElements(elementName);
+ return inputElements;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Return a list of child XSD elements under the wrapped response element
+ *
+ * @return a list of child XSD elements or null if if the response element is not wrapped
+ */
+ public List<XmlSchemaElement> getOutputChildElements() {
+ if (outputElements != null) {
+ return outputElements;
+ }
+ Output output = operation.getOutput();
+ if (output != null) {
+ Message outputMsg = output.getMessage();
+ Collection parts = outputMsg.getParts().values();
+ if (parts.size() != 1) {
+ return null;
+ }
+ Part part = (Part) parts.iterator().next();
+ QName elementName = part.getElementName();
+ if (elementName == null) {
+ return null;
+ }
+ outputElements = getChildElements(elementName);
+ // FIXME: Do we support multiple child elements for the response?
+ return outputElements;
+ } else {
+ return null;
+ }
+ }
+
+ public List<XmlSchemaObject> getMessageSignature(Message message) {
+ List<XmlSchemaObject> signature = new ArrayList<XmlSchemaObject>();
+ Collection parts = message.getOrderedParts(null);
+ for (Object p : parts) {
+ Part part = (Part) p;
+ QName elementName = part.getElementName();
+ if (elementName != null) {
+ signature.add(schemaRegistry.getElement(elementName));
+ } else {
+ // QName name = new QName(null, part.getName());
+ signature.add(schemaRegistry.getType(part.getTypeName()));
+ }
+ }
+ return signature;
+ }
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperation.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java?view=auto&rev=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java Sun Sep 10 12:01:37 2006
@@ -0,0 +1,87 @@
+/*
+ * 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.tuscany.idl.wsdl;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import javax.wsdl.Definition;
+import javax.xml.namespace.QName;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaException;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * A service for caching XML Schemas
+ *
+ * @version $Rev$ $Date$
+ */
+public interface XMLSchemaRegistry {
+ /**
+ * Load all inline schemas from the WSDL definition
+ *
+ * @param definition The WSDL defintion whose types element contains a list of schemas
+ * @return A list of inline schemas
+ */
+ List<XmlSchema> loadSchemas(Definition definition);
+
+ /**
+ * Loads and registers a XML schema.
+ *
+ * @param namespace the expected namespace, or null if any namespace should be allowed
+ * @param location the location to load the schema from
+ * @return the loaded Definition
+ * @throws IOException if there was a problem reading the document
+ * @throws XmlSchemaException if there was a problem parsing the schema
+ */
+ XmlSchema loadSchema(String namespace, URL location) throws IOException, XmlSchemaException;
+
+ /**
+ * Load and register a XML schema as specified in a XSD schemaLocation attribute.
+ *
+ * @param schemaLocation the value of the schemaLocation attribute
+ * @param classLoader application classloader used to support relative locations
+ * @return the loaded schema
+ * @throws IOException if there was a problem reading the document
+ * @throws XmlSchemaException if there was a problem parsing the schema
+ */
+ XmlSchema loadSchema(String schemaLocation, ClassLoader classLoader) throws IOException, XmlSchemaException;
+
+ /**
+ * Returns the XSD Element with the supplied qualified name, or null if no such element has been defined.
+ *
+ * @param name the qualified name of the XSD element
+ * @return the XSD element for the supplied name, or null if none has been defined
+ */
+ XmlSchemaElement getElement(QName name);
+
+ /**
+ * Returns the XmlSchemaType with the supplied qualified name, or null if no such type has been defined.
+ *
+ * @param name the qualified name of the XSD type
+ * @return the XSD type for the supplied name, or null if none has been defined
+ */
+ XmlSchemaType getType(QName name);
+
+
+
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java?view=auto&rev=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java Sun Sep 10 12:01:37 2006
@@ -0,0 +1,126 @@
+/*
+ * 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.tuscany.idl.wsdl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Types;
+import javax.wsdl.extensions.schema.Schema;
+import javax.xml.namespace.QName;
+
+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.XmlSchemaException;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Element;
+
+/**
+ * Default implementation of XMLSchemaRegistry
+ */
+@Service(XMLSchemaRegistry.class)
+public class XMLSchemaRegistryImpl implements XMLSchemaRegistry {
+ private final XmlSchemaCollection collection;
+
+ /**
+ * @param collection
+ */
+ public XMLSchemaRegistryImpl(XmlSchemaCollection collection) {
+ super();
+ this.collection = collection;
+ }
+
+ public XMLSchemaRegistryImpl() {
+ super();
+ this.collection = new XmlSchemaCollection();
+ }
+
+ public XmlSchemaElement getElement(QName name) {
+ return collection.getElementByQName(name);
+ }
+
+ public XmlSchemaType getType(QName name) {
+ return collection.getTypeByQName(name);
+ }
+
+ public List<XmlSchema> loadSchemas(Definition definition) {
+ Types types = definition.getTypes();
+ if (types == null) {
+ return Collections.emptyList();
+ }
+ List<XmlSchema> schemas = new ArrayList<XmlSchema>();
+ for (Object ext : types.getExtensibilityElements()) {
+ if (ext instanceof Schema) {
+ Element element = ((Schema) ext).getElement();
+ XmlSchema s = collection.read(element);
+ schemas.add(s);
+ }
+ }
+ return schemas;
+ }
+
+ public XmlSchema loadSchema(String namespace, URL location) throws IOException, XmlSchemaException {
+ XmlSchema schema = collection.getXmlSchema(location.toExternalForm());
+ if (schema == null) {
+ InputStream is = location.openStream();
+ schema = collection.read(new InputStreamReader(is), null);
+ is.close();
+ }
+ if (namespace != null && schema != null && !namespace.equals(schema.getTargetNamespace())) {
+ throw new XmlSchemaException(namespace + " != " + schema.getTargetNamespace());
+ }
+ return schema;
+ }
+
+ public XmlSchema loadSchema(String schemaLocation, ClassLoader classLoader) throws IOException, XmlSchemaException {
+ int index = schemaLocation.indexOf(' ');
+ if (index == -1) {
+ throw new XmlSchemaException("Invalid schemaLocation: " + schemaLocation);
+ }
+ String namespace = schemaLocation.substring(0, index).trim();
+ URL url;
+ URI uri;
+ try {
+ uri = new URI(schemaLocation.substring(index + 1).trim());
+ } catch (URISyntaxException e) {
+ throw new XmlSchemaException("Invalid schemaLocation: " + schemaLocation);
+ }
+ if (uri.isAbsolute()) {
+ url = uri.toURL();
+ } else {
+ url = classLoader.getResource(uri.toString());
+ if (url == null) {
+ throw new XmlSchemaException("Resource cannot be resolved: schemaLocation: " + schemaLocation);
+ }
+ }
+ return loadSchema(namespace, url);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/idl/wsdl/src/main/resources/META-INF/tuscany/interface-wsdl.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/main/resources/META-INF/tuscany/interface-wsdl.scdl?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/main/resources/META-INF/tuscany/interface-wsdl.scdl (original)
+++ incubator/tuscany/java/sca/idl/wsdl/src/main/resources/META-INF/tuscany/interface-wsdl.scdl Sun Sep 10 12:01:37 2006
@@ -33,6 +33,10 @@
<system:implementation.system class="org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl" initLevel="40" />
</component>
+ <component name="xmlSchema.registry">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.XMLSchemaRegistryImpl" initLevel="35" />
+ </component>
+
<component name="interface.wsdl.Introspector">
<system:implementation.system class="org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospectorImpl" initLevel="40" />
</component>
Modified: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java (original)
+++ incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java Sun Sep 10 12:01:37 2006
@@ -25,23 +25,22 @@
import javax.wsdl.Definition;
import javax.wsdl.PortType;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
import org.apache.tuscany.spi.idl.InvalidServiceContractException;
import org.apache.tuscany.spi.model.DataType;
import org.apache.tuscany.spi.model.Operation;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
/**
- *
+ * Test case for InterfaceWSDLIntrospectorImpl
*/
public class InterfaceWSDLIntrospectorImplTestCase extends TestCase {
private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType");
+ private WSDLDefinitionRegistryImpl registry;
private PortType portType;
/**
@@ -49,16 +48,15 @@
*/
protected void setUp() throws Exception {
super.setUp();
- WSDLFactory factory = WSDLFactory.newInstance();
+ registry = new WSDLDefinitionRegistryImpl();
+ registry.setSchemaRegistry(new XMLSchemaRegistryImpl());
URL url = getClass().getResource("stockquote.wsdl");
- WSDLReader reader = factory.newWSDLReader();
- reader.setFeature("javax.wsdl.verbose", false);
- Definition definition = reader.readWSDL(url.toExternalForm());
+ Definition definition = registry.loadDefinition(null, url);
portType = definition.getPortType(PORTTYPE_NAME);
}
public final void testIntrospectPortType() throws InvalidServiceContractException {
- InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl();
+ InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl(registry);
WSDLServiceContract contract = introspector.introspect(portType);
Assert.assertEquals(contract.getInterfaceName(), "StockQuotePortType");
Map<String, Operation<QName>> operations = contract.getOperations();
@@ -70,10 +68,15 @@
DataType<QName> returnType = operation.getOutputType();
Assert.assertNotNull(returnType);
Assert.assertEquals(0, operation.getFaultTypes().size());
+ WrapperStyleOperation op =
+ (WrapperStyleOperation) operation.getMetaData().get(WrapperStyleOperation.class.getName());
+ Assert.assertNotNull(op);
+ Assert.assertEquals(1, op.getInputChildElements().size());
+ Assert.assertEquals(1, op.getOutputChildElements().size());
}
public final void testIntrospectPortTypePortType() throws InvalidServiceContractException {
- InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl();
+ InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl(registry);
WSDLServiceContract contract = introspector.introspect(portType, portType);
Assert.assertEquals("StockQuotePortType", contract.getInterfaceName());
Assert.assertEquals("StockQuotePortType", contract.getCallbackName());
Modified: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java?view=diff&rev=441986&r1=441985&r2=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java (original)
+++ incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java Sun Sep 10 12:01:37 2006
@@ -71,6 +71,7 @@
protected void setUp() throws Exception {
super.setUp();
wsdlRegistry = new WSDLDefinitionRegistryImpl();
+ wsdlRegistry.setSchemaRegistry(new XMLSchemaRegistryImpl());
wsdlRegistry.setMonitor(NULL_MONITOR);
exampleWsdl = getClass().getResource("example.wsdl");
cl = getClass().getClassLoader();
Added: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java?view=auto&rev=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java Sun Sep 10 12:01:37 2006
@@ -0,0 +1,76 @@
+/*
+ * 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.tuscany.idl.wsdl;
+
+import java.net.URL;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test case for WrapperStyleOperation
+ */
+public class WrapperStyleOperationTestCase extends TestCase {
+ private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType");
+
+ private WSDLDefinitionRegistryImpl registry;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new WSDLDefinitionRegistryImpl();
+ registry.setSchemaRegistry(new XMLSchemaRegistryImpl());
+ }
+
+ public final void testWrappedOperation() throws Exception {
+ URL url = getClass().getResource("stockquote.wsdl");
+ Definition definition = registry.loadDefinition(null, url);
+ PortType portType = definition.getPortType(PORTTYPE_NAME);
+ Operation operation = portType.getOperation("getLastTradePrice", null, null);
+ WrapperStyleOperation op = new WrapperStyleOperation(operation, registry.getSchemaRegistry());
+ Assert.assertTrue(op.isWrapperStyle());
+ Assert.assertEquals(1, op.getInputChildElements().size());
+ Assert.assertEquals(1, op.getOutputChildElements().size());
+ }
+
+ public final void testUnwrappedOperation() throws Exception {
+ URL url = getClass().getResource("unwrapped-stockquote.wsdl");
+ Definition definition = registry.loadDefinition(null, url);
+ PortType portType = definition.getPortType(PORTTYPE_NAME);
+ Operation operation = portType.getOperation("getLastTradePrice1", null, null);
+ WrapperStyleOperation op = new WrapperStyleOperation(operation, registry.getSchemaRegistry());
+ Assert.assertFalse(op.isWrapperStyle());
+ operation = portType.getOperation("getLastTradePrice2", null, null);
+ op = new WrapperStyleOperation(operation, registry.getSchemaRegistry());
+ Assert.assertFalse(op.isWrapperStyle());
+ operation = portType.getOperation("getLastTradePrice3", null, null);
+ op = new WrapperStyleOperation(operation, registry.getSchemaRegistry());
+ Assert.assertFalse(op.isWrapperStyle());
+
+ }
+
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java?view=auto&rev=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java Sun Sep 10 12:01:37 2006
@@ -0,0 +1,105 @@
+/*
+ * 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.tuscany.idl.wsdl;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import javax.wsdl.Definition;
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+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.XmlSchemaException;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+/**
+ * Verifies the default XSD registry implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLSchemaRegistryImplTestCase extends TestCase {
+ private static final QName PO_ELEMENT_NAME = new QName("http://www.example.com/IPO", "purchaseOrder");
+ private static final QName PO_TYPE_NAME = new QName("http://www.example.com/IPO", "PurchaseOrderType");
+
+ private static final String NS = "http://example.com/stockquote.xsd";
+ private static final QName GET_LAST_TRADE_PRICE_ELEMENT_NAME = new QName(NS, "getLastTradePrice");
+
+ private XMLSchemaRegistryImpl xsdRegistry;
+
+ private WSDLDefinitionRegistryImpl wsdlRegistry;
+
+ private ClassLoader cl;
+
+ private URL wsdl;
+
+ public void testLoadFromAbsoluteWSDLLocation() {
+ try {
+ Definition definition = wsdlRegistry.loadDefinition(null, wsdl);
+ List<XmlSchema> schemas = xsdRegistry.loadSchemas(definition);
+ Assert.assertTrue(schemas.size() == 1);
+ XmlSchema schema = schemas.get(0);
+ XmlSchemaElement element = schema.getElementByName(GET_LAST_TRADE_PRICE_ELEMENT_NAME);
+ Assert.assertNotNull(element);
+ XmlSchemaType type = element.getSchemaType();
+ XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+ XmlSchemaSequence sequence = (XmlSchemaSequence) complexType.getParticle();
+ XmlSchemaObjectCollection items = sequence.getItems();
+ Assert.assertTrue(items.getItem(0) instanceof XmlSchemaElement);
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ public void testSchemaLocation() throws IOException {
+ String schemaLocation = "http://www.example.com/IPO org/apache/tuscany/idl/wsdl/ipo.xsd";
+ XmlSchema schema = xsdRegistry.loadSchema(schemaLocation, cl);
+ Assert.assertNotNull(schema);
+ Assert.assertNotNull(schema.getElementByName(PO_ELEMENT_NAME));
+ Assert.assertNotNull(xsdRegistry.getElement(PO_ELEMENT_NAME));
+ Assert.assertNotNull(schema.getTypeByName(PO_TYPE_NAME));
+ Assert.assertNotNull(xsdRegistry.getType(PO_TYPE_NAME));
+
+
+ schemaLocation = "http://www.example.com/IPO1 org/apache/tuscany/idl/wsdl/ipo.xsd";
+ try {
+ schema = xsdRegistry.loadSchema(schemaLocation, cl);
+ Assert.fail("");
+ } catch (XmlSchemaException e) {
+ Assert.assertTrue(e.getMessage().contains("http://www.example.com/IPO1 !="));
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ xsdRegistry = new XMLSchemaRegistryImpl();
+ wsdlRegistry = new WSDLDefinitionRegistryImpl();
+ wsdlRegistry.setSchemaRegistry(xsdRegistry);
+ wsdl = getClass().getResource("stockquote.wsdl");
+ cl = getClass().getClassLoader();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd?view=auto&rev=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd Sun Sep 10 12:01:37 2006
@@ -0,0 +1,118 @@
+<schema targetNamespace="http://www.example.com/IPO"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:ipo="http://www.example.com/IPO">
+
+ <annotation>
+ <documentation xml:lang="en">
+ International Purchase order schema for Example.com
+ Copyright 2000 Example.com. All rights reserved.
+ </documentation>
+ </annotation>
+
+
+ <element name="purchaseOrder" type="ipo:PurchaseOrderType" />
+
+ <element name="comment" type="string" />
+
+ <complexType name="PurchaseOrderType">
+ <sequence>
+ <element name="shipTo" type="ipo:Address" />
+ <element name="billTo" type="ipo:Address" />
+ <element ref="ipo:comment" minOccurs="0" />
+ <element name="items" type="ipo:Items" />
+ </sequence>
+ <attribute name="orderDate" type="date" />
+ </complexType>
+
+ <complexType name="Items">
+ <sequence>
+ <element name="item" minOccurs="0" maxOccurs="unbounded">
+ <complexType>
+ <sequence>
+ <element name="productName" type="string" />
+ <element name="quantity">
+ <simpleType>
+ <restriction base="positiveInteger">
+ <maxExclusive value="100" />
+ </restriction>
+ </simpleType>
+ </element>
+ <element name="USPrice" type="decimal" />
+ <element ref="ipo:comment" minOccurs="0" />
+ <element name="shipDate" type="date"
+ minOccurs="0" />
+ </sequence>
+ <attribute name="partNum" type="ipo:SKU"
+ use="required" />
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+
+ <simpleType name="SKU">
+ <restriction base="string">
+ <pattern value="\d{3}-[A-Z]{2}" />
+ </restriction>
+ </simpleType>
+
+ <complexType name="Address">
+ <sequence>
+ <element name="name" type="string" />
+ <element name="street" type="string" />
+ <element name="city" type="string" />
+ </sequence>
+ </complexType>
+
+ <complexType name="USAddress">
+ <complexContent>
+ <extension base="ipo:Address">
+ <sequence>
+ <element name="state" type="ipo:USState" />
+ <element name="zip" type="positiveInteger" />
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="UKAddress">
+ <complexContent>
+ <extension base="ipo:Address">
+ <sequence>
+ <element name="postcode" type="ipo:UKPostcode" />
+ </sequence>
+ <attribute name="exportCode" type="positiveInteger"
+ fixed="1" />
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <!-- other Address derivations for more countries -->
+
+ <simpleType name="USState">
+ <restriction base="string">
+ <enumeration value="AK" />
+ <enumeration value="AL" />
+ <enumeration value="AR" />
+ <enumeration value="CA" />
+ <enumeration value="PA" />
+ <!-- and so on ... -->
+ </restriction>
+ </simpleType>
+
+ <simpleType name="Postcode">
+ <restriction base="string">
+ <length value="7" fixed="true" />
+ </restriction>
+ </simpleType>
+
+
+ <simpleType name="UKPostcode">
+ <restriction base="ipo:Postcode">
+ <pattern value="[A-Z]{2}\d\s\d[A-Z]{2}" />
+ </restriction>
+ </simpleType>
+
+
+
+</schema>
+
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl?view=auto&rev=441986
==============================================================================
--- incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl (added)
+++ incubator/tuscany/java/sca/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl Sun Sep 10 12:01:37 2006
@@ -0,0 +1,70 @@
+<?xml version="1.0"?>
+<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl"
+ xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2001/XMLSchema">
+ <element name="getLastTradePrice">
+ <complexType>
+ <sequence>
+ <element name="tickerSymbol" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="getLastTradePriceResponse">
+ <complexType>
+ <sequence>
+ <element name="price" type="float" />
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </types>
+
+ <message name="GetLastTradePriceInput1">
+ <part name="body" element="xsd1:getLastTradePrice" />
+ </message>
+
+ <message name="GetLastTradePriceOutput1">
+ <part name="body" element="xsd1:getLastTradePriceResponse" />
+ </message>
+
+ <message name="GetLastTradePriceInput2">
+ <part name="body" element="xsd1:getLastTradePrice" />
+ <part name="other" element="xsd:string"/>
+ </message>
+
+ <message name="GetLastTradePriceOutput2">
+ <part name="body" element="xsd1:getLastTradePriceResponse" />
+ </message>
+
+ <message name="GetLastTradePriceInput3">
+ <part name="body" element="xsd1:getLastTradePrice" />
+ </message>
+
+ <message name="GetLastTradePriceOutput3">
+ <part name="body" element="xsd1:getLastTradePriceResponse" />
+ </message>
+
+ <portType name="StockQuotePortType">
+ <operation name="getLastTradePrice">
+ <input message="tns:GetLastTradePriceInput1" />
+ <output message="tns:GetLastTradePriceOutput1" />
+ </operation>
+ <operation name="getLastTradePrice1">
+ <input message="tns:GetLastTradePriceInput1" />
+ <output message="tns:GetLastTradePriceOutput1" />
+ </operation>
+ <operation name="getLastTradePrice2">
+ <input message="tns:GetLastTradePriceInput2" />
+ <output message="tns:GetLastTradePriceOutput2" />
+ </operation>
+ <operation name="getLastTradePrice3">
+ <input message="tns:GetLastTradePriceInput3" />
+ <output message="tns:GetLastTradePriceOutput3" />
+ </operation>
+ </portType>
+
+</definitions>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org
XmlSchema version, was: svn commit: r441986
Posted by Jeremy Boynes <jb...@apache.org>.
On Sep 10, 2006, at 12:01 PM, rfeng@apache.org wrote:
> Author: rfeng
> Date: Sun Sep 10 12:01:37 2006
> New Revision: 441986
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=441986
> Log:
> Add XML schema loading with Apache XmlSchema to WSDL IDL to
> introspect JAX-WS Wrapper Style operation
We had a problem with XmlSchema SNAPSHOTs - the one in the M2 repo is
from May whereas the current one is being published only to the M1
repo. The code in XmlSchemaRegistryImpl was using the old API and
will not compile against the current SNAPSHOT.
I've changed the sca parent pom to include the M1 repository so we
get the latest snapshot. I had to hack the registry to get around the
API changes - it compiles and tests ok but I don't know that it is
doing the right thing - see r441995
This may also address the issue Meeraj was seeing with the tools
project failing.
--
Jeremy
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org