diff options
Diffstat (limited to 'branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util')
4 files changed, 0 insertions, 1091 deletions
diff --git a/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java b/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java deleted file mode 100644 index 0caf2293d6..0000000000 --- a/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/SDODataBinding.java +++ /dev/null @@ -1,104 +0,0 @@ -/**
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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.binding.axis2.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
-import org.apache.tuscany.core.wire.InvocationRuntimeException;
-import org.apache.tuscany.databinding.sdo.SDOXMLHelper;
-import org.apache.tuscany.sdo.util.SDOUtil;
-import org.osoa.sca.ServiceRuntimeException;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XMLHelper;
-
-/**
- * DataBinding for converting between AXIOM OMElement and Java Objects
- */
-public class SDODataBinding {
-
- private ClassLoader classLoader;
-
- private TypeHelper typeHelper;
-
- private QName elementQName;
-
- private boolean isWrapped;
-
- public SDODataBinding(ClassLoader classLoader, TypeHelper typeHelper, QName elementQName, boolean isWrapped) {
- this.classLoader = classLoader;
- this.typeHelper = typeHelper;
- this.elementQName = elementQName;
- this.isWrapped = isWrapped;
- }
-
- public Object[] fromOMElement(OMElement omElement) {
- try {
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- omElement.serialize(baos);
-
- baos.flush();
- baos.close();
-
- return SDOXMLHelper.toObjects(classLoader,typeHelper, baos.toByteArray(), isWrapped);
-
- } catch (IOException e) {
- throw new InvocationRuntimeException(e);
- } catch (XMLStreamException e) {
- throw new InvocationRuntimeException(e);
- }
- }
-
- public OMElement toOMElement(Object[] os) {
- try {
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- DataObject dataObject = SDOXMLHelper.toDataObject(classLoader, typeHelper, os, elementQName, isWrapped);
- XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper);
- xmlHelper.save(dataObject, elementQName.getNamespaceURI(), elementQName.getLocalPart(), baos);
- baos.close();
-
- XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
- OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), xsr);
- OMElement omElement = builder.getDocumentElement();
-
- return omElement;
-
- } catch (IOException e) {
- throw new ServiceRuntimeException(e);
- } catch (XMLStreamException e) {
- throw new ServiceRuntimeException(e);
- } catch (FactoryConfigurationError e) {
- throw new ServiceRuntimeException(e);
- }
- }
-}
diff --git a/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java b/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java deleted file mode 100644 index a5795d076e..0000000000 --- a/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java +++ /dev/null @@ -1,88 +0,0 @@ -/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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.binding.axis2.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.deployment.AxisConfigBuilder;
-import org.apache.axis2.deployment.DeploymentEngine;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.axis2.engine.AxisConfigurator;
-import org.apache.tuscany.common.resource.ResourceLoader;
-import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
-import org.osoa.sca.ServiceRuntimeException;
-
-/**
- * Helps configure Axis2 from a resource in binding.axis2 instead of Axis2.xml
- *
- * TODO: Review: should there be a single global Axis ConfigurationContext
- */
-public class TuscanyAxisConfigurator implements AxisConfigurator {
-
- protected AxisConfiguration axisConfiguration;
-
- protected final ResourceLoader resourceLoader;
-
- /**
- * @param resourceLoader
- * desired resource loader if null use thread context.
- * @param axisConfiguration
- * Starting axis configuration, null then use uninitialized configuration.
- */
- public TuscanyAxisConfigurator(ResourceLoader resourceLoader, AxisConfiguration axisConfiguration) {
- this.resourceLoader = resourceLoader != null ? resourceLoader : new ResourceLoaderImpl(getClass().getClassLoader());
- this.axisConfiguration = axisConfiguration == null ? new AxisConfiguration() : axisConfiguration;
- }
-
- public AxisConfiguration getAxisConfiguration() {
-
- return axisConfiguration;
- }
-
- public ConfigurationContext getConfigurationContext() throws ServiceRuntimeException {
-
- try {
- URL url = resourceLoader.getResource("org/apache/tuscany/binding/axis2/engine/config/axis2.xml");
-
- InputStream serviceInputStream = url.openStream();
- AxisConfigBuilder axisConfigBuilder = new AxisConfigBuilder(serviceInputStream, new DeploymentEngine(), axisConfiguration);
- axisConfigBuilder.populateConfig();
- serviceInputStream.close();
- return ConfigurationContextFactory.createConfigurationContext(this);
- } catch (IOException e) {
-
- throw new ServiceRuntimeException(e);
- }
-
- }
-
- public void loadServices() {
- // TODO Auto-generated method stub
-
- }
-
- public void engageGlobalModules() throws AxisFault {
- // TODO Auto-generated method stub
-
- }
-
-}
diff --git a/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java b/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java deleted file mode 100644 index 1ebca5d3fc..0000000000 --- a/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java +++ /dev/null @@ -1,499 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.binding.axis2.util; - -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.wsdl.Binding; -import javax.wsdl.BindingInput; -import javax.wsdl.BindingOperation; -import javax.wsdl.BindingOutput; -import javax.wsdl.Input; -import javax.wsdl.Message; -import javax.wsdl.Operation; -import javax.wsdl.Output; -import javax.wsdl.Part; -import javax.wsdl.extensions.soap.SOAPBinding; -import javax.wsdl.extensions.soap.SOAPHeader; -import javax.wsdl.extensions.soap.SOAPOperation; -import javax.xml.namespace.QName; - -/** - * Metadata for a WSDL operation - * - */ -public class WebServiceOperationMetaData { - // WSDL Binding and BindingOperation - private Binding binding; - - private BindingOperation bindingOperation; - - // Fields to cache derived metadata - private transient Set<Part> inputHeaderParts; - - private transient Set<Part> outputHeaderParts; - - private transient String style; - - private transient String use; - - private transient String soapAction; - - private transient List<Object> signature; - - private String encoding; - - private transient QName rpcOperationName; - - public WebServiceOperationMetaData(Binding binding, BindingOperation bindingOperation) { - this.binding = binding; - this.bindingOperation = bindingOperation; - } - - public WebServiceOperationMetaData(Binding binding, BindingOperation bindingOperation, String style, String use, String encoding, - String soapAction) { - this.binding = binding; - this.bindingOperation = bindingOperation; - this.style = style; - this.use = use; - this.encoding = encoding; - this.soapAction = soapAction; - } - - public Set<Part> getInputHeaderParts() { - if (inputHeaderParts == null) { - // Build a set of header parts that we need to exclude - inputHeaderParts = new HashSet<Part>(); - BindingInput bindingInput = bindingOperation.getBindingInput(); - - if (bindingInput != null) { - Operation operation = bindingOperation.getOperation(); - javax.wsdl.Message message = operation.getInput().getMessage(); - List elements = bindingInput.getExtensibilityElements(); - for (Iterator i = elements.iterator(); i.hasNext();) { - Object extensibilityElement = i.next(); - Part part = getPartFromSOAPHeader(message, extensibilityElement); - if (part != null) { - inputHeaderParts.add(part); - } - } - } - } - return inputHeaderParts; - } - - public Set<Part> getOutputHeaderParts() { - if (outputHeaderParts == null) { - // Build a set of header parts that we need to exclude - outputHeaderParts = new HashSet<Part>(); - BindingOutput bindingOutput = bindingOperation.getBindingOutput(); - - if (bindingOutput != null) { - Operation operation = bindingOperation.getOperation(); - javax.wsdl.Message message = operation.getOutput().getMessage(); - List elements = bindingOutput.getExtensibilityElements(); - for (Iterator i = elements.iterator(); i.hasNext();) { - Object extensibilityElement = i.next(); - Part part = getPartFromSOAPHeader(message, extensibilityElement); - if (part != null) { - outputHeaderParts.add(part); - } - } - } - } - return outputHeaderParts; - } - - private Part getPartFromSOAPHeader(Message message, Object extensibilityElement) { - Part part = null; - if (extensibilityElement instanceof SOAPHeader) { - SOAPHeader soapHeader = (SOAPHeader) extensibilityElement; - QName msgName = soapHeader.getMessage(); - if (message.getQName().equals(msgName)) { - part = message.getPart(soapHeader.getPart()); - } - } else if (extensibilityElement instanceof SOAPHeader) { - SOAPHeader soapHeader = (SOAPHeader) extensibilityElement; - QName msgName = soapHeader.getMessage(); - if (message.getQName().equals(msgName)) { - part = message.getPart(soapHeader.getPart()); - } - } - return part; - } - - public String getStyle() { - if (style == null) { - SOAPOperation soapOperation = (SOAPOperation) WebServicePortMetaData.getExtensibilityElement(bindingOperation.getExtensibilityElements(), - SOAPOperation.class); - if (soapOperation != null) { - style = soapOperation.getStyle(); - } - if (style == null) { - SOAPBinding soapBinding = WebServicePortMetaData.getExtensibilityElement(binding.getExtensibilityElements(), SOAPBinding.class); - if (soapBinding != null) { - style = soapBinding.getStyle(); - } - } - if (style == null) { - style = "document"; - } - } - return style; - } - - /** - * Returns the SOAP action for the given operation. - * - * @param wsdlBindingOperation - * @return - */ - public String getSOAPAction() { - if (soapAction == null) { - final List wsdlBindingOperationExtensions = bindingOperation.getExtensibilityElements(); - final SOAPOperation soapOp = WebServicePortMetaData.getExtensibilityElement(wsdlBindingOperationExtensions, SOAPOperation.class); - if (soapOp != null) { - soapAction = soapOp.getSoapActionURI(); - } - } - return soapAction; - } - - public QName getRPCOperationName() { - if (rpcOperationName == null) { - javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true); - String ns = (soapBody != null) ? soapBody.getNamespaceURI() : binding.getPortType().getQName().getNamespaceURI(); - String name = bindingOperation.getOperation().getName(); - rpcOperationName = new QName(ns, name); - } - return rpcOperationName; - } - - private List<String> getSOAPBodyParts(boolean input) { - javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(input); - if (soapBody != null) { - List parts = soapBody.getParts(); - if (parts != null) { - List<String> names = new ArrayList<String>(); - for (Iterator i = parts.iterator(); i.hasNext();) { - Object part = i.next(); - if (part instanceof String) { - names.add((String) part); - } else if (part instanceof Part) { - names.add(((Part) part).getName()); - } - } - return names; - } else { - return null; - } - } else { - return null; - } - } - - private javax.wsdl.extensions.soap.SOAPBody getSOAPBody(boolean input) { - List elements = null; - if (input) { - BindingInput bindingInput = bindingOperation.getBindingInput(); - if (bindingInput == null) { - return null; - } - elements = bindingInput.getExtensibilityElements(); - } else { - BindingOutput bindingOutput = bindingOperation.getBindingOutput(); - if (bindingOutput == null) { - return null; - } - elements = bindingOutput.getExtensibilityElements(); - } - javax.wsdl.extensions.soap.SOAPBody soapBody = WebServicePortMetaData.getExtensibilityElement(elements, - javax.wsdl.extensions.soap.SOAPBody.class); - return soapBody; - } - - /** - * Returns the use attribute - * - * @param wsdlOperation - * @return - */ - public String getUse() { - if (use == null) { - javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true); - if (soapBody != null) { - use = soapBody.getUse(); - } - if (use == null) { - use = "literal"; - } - } - return use; - } - - @SuppressWarnings("unchecked") - public String getEncoding() { - if (encoding == null) { - javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true); - if (soapBody != null) { - List<String> styles = (List<String>) soapBody.getEncodingStyles(); - if (styles != null && !styles.isEmpty()) { - encoding = styles.get(0); - } - } - if (encoding == null) { - encoding = ""; - } - } - return encoding; - } - - public boolean isDocLitWrapped() { - boolean flag = getStyle().equals("document") && getUse().equals("literal"); - if (!flag) { - return false; - } - Message msg = getMessage(true); - if (msg == null) { - return false; - } - List parts = msg.getOrderedParts(null); - if (parts.size() != 1) { - return false; - } - Part part = (Part) parts.get(0); - QName element = part.getElementName(); - if (element == null) { - return false; - } - return element.getLocalPart().equals(bindingOperation.getOperation().getName()); - } - - /* - * public SOAPMediator createMediator(boolean serverMode) throws SOAPException { // create a new mediator for each invoke for thread-safety - * boolean rpcStyle = getStyle().equals("rpc"); boolean rpcEncoded = isEncoded(); - * - * SOAPMediator mediator = null; - * - * if (!rpcStyle) { // Document mediator = new SOAPDocumentLiteralMediatorImpl(this, serverMode); } else { if (!rpcEncoded) mediator = new - * SOAPRPCLiteralMediatorImpl(this, serverMode); // RPC-literal else mediator = new SOAPRPCEncodedMediatorImpl(this, serverMode); // RPC-encoded } - * return mediator; } - */ - - /** - * Get the operation signature from the WSDL operation - * - * @param wsdlBinding - * @param bindingOperation - * @return - */ - public List<?> getOperationSignature() { - if (signature == null) { - signature = new ArrayList<Object>(); - - Operation operation = bindingOperation.getOperation(); - if (operation == null) { - return signature; - } - - final Input input = operation.getInput(); - if (input == null) { - return signature; - } - - String sstyle = getStyle(); - - if ("rpc".equals(sstyle)) { - Collection partNames = input.getMessage().getParts().values(); - for (Iterator i = partNames.iterator(); i.hasNext();) { - Part part = (Part) i.next(); - signature.add(part.getName()); - } - } else { - /* - * WS-I Basic Profile 1.1 4.7.6 Operation Signatures Definition: operation signature - * - * The profile defines the "operation signature" to be the fully qualified name of the child element of SOAP body of the SOAP input - * message described by an operation in a WSDL binding. - * - * In the case of rpc-literal binding, the operation name is used as a wrapper for the part accessors. In the document-literal case, - * since a wrapper with the operation name is not present, the message signatures must be correctly designed so that they meet this - * requirement. - * - * An endpoint that supports multiple operations must unambiguously identify the operation being invoked based on the input message - * that it receives. This is only possible if all the operations specified in the wsdl:binding associated with an endpoint have a - * unique operation signature. - * - * R2710 The operations in a wsdl:binding in a DESCRIPTION MUST result in operation signatures that are different from one another. - */ - List<String> bodyParts = getSOAPBodyParts(true); - - Collection<?> parts = input.getMessage().getParts().values(); - // Exclude the parts to be transmitted in SOAP header - if (bodyParts == null) { - parts.removeAll(getInputHeaderParts()); - } - for (Iterator i = parts.iterator(); i.hasNext();) { - Part part = (Part) i.next(); - if (bodyParts == null) { - // All parts - QName elementName = part.getElementName(); - if (elementName == null) { - elementName = new QName("", part.getName()); - // TODO: [rfeng] throw new - // ServiceRuntimeException("Message part for - // document style must refer to an XSD element - // using a QName: " + part); - } - signature.add(elementName); - } else { - // "parts" in soap:body - if (bodyParts.contains(part.getName())) { - QName elementName = part.getElementName(); - if (elementName == null) { - elementName = new QName("", part.getName()); - // TODO: [rfeng] throw new - // ServiceRuntimeException("Message part for - // document style must refer to an XSD - // element using a QName: " + part); - } - signature.add(elementName); - } - - } - } - } - } - return signature; - } - - public Message getMessage(boolean isInput) { - Operation operation = bindingOperation.getOperation(); - if (operation == null) { - return null; - } - - if (isInput) { - final Input input = operation.getInput(); - return input == null ? null : input.getMessage(); - } else { - final Output output = operation.getOutput(); - return output == null ? null : output.getMessage(); - } - } - - public Part getInputPart(int index) { - Part part = null; - Message message = getMessage(true); - if (message == null) { - return part; - } - - List parts = message.getOrderedParts(null); - return (Part) parts.get(index); - - } - - public Part getOutputPart(int index) { - Part part = null; - Message message = getMessage(false); - if (message == null) { - return part; - } - - List parts = message.getOrderedParts(null); - return (Part) parts.get(index); - - } - - /** - * Get a list of indexes for each part in the SOAP body - * - * @param isInput - * TODO - * @return - */ - public List<Integer> getBodyPartIndexes(boolean isInput) { - List<Integer> indexes = new ArrayList<Integer>(); - - Message message = getMessage(isInput); - if (message == null) { - return indexes; - } - - List<String> bodyParts = getSOAPBodyParts(isInput); - List parts = message.getOrderedParts(null); - Set headerParts = isInput ? getInputHeaderParts() : getOutputHeaderParts(); - - int index = 0; - for (Iterator i = parts.iterator(); i.hasNext(); index++) { - Part part = (Part) i.next(); - if (headerParts.contains(part)) { - continue; - } - if (bodyParts == null) { - // All parts - indexes.add(index); - } else { - // "parts" in soap:body - if (bodyParts.contains(part.getName())) { - indexes.add(index); - } - } - } - return indexes; - } - - /** - * Get the corresponding index for a part in the SOAP header by element name - * - * @param elementName - * @param isInput - * TODO - * @return - */ - public int getHeaderPartIndex(QName elementName, boolean isInput) { - - Message message = getMessage(isInput); - if (message == null) { - return -1; - } - - List parts = message.getOrderedParts(null); - Set headerParts = isInput ? getInputHeaderParts() : getOutputHeaderParts(); - - int index = 0; - for (Iterator i = parts.iterator(); i.hasNext(); index++) { - Part part = (Part) i.next(); - // Test if the part is in header section - if (headerParts.contains(part) && elementName.equals(part.getElementName())) { - return index; - } - } - return -1; - } - - public BindingOperation getBindingOperation() { - return bindingOperation; - } - -}
\ No newline at end of file diff --git a/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java b/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java deleted file mode 100644 index 694a8fbf5f..0000000000 --- a/branches/java-post-M1/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java +++ /dev/null @@ -1,400 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.binding.axis2.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import javax.wsdl.Binding; -import javax.wsdl.BindingOperation; -import javax.wsdl.Definition; -import javax.wsdl.Operation; -import javax.wsdl.Port; -import javax.wsdl.PortType; -import javax.wsdl.Service; -import javax.wsdl.extensions.soap.SOAPAddress; -import javax.wsdl.extensions.soap.SOAPBinding; -import javax.xml.namespace.QName; - -import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; - -/** - * Metadata for a WSDL port - * - */ -public class WebServicePortMetaData { - - private Service wsdlService; - - private QName wsdlServiceName; - - private Port wsdlPort; - - private Binding wsdlBinding; - - private QName wsdlPortName; - - private PortType wsdlPortType; - - private QName wsdlPortTypeName; - - private String endpoint; - - private boolean managed; - - private List<WebServiceOperationMetaData> allOperationMetaData; - - private WSDLServiceContract interfaceType; - - /** - * Constructor - * - * @param wsdlDefinition - * @param portName - */ - public WebServicePortMetaData(Definition wsdlDefinition, Port wsdlPort, String endpoint, boolean managed) { - - // Lookup the named port - this.wsdlPort = wsdlPort; - wsdlPortName = new QName(wsdlDefinition.getTargetNamespace(), wsdlPort.getName()); - - Collection services = wsdlDefinition.getServices().values(); - for (Object serviceObj : services) { - Service service = (Service) serviceObj; - if (service.getPorts().containsValue(wsdlPort)) { - wsdlService = service; - wsdlServiceName = service.getQName(); - break; - } - } - - // Save the binding - wsdlBinding = wsdlPort.getBinding(); - if (wsdlBinding == null) { - throw new IllegalArgumentException("WSDL binding cannot be found for " + wsdlPortName); - } - - // Save the portType - wsdlPortType = wsdlBinding.getPortType(); - if (wsdlPortType == null) { - throw new IllegalArgumentException("WSDL portType cannot be found for " + wsdlPortName); - } - wsdlPortTypeName = wsdlPortType.getQName(); - - // Save the endpoint - this.endpoint = endpoint; - - // Track if this endpoint is managed or not - this.managed = managed; - } - - /** - * Constructor - * - * @param serviceName - * @param portName - * @param portType - */ - public WebServicePortMetaData(QName serviceName, String portName, QName portTypeName, String endpoint) { - wsdlServiceName = serviceName; - wsdlPortName = new QName(serviceName.getNamespaceURI(), portName); - wsdlPortTypeName = portTypeName; - this.endpoint = endpoint; - } - - /** - * @return Returns the wsdlPort. - */ - public javax.wsdl.Port getPort() { - return wsdlPort; - } - - /** - * @return Returns the wsdlService. - */ - public QName getServiceName() { - return wsdlServiceName; - } - - /** - * @return Returns the wsdlService. - */ - public javax.wsdl.Service getService() { - return wsdlService; - } - - /** - * @return Returns the wsdlPortType. - */ - public PortType getPortType() { - return wsdlPortType; - } - - /** - * @return Returns the wsdlPortType. - */ - public QName getPortTypeName() { - return wsdlPortTypeName; - } - - /** - * @return Returns the wsdlBinding. - */ - public Binding getBinding() { - return wsdlBinding; - } - - /** - * @return Returns the wsdlPortName. - */ - public QName getPortName() { - return wsdlPortName; - } - - /** - * Returns the endpoint of a given port. - * - * @param wsdlPort - * @return - */ - public String getEndpoint() { - - // Return the specified endpoint - if (endpoint != null) { - return endpoint; - } - - // Find the target endpoint on the port - if (wsdlPort != null) { - final List wsdlPortExtensions = wsdlPort.getExtensibilityElements(); - for (Iterator i = wsdlPortExtensions.iterator(); i.hasNext();) { - final Object extension = i.next(); - if (extension instanceof SOAPAddress) { - return ((SOAPAddress) extension).getLocationURI(); - } - } - } - - return null; - } - - /** - * Returns the SOAP binding style. - * - * @return - */ - public String getStyle() { - - // Find the binding style - String style = null; - if (wsdlBinding != null) { - final List wsdlBindingExtensions = wsdlBinding.getExtensibilityElements(); - SOAPBinding soapBinding = getExtensibilityElement(wsdlBindingExtensions, SOAPBinding.class); - if (soapBinding != null) { - style = soapBinding.getStyle(); - } - } - - // Default to document - return (style == null) ? "document" : style; - } - - /** - * Returns the use attribute - * - * @return - */ - public String getUse() { - List<WebServiceOperationMetaData> list = getAllOperationMetaData(); - return list.get(0).getUse(); - } - - /** - * Returns the encoding attribute - * - * @return - */ - public String getEncoding() { - List<WebServiceOperationMetaData> list = getAllOperationMetaData(); - return list.get(0).getEncoding(); - } - - /** - * @return Returns true if this is a managed web service. - */ - public boolean isManaged() { - return managed; - } - - /** - * Returns the first extensibility element of the given type. - * - * @param elements - * @param type - * @return - */ - public static <T> T getExtensibilityElement(List elements, Class<T> type) { - for (Iterator i = elements.iterator(); i.hasNext();) { - Object element = i.next(); - if (type.isInstance(element)) { - return type.cast(element); - } - } - return null; - } - - /** - * Returns the extensibility elements of the given type. - * - * @param elements - * @param type - * @return - */ - public static <T> List<T> getExtensibilityElements(List elements, Class<T> type) { - List<T> result = new ArrayList<T>(); - for (Iterator i = elements.iterator(); i.hasNext();) { - Object element = i.next(); - if (type.isInstance(element)) { - result.add(type.cast(element)); - } - } - return result; - } - - /** - * Get the operation signature from the SOAP Body - * - * @param body - * @return A list of QNames - */ - // public static List getOperationSignature(javax.xml.soap.SOAPBody body) { - // List signature = new ArrayList(); - // for (Iterator i = body.getChildElements(); i.hasNext();) { - // Object child = i.next(); - // if (child instanceof SOAPBodyElement) { - // Name name = ((SOAPBodyElement) child).getElementName(); - // QName qname = new QName(name.getURI(), name.getLocalName(), name.getPrefix()); - // signature.add(qname); - // } - // } - // return signature; - // } - // public static List getRPCOperationSignature(javax.xml.soap.SOAPBody body) { - // List signature = new ArrayList(); - // for (Iterator i = body.getChildElements(); i.hasNext();) { - // Object child = i.next(); - // if (child instanceof SOAPBodyElement) { - // SOAPBodyElement op = ((SOAPBodyElement) child); - // for (Iterator j = op.getChildElements(); j.hasNext();) { - // Object part = i.next(); - // if (part instanceof SOAPElement) { - // SOAPElement p = (SOAPElement) part; - // signature.add(p.getLocalName()); - // } - // } - // } - // } - // return signature; - // } - // public WebServiceOperationMetaData getOperationMetaData(javax.xml.soap.SOAPBody body) { - // List s1 = getOperationSignature(body); - // // List rpcParts = getRPCOperationSignature(body); - // for (Iterator it = getAllOperationMetaData().iterator(); it.hasNext();) { - // WebServiceOperationMetaData descriptor = (WebServiceOperationMetaData) it.next(); - // - // String style = descriptor.getStyle(); - // - // if (style.equals("document")) { - // List s2 = descriptor.getOperationSignature(); - // if (s1.equals(s2)) - // return descriptor; - // } else { - // QName op1 = (QName) s1.get(0); - // QName op2 = descriptor.getRPCOperationName(); - // if (op1.equals(op2)) { - // /* - // * // FIXME: [rfeng] We don't support method overloading - // * List partNames = getOperationSignature(binding, - // * bindingOperation); if (rpcParts.equals(partNames)) - // */ - // return descriptor; - // } - // } - // } - // return null; - // } - public List<WebServiceOperationMetaData> getAllOperationMetaData() { - if (allOperationMetaData == null) { - allOperationMetaData = new ArrayList<WebServiceOperationMetaData>(); - for (Iterator it = wsdlBinding.getBindingOperations().iterator(); it.hasNext();) { - final BindingOperation bindingOperation = (BindingOperation) it.next(); - if (bindingOperation.getOperation() != null) { - allOperationMetaData.add(new WebServiceOperationMetaData(wsdlBinding, bindingOperation)); - } - } - } - return allOperationMetaData; - } - - public WebServiceOperationMetaData getOperationMetaData(String operationName) { - StringBuilder sb = new StringBuilder(operationName); - sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); - String capatalizedOpName = sb.toString(); - - for (Iterator it = getAllOperationMetaData().iterator(); it.hasNext();) { - WebServiceOperationMetaData descriptor = (WebServiceOperationMetaData) it.next(); - String opName = descriptor.getBindingOperation().getOperation().getName(); - - if (opName.equals(operationName) || opName.equals(capatalizedOpName)) { - return descriptor; - } - } - return null; - } - - /** - * Returns the WSDL service contract - * - * @return - */ - public WSDLServiceContract getInterfaceType() { - return interfaceType; - } - - /** - * Get the WSDL operation name for a Java method name - */ - public String getWSDLOperationName(String methodName) { - StringBuilder sb = new StringBuilder(methodName); - sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); - String capatalizedOpName = sb.toString(); - for (Object o : wsdlPortType.getOperations()) { - Operation operation = (Operation) o; - String wsdlOpName = operation.getName(); - if (wsdlOpName.equals(methodName)) { - return wsdlOpName; - } - if (wsdlOpName.equals(capatalizedOpName)) { - return wsdlOpName; - } - } - return null; - } - -}
\ No newline at end of file |