You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2006/07/11 21:33:22 UTC
svn commit: r420955 [5/8] - in /webservices/axis2/trunk/java/modules/jaxws:
./ src/javax/jws/ src/javax/xml/ws/handler/ src/org/apache/axis2/jaxws/
src/org/apache/axis2/jaxws/binding/ src/org/apache/axis2/jaxws/client/
src/org/apache/axis2/jaxws/core/ ...
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,380 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.message.util.impl;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.message.util.SAAJConverter;
+import org.apache.axis2.jaxws.message.util.SOAPElementReader;
+
+/**
+ * SAAJConverterImpl
+ * Provides an conversion methods between OM<->SAAJ
+ */
+public class SAAJConverterImpl implements SAAJConverter {
+
+ /**
+ * Constructed via SAAJConverterFactory
+ */
+ SAAJConverterImpl() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axis2.jaxws.message.util.SAAJConverter#toSAAJ(org.apache.axiom.soap.SOAPEnvelope)
+ */
+ public SOAPEnvelope toSAAJ(org.apache.axiom.soap.SOAPEnvelope omEnvelope)
+ throws MessageException {
+ SOAPEnvelope soapEnvelope = null;
+ try {
+ // Build the default envelope
+ MessageFactory mf = MessageFactory.newInstance();
+ SOAPMessage sm = mf.createMessage();
+ SOAPPart sp = sm.getSOAPPart();
+ soapEnvelope = sp.getEnvelope();
+
+ // The getSOAPEnvelope() call creates a default SOAPEnvelope with a SOAPHeader and SOAPBody.
+ // The SOAPHeader and SOAPBody are removed (they will be added back in if they are present in the
+ // OMEnvelope).
+ SOAPBody soapBody = soapEnvelope.getBody();
+ if (soapBody != null) {
+ soapBody.detachNode();
+ //soapEnvelope.removeChild(soapBody);
+ }
+ SOAPHeader soapHeader = soapEnvelope.getHeader();
+ if (soapHeader != null) {
+ soapHeader.detachNode();
+ //soapEnvelope.removeChild(soapHeader);
+ }
+
+ // Adjust tag data on the SOAPEnvelope. (i.e. set the prefix, set the attributes)
+ //adjustTagData(soapEnvelope, omEnvelope);
+
+ // We don't know if there is a real OM tree or just a backing XMLStreamReader.
+ // The best way to walk the data is to get the XMLStreamReader and use this
+ // to build the SOAPElements
+ XMLStreamReader reader = omEnvelope.getXMLStreamReaderWithoutCaching();
+
+ buildSOAPTree(soapEnvelope, soapEnvelope, null, reader, false);
+ } catch (MessageException e) {
+ throw e;
+ } catch (SOAPException e) {
+ throw new MessageException(e);
+ }
+ return soapEnvelope;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axis2.jaxws.message.util.SAAJConverter#toOM(javax.xml.soap.SOAPEnvelope)
+ */
+ public org.apache.axiom.soap.SOAPEnvelope toOM(SOAPEnvelope saajEnvelope)
+ throws MessageException {
+ // Get a XMLStreamReader backed by a SOAPElement tree
+ XMLStreamReader reader = new SOAPElementReader(saajEnvelope);
+ // Get a SOAP OM Builder. Passing null causes the version to be automatically triggered
+ StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(reader, null);
+ // Create and return the OM Envelope
+ org.apache.axiom.soap.SOAPEnvelope omEnvelope = builder.getSOAPEnvelope();
+ return omEnvelope;
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.apache.axis2.jaxws.message.util.SAAJConverter#toOM(javax.xml.soap.SOAPElement)
+ */
+ public OMElement toOM(SOAPElement soapElement) throws MessageException {
+ // Get a XMLStreamReader backed by a SOAPElement tree
+ XMLStreamReader reader = new SOAPElementReader(soapElement);
+ // Get a OM Builder. Passing null causes the version to be automatically triggered
+ StAXOMBuilder builder = new StAXOMBuilder(reader);
+ // Create and return the OM Envelope
+ OMElement om = builder.getDocumentElement();
+ return om;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axis2.jaxws.message.util.SAAJConverter#toSAAJ(org.apache.axiom.om.OMElement, javax.xml.soap.SOAPElement)
+ */
+ public SOAPElement toSAAJ(OMElement omElement, SOAPElement parent) throws MessageException {
+ XMLStreamReader reader = omElement.getXMLStreamReaderWithoutCaching();
+ SOAPElement env = parent;
+ while (env != null && !(env instanceof SOAPEnvelope)) {
+ env = env.getParentElement();
+ }
+ if (env == null) {
+ // TODO NLS
+ throw new MessageException("SOAPEnvelope is needed!");
+ }
+ return buildSOAPTree((SOAPEnvelope) env, null, parent, reader, false);
+ }
+
+ /**
+ * Build SOAPTree
+ * Either the root or the parent is null.
+ * If the root is null, a new element is created under the parent using information from the reader
+ * If the parent is null, the existing root is updated with the information from the reader
+ * @param envelope SOAPEnvelope (used only to create Name objects)
+ * @param root SOAPElement (the element that represents the data in the reader)
+ * @param parent (the parent of the element represented by the reader)
+ * @param reader XMLStreamReader. the first START_ELEMENT matches the root
+ * @param quitAtBody - true if quit reading after the body START_ELEMENT
+ */
+ protected SOAPElement buildSOAPTree(SOAPEnvelope envelope,
+ SOAPElement root,
+ SOAPElement parent,
+ XMLStreamReader reader,
+ boolean quitAtBody)
+ throws MessageException {
+ try {
+ while(reader.hasNext()) {
+ int eventID = reader.next();
+ switch (eventID) {
+ case XMLStreamReader.START_ELEMENT: {
+
+ // The first START_ELEMENT defines the prefix and attributes of the root
+ if (parent == null) {
+ updateTagData(envelope, root, reader);
+ parent = root;
+ } else {
+ parent = createElementFromTag(envelope, parent, reader);
+ if (root == null) {
+ root = parent;
+ }
+ }
+ if (quitAtBody && parent instanceof SOAPBody) {
+ return root;
+ }
+ break;
+ }
+ case XMLStreamReader.ATTRIBUTE: {
+ String eventName ="ATTRIBUTE";
+ this._unexpectedEvent(eventName);
+ }
+ case XMLStreamReader.NAMESPACE: {
+ String eventName ="NAMESPACE";
+ this._unexpectedEvent(eventName);
+ }
+ case XMLStreamReader.END_ELEMENT: {
+ if (parent instanceof SOAPEnvelope) {
+ parent = null;
+ } else {
+ parent = parent.getParentElement();
+ }
+ break;
+ }
+ case XMLStreamReader.CHARACTERS: {
+ parent.addTextNode(reader.getText());
+ break;
+ }
+ case XMLStreamReader.CDATA: {
+ parent.addTextNode(reader.getText());
+ break;
+ }
+ case XMLStreamReader.COMMENT: {
+ // SOAP really doesn't have an adequate representation for comments.
+ // The defacto standard is to add the whole element as a text node.
+ parent.addTextNode("<!--" + reader.getText() + "-->");
+ break;
+ }
+ case XMLStreamReader.SPACE: {
+ parent.addTextNode(reader.getText());
+ break;
+ }
+ case XMLStreamReader.START_DOCUMENT: {
+ // Ignore
+ break;
+ }
+ case XMLStreamReader.END_DOCUMENT: {
+ // Ignore
+ break;
+ }
+ case XMLStreamReader.PROCESSING_INSTRUCTION: {
+ // Ignore
+ break;
+ }
+ case XMLStreamReader.ENTITY_REFERENCE: {
+ // Ignore. this is unexpected in a web service message
+ break;
+ }
+ case XMLStreamReader.DTD: {
+ // Ignore. this is unexpected in a web service message
+ break;
+ }
+ default:
+ this._unexpectedEvent("EventID " +String.valueOf(eventID));
+ }
+ }
+ } catch (MessageException e) {
+ throw e;
+ } catch (XMLStreamException e) {
+ throw new MessageException(e);
+ } catch (SOAPException e) {
+ throw new MessageException(e);
+ }
+ return root;
+ }
+
+ /**
+ * Create SOAPElement from the current tag data
+ * @param envelope SOAPEnvelope
+ * @param parent SOAPElement for the new SOAPElement
+ * @param reader XMLStreamReader whose cursor is at the START_ELEMENT
+ * @return
+ */
+ protected SOAPElement createElementFromTag(SOAPEnvelope envelope,
+ SOAPElement parent,
+ XMLStreamReader reader)
+ throws SOAPException {
+ // Unfortunately, the SAAJ object is a product of both the
+ // QName of the element and the parent object. For example,
+ // All element children of a SOAPBody must be object's that are SOAPBodyElements.
+ // createElement creates the proper child element.
+ QName qName = reader.getName();
+ String prefix = reader.getPrefix();
+ Name name = envelope.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI());
+ SOAPElement child = createElement(parent, name);
+
+ // Update the tag data on the child
+ updateTagData(envelope, child, reader);
+ return child;
+ }
+
+ /**
+ * Create child SOAPElement
+ * @param parent SOAPElement
+ * @param name Name
+ * @return
+ */
+ protected SOAPElement createElement(SOAPElement parent, Name name)
+ throws SOAPException {
+ SOAPElement child;
+ if (parent instanceof SOAPEnvelope) {
+ if (name.getURI().equals(parent.getNamespaceURI())) {
+ if (name.getLocalName().equals("Body")) {
+ child = ((SOAPEnvelope)parent).addBody();
+ } else {
+ child = ((SOAPEnvelope)parent).addHeader();
+ }
+ } else {
+ child = parent.addChildElement(name);
+ }
+ } else if (parent instanceof SOAPBody) {
+ if (name.getURI().equals(parent.getNamespaceURI()) &&
+ name.getLocalName().equals("Fault")) {
+ child = ((SOAPBody)parent).addFault();
+ } else {
+ child = ((SOAPBody)parent).addBodyElement(name);
+ }
+ } else if (parent instanceof SOAPHeader) {
+ child = ((SOAPHeader)parent).addHeaderElement(name);
+ } else if (parent instanceof SOAPFault) {
+ // This call assumes that the addChildElement implementation
+ // is smart enough to add "Detail" or "SOAPFaultElement" objects.
+ child = parent.addChildElement(name);
+ } else if (parent instanceof Detail) {
+ child = ((Detail) parent).addDetailEntry(name);
+ } else {
+ child = parent.addChildElement(name);
+ }
+
+ return child;
+ }
+
+ /**
+ * update the tag data of the SOAPElement
+ * @param envelope SOAPEnvelope
+ * @param element SOAPElement
+ * @param reader XMLStreamReader whose cursor is at START_ELEMENT
+ */
+ protected void updateTagData(SOAPEnvelope envelope,
+ SOAPElement element,
+ XMLStreamReader reader) throws SOAPException {
+ String prefix = reader.getPrefix();
+ prefix = (prefix == null) ? "" : prefix;
+
+ // Make sure the prefix is correct
+ if (prefix.length() > 0 && !element.getPrefix().equals(prefix)) {
+ element.setPrefix(prefix);
+ }
+
+ //Remove all of the namespace declarations on the element
+ Iterator it = element.getNamespacePrefixes();
+ while (it.hasNext()) {
+ String aPrefix = (String)it.next();
+ element.removeNamespaceDeclaration(aPrefix);
+ }
+
+ // Add the namespace declarations from the reader
+ int size = reader.getNamespaceCount();
+ for (int i=0; i<size; i++) {
+ element.addNamespaceDeclaration(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
+ }
+
+ // Add attributes
+ addAttributes(envelope, element, reader);
+
+ return;
+ }
+
+ /** add attributes
+ * @param envelope SOAPEnvelope
+ * @param element SOAPElement which is the target of the new attributes
+ * @param reader XMLStreamReader whose cursor is at START_ELEMENT
+ * @throws SOAPException
+ */
+ protected void addAttributes(SOAPEnvelope envelope,
+ SOAPElement element,
+ XMLStreamReader reader) throws SOAPException {
+
+ // Add the attributes from the reader
+ int size = reader.getAttributeCount();
+ for (int i=0; i<size; i++) {
+ QName qName = reader.getAttributeName(i);
+ String prefix = reader.getAttributePrefix(i);
+ String value = reader.getAttributeValue(i);
+ Name name = envelope.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI());
+ element.addAttribute(name, value);
+ }
+ }
+
+ private void _unexpectedEvent(String event) throws MessageException {
+ // Review We need NLS for this message, but this code will probably
+ // be added to JAX-WS. So for now we there is no NLS.
+ // TODO NLS
+ throw new MessageException("Unexpected XMLStreamReader event:" + event);
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/XMLStreamReaderFromDOM.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/XMLStreamReaderFromDOM.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/XMLStreamReaderFromDOM.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/XMLStreamReaderFromDOM.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,732 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.message.util.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+
+/**
+ * XMLStreamReader created from walking a DOM.
+ * This is an implementation class used by SOAPElementReader.
+ * @see org.apache.axis2.jaxws.util.SOAPElementReader
+ */
+public class XMLStreamReaderFromDOM implements XMLStreamReader {
+
+ private Node cursor;
+ private Stack<Node> nextCursorStack = new Stack<Node>();
+ private Node root;
+ private int event = XMLStreamReader.START_DOCUMENT;
+ private Node nextCursor = null;
+ private int nextEvent = -1;
+
+ private NamespaceContextFromDOM cacheNCI = null;
+ private Element cacheNCIKey = null;
+
+ private List cacheND = null;
+ private Element cacheNDKey = null;
+
+
+ /**
+ * Create the XMLStreamReader with an Envelope
+ * @param envelope Element (probably an SAAJ SOAPEnvelope) representing the Envelope
+ */
+ public XMLStreamReaderFromDOM(Element envelope) {
+ root = envelope;
+ cursor = root;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getProperty(java.lang.String)
+ */
+ public Object getProperty(String key) throws IllegalArgumentException {
+ if (key == null) {
+ throw new IllegalArgumentException(ERR_1);
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#next()
+ */
+ public int next() throws XMLStreamException {
+ if (!hasNext()) {
+ throw new XMLStreamException(ERR_2);
+ }
+ getNext();
+ cursor = nextCursor;
+ event = nextEvent;
+ return event;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#require(int, java.lang.String, java.lang.String)
+ */
+ public void require(int event, String namespace, String localPart)
+ throws XMLStreamException {
+ try {
+ if (event != this.event) {
+ throw new XMLStreamException(ERR_3 + " expected " + event + " found " + this.event);
+ }
+ if (namespace != null &&
+ !namespace.equals(cursor.getNamespaceURI())) {
+ throw new XMLStreamException(ERR_3 + " expected " + namespace + " found " + this.cursor.getNamespaceURI());
+ }
+ if (localPart != null &&
+ !localPart.equals(cursor.getLocalName())) {
+ throw new XMLStreamException(ERR_3 + " expected " + localPart + " found " + this.cursor.getLocalName());
+ }
+ } catch (XMLStreamException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getElementText()
+ */
+ public String getElementText() throws XMLStreamException {
+ if (event == XMLStreamReader.START_ELEMENT) {
+ next();
+ StringBuffer buffer = new StringBuffer();
+ while(event != XMLStreamReader.END_ELEMENT ) {
+ if (event == XMLStreamReader.CHARACTERS ||
+ event == XMLStreamReader.CDATA ||
+ event == XMLStreamReader.SPACE ||
+ event == XMLStreamReader.ENTITY_REFERENCE) {
+ buffer.append(getText());
+ } else if (event == XMLStreamReader.PROCESSING_INSTRUCTION ||
+ event == XMLStreamReader.COMMENT) {
+ // whitespace
+ } else {
+ throw new XMLStreamException(ERR_4 + "getElementText()");
+ }
+ next();
+ }
+ return buffer.toString();
+ }
+ throw new XMLStreamException(ERR_4 + "getElementText()");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#nextTag()
+ */
+ public int nextTag() throws XMLStreamException {
+ next();
+ while(event == XMLStreamReader.CHARACTERS && isWhiteSpace() ||
+ event == XMLStreamReader.CDATA && isWhiteSpace() ||
+ event == XMLStreamReader.SPACE ||
+ event == XMLStreamReader.PROCESSING_INSTRUCTION ||
+ event == XMLStreamReader.COMMENT) {
+ event = next();
+ }
+ if (event == XMLStreamReader.START_ELEMENT ||
+ event == XMLStreamReader.END_ELEMENT) {
+ return event;
+ }
+ throw new XMLStreamException(ERR_4 + "nextTag()");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#hasNext()
+ */
+ public boolean hasNext() throws XMLStreamException {
+ return (event != XMLStreamReader.END_DOCUMENT);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#close()
+ */
+ public void close() throws XMLStreamException {
+ return;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getNamespaceURI(java.lang.String)
+ */
+ public String getNamespaceURI(String prefix) {
+ if (cursor instanceof Element) {
+ return getNamespaceContext().getNamespaceURI(prefix);
+ }
+ throw new IllegalStateException(ERR_4 + "getNamespaceURI(String)");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#isStartElement()
+ */
+ public boolean isStartElement() {
+ return (event == XMLStreamReader.START_ELEMENT);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#isEndElement()
+ */
+ public boolean isEndElement() {
+ return (event == XMLStreamReader.END_ELEMENT);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#isCharacters()
+ */
+ public boolean isCharacters() {
+ return (event == XMLStreamReader.CHARACTERS);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#isWhiteSpace()
+ */
+ public boolean isWhiteSpace() {
+ if (event == XMLStreamReader.CHARACTERS ||
+ event == XMLStreamReader.CDATA) {
+ String value = ((CharacterData) cursor).getData();
+ StringTokenizer st = new StringTokenizer(value);
+ return !(st.hasMoreTokens());
+ }
+ return false;
+ }
+
+ /**
+ * @return list of attributes that are not namespace declarations
+ */
+ private List getAttributes() {
+ if (event == XMLStreamReader.START_ELEMENT) {
+ List attrs = new ArrayList();
+ NamedNodeMap map = ((Element) cursor).getAttributes();
+ if (map != null) {
+ for (int i=0; i<map.getLength(); i++) {
+ Attr attr = (Attr) map.item(i);
+ if (attr.getName().equals("xmlns") ||
+ attr.getName().startsWith("xmlns:")) {
+ // this is a namespace declaration
+ } else {
+ attrs.add(attr);
+ }
+ }
+ }
+ return attrs;
+ }
+ throw new IllegalStateException(ERR_4 + "getAttributes()");
+ }
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getAttributeValue(java.lang.String, java.lang.String)
+ */
+ public String getAttributeValue(String namespace, String localPart) {
+ if (event == XMLStreamReader.START_ELEMENT) {
+ return ((Element)cursor).getAttributeNS(namespace, localPart);
+ }
+ throw new IllegalStateException(ERR_4 + "getAttributeValue(String, String)");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getAttributeCount()
+ */
+ public int getAttributeCount() {
+ return getAttributes().size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getAttributeName(int)
+ */
+ public QName getAttributeName(int index) {
+ Attr attr = (Attr) getAttributes().get(index);
+ return new QName(attr.getNamespaceURI(), attr.getLocalName());
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getAttributeNamespace(int)
+ */
+ public String getAttributeNamespace(int index) {
+ Attr attr = (Attr) getAttributes().get(index);
+ return attr.getNamespaceURI();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getAttributeLocalName(int)
+ */
+ public String getAttributeLocalName(int index) {
+ Attr attr = (Attr) getAttributes().get(index);
+ return attr.getLocalName();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getAttributePrefix(int)
+ */
+ public String getAttributePrefix(int index) {
+ Attr attr = (Attr) getAttributes().get(index);
+ return attr.getPrefix();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getAttributeType(int)
+ */
+ public String getAttributeType(int index) {
+ Attr attr = (Attr) getAttributes().get(index);
+ return attr.getSchemaTypeInfo().getTypeName();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getAttributeValue(int)
+ */
+ public String getAttributeValue(int index) {
+ Attr attr = (Attr) getAttributes().get(index);
+ return attr.getValue();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#isAttributeSpecified(int)
+ */
+ public boolean isAttributeSpecified(int arg0) {
+ return true;
+ }
+
+ /*
+ * @return number of namespace declarations on this element
+ */
+ public int getNamespaceCount() {
+ if (cursor instanceof Element) {
+ List list = getNamespaceDeclarations();
+ return list.size();
+ }
+ throw new IllegalStateException(ERR_4 + "getNamespaceCount()");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getNamespacePrefix(int)
+ */
+ public String getNamespacePrefix(int index) {
+ if (cursor instanceof Element) {
+ List list = getNamespaceDeclarations();
+ return ((NamespaceDeclare) list.get(index)).getPrefix();
+ }
+ throw new IllegalStateException(ERR_4 + "getNamespacePrefix(int)");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getNamespaceURI(int)
+ */
+ public String getNamespaceURI(int index) {
+ if (cursor instanceof Element) {
+ List list = getNamespaceDeclarations();
+ return ((NamespaceDeclare) list.get(index)).getURI();
+ }
+ throw new IllegalStateException(ERR_4 + "getNamespaceURI(int)");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getNamespaceContext()
+ */
+ public NamespaceContext getNamespaceContext() {
+ Element element = null;
+ if (cursor instanceof Element) {
+ element = (Element) cursor;
+ } else {
+ Element parent = (Element) cursor.getParentNode();
+ if (parent == null) {
+ parent = (Element) nextCursorStack.peek();
+ }
+ element = (Element) cursor.getParentNode();
+ }
+ if (element == cacheNCIKey) {
+ return cacheNCI;
+ }
+ cacheNCIKey = element;
+ cacheNCI = new NamespaceContextFromDOM(element);
+ return cacheNCI;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getEventType()
+ */
+ public int getEventType() {
+ return event;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getText()
+ */
+ public String getText() {
+ if (event == XMLStreamReader.CHARACTERS ||
+ event == XMLStreamReader.CDATA ||
+ event == XMLStreamReader.COMMENT) {
+ return ((CharacterData) cursor).getData();
+ }
+ throw new IllegalStateException(ERR_4 + "getText()");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getTextCharacters()
+ */
+ public char[] getTextCharacters() {
+ return getText().toCharArray();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getTextCharacters(int, char[], int, int)
+ */
+ public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
+ throws XMLStreamException {
+ String value = getText();
+ // Calculate the sourceEnd index
+ int sourceEnd = sourceStart + length;
+ if (value.length() < sourceEnd) {
+ sourceEnd = value.length();
+ }
+ value.getChars(sourceStart, sourceEnd, target, targetStart);
+ return sourceEnd - sourceStart;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getTextStart()
+ */
+ public int getTextStart() {
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getTextLength()
+ */
+ public int getTextLength() {
+ return getText().length();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getEncoding()
+ */
+ public String getEncoding() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#hasText()
+ */
+ public boolean hasText() {
+ return (event == XMLStreamReader.CHARACTERS ||
+ event == XMLStreamReader.CDATA ||
+ event == XMLStreamReader.COMMENT);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getLocation()
+ */
+ public Location getLocation() {
+ return dummyLocation;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getName()
+ */
+ public QName getName() {
+ if (cursor instanceof Element) {
+ return new QName(cursor.getNamespaceURI(), cursor.getLocalName());
+ }
+ throw new IllegalStateException(ERR_4 + "getName()");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getLocalName()
+ */
+ public String getLocalName() {
+ if (cursor instanceof Element) {
+ return cursor.getLocalName();
+ }
+ throw new IllegalStateException(ERR_4 + "getLocalName()");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#hasName()
+ */
+ public boolean hasName() {
+ return (isStartElement() || isEndElement());
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getNamespaceURI()
+ */
+ public String getNamespaceURI() {
+ if (cursor instanceof Element) {
+ return cursor.getNamespaceURI();
+ } else {
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getPrefix()
+ */
+ public String getPrefix() {
+ if (cursor instanceof Element) {
+ return cursor.getPrefix();
+ } else {
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getVersion()
+ */
+ public String getVersion() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#isStandalone()
+ */
+ public boolean isStandalone() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#standaloneSet()
+ */
+ public boolean standaloneSet() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getCharacterEncodingScheme()
+ */
+ public String getCharacterEncodingScheme() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getPITarget()
+ */
+ public String getPITarget() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.xml.stream.XMLStreamReader#getPIData()
+ */
+ public String getPIData() {
+ return null;
+ }
+
+ /**
+ * Sets nextCursor and nextEvent from
+ * using the current cursor and event.
+ */
+ private void getNext() throws IllegalStateException {
+ switch (event) {
+ case XMLStreamReader.START_DOCUMENT: {
+ nextCursor = cursor;
+ nextEvent = XMLStreamReader.START_ELEMENT;
+ break;
+ }
+
+ case XMLStreamReader.START_ELEMENT: {
+ if (cursor.getFirstChild() != null) {
+ nextCursorStack.push(nextCursor);
+ nextCursor = cursor.getFirstChild();
+ nextEvent = startEvent(nextCursor);
+ } else {
+ nextEvent = XMLStreamReader.END_ELEMENT;
+ }
+ break;
+ }
+ case XMLStreamReader.ATTRIBUTE: {
+ throw new IllegalStateException(ERR_5 + "ATTRIBUTE");
+ }
+ case XMLStreamReader.NAMESPACE: {
+ throw new IllegalStateException(ERR_5 + "NAMESPACE");
+ }
+ case XMLStreamReader.END_ELEMENT:
+ case XMLStreamReader.CHARACTERS:
+ case XMLStreamReader.CDATA:
+ case XMLStreamReader.COMMENT:
+ case XMLStreamReader.SPACE:
+ case XMLStreamReader.PROCESSING_INSTRUCTION:
+ case XMLStreamReader.ENTITY_REFERENCE:
+ case XMLStreamReader.DTD:
+ {
+ if (cursor.getNextSibling() != null) {
+ nextCursor = cursor.getNextSibling();
+ nextEvent = startEvent(nextCursor);
+ } else if (cursor == root) {
+ nextEvent = XMLStreamReader.END_DOCUMENT;
+ } else {
+ // The following does not work with
+ // Axiom Text nodes
+ // nextCursor = cursor.getParentNode();
+ // This is the reason why a stack is used.
+ nextCursor = nextCursorStack.pop();
+
+ nextEvent = XMLStreamReader.END_ELEMENT;
+ }
+ break;
+ }
+
+ case XMLStreamReader.END_DOCUMENT: {
+ nextCursor = null;
+ nextEvent = -1;
+ }
+ default:
+ throw new IllegalStateException(ERR_5 + event);
+ }
+
+ }
+
+ /**
+ * Returns the start event for this particular node
+ * @param node
+ * @return
+ */
+ private int startEvent(Node node) {
+ if (node instanceof ProcessingInstruction) {
+ return XMLStreamReader.PROCESSING_INSTRUCTION;
+ }
+ if (node instanceof CDATASection) {
+ return XMLStreamReader.CDATA;
+ }
+ if (node instanceof Comment) {
+ return XMLStreamReader.COMMENT;
+ }
+ if (node instanceof Text) {
+ if (node instanceof javax.xml.soap.Text) {
+ javax.xml.soap.Text soapText = (javax.xml.soap.Text) node;
+ if (soapText.isComment()) {
+ return XMLStreamReader.COMMENT;
+ } else {
+ return XMLStreamReader.CHARACTERS;
+ }
+ }
+ return XMLStreamReader.CHARACTERS;
+ }
+ if (node instanceof Element) {
+ return XMLStreamReader.START_ELEMENT;
+ }
+ if (node instanceof Attr) {
+ return XMLStreamReader.ATTRIBUTE;
+ }
+ if (node instanceof Document) {
+ return XMLStreamReader.START_DOCUMENT;
+ }
+ if (node instanceof EntityReference) {
+ return XMLStreamReader.ENTITY_REFERENCE;
+ }
+ if (node instanceof DocumentType) {
+ return XMLStreamReader.DTD;
+ }
+ return -1;
+ }
+
+ // This is the definition of a dummy Location
+ private DummyLocation dummyLocation = new DummyLocation();
+ private class DummyLocation implements Location {
+
+ public int getLineNumber() {
+ return -1;
+ }
+
+ public int getColumnNumber() {
+ return 0;
+ }
+
+ public int getCharacterOffset() {
+ return 0;
+ }
+
+ public String getPublicId() {
+ return null;
+ }
+
+ public String getSystemId() {
+ return null;
+ }
+
+ }
+
+ public List getNamespaceDeclarations() {
+ Element element = null;
+ if (cursor instanceof Element) {
+ element = (Element) cursor;
+ } else {
+ return new ArrayList();
+ }
+ if (element == cacheNDKey) {
+ return cacheND;
+ }
+ cacheNDKey = element;
+ cacheND = new ArrayList();
+ NamedNodeMap attrs = element.getAttributes();
+ if (attrs != null) {
+ for (int i=0; i<attrs.getLength(); i++) {
+ Attr attr = (Attr) attrs.item(i);
+ String name = attr.getNodeName();
+ if (name.startsWith("xmlns")) {
+ String prefix = "";
+ if (name.startsWith("xmlns:")) {
+ prefix = name.substring(6);
+ }
+ NamespaceDeclare nd = new NamespaceDeclare(prefix, attr.getNodeValue());
+ cacheND.add(nd);
+ }
+ }
+ }
+ return cacheND;
+ }
+
+ class NamespaceDeclare {
+ String prefix;
+ String uri;
+ NamespaceDeclare(String prefix, String uri) {
+ this.prefix = prefix;
+ this.uri = uri;
+ }
+ String getPrefix() {
+ return prefix;
+ }
+ String getURI() {
+ return uri;
+ }
+ }
+
+ Node getNode() {
+ return cursor;
+ }
+
+ // TODO NLS
+ private static final String ERR_1 = "The method getProperty was called with a null key";
+ private static final String ERR_2 = "There are no more events";
+ private static final String ERR_3 = "The require() method failed";
+ private static final String ERR_4 = "Failure occured in method ";
+ private static final String ERR_5 = "The following event is not supported in getNext():";
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/param/ParameterUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/param/ParameterUtils.java?rev=420955&r1=420954&r2=420955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/param/ParameterUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/param/ParameterUtils.java Tue Jul 11 12:33:12 2006
@@ -50,7 +50,7 @@
SOAPFactory soapfactory = SoapUtils.getSoapFactory(soapVersionURI);
SOAPEnvelope env = null;
try{
- if(mode !=null && mode.equals(Mode.MESSAGE)){
+ if(mode != null && mode.equals(Mode.MESSAGE)){
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(param.getValueAsStreamReader(),
soapfactory, soapVersionURI);
return builder.getSOAPEnvelope();
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.registry;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.axis2.jaxws.message.databinding.impl.JAXBBlockFactoryImpl;
+import org.apache.axis2.jaxws.message.databinding.impl.OMBlockFactoryImpl;
+import org.apache.axis2.jaxws.message.databinding.impl.SourceBlockFactoryImpl;
+import org.apache.axis2.jaxws.message.databinding.impl.XMLStringBlockFactoryImpl;
+import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.factory.OMBlockFactory;
+import org.apache.axis2.jaxws.message.factory.SAAJConverterFactory;
+import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
+import org.apache.axis2.jaxws.message.factory.XMLPartFactory;
+import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
+import org.apache.axis2.jaxws.message.impl.MessageFactoryImpl;
+import org.apache.axis2.jaxws.message.impl.XMLPartFactoryImpl;
+import org.apache.axis2.jaxws.message.util.impl.SAAJConverterFactoryImpl;
+
+/**
+ * FactoryRegistry
+ * Registry containing Factories related to the JAX-WS Implementation
+ */
+public class FactoryRegistry {
+
+ private final static Map<Class,Object> table;
+ static {
+ table = new Hashtable<Class,Object>();
+ table.put(XMLStringBlockFactory.class, new XMLStringBlockFactoryImpl());
+ table.put(JAXBBlockFactory.class, new JAXBBlockFactoryImpl());
+ table.put(OMBlockFactory.class, new OMBlockFactoryImpl());
+ table.put(SourceBlockFactory.class, new SourceBlockFactoryImpl());
+ table.put(MessageFactory.class, new MessageFactoryImpl());
+ table.put(XMLPartFactory.class, new XMLPartFactoryImpl());
+ table.put(SAAJConverterFactory.class, new SAAJConverterFactoryImpl());
+ }
+ /**
+ * FactoryRegistry is currently a static singleton
+ */
+ private FactoryRegistry() {
+ }
+
+ /**
+ * getFactory
+ * @param intface of the Factory
+ * @return Object that is the factory implementation for the intface
+ */
+ public static Object getFactory(Class intface) {
+ return table.get(intface);
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.server;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import javax.xml.ws.Provider;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.jaxws.param.ParameterFactory;
+
+
+public class EndpointController {
+ private static String PARAM_SERVICE_CLASS = "ServiceClass";
+ private MessageContext msgContext = null;
+
+ /**
+ * @param _msgContext
+ */
+ public EndpointController(MessageContext _msgContext) {
+ this.msgContext = _msgContext;
+ }
+
+ /**
+ * Get OMElement from message context
+ *
+ * @return ome
+ */
+ private OMElement getOMElement() throws Exception{
+ SOAPEnvelope env = msgContext.getEnvelope();
+ SOAPBody body = env.getBody();
+ OMElement ome = body.getFirstElement();
+
+ return ome;
+ }
+
+ /**
+ * Given a MessageContext, get the contents out and turn them into a Parameter
+ * instance based on what the Provider expects.
+ *
+ * @param msgContext
+ * @return
+ */
+ private org.apache.axis2.jaxws.param.Parameter getParam(Class _class) throws Exception{
+ Class<?> clazz = getClassType(_class);
+ org.apache.axis2.jaxws.param.Parameter param = ParameterFactory.createParameter(clazz);
+ return param;
+ }
+
+ /**
+ * Get the appropriate dispatcher for a given service endpoint.
+ *
+ * @return EndpointDispatcher
+ * @throws Exception
+ */
+ public EndpointDispatcher getDispatcher() throws Exception {
+ EndpointDispatcher dispatcherInstance = null;
+ AxisService as = msgContext.getAxisService();
+ Parameter asp = as.getParameter(PARAM_SERVICE_CLASS);
+
+ Class cls = getImplClass(as,asp);
+ if(cls.getSuperclass().isInstance(Provider.class)){
+ ProviderDispatcher pd = new ProviderDispatcher(cls);
+ if(pd.getProvider() != null){
+ org.apache.axis2.jaxws.param.Parameter param = getParam(cls);
+ param.fromOM(getOMElement());
+ pd.setParam(param);
+ }
+ dispatcherInstance = pd;
+ }
+
+ return dispatcherInstance;
+ }
+
+ /**
+ * @param as
+ * @param asp
+ * @return Class
+ */
+ private Class getImplClass(AxisService as, Parameter asp){
+ Class _class = null;
+ try{
+ String className = ((String) asp.getValue()).trim();
+ _class = Class.forName(className, true, as.getClassLoader());
+
+ }catch(java.lang.ClassNotFoundException cnf ){
+ cnf.printStackTrace();
+ }
+
+ return _class;
+ }
+
+ /**
+ *
+ * @param _class
+ * @return
+ * @throws Exception
+ */
+ private Class<?> getClassType(Class _class)throws Exception{
+
+ Class classType = null;
+
+ Type[] giTypes = _class.getGenericInterfaces();
+ for(Type giType : giTypes){
+ ParameterizedType paramType = null;
+ try{
+ paramType = (ParameterizedType)giType;
+ }catch(ClassCastException e){
+ throw new Exception("Provider based SEI Class has to implement javax.xml.ws.Provider as javax.xml.ws.Provider<String>, javax.xml.ws.Provider<SOAPMessage>, javax.xml.ws.Provider<Source> or javax.xml.ws.Provider<JAXBContext>");
+ }
+ Class interfaceName = (Class)paramType.getRawType();
+ System.out.println(">> Intereface name is [" + interfaceName.getName() + "]");
+
+ if(interfaceName == javax.xml.ws.Provider.class){
+ if(paramType.getActualTypeArguments().length > 1){
+ throw new Exception("Provider cannot have more than one Generic Types defined as Per JAX-WS Specification");
+ }
+ classType = (Class)paramType.getActualTypeArguments()[0];
+ }
+ }
+ return classType;
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointDispatcher.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointDispatcher.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointDispatcher.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.server;
+
+/**
+ * All endpoint dispatcher types must extend this class
+ *
+ */
+public abstract class EndpointDispatcher {
+ public abstract Object execute() throws Exception;
+
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java?rev=420955&r1=420954&r2=420955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java Tue Jul 11 12:33:12 2006
@@ -17,16 +17,7 @@
package org.apache.axis2.jaxws.server;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-
-import javax.xml.soap.SOAPMessage;
-import javax.xml.transform.Source;
-import javax.xml.ws.Provider;
import javax.xml.ws.Service.Mode;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
@@ -45,19 +36,18 @@
*/
public class JAXWSMessageReceiver implements MessageReceiver {
- private static String PARAM_SERVICE_CLASS = "ServiceClass";
-
- private String className;
- private Class implClass;
- private Provider endpointInstance;
- private Class providerType = null;
-
+ private static String PARAM_SERVICE_CLASS = "ServiceClass";
/**
* We should have already determined which AxisService we're targetting at
* this point. So now, just get the service implementation and invoke
* the appropriate method.
*/
public void receive(MessageContext reqMsgContext) throws AxisFault {
+
+ if(reqMsgContext == null){
+ throw new AxisFault("Message Context is null");
+ }
+
// Let's go ahead and create the MessageContext for the response and add
// it to the list.
MessageContext rspMsgContext = Utils.createOutMessageContext(reqMsgContext);
@@ -66,42 +56,26 @@
// Get the name of the service impl that was stored as a parameter
// inside of the services.xml.
AxisService service = reqMsgContext.getAxisService();
- org.apache.axis2.description.Parameter svcClassParam = service.getParameter(PARAM_SERVICE_CLASS);
+ if(service == null){
+ throw new AxisFault("Axis service is null");
+ }
- // Create an instance of the Provider class that will be dispatched to.
+ org.apache.axis2.description.Parameter svcClassParam = service.getParameter(PARAM_SERVICE_CLASS);
+ if(svcClassParam == null){
+ throw new RuntimeException("No service class was found for this AxisService");
+ }
+
try {
- if (svcClassParam != null) {
- className = ((String) svcClassParam.getValue()).trim();
- implClass = Class.forName(className, true, service.getClassLoader());
- endpointInstance = getProviderInstance();
- }
- else {
- throw new RuntimeException("No service class was found for this AxisService");
- }
+
+ // Get the appropriate endpoint dispatcher for this service
+ EndpointDispatcher endpointDispatcher = new EndpointController(reqMsgContext).getDispatcher();
+ Object response = endpointDispatcher.execute();
- Parameter param = extractParam(reqMsgContext);
- if (endpointInstance != null) {
- Class paramType = getProviderType();
-
- Object input = paramType.cast(param.getValue());
-
- /*
- String input = (String) param.getValue();
- System.out.println(">> invoking Provider with param [" + input + "]");
- */
-
- // TODO : Params will not always be Strings. Add more code to
- // handle different param types and different numbers of params (not for
- // Provider but for other endpoints)
- // Added more code to ensure we are handling all param types. NVT
- Object response = endpointInstance.invoke(input);
-
- Parameter rspParam = ParameterFactory.createParameter(response);
- SOAPEnvelope rspEnvelope = rspParam.toEnvelope(Mode.PAYLOAD, null);
- rspMsgContext.setEnvelope(rspEnvelope);
- }
+ Parameter rspParam = ParameterFactory.createParameter(response);
+ SOAPEnvelope rspEnvelope = rspParam.toEnvelope(Mode.PAYLOAD, null);
+ rspMsgContext.setEnvelope(rspEnvelope);
- // Create the AxisEngine for the reponse and send it.
+ // Create the AxisEngine for the response and send it.
AxisEngine engine = new AxisEngine(rspMsgContext.getConfigurationContext());
engine.send(rspMsgContext);
} catch (Exception e) {
@@ -109,81 +83,5 @@
Exception ex = new Exception("Server Side Exception :" +e.getMessage());
throw AxisFault.makeFault(ex);
}
- //Lets extract jax-ws parameter that we can use to create the response message context.
-
-
- }
-
- /**
- * Given a MessageContext, get the contents out and turn them into a Parameter
- * instance based on what the Provider expects.
- *
- * @param msgContext
- * @return
- */
- private Parameter extractParam(MessageContext msgContext) throws Exception{
- SOAPEnvelope env = msgContext.getEnvelope();
- SOAPBody body = env.getBody();
- OMElement om = body.getFirstElement();
- //Using Provider implClass and getting the Invoke method's parameter type, this will be the jax-ws parameter.
- Class<?> clazz = getProviderType();
- Parameter param = ParameterFactory.createParameter(clazz);
- param.fromOM(om);
- return param;
- }
-
- private Class<?> getProviderType()throws Exception{
- if(providerType != null){
- return providerType;
- }
-
- Type[] giTypes = implClass.getGenericInterfaces();
- for(Type giType : giTypes){
- ParameterizedType paramType = null;
- try{
- paramType = (ParameterizedType)giType;
- }catch(ClassCastException e){
- throw new Exception("Provider based SEI Class has to implement javax.xml.ws.Provider as javax.xml.ws.Provider<String>, javax.xml.ws.Provider<SOAPMessage>, javax.xml.ws.Provider<Source> or javax.xml.ws.Provider<JAXBContext>");
- }
- Class interfaceName = (Class)paramType.getRawType();
- if(interfaceName == javax.xml.ws.Provider.class){
- if(paramType.getActualTypeArguments().length > 1){
- throw new Exception("Provider cannot have more than one Generic Types defined as Per JAX-WS Specification");
- }
- providerType = (Class)paramType.getActualTypeArguments()[0];
- }
- }
- return providerType;
- }
-
- private Provider getProviderInstance()throws Exception{
- Provider provider = null;
- Class<?> clazz =getProviderType();
- if(!isValidProviderType(clazz)){
- //TODO This will change once deployment code it in place
- throw new Exception("Invalid Provider Implementation, Only String, Source, SOAPMessage and JAXBContext Supported by JAX-WS ");
- }
- if(clazz == String.class){
- return (Provider<String>) implClass.newInstance();
- }
- if(clazz == Source.class){
- return (Provider<Source>) implClass.newInstance();
- }
- if(clazz == SOAPMessage.class){
- return (Provider<SOAPMessage>) implClass.newInstance();
- }
- /* TODO: Wait till we get SUN RI binary for JAXB
- if(clazz == JAXContext.class){
- return (Provider<JAXBContext>)implClass.newInstance();
- }
- */
- return provider;
-
- }
-
- private boolean isValidProviderType(Class clazz){
-
- return clazz == String.class || clazz == SOAPMessage.class || clazz == Source.class;
- //TODO: clazz == JAXBContext.class
}
}
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ProviderDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ProviderDispatcher.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ProviderDispatcher.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ProviderDispatcher.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.server;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.Source;
+import javax.xml.ws.Provider;
+import org.apache.axis2.jaxws.param.Parameter;
+import javax.xml.bind.JAXBContext;
+
+/**
+ * From a given service class, determine and invoke the appropriate endpoint with associated parameter.
+ *
+ */
+public class ProviderDispatcher extends EndpointDispatcher{
+ private Class svcImplClass = null;
+ private Provider providerInstance = null;
+ private Parameter parameter = null;
+
+ /**
+ * Constructor
+ *
+ * @param _class
+ */
+ public ProviderDispatcher(Class _class) {
+ this.svcImplClass = _class;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axis2.jaxws.server.EndpointDispatcher#execute()
+ */
+ public Object execute()throws Exception{
+
+ Class paramType = getProviderType();
+ Object input = paramType.cast(getParam().getValue());
+
+ String input1 = getParam().getValue().getClass().getName();
+ System.out.println(">> invoking Provider with param [" + input1 + "]");
+
+ return providerInstance.invoke(input);
+ }
+
+ /**
+ * Get the endpoint provider instance
+ *
+ * @return Provider
+ * @throws Exception
+ */
+ public Provider getProvider() throws Exception{
+ Provider p = getProviderInstance();
+ setProvider(p);
+ return p;
+ }
+
+ /**
+ * Set the endpoint provider instance
+ *
+ * @param _provider
+ */
+ public void setProvider(Provider _provider) {
+ this.providerInstance = _provider;
+ }
+
+ /**
+ * Get the parameter for a given endpoint invocation
+ *
+ * @return
+ * @throws Exception
+ */
+ public Parameter getParam()throws Exception {
+ return parameter;
+ }
+
+ /**
+ * Set the parameter for a given endpoint invocation
+ *
+ * @param _parameter
+ */
+ public void setParam(Parameter _parameter) {
+ this.parameter = _parameter;
+ }
+
+ /**
+ * Determine the Provider type for this instance
+ *
+ * @return Provider
+ * @throws Exception
+ */
+ private Provider getProviderInstance()throws Exception{
+ Provider provider = null;
+ Class<?> clazz =getProviderType();
+ if(!isValidProviderType(clazz)){
+ //TODO This will change once deployment code it in place
+ throw new Exception("Invalid Provider Implementation, Only String, Source, SOAPMessage and JAXBContext Supported by JAX-WS ");
+ }
+ if(clazz == String.class){
+ return (Provider<String>) this.svcImplClass.newInstance();
+ }
+ if(clazz == Source.class){
+ return (Provider<Source>) this.svcImplClass.newInstance();
+ }
+ if(clazz == SOAPMessage.class){
+ return (Provider<SOAPMessage>) this.svcImplClass.newInstance();
+ }
+ if(clazz == JAXBContext.class){
+ return (Provider<JAXBContext>)this.svcImplClass.newInstance();
+ }
+
+ return provider;
+
+ }
+
+ /**
+ * Get the provider type from a given implemention class instance
+ *
+ * @return class
+ * @throws Exception
+ */
+ private Class<?> getProviderType()throws Exception{
+
+ Class providerType = null;
+
+ Type[] giTypes = this.svcImplClass.getGenericInterfaces();
+ for(Type giType : giTypes){
+ ParameterizedType paramType = null;
+ try{
+ paramType = (ParameterizedType)giType;
+ }catch(ClassCastException e){
+ throw new Exception("Provider based SEI Class has to implement javax.xml.ws.Provider as javax.xml.ws.Provider<String>, javax.xml.ws.Provider<SOAPMessage>, javax.xml.ws.Provider<Source> or javax.xml.ws.Provider<JAXBContext>");
+ }
+ Class interfaceName = (Class)paramType.getRawType();
+ System.out.println(">> Intereface name is [" + interfaceName.getName() + "]");
+
+ if(interfaceName == javax.xml.ws.Provider.class){
+ if(paramType.getActualTypeArguments().length > 1){
+ throw new Exception("Provider cannot have more than one Generic Types defined as Per JAX-WS Specification");
+ }
+ providerType = (Class)paramType.getActualTypeArguments()[0];
+ }
+ }
+ return providerType;
+ }
+
+ /**
+ * Validate provider type against require types for the Provider interface.
+ *
+ * @param clazz
+ * @return boolean
+ */
+ private boolean isValidProviderType(Class clazz){
+ return clazz == String.class || clazz == SOAPMessage.class || clazz == Source.class;
+ }
+
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java?rev=420955&r1=420954&r2=420955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java Tue Jul 11 12:33:12 2006
@@ -36,40 +36,42 @@
import org.apache.axis2.jaxws.ClientMediator;
import org.apache.axis2.jaxws.JAXWSClientContext;
+import org.apache.axis2.jaxws.client.JAXBDispatch;
+import org.apache.axis2.jaxws.client.XMLDispatch;
+import org.apache.axis2.jaxws.description.ServiceDescription;
import org.apache.axis2.jaxws.handler.PortData;
import org.apache.axis2.jaxws.handler.PortInfoImpl;
import org.apache.axis2.jaxws.util.WSDL4JWrapper;
import org.apache.axis2.jaxws.util.WSDLWrapper;
+import org.apache.commons.logging.LogFactory;
public class ServiceDelegate extends javax.xml.ws.spi.ServiceDelegate {
private Executor executor;
private Map<QName, org.apache.axis2.jaxws.handler.PortData> ports;
+
+ private ServiceDescription serviceDescription;
private QName serviceQname;
- private WSDLWrapper wsdl = null;
- private URL wsdlLocation;
private ClientMediator mediator = null;
+
+ // If no binding ID is available, use this one
+ private static String DEFAULT_BINDING_ID = SOAPBinding.SOAP11HTTP_BINDING;
public ServiceDelegate(URL url, QName qname, Class clazz) throws WebServiceException{
super();
- this.wsdlLocation = url;
this.serviceQname = qname;
ports = new Hashtable<QName, PortData>();
mediator = new ClientMediator();
- if(!isValidServiceName()){
+
+ if(!isValidServiceName()){
throw new WebServiceException("Invalid Service QName, Service Name cannot be null or empty");
}
-
- if(isValidWSDLLocation()){
- try{
- setWSDLWrapper();
- }catch(WSDLException e){
- throw new WebServiceException(e.getMessage());
- }
- if(!isServiceDefined(serviceQname)){
- throw new WebServiceException("Service " +qname+ " not defined in WSDL");
-
- }
- readPorts();
+
+ serviceDescription = new ServiceDescription(url, serviceQname, clazz);
+ if (isValidWSDLLocation()) {
+ if(!isServiceDefined(serviceQname)){
+ throw new WebServiceException("Service " + serviceQname + " not defined in WSDL");
+ }
+ readPorts();
}
}
@@ -81,10 +83,17 @@
if("".equals(portName)){
throw new WebServiceException("Invalid port name");
}
+ if (endpointAddress == null) {
+ throw new WebServiceException("Invalid endpointAddress, endpointAddress cannot be null");
+ }
if(bindingId!=null && !bindingId.equals(SOAPBinding.SOAP11HTTP_BINDING)){
throw new UnsupportedOperationException("Only SOAP11HTTP_BINDING supported at this time.");
}
+
+ if (bindingId == null) {
+ bindingId = DEFAULT_BINDING_ID;
+ }
if(!ports.containsKey(portName)){
PortData port = new PortInfoImpl(serviceQname, portName, bindingId, endpointAddress);
ports.put(portName, port);
@@ -101,15 +110,10 @@
}
private <T> JAXWSClientContext<T> createClientContext(PortData portData, Class<T> clazz, Mode mode){
JAXWSClientContext<T> clientContext = new JAXWSClientContext<T>();
+ clientContext.setServiceDescription(serviceDescription);
clientContext.setPort(portData);
clientContext.setClazz(clazz);
clientContext.setServiceMode(mode);
- clientContext.setWsdlContext(wsdl);
- try{
- clientContext.setWsdlContext(getWSDLWrapper());
- }catch(WSDLException e){
- throw new WebServiceException(e.getMessage());
- }
clientContext.setExecutor(this.getExecutor());
return clientContext;
}
@@ -130,10 +134,9 @@
addBinding(portData.getBindingID());
JAXWSClientContext<T> clientContext = createClientContext(portData, clazz, mode);
- Dispatch<T> dispatch = mediator.createDispatch(clientContext);
-
- return dispatch;
-
+ XMLDispatch<T> dispatch = mediator.createXMLDispatch(clientContext);
+ dispatch.setServiceDelegate(this);
+ return dispatch;
}
public Dispatch<java.lang.Object> createDispatch(QName qname, JAXBContext context, Mode mode) {
@@ -152,7 +155,8 @@
JAXWSClientContext clientCtx = createClientContext(portData, Object.class, mode);
clientCtx.setJAXBContext(context);
- Dispatch<Object> dispatch = mediator.createDispatch(clientCtx);
+ JAXBDispatch<Object> dispatch = mediator.createJAXBDispatch(clientCtx);
+ dispatch.setServiceDelegate(this);
return dispatch;
}
@@ -229,9 +233,12 @@
return serviceQname;
}
+ public ServiceDescription getServiceDescription() {
+ return serviceDescription;
+ }
+
public URL getWSDLDocumentLocation() {
- // TODO Auto-generated method stub
- return wsdlLocation;
+ return serviceDescription.getWSDLLocation();
}
private boolean isPortValid(QName portName){
@@ -243,17 +250,18 @@
}
private boolean isValidWSDLLocation(){
+ URL wsdlLocation = getWSDLDocumentLocation();
return wsdlLocation != null && !"".equals(wsdlLocation.toString().trim());
}
private void readPorts(){
- String[] portNames = wsdl.getPorts(serviceQname);
- String targetNamespace = wsdl.getTargetNamespace();
+ String[] portNames = getWSDLWrapper().getPorts(serviceQname);
+ String targetNamespace = getWSDLWrapper().getTargetNamespace();
for(String portName: portNames){
QName portQname = new QName(targetNamespace, portName);
- String address = wsdl.getSOAPAddress(serviceQname, portQname);
- //get Binding ID from WSDL and add it here.
- PortData portInfo = new PortInfoImpl(serviceQname, portQname, null, address);
+ String address = getWSDLWrapper().getSOAPAddress(serviceQname, portQname);
+ //TODO: get Binding ID from WSDL and add it here.
+ PortData portInfo = new PortInfoImpl(serviceQname, portQname, DEFAULT_BINDING_ID, address);
ports.put(portQname, portInfo);
}
}
@@ -271,23 +279,13 @@
// TODO Auto-generated method stub
}
- private void setWSDLWrapper()throws WSDLException{
- if(isValidWSDLLocation()){
- wsdl = new WSDL4JWrapper(wsdlLocation);
- }
- }
-
- private WSDLWrapper getWSDLWrapper()throws WSDLException{
- if(this.wsdl!=null){
- return this.wsdl;
- }
- setWSDLWrapper();
-
- return wsdl;
+ // TODO: Remove this method and put the WSDLWrapper methods on the ServiceDescriptor directly
+ private WSDLWrapper getWSDLWrapper() {
+ return serviceDescription.getWSDLWrapper();
}
private boolean isServiceDefined(QName serviceName){
- return wsdl.getService(serviceName)!=null;
+ return getWSDLWrapper().getService(serviceName)!= null;
}
private void addBinding(String bindingId){
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java?rev=420955&r1=420954&r2=420955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java Tue Jul 11 12:33:12 2006
@@ -252,7 +252,7 @@
- public URL getWSLDLocation() {
+ public URL getWSDLLocation() {
// TODO Auto-generated method stub
return this.wsdlURL;
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/WSDLWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/WSDLWrapper.java?rev=420955&r1=420954&r2=420955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/WSDLWrapper.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/WSDLWrapper.java Tue Jul 11 12:33:12 2006
@@ -49,7 +49,7 @@
public String getSOAPAction(QName serviceQname, QName portQname);
public String getSOAPAction(QName serviceQname, QName portQName, QName operationQname);
public String getSOAPAddress(QName serviceQname, QName portQname);
- public URL getWSLDLocation();
+ public URL getWSDLLocation();
public String getTargetNamespace();
public Definition getDefinition();
-}
+}
\ No newline at end of file
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.wrapper;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+
+import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperException;
+
+
+public interface JAXBWrapperTool {
+ /**
+ * unwrap
+ * Returns the list of child elements of the jaxb object
+ * @param javab Object that is the wrapper element
+ * @param jaxbContext JAXBContext
+ * @param childNames list of xml child names as String
+ * @return list of Objects in the same order as the element names.
+ */
+ public Object[] unWrap(Object jaxbObject, ArrayList<String> childNames) throws JAXBWrapperException;
+
+
+ /**
+ * wrap
+ * Creates a jaxb object that is initialized with the child objects
+ * @param javabClass Class of the JAXB object to return
+ * @param jaxbContext JAXBContext
+ * @param childObjects, component objects
+ * @param childNames list of xml child names as String
+ * @return list of Objects in the same order as the element names.
+ */
+ public Object wrap(Class jaxbClass, String jaxbClassName, ArrayList<String> childNames, Map<String, Object> childObjects) throws JAXBWrapperException;
+
+ /**
+ * wrapAsJAXBElement
+ * Creates a JAXBElement that is initialized with the child objects and can be serialsed to xml later.
+ * @param javabClass Class of the JAXB object to return
+ * @param jaxbContext JAXBContext
+ * @param childObjects, component objects
+ * @param childNames list of xml child names as String
+ * @return JAXBElement;
+ */
+ public JAXBElement wrapAsJAXBElement(Class jaxbClass, String jaxbClassName,
+ ArrayList<String> childNames, Map<String, Object> childObjects) throws JAXBWrapperException;
+
+}
+
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperException.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperException.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperException.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperException.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.wrapper.impl;
+
+
+public class JAXBWrapperException extends Exception {
+
+ /**
+ *
+ */
+ public JAXBWrapperException() {
+ super();
+
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public JAXBWrapperException(String message, Throwable cause) {
+ super(message, cause);
+
+ }
+
+ /**
+ * @param message
+ */
+ public JAXBWrapperException(String message) {
+ super(message);
+
+ }
+
+ /**
+ * @param cause
+ */
+ public JAXBWrapperException(Throwable cause) {
+ super(cause);
+
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.wrapper.impl;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.beans.PropertyEditor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.TypeVariable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.jaxws.wrapper.JAXBWrapperTool;
+
+
+public class JAXBWrapperToolImpl implements JAXBWrapperTool {
+
+ /* (non-Javadoc)
+ * @see org.apache.axis2.jaxws.wrapped.JAXBWrapperTool#unWrap(java.lang.Object, javax.xml.bind.JAXBContext, java.util.ArrayList)
+ */
+
+ /*
+ * create property descriptor using jaxbObject and child Names,
+ * getReader and read the object, form the object array and return them.
+ */
+
+ public Object[] unWrap(Object jaxbObject,
+ ArrayList<String> childNames) throws JAXBWrapperException{
+ try{
+ if(jaxbObject == null){
+ throw new JAXBWrapperException("input JAXB Object cannot be null");
+ }
+ if(childNames == null){
+ throw new JAXBWrapperException("Input childNames cannot be null");
+ }
+ ArrayList<Object> objList = new ArrayList<Object>();
+ if(jaxbObject == null){
+
+ throw new JAXBWrapperException(new NullPointerException("UnWrap cannot continue, input parameter jaxbObject is null "));
+ }
+ Map<String , PropertyInfo> pdTable = createPropertyDescriptors(jaxbObject.getClass(), childNames);
+ for(String childName:childNames){
+ PropertyInfo propInfo = pdTable.get(childName);
+ Object object = propInfo.get(jaxbObject);
+ objList.add(object);
+ }
+ Object[] jaxbObjects = objList.toArray();
+ objList = null;
+ return jaxbObjects;
+ }catch(IntrospectionException e){
+ throw new JAXBWrapperException(e);
+ }catch(IllegalAccessException e){
+ throw new JAXBWrapperException(e);
+ }catch(InvocationTargetException e){
+ throw new JAXBWrapperException(e);
+ }catch(NoSuchFieldException e){
+ throw new JAXBWrapperException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axis2.jaxws.wrapped.JAXBWrapperTool#wrap(java.lang.Class, java.lang.String, java.util.ArrayList, java.util.ArrayList)
+ */
+ public Object wrap(Class jaxbClass, String jaxbClassName,
+ ArrayList<String> childNames, Map<String, Object> childObjects)
+ throws JAXBWrapperException {
+
+ try{
+ if(childNames == null|| childObjects == null){
+ throw new JAXBWrapperException("Input Child Name or Child Object values cannot be null");
+ }
+ if(childNames.size() != childObjects.size()){
+ throw new JAXBWrapperException("Input ChildNames should be same as input childObjects ");
+ }
+ Map<String, PropertyInfo> pdTable = createPropertyDescriptors(jaxbClass, childNames);
+ Object jaxbObject = jaxbClass.newInstance();
+ for(String childName:childNames){
+ PropertyInfo propInfo = pdTable.get(childName);
+ propInfo.set(jaxbObject, childObjects.get(childName));
+ }
+ return jaxbObject;
+ }catch(IntrospectionException e){
+ throw new JAXBWrapperException(e);
+ }catch(InstantiationException e){
+ throw new JAXBWrapperException(e);
+ }catch(IllegalAccessException e){
+ throw new JAXBWrapperException(e);
+ }catch(InvocationTargetException e){
+ throw new JAXBWrapperException(e);
+ }catch(NoSuchFieldException e){
+ throw new JAXBWrapperException(e);
+ }
+ }
+
+ public JAXBElement wrapAsJAXBElement(Class jaxbClass, String jaxbClassName,
+ ArrayList<String> childNames, Map<String, Object> childObjects) throws JAXBWrapperException{
+
+ Object obj = wrap( jaxbClass, jaxbClassName, childNames, childObjects);
+ JAXBElement<Object> element = new JAXBElement<Object>(new QName(jaxbClassName), jaxbClass, obj);
+ return element;
+ }
+
+ /** creates propertyDescriptor for the childNames using the jaxbClass.
+ * use Introspector.getBeanInfo().getPropertyDescriptors() to get all the property descriptors. Assert if # of childNames and propertyDescriptor array
+ * length do not match. if they match then get the xmlElement name from jaxbClass using propertyDescriptor's display name. See if the xmlElementName matches the
+ * childName if not use xmlElement annotation name and create PropertyInfo add childName or xmlElement name there, set propertyDescriptor
+ * and return Map<ChileName, PropertyInfo>.
+ * @param jaxbClass - Class jaxbClass name
+ * @param childNames - ArrayList<String> of childNames
+ * @return Map<String, PropertyInfo> - map of ChildNames that map to PropertyInfo that hold the propertyName and PropertyDescriptor.
+ * @throws IntrospectionException, NoSuchFieldException
+ */
+ private Map<String, PropertyInfo> createPropertyDescriptors(Class jaxbClass, ArrayList<String> childNames) throws IntrospectionException, NoSuchFieldException, JAXBWrapperException{
+ Map<String, PropertyInfo> map = new WeakHashMap<String, PropertyInfo>();
+ PropertyDescriptor[] pds = Introspector.getBeanInfo(jaxbClass).getPropertyDescriptors();
+
+ Map<String, PropertyDescriptor> jaxbClassPds = filterDescriptors(pds, jaxbClass);
+ Field field[] = jaxbClass.getDeclaredFields();
+ if(field.length != childNames.size()){
+ throw new JAXBWrapperException("Number of field defined in JAXBClass ["+jaxbClass+"] is not equal to the input ChildNames and Child Objects provided to map");
+ }
+ pds=null;
+
+ for(int i=0; i<field.length ;i++){
+ PropertyInfo propInfo= null;
+ String fieldName = field[i].getName();
+ String childName = childNames.get(i);
+ PropertyDescriptor pd = jaxbClassPds.get(childName);
+ if(pd == null){
+ pd = jaxbClassPds.get(fieldName);
+ if(pd == null){
+ throw new JAXBWrapperException("No Such Field [ChildName: "+childName+ "]");
+ }
+ }
+ propInfo = new PropertyInfo(fieldName, pd);
+ map.put(childName, propInfo);
+ }
+ jaxbClassPds = null;
+ field = null;
+ return map;
+ }
+
+
+ /** Filter PropertyDescriptors that belong to super class, return only the ones that belong to JABXClass
+ * create map of java fieldName and propertyDescriptor, if propertyName different than java fieldName then
+ * check the xmlElementName ensure they are same if not do conver both xmlName and propertyName to lowercase and
+ * ensure they are same if they match then add the corrosponding javaFieldName and PropertyDescriptor in map. If they dont
+ * match the propertyName belongs to super class and we ignore it.
+ * @param allPds
+ * @param jaxbClass
+ * @return
+ */
+ private Map<String, PropertyDescriptor> filterDescriptors(PropertyDescriptor[] allPds, Class jaxbClass) throws NoSuchFieldException{
+ Map<String, PropertyDescriptor> filteredPds = new WeakHashMap<String, PropertyDescriptor>();
+ Field[] fields = jaxbClass.getDeclaredFields();
+ for(PropertyDescriptor pd:allPds){
+ for(Field field:fields){
+ if(field.getName().equals(pd.getDisplayName())){
+ filteredPds.put(pd.getDisplayName(), pd);
+ break;
+ }else{
+ String xmlName =getXmlElementName(jaxbClass, field.getName());
+ if(xmlName.equals(pd.getDisplayName())){
+ filteredPds.put(field.getName(), pd);
+ break;
+ }
+ if(xmlName.toLowerCase().equals(pd.getDisplayName().toLowerCase())){
+ filteredPds.put(field.getName(), pd);
+ break;
+ }
+ }
+ }
+ }
+ allPds=null;
+ return filteredPds;
+ }
+
+ private String getXmlElementName(Class jaxbClass, String fieldName)throws NoSuchFieldException{
+ Field field = jaxbClass.getDeclaredField(fieldName);
+ XmlElement xmlElement =field.getAnnotation(XmlElement.class);
+ return xmlElement.name();
+
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java Tue Jul 11 12:33:12 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.wrapper.impl;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+
+public class PropertyInfo {
+ String propertyName;
+ PropertyDescriptor descriptor;
+
+ /**
+ * @param propertyName
+ * @param descriptor
+ */
+ public PropertyInfo(String propertyName, PropertyDescriptor descriptor) {
+ super();
+
+ this.propertyName = propertyName;
+ this.descriptor = descriptor;
+ }
+
+ public String getPropertyName(){
+ return this.propertyName;
+ }
+
+ public Object get(Object targetBean)throws InvocationTargetException, IllegalAccessException{
+ Method method = descriptor.getReadMethod();
+ return method.invoke(targetBean, null);
+ }
+
+ public void set(Object targetBean, Object propValue)throws InvocationTargetException, IllegalAccessException{
+ Method method = descriptor.getWriteMethod();
+ method.invoke(targetBean, propValue);
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws/test-resources/provider/xml/web.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test-resources/provider/xml/web.xml?rev=420955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test-resources/provider/xml/web.xml (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test-resources/provider/xml/web.xml Tue Jul 11 12:33:12 2006
@@ -0,0 +1,43 @@
+<invoke>
+<web-app>
+ <servlet>
+ <servlet-name>snoop</servlet-name>
+ <servlet-class>SnoopServlet</servlet-class>
+ </servlet>
+ <servlet>
+ <servlet-name>file</servlet-name>
+ <servlet-class>ViewFile</servlet-class>
+ <init-param>
+ <param-name>initial</param-name>
+ <param-value>
+ 1000
+ </param-value>
+ <description>
+ The initial value for the counter <!-- optional -->
+ </description>
+ </init-param>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>
+ mv
+ </servlet-name>
+ <url-pattern>
+ *.wm
+ </url-pattern>
+ </servlet-mapping>
+
+ <distributed/>
+
+ <security-role>
+ <role-name>
+ manager
+ </role-name>
+ <role-name>
+ director
+ </role-name>
+ <role-name>
+ president
+ </role-name>
+ </security-role>
+</web-app>
+</invoke>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org