You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by sc...@apache.org on 2006/06/02 19:33:13 UTC
svn commit: r411218 [20/34] - in /webservices/muse: branches/1.0/
branches/1.0/src/examples/broker/ branches/1.0/src/examples/broker/WEB-INF/
branches/1.0/src/examples/consumer/ branches/1.0/src/examples/consumer/epr/
branches/1.0/src/examples/consumer...
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/JaxpUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/JaxpUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/JaxpUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/JaxpUtils.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,208 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.util.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.i18n.MessagesImpl;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+/**
+ * A set of generic JAXP utility methods.
+ *
+ * @author Ian P. Springer
+ */
+public abstract class JaxpUtils
+{
+ private static final Log LOG = LogFactory.getLog( JaxpUtils.class );
+
+ /** DOCUMENT_ME */
+ public static final Messages MSG = MessagesImpl.getInstance( );
+
+ /**
+ * DOCUMENT_ME
+ */
+ private static final Object TRANSFORMER_LOCK = new Object( );
+
+ /**
+ * DOCUMENT_ME
+ */
+ private static final String INDENT_SPACES = "2";
+
+ /**
+ * thread local that gives each thread its own TransformerFactory (since it is not thread-safe)
+ */
+ public static ThreadLocal TRANSFORMER_FACTORIES =
+ new ThreadLocal( )
+ {
+ protected synchronized Object initialValue( )
+ {
+ return TransformerFactory.newInstance( );
+ }
+ };
+
+ /**
+ * thread local that gives each thread its own DocumentBuilderFactory (since it is not thread-safe)
+ */
+ public static ThreadLocal DOCUMENT_BUILDER_FACTORIES =
+ new ThreadLocal( )
+ {
+ protected synchronized Object initialValue( )
+ {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance( );
+ dbf.setNamespaceAware( true );
+
+ return ( dbf );
+ }
+ };
+
+ /**
+ * Loads a DOM Document from an InputSource.
+ *
+ * @param in_source
+ *
+ * @return Document
+ *
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ */
+ public static Document loadDocument( InputSource in_source )
+ throws ParserConfigurationException,
+ SAXException,
+ IOException
+ {
+ DocumentBuilderFactory dbf = (DocumentBuilderFactory) DOCUMENT_BUILDER_FACTORIES.get( );
+ DocumentBuilder db = dbf.newDocumentBuilder( );
+
+ return ( db.parse( in_source ) );
+ }
+
+ /**
+ * Method to load a DOM Document from an InputStream.
+ *
+ * @param in_stream
+ *
+ * @return Document
+ *
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ */
+ public static Document loadDocument( InputStream in_stream )
+ throws ParserConfigurationException,
+ SAXException,
+ IOException
+ {
+ InputStreamReader utf8_stream = new InputStreamReader( in_stream, "UTF-8" );
+ Document doc = loadDocument( new InputSource( utf8_stream ) );
+ utf8_stream.close( );
+
+ return ( doc );
+ }
+
+ /**
+ * Converts a string containing an XML document into a {@link Document}.
+ *
+ * @param xmlString
+ *
+ * @return the W3C DOM document
+ *
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ */
+ public static Document toDocument( String xmlString )
+ throws ParserConfigurationException,
+ SAXException,
+ IOException
+ {
+ LOG.debug( MSG.getMessage( Keys.LOAD_XML_STRING, xmlString ) );
+ return ( loadDocument( IoUtils.toInputStream( xmlString ) ) );
+ }
+
+ /**
+ * Converts an XML {@link Node} into a string containing the corresponding XML. ***NOTE*** requires an XSLT
+ * implementation (ie - Xalan) in the classpath at runtime
+ *
+ * @param node a DOM node
+ *
+ * @return String representation of the node
+ *
+ * @throws Exception
+ */
+ public static String toString( Node node )
+ throws Exception
+ {
+ return ( toString( node, false ) );
+ }
+
+ /**
+ * Converts an XML {@link Node} into a string containing the corresponding XML, optionally pretty-printed with
+ * indenting and newlines. ***NOTE*** requires an XSLT implementation (ie - Xalan) in the classpath at runtime
+ *
+ * @param node a DOM node
+ * @param indentOutput whether or not to indent the output XML
+ *
+ * @return String representation of the node
+ *
+ * @throws Exception
+ */
+ public static String toString( Node node,
+ boolean indentOutput )
+ throws Exception
+ {
+ /**
+ * Due to a bug in the Transformer implementation we need to
+ * synchronize access to the transform() method.
+ */
+ synchronized ( TRANSFORMER_LOCK )
+ {
+ TransformerFactory transformer_factory = (TransformerFactory) TRANSFORMER_FACTORIES.get( );
+ Transformer transformer = transformer_factory.newTransformer( );
+
+ if ( indentOutput )
+ {
+ transformer.setOutputProperty( TransformConstants.OUTPUT_PROP_INDENT, "yes" );
+ transformer.setOutputProperty( TransformConstants.OUTPUT_PROP_INDENT_AMOUNT, INDENT_SPACES );
+ }
+
+ DOMSource dom_source = new DOMSource( node );
+ ByteArrayOutputStream doc_stream = new ByteArrayOutputStream( );
+ StreamResult result = new StreamResult( doc_stream );
+
+ transformer.transform( dom_source, result );
+
+ return ( doc_stream.toString( ) );
+ }
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/NameUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/NameUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/NameUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/NameUtils.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,171 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.util.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.i18n.MessagesImpl;
+import javax.xml.namespace.QName;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import java.util.Hashtable;
+import java.util.Map;
+
+/**
+ * @author Ian P. Springer (Hewlett-Packard Company), Sal Campana (Hewlett-Packard Company)
+ */
+public abstract class NameUtils
+{
+ private static final Log LOG = LogFactory.getLog( NameUtils.class );
+
+ /** DOCUMENT_ME */
+ public static final Messages MSG = MessagesImpl.getInstance( );
+ private static Map s_namespace_to_prefix_map = new Hashtable( );
+
+ /**
+ * Builds a valid concise prefix for the specified namespace URI.
+ *
+ * @param nsURI the namespace URI
+ *
+ * @return the prefix
+ */
+ public static String getNamespacePrefix( String nsURI )
+ {
+ LOG.debug( MSG.getMessage( Keys.BLD_PREFIX_FOR_NAMESPC, nsURI ) );
+ if ( nsURI == null )
+ {
+ return "";
+ }
+
+ //first check to see if we've done this yet
+ if ( s_namespace_to_prefix_map.containsKey( nsURI ) )
+ {
+ return (String) s_namespace_to_prefix_map.get( nsURI );
+ }
+
+ // haven't done it yet so do it now
+ String prefix = nsURI;
+
+ while ( ( prefix.length( ) > 0 ) && !Character.isLetterOrDigit( prefix.charAt( prefix.length( ) - 1 ) ) )
+ {
+ prefix = prefix.substring( 0, prefix.length( ) - 1 );
+ }
+
+ int start_index = prefix.lastIndexOf( '/' );
+
+ if ( start_index == -1 )
+ {
+ start_index = prefix.lastIndexOf( '.' );
+ }
+
+ if ( start_index == -1 )
+ {
+ start_index = prefix.lastIndexOf( ':' );
+ }
+
+ prefix = prefix.substring( start_index + 1 );
+
+ String newPrefix = prefix;
+
+ for ( int i = 0; i < prefix.length( ); i++ )
+ {
+ char current_char = prefix.charAt( i );
+
+ if ( !isValidPrefixChar( current_char ) )
+ {
+ newPrefix = newPrefix.replace( current_char, '-' );
+ }
+ }
+
+ return getUniquePrefix( newPrefix, nsURI );
+ }
+
+ /**
+ * Creates a SAAJ {@link Name} with the specified localpart, prefix, and namespace URI.
+ *
+ * @return a SAAJ {@link Name}
+ */
+ public static Name createName( String localpart,
+ String prefix,
+ String uri )
+ throws SOAPException
+ {
+ LOG.debug( MSG.getMessage( Keys.CREATING_NAME, localpart, prefix, uri ) );
+ return ( SOAPFactory.newInstance( ).createName( localpart, prefix, uri ) );
+ }
+
+ /**
+ * Converts a JAX {@link QName} to a SAAJ {@link Name}.
+ *
+ * @param qname a JAX {@link QName}
+ *
+ * @return a SAAJ {@link Name}
+ */
+ public static Name toName( QName qname )
+ throws SOAPException
+ {
+ LOG.debug( MSG.getMessage( Keys.CONVRT_QNAME_TO_NAME,
+ qname.toString( ) ) );
+ return createName( qname.getLocalPart( ),
+ qname.getPrefix( ),
+ qname.getNamespaceURI( ) );
+ }
+
+ /**
+ * Converts a {@link javax.xml.soap.Name} to a {@link javax.xml.namespace.QName}.
+ *
+ * @param name a SAAJ {@link javax.xml.soap.Name}
+ *
+ * @return a JAX {@link javax.xml.namespace.QName}
+ */
+ public static QName toQName( Name name )
+ {
+ LOG.debug( MSG.getMessage( Keys.CONVRT_NAME_TO_QNAME,
+ name.getQualifiedName( ) ) );
+ return ( name != null ) ? new QName( name.getURI( ),
+ name.getLocalName( ) ) : null;
+ }
+
+ private static String getUniquePrefix( String newprefix,
+ String ns_uri )
+ {
+ //check if this prefix has been defined
+ while ( s_namespace_to_prefix_map.containsValue( newprefix ) )
+ {
+ newprefix = newprefix + "X";
+ }
+
+ s_namespace_to_prefix_map.put( ns_uri, newprefix );
+
+ return newprefix;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param current_char DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ private static boolean isValidPrefixChar( char current_char )
+ {
+ return ( Character.isLetterOrDigit( current_char ) ) || ( current_char == '-' ) || ( current_char == '_' )
+ || ( current_char == '.' );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/OperationInfo.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/OperationInfo.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/OperationInfo.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/OperationInfo.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,239 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.ws.resource.tool.GenerationUtils;
+import javax.wsdl.Fault;
+import javax.wsdl.Input;
+import javax.wsdl.Operation;
+import javax.wsdl.Output;
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * The Java method signature info for a WSDL operation.
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
+ */
+public class OperationInfo
+{
+ private String m_methodName;
+ private String m_methodSig;
+ private QName m_requestElemName;
+ private Map m_faults;
+ private String m_fullyQualifiedResponseClassName;
+ private String m_fullyQualifiedRequestClassName;
+
+ /**
+ * Creates a new {@link OperationInfo} object.
+ *
+ * @param op DOCUMENT_ME
+ * @param targetNamespace DOCUMENT_ME
+ */
+ public OperationInfo( Operation op,
+ String targetNamespace )
+ {
+ m_methodName = StringUtils.uncapitalize( op.getName( ) );
+ Input input = op.getInput( );
+ if ( input != null )
+ {
+ Map inputParts = input.getMessage( ).getParts( );
+ if ( inputParts.size( ) > 1 )
+ {
+ throw new RuntimeException( "WSDL input message named " + input.getMessage( ).getQName( )
+ + " has more than one part - input messages must have at most one part." );
+ }
+
+ if ( inputParts.size( ) == 1 )
+ {
+ Part inputPart = (Part) inputParts.values( ).iterator( ).next( );
+ m_requestElemName = inputPart.getElementName( );
+ m_fullyQualifiedRequestClassName =
+ XmlBeanNameUtils.getDocumentElementXmlBeanClassName( m_requestElemName );
+ }
+ else // no input parts
+ {
+ m_fullyQualifiedRequestClassName = "";
+ }
+ }
+ else
+ {
+ m_fullyQualifiedRequestClassName = "";
+ }
+
+ Output output = op.getOutput( );
+ if ( output != null )
+ {
+ Map outputParts = output.getMessage( ).getParts( );
+ if ( outputParts.size( ) > 1 )
+ {
+ throw new RuntimeException( "WSDL output message named " + input.getMessage( ).getQName( )
+ + " has more than one part - output messages must have at most one part." );
+ }
+
+ if ( outputParts.size( ) == 1 )
+ {
+ Part outputPart = (Part) outputParts.values( ).iterator( ).next( );
+ m_fullyQualifiedResponseClassName =
+ XmlBeanNameUtils.getDocumentElementXmlBeanClassName( outputPart.getElementName( ) );
+ }
+ else // no output parts
+ {
+ m_fullyQualifiedResponseClassName = "void";
+ }
+ }
+ else // no output
+ {
+ m_fullyQualifiedResponseClassName = "void";
+ }
+
+ m_methodSig =
+ m_fullyQualifiedResponseClassName + " " + m_methodName + "( " + m_fullyQualifiedRequestClassName
+ + " requestDoc )";
+
+ //add faults to signature....
+ m_faults = op.getFaults( );
+ if ( !m_faults.isEmpty( ) )
+ {
+ m_methodSig += " throws ";
+ Iterator iterator = m_faults.keySet( ).iterator( );
+ while ( iterator.hasNext( ) )
+ {
+ String faultName = (String) iterator.next( );
+ Fault fault = (Fault) m_faults.get( faultName );
+ Part part = (Part) fault.getMessage( ).getParts( ).values( ).iterator( ).next( );
+ String javaPackageName = GenerationUtils.getJavaPackageName( targetNamespace );
+ if ( part.getElementName( ) == null )
+ {
+ //its a type..get the name of the type
+ faultName = part.getTypeName( ).getLocalPart( );
+ }
+
+ faultName = javaPackageName + "." + faultName + "Exception";
+ m_methodSig += faultName;
+ if ( iterator.hasNext( ) )
+ {
+ m_methodSig += ", ";
+ }
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Map getFaults( )
+ {
+ return m_faults;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getFullyQualifiedRequestClassName( )
+ {
+ return m_fullyQualifiedRequestClassName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getFullyQualifiedResponseClassName( )
+ {
+ return m_fullyQualifiedResponseClassName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getJavaMethodName( )
+ {
+ return m_methodName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getJavaMethodSignature( )
+ {
+ return m_methodSig;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public QName getRequestElementName( )
+ {
+ return m_requestElemName;
+ }
+
+ /**
+ * Returns the class name without the package
+ *
+ * @return class name without the package
+ */
+ public String getUnqualifiedRequestClassName( )
+ {
+ return m_fullyQualifiedRequestClassName.substring( m_fullyQualifiedRequestClassName.lastIndexOf( "." ) + 1 );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getUnqualifiedRequestTypeName( )
+ {
+ return getUnqualifiedRequestClassName( ).substring( 0,
+ getUnqualifiedRequestClassName( ).lastIndexOf( "Document" ) );
+ }
+
+ /**
+ * Returns the class name without the package
+ *
+ * @return Class name without the package
+ */
+ public String getUnqualifiedResponseClassName( )
+ {
+ return m_fullyQualifiedResponseClassName.substring( m_fullyQualifiedResponseClassName.lastIndexOf( "." ) + 1 );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getUnqualifiedResponseTypeName( )
+ {
+ return getUnqualifiedResponseClassName( ).substring( 0,
+ getUnqualifiedResponseClassName( ).lastIndexOf( "Document" ) );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/SaajUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/SaajUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/SaajUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/SaajUtils.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,277 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import org.apache.ws.util.helper.Dom2SaajConverter;
+import org.apache.ws.util.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.i18n.MessagesImpl;
+import org.w3c.dom.Element;
+import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.Node;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.Text;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * LOG-DONE
+ *
+ * @author Ian P. Springer (Hewlett-Packard Company)
+ */
+public abstract class SaajUtils
+{
+ /** DOCUMENT_ME */
+ public static final Messages MSG = MessagesImpl.getInstance( );
+
+ /**
+ * Given a {@link SOAPElement}, returns a list containing the children of that element. If at least one of the
+ * children is a SOAPElement, any {@link Text} nodes are excluded from the list. This is because it is assumed that
+ * if the specified element has mixed content, it is only because of insignificant whitespace text nodes.
+ *
+ * @param soapElem a SAAJ {@link SOAPElement}
+ *
+ * @return a list containing the children of the specified {@link SOAPElement}
+ */
+ public static List getChildNodes( SOAPElement soapElem )
+ {
+ List elem_children = new ArrayList( );
+ List text_children = new ArrayList( );
+ Iterator node_iter = soapElem.getChildElements( );
+
+ while ( node_iter.hasNext( ) )
+ {
+ Node child_node = (Node) node_iter.next( );
+
+ if ( isSOAPElement( child_node ) )
+ {
+ elem_children.add( child_node );
+ }
+ else
+ {
+ text_children.add( child_node );
+ }
+ }
+
+ return ( elem_children.isEmpty( ) ? text_children : elem_children );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param elem DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static QName getQualifiedName( SOAPElement elem )
+ {
+ return ( elem != null ) ? NameUtils.toQName( elem.getElementName( ) ) : null;
+ }
+
+ /**
+ * Returns true if the specified SAAJ node is an element, or false otherwise.
+ *
+ * @param soap_node a SAAJ node
+ *
+ * @return true if the specified SAAJ node is an element, or false otherwise
+ */
+ public static boolean isSOAPElement( Node soap_node )
+ {
+ // NOTE: the second condition below is nessary for Axis, because its Text impl also implements SOAPElement
+ return ( soap_node instanceof SOAPElement && !( soap_node instanceof Text ) );
+ }
+
+ /**
+ * Returns true if the specified SAAJ node is text, or false otherwise.
+ *
+ * @param soap_node a SAAJ node
+ *
+ * @return true if the specified SAAJ node is text, or false otherwise
+ */
+ public static boolean isText( Node soap_node )
+ {
+ return ( soap_node instanceof Text );
+ }
+
+ /**
+ * Returns the value of the specified SAAJ text node.
+ *
+ * @param soapNode a SAAJ text node
+ *
+ * @return the value of the specified SAAJ text node
+ *
+ * @throws SOAPException
+ */
+ public static String getValue( Node soapNode )
+ throws SOAPException
+ {
+ if ( soapNode == null )
+ {
+ throw new IllegalArgumentException( MSG.getMessage( Keys.PARAM_MAY_NOT_BE_NULL ) );
+ }
+
+ if ( isText( soapNode ) )
+ {
+ return getTextValue( (Text) soapNode );
+ }
+ else
+ {
+ return getSOAPElementValue( (SOAPElement) soapNode );
+ }
+ }
+
+ /**
+ * Adds a DOM {@link org.w3c.dom.Element} as an entry to a SAAJ {@link Detail}.
+ *
+ * @param detail a SAAJ detail
+ * @param domElem a DOM element to be added as an entry in the specified detail
+ *
+ * @return a SAAJ detail entry
+ *
+ * @throws javax.xml.soap.SOAPException
+ */
+ public static DetailEntry addDetailEntry( Detail detail,
+ Element domElem )
+ throws SOAPException
+ {
+ return ( new Dom2SaajConverter( ).addDetailEntry( detail, domElem ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param soapElem DOCUMENT_ME
+ * @param value DOCUMENT_ME
+ *
+ * @throws SOAPException DOCUMENT_ME
+ */
+ public static void addTextNode( SOAPElement soapElem,
+ String value )
+ throws SOAPException
+ {
+ soapElem.addTextNode( value );
+
+ if ( soapElem.getValue( ) == null )
+ {
+ Iterator childElemIter = soapElem.getChildElements( );
+
+ if ( childElemIter.hasNext( ) )
+ {
+ Node firstChild = (Node) childElemIter.next( );
+
+ if ( firstChild instanceof Text )
+ {
+ firstChild.setValue( value );
+
+ return;
+ }
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param value DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws SOAPException DOCUMENT_ME
+ */
+ public static Text createTextNode( String value )
+ throws SOAPException
+ {
+ return ( (Text) SOAPFactory.newInstance( ).createElement( "foo" ).addTextNode( value ).getChildElements( )
+ .next( ) );
+ }
+
+ /**
+ * Converts a DOM {@link org.w3c.dom.Element} to a SAAJ {@link javax.xml.soap.SOAPElement}.
+ *
+ * @param elem a DOM {@link org.w3c.dom.Element}
+ *
+ * @return a {@link javax.xml.soap.SOAPElement}
+ *
+ * @throws javax.xml.soap.SOAPException
+ */
+ public static SOAPElement toSOAPElement( Element elem )
+ throws SOAPException
+ {
+ return ( new Dom2SaajConverter( ).toSOAPElement( elem ) );
+ }
+
+ private static String getSOAPElementValue( SOAPElement soapElem )
+ {
+ String value = soapElem.getValue( );
+
+ if ( value == null )
+ {
+ Text textNode = getTextNode( soapElem );
+
+ if ( textNode != null )
+ {
+ value = textNode.getValue( );
+ }
+ }
+
+ if ( value == null )
+ {
+ value = soapElem.getNodeValue( );
+ }
+
+ return value;
+ }
+
+ private static Text getTextNode( SOAPElement soapElem )
+ {
+ Iterator childElemIter = soapElem.getChildElements( );
+
+ if ( childElemIter.hasNext( ) )
+ {
+ Node firstChild = (Node) childElemIter.next( );
+
+ if ( firstChild instanceof Text )
+ {
+ return (Text) firstChild;
+ }
+ }
+
+ return null;
+ }
+
+ private static String getTextValue( Text soapText )
+ throws SOAPException
+ {
+ String value = soapText.getValue( );
+
+ if ( value == null )
+ {
+ value = soapText.toString( );
+ }
+
+ if ( value == null )
+ {
+ throw new SOAPException( MSG.getMessage( Keys.TEXT_NODE_IS_NULL ) );
+ }
+
+ return value;
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/TransformConstants.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/TransformConstants.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/TransformConstants.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/TransformConstants.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,99 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+
+/**
+ * Created by IntelliJ IDEA. User: ips Date: Oct 22, 2004 Time: 2:33:45 PM To change this template use File | Settings |
+ * File Templates.
+ */
+public interface TransformConstants
+{
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_METHOD = "method";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_VERSION = "version";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_ENCODING = "encoding";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_OMIT_XML_DECLARATION = "omit-xml-declaration";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_STANDALONE = "standalone";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_DOCTYPE_PUBLIC = "doctype-public";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_DOCTYPE_SYSTEM = "doctype-system";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_CDATA_SECTION_ELEMENTS = "cdata-section-elements";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_INDENT = "indent";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_MEDIA_TYPE = "media-type";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_INDENT_AMOUNT = "{http://xml.apache.org/xalan}indent-amount";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_CONTENT_HANDLER = "{http://xml.apache.org/xalan}content-handler";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_ENTITIES = "{http://xml.apache.org/xalan}entities";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_USE_URL_ESCAPING = "{http://xml.apache.org/xalan}use-url-escaping";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String OUTPUT_PROP_OMIT_META_TAG = "{http://xml.apache.org/xalan}omit-meta-tag";
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/WsdlUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/WsdlUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/WsdlUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/WsdlUtils.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,158 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import javax.wsdl.Import;
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Output;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Generic utility methods for working with various JWSDL objects.
+ *
+ * @author Ian Springer (Hewlett-Packard Company)
+ */
+public abstract class WsdlUtils
+{
+ /**
+ * DOCUMENT_ME
+ *
+ * @param service DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static Map getPortTypes( Service service )
+ {
+ Map portTypes = new HashMap( );
+ Map ports = service.getPorts( );
+ Iterator portsIter = ports.values( ).iterator( );
+ while ( portsIter.hasNext( ) )
+ {
+ Port port = (Port) portsIter.next( );
+ PortType portType = port.getBinding( ).getPortType( );
+ portTypes.put( portType.getQName( ),
+ portType );
+ }
+
+ return portTypes;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param import1 DOCUMENT_ME
+ * @param import2 DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static boolean equals( Import import1,
+ Import import2 )
+ {
+ if ( import1 == null )
+ {
+ return import2 == null;
+ }
+ else if ( import2 == null )
+ {
+ return false;
+ }
+
+ return import1.getNamespaceURI( ).equals( import2.getNamespaceURI( ) )
+ && import1.getLocationURI( ).equals( import2.getLocationURI( ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param op1 DOCUMENT_ME
+ * @param op2 DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static boolean equals( Operation op1,
+ Operation op2 )
+ {
+ if ( op1 == null )
+ {
+ return op2 == null;
+ }
+
+ if ( op2 == null )
+ {
+ return false;
+ }
+
+ return equals( op1.getInput( ),
+ op2.getInput( ) ) && equals( op1.getOutput( ),
+ op2.getOutput( ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param input1 DOCUMENT_ME
+ * @param input2 DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static boolean equals( Input input1,
+ Input input2 )
+ {
+ return equals( input1.getMessage( ),
+ input2.getMessage( ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param output1 DOCUMENT_ME
+ * @param output2 DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static boolean equals( Output output1,
+ Output output2 )
+ {
+ if ( ( output1 == null ) && ( output2 == null ) )
+ {
+ return true;
+ }
+
+ return equals( output1.getMessage( ),
+ output2.getMessage( ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param msg1 DOCUMENT_ME
+ * @param msg2 DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static boolean equals( Message msg1,
+ Message msg2 )
+ {
+ return msg1.getQName( ).equals( msg2.getQName( ) );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/WsrfWsdlUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/WsrfWsdlUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/WsrfWsdlUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/WsrfWsdlUtils.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,543 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import org.apache.ws.resource.InvalidWsrfWsdlException;
+import org.apache.xml.utils.PrefixResolver;
+import org.apache.xml.utils.PrefixResolverDefault;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.PortType;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+import javax.xml.namespace.QName;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+/**
+ * Utility methods for working with a WSRF WSDL definition.
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
+ */
+public abstract class WsrfWsdlUtils
+{
+ /**
+ * DOCUMENT_ME
+ *
+ * @param portType DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws org.apache.ws.resource.InvalidWsrfWsdlException DOCUMENT_ME
+ */
+ public static String getMetadataDescriptorLocation( PortType portType )
+ throws org.apache.ws.resource.InvalidWsrfWsdlException
+ {
+ Map extAttribs = portType.getExtensionAttributes( );
+ final QName METADATA_DESCRIPTOR_PORTTYPE_ATTRIB =
+ new QName( "http://docs.oasis-open.org/wsrf/2004/10/wsrf-WSResourceMetadataDescriptor-1.0-draft-01.xsd",
+ "metadataDescriptorLocation", "wsrmd" );
+ QName qValue = ( (QName) extAttribs.get( METADATA_DESCRIPTOR_PORTTYPE_ATTRIB ) );
+ if ( qValue == null )
+ {
+ return null;
+ }
+
+ String value = qValue.getLocalPart( );
+ StringTokenizer tokenizer = new StringTokenizer( value );
+ if ( tokenizer.countTokens( ) != 2 )
+ {
+ throw new org.apache.ws.resource.InvalidWsrfWsdlException( METADATA_DESCRIPTOR_PORTTYPE_ATTRIB
+ + " attribute on portType must be of the format \"namespaceURI locationURL\"" );
+ }
+
+ tokenizer.nextToken( );
+ return tokenizer.nextToken( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param portType DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static QName getMetadataDescriptorName( PortType portType )
+ {
+ Map extAttribs = portType.getExtensionAttributes( );
+ return (QName) extAttribs.get( new QName( "http://docs.oasis-open.org/wsrf/2004/10/wsrf-WSResourceMetadataDescriptor-1.0-draft-01.xsd",
+ "metadataDescriptor", "wsrmd" ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param portType DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static QName getResourcePropertiesDocumentName( PortType portType )
+ {
+ Map extAttribs = portType.getExtensionAttributes( );
+ QName rpDocDefQName =
+ (QName) extAttribs.get( org.apache.ws.resource.properties.v2004_11.ResourcePropertiesConstants.RESOURCE_PROPERTIES_PORTTYPE_ATTRIB );
+ if ( rpDocDefQName == null )
+ {
+ rpDocDefQName =
+ (QName) extAttribs.get( org.apache.ws.resource.properties.v2004_06.ResourcePropertiesConstants.RESOURCE_PROPERTIES_PORTTYPE_ATTRIB );
+ }
+
+ return rpDocDefQName;
+ }
+
+ /**
+ * @param rpDocElemName
+ * @param def
+ * @param baseUrl
+ *
+ * @return the names of the resource properties associated with the specified portType
+ */
+ public static QName[] getResourcePropertyNames( QName rpDocElemName,
+ Definition def,
+ URL baseUrl )
+ throws InvalidWsrfWsdlException
+ {
+ if ( rpDocElemName == null )
+ {
+ return null;
+ }
+
+ Set propNames = new HashSet( );
+ Element[] schemaElems = getSchemaElements( def );
+ XsdElement rpDocXsdElem = null;
+ for ( int i = 0; i < schemaElems.length; i++ )
+ {
+ rpDocXsdElem = getXsdElementElementRecursively( schemaElems[i], rpDocElemName, baseUrl );
+ if ( rpDocXsdElem != null )
+ {
+ break;
+ }
+ }
+
+ if ( rpDocXsdElem == null )
+ {
+ throw new InvalidWsrfWsdlException( "Unable to locate the ResourceProperties document element with QName "
+ + rpDocElemName );
+ }
+
+ QName type = getQualifiedAttribute( rpDocXsdElem, "type" );
+ Element rpDocTypeElem;
+ if ( type != null )
+ {
+ if ( !type.getNamespaceURI( ).equals( rpDocXsdElem.getSchemaElement( ).getAttribute( "targetNamespace" ) ) )
+ {
+ throw new InvalidWsrfWsdlException( "This tool currently does not support referencing a ResourceProperties complexType that is not in the current schema's targetNamespace." );
+ }
+
+ rpDocTypeElem = getComplexTypeByName( rpDocXsdElem.getSchemaElement( ),
+ type.getLocalPart( ) );
+ }
+ else
+ {
+ rpDocTypeElem =
+ (Element) rpDocXsdElem.getElement( )
+ .getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, "complexType" ).item( 0 );
+ }
+
+ if ( rpDocTypeElem == null )
+ {
+ throw new InvalidWsrfWsdlException( "Unable to determine type of the ResourceProperties document element with QName "
+ + rpDocElemName
+ + " - expected either a type atribute or a nested anonymous complexType element." );
+ }
+
+ Element sequenceElem = null;
+ NodeList sequenceNodes = rpDocTypeElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, "sequence" );
+ if ( sequenceNodes != null )
+ {
+ sequenceElem = (Element) sequenceNodes.item( 0 );
+ }
+ else
+ {
+ sequenceNodes = rpDocTypeElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, "all" );
+ if ( sequenceNodes != null )
+ {
+ sequenceElem = (Element) sequenceNodes.item( 0 );
+ }
+ }
+
+ if ( sequenceElem == null )
+ {
+ throw new RuntimeException( "Resource property element definitions must be contained in an xsd:sequence or an xsd:all element." );
+ }
+
+ NodeList propElems = sequenceElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, "element" );
+ for ( int j = 0; j < propElems.getLength( ); j++ )
+ {
+ Element propElem = (Element) propElems.item( j );
+ QName propName =
+ getQualifiedAttribute( new XsdElement( propElem,
+ rpDocXsdElem.getSchemaElement( ) ),
+ "ref" );
+ if ( propName == null )
+ {
+ throw new InvalidWsrfWsdlException( "All element defs within the resource property document def must have a 'ref' attribute that points at a global element def." );
+ }
+
+ propNames.add( propName );
+ }
+
+ return (QName[]) propNames.toArray( new QName[0] );
+ }
+
+ /**
+ *
+ * @param def a JWSDL definition
+ *
+ * @return array of DOM elements, representing any xsd:schema elements within the specified definition's types section
+ */
+ public static Element[] getSchemaElements( Definition def )
+ {
+ List schemaElems = new ArrayList( );
+ if ( def.getTypes( ) != null )
+ {
+ List extElems = def.getTypes( ).getExtensibilityElements( );
+ for ( int i = 0; i < extElems.size( ); i++ )
+ {
+ ExtensibilityElement extElem = (ExtensibilityElement) extElems.get( i );
+ if ( extElem instanceof UnknownExtensibilityElement )
+ {
+ UnknownExtensibilityElement unknownExtElem = (UnknownExtensibilityElement) extElem;
+ Element elem = unknownExtElem.getElement( );
+ if ( elem.getNamespaceURI( ).equals( XmlConstants.NSURI_SCHEMA_XSD )
+ && elem.getLocalName( ).equals( XmlConstants.XSD_SCHEMA.getLocalPart( ) ) )
+ {
+ schemaElems.add( elem );
+ }
+ }
+ }
+ }
+
+ return (Element[]) schemaElems.toArray( new Element[0] );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param mostDerivedPortType DOCUMENT_ME
+ * @param specPortType DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static boolean implementsPortType( PortType mostDerivedPortType,
+ PortType specPortType )
+ {
+ List specOps = specPortType.getOperations( );
+ if ( specOps.size( ) == 0 )
+ {
+ return false;
+
+ // TODO (v1.1): need to determine if props are present for portTypes which have no ops.
+ }
+
+ boolean foundSome = false;
+ for ( int i = 0; i < specOps.size( ); i++ )
+ {
+ Operation specOp = (Operation) specOps.get( i );
+ Operation aggregatedOp = mostDerivedPortType.getOperation( specOp.getName( ),
+ null,
+ null );
+ if ( !WsdlUtils.equals( specOp, aggregatedOp ) )
+ {
+ if ( foundSome )
+ {
+ System.out.println( "WARNING: PortType " + mostDerivedPortType.getQName( )
+ + " contains some, but not all, operations from portType "
+ + specPortType.getQName( ) );
+ }
+
+ return false;
+ }
+
+ if ( !isInheritedOperation( specOp, specPortType ) )
+ {
+ foundSome = true;
+ }
+ }
+
+ return true;
+ }
+
+ private static Element getComplexTypeByName( Element schemaElem,
+ String name )
+ {
+ NodeList children = schemaElem.getChildNodes( );
+ for ( int i = 0; i < children.getLength( ); i++ )
+ {
+ Node child = children.item( i );
+ if ( child instanceof Element && child.getLocalName( ).equals( "complexType" ) )
+ {
+ Element elementElem = (Element) child;
+ if ( String.valueOf( elementElem.getAttribute( "name" ) ).equals( name ) )
+ {
+ return elementElem;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private static boolean isInheritedOperation( Operation specOp,
+ PortType specPortType )
+ {
+ return !specOp.getInput( ).getMessage( ).getQName( ).getNamespaceURI( ).equals( specPortType.getQName( )
+ .getNamespaceURI( ) );
+ }
+
+ private static QName getQualifiedAttribute( XsdElement xsdElem,
+ String attribName )
+ throws InvalidWsrfWsdlException
+ {
+ String value = xsdElem.getElement( ).getAttribute( attribName );
+ if ( "".equals( value ) )
+ {
+ return null;
+ }
+
+ PrefixResolver prefixResolver = new PrefixResolverDefault( xsdElem.getSchemaElement( ) );
+ QName propName = null;
+ try
+ {
+ propName = toQName( value, prefixResolver );
+ }
+ catch ( PrefixResolutionException pre )
+ {
+ throw new InvalidWsrfWsdlException( "Unable to resolve prefix '" + pre.getPrefix( )
+ + "' in xsd:element '" + attribName + "' attribute value." );
+ }
+ catch ( InvalidValueException ive )
+ {
+ throw new InvalidWsrfWsdlException( "Value for xsd:element 'ref' attribute must be qualified via a namespace prefix." );
+ }
+
+ return propName;
+ }
+
+ private static XsdElement getXsdElementElement( Element schemaElem,
+ QName name )
+ {
+ NodeList children = schemaElem.getChildNodes( );
+ for ( int i = 0; i < children.getLength( ); i++ )
+ {
+ Node child = children.item( i );
+ if ( child instanceof Element && child.getLocalName( ).equals( "element" ) )
+ {
+ Element elementElem = (Element) child;
+ if ( String.valueOf( elementElem.getAttribute( "name" ) ).equals( name.getLocalPart( ) ) )
+ {
+ return new XsdElement( elementElem, schemaElem );
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private static XsdElement getXsdElementElementRecursively( Element xsdSchemaElem,
+ QName xsdElemName,
+ URL baseUrl )
+ throws InvalidWsrfWsdlException
+ {
+ XsdElement xsdElementElem = getXsdElementElement( xsdSchemaElem, xsdElemName );
+ if ( xsdElementElem == null )
+ {
+ String[] schemaLocations = findImportsAndIncludes( xsdSchemaElem,
+ xsdElemName.getNamespaceURI( ) );
+ for ( int j = 0; j < schemaLocations.length; j++ )
+ {
+ String location = schemaLocations[j];
+ URL schemaUrl = null;
+ Document schemaDoc = null;
+ try
+ {
+ schemaUrl = new URL( baseUrl, location );
+ schemaDoc = JaxpUtils.loadDocument( schemaUrl.openStream( ) );
+ }
+ catch ( Exception e )
+ {
+ throw new InvalidWsrfWsdlException( "Failed to load schema at location " + location );
+ }
+
+ xsdElementElem =
+ getXsdElementElementRecursively( schemaDoc.getDocumentElement( ),
+ xsdElemName,
+ schemaUrl );
+ if ( xsdElementElem != null )
+ {
+ break;
+ }
+ }
+ }
+
+ return xsdElementElem;
+ }
+
+ private static String[] findImportsAndIncludes( Element schemaElem,
+ String namespaceURI )
+ {
+ List elems = new ArrayList( );
+ NodeList imports =
+ schemaElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, XmlConstants.XSD_ATTRIB_IMPORT );
+ for ( int i = 0; i < imports.getLength( ); i++ )
+ {
+ Element importNode = (Element) imports.item( i );
+ Attr attributeNode = importNode.getAttributeNode( "namespace" );
+ if ( attributeNode != null )
+ {
+ if ( namespaceURI.equals( attributeNode.getValue( ) ) )
+ {
+ elems.add( importNode );
+ }
+ }
+ }
+
+ NodeList includes =
+ schemaElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, XmlConstants.XSD_ATTRIB_INCLUDE );
+ for ( int i = 0; i < includes.getLength( ); i++ )
+ {
+ elems.add( includes.item( i ) );
+ }
+
+ String[] locations = new String[elems.size( )];
+ for ( int i = 0; i < elems.size( ); i++ )
+ {
+ Element element = (Element) elems.get( i );
+ Attr attributeNode = element.getAttributeNode( "schemaLocation" );
+ if ( attributeNode != null )
+ {
+ locations[i] = attributeNode.getValue( );
+ }
+ }
+
+ return locations;
+ }
+
+ private static QName toQName( String value,
+ PrefixResolver prefixResolver )
+ throws InvalidValueException,
+ PrefixResolutionException
+ {
+ StringTokenizer tokenizer = new StringTokenizer( value, ":" );
+ if ( tokenizer.countTokens( ) != 2 )
+ {
+ throw new InvalidValueException( );
+ }
+
+ String prefix = tokenizer.nextToken( );
+ String localName = tokenizer.nextToken( );
+
+ // TODO: write our own prefix resolver to eliminate dep on Xalan
+ String namespace = prefixResolver.getNamespaceForPrefix( prefix );
+ if ( namespace == null )
+ {
+ throw new PrefixResolutionException( prefix );
+ }
+
+ return new QName( namespace, localName, prefix );
+ }
+
+ private static class InvalidValueException
+ extends Exception
+ {
+ }
+
+ private static class PrefixResolutionException
+ extends Exception
+ {
+ private String m_prefix;
+
+ /**
+ * Creates a new {@link PrefixResolutionException} object.
+ *
+ * @param prefix DOCUMENT_ME
+ */
+ public PrefixResolutionException( String prefix )
+ {
+ super( );
+ m_prefix = prefix;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getPrefix( )
+ {
+ return m_prefix;
+ }
+ }
+
+ private static class XsdElement
+ {
+ private Element m_elem;
+ private Element m_schemaElem;
+
+ /**
+ * Creates a new {@link XsdElement} object.
+ *
+ * @param elem DOCUMENT_ME
+ * @param schemaElem DOCUMENT_ME
+ */
+ public XsdElement( Element elem,
+ Element schemaElem )
+ {
+ m_elem = elem;
+ m_schemaElem = schemaElem;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Element getElement( )
+ {
+ return m_elem;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Element getSchemaElement( )
+ {
+ return m_schemaElem;
+ }
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlBeanNameUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlBeanNameUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlBeanNameUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlBeanNameUtils.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,78 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import org.apache.xmlbeans.impl.common.NameUtil;
+import javax.xml.namespace.QName;
+
+/**
+ * A set of utility methods for obtaining the names of the Java classes associated with
+ * a particular qualified element name.
+ *
+ * @author Ian Springer
+ */
+public abstract class XmlBeanNameUtils
+{
+ /**
+ * DOCUMENT_ME
+ *
+ * @param propsDocElemQName DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static String getDocumentElementXmlBeanClassName( QName propsDocElemQName )
+ {
+ return NameUtil.getClassNameFromQName( propsDocElemQName ) + "Document";
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param propsDocElemQName DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static String getDocumentElementXmlBeanFactoryClassName( QName propsDocElemQName )
+ {
+ return getDocumentElementXmlBeanClassName( propsDocElemQName ) + "$Factory";
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param propsDocElemQName DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static String getElementXmlBeanClassName( QName propsDocElemQName )
+ {
+ return getDocumentElementXmlBeanClassName( propsDocElemQName ) + "."
+ + getElementXmlBeanUnqualifiedClassName( propsDocElemQName );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param propsDocElemQName DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static String getElementXmlBeanUnqualifiedClassName( QName propsDocElemQName )
+ {
+ String props_xml_bean_class_name = NameUtil.getClassNameFromQName( propsDocElemQName );
+ return props_xml_bean_class_name.substring( props_xml_bean_class_name.lastIndexOf( '.' ) + 1 );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlBeanUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlBeanUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlBeanUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlBeanUtils.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,668 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import org.apache.ws.util.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.i18n.MessagesImpl;
+import org.apache.xmlbeans.SchemaType;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPElement;
+import java.io.File;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Generic utility methods for working with Apache XMLBeans.
+ *
+ * @author Ian Springer
+ * @author Sal Campana
+ */
+public abstract class XmlBeanUtils
+{
+ private static final Messages MSG = MessagesImpl.getInstance( );
+
+ /**
+ *
+ * @param xBean
+ * @param attribName
+ * @return
+ */
+ public static String getAttributeValue( XmlObject xBean,
+ QName attribName )
+ {
+ XmlCursor xCursor = xBean.newCursor( );
+ String value = xCursor.getAttributeText( attribName );
+ xCursor.dispose( );
+ return value;
+ }
+
+ /**
+ * @param xBean
+ *
+ * @return
+ */
+ public static QName getAttributeValueAsQName( XmlObject xBean,
+ QName attribName )
+ {
+ String value = getAttributeValue( xBean, attribName );
+ return toQName( value, xBean );
+ }
+
+ /**
+ * Returns an array containing all child elements, with the specified name, of the specified XMLBean.
+ *
+ * @param xBean an XMLBean that represents an XML element
+ * @param name the name to look for, or null to return all child elements
+ *
+ * @return an array containing all child elements, with the specified name, of the specified XMLBean
+ */
+ public static XmlObject[] getChildElements( XmlObject xBean,
+ QName name )
+ {
+ List foundElems = new ArrayList( );
+ xBean = getRootElement( xBean );
+ XmlCursor xCursor = xBean.newCursor( );
+ for ( boolean hasNext = xCursor.toFirstChild( ); hasNext; hasNext = xCursor.toNextSibling( ) )
+ {
+ if ( ( name == null ) || getName( xCursor ).equals( name ) )
+ {
+ foundElems.add( xCursor.getObject( ) );
+ }
+ }
+
+ xCursor.dispose( );
+ return (XmlObject[]) foundElems.toArray( new XmlObject[0] );
+ }
+
+ /**
+ * Returns an array containing all child elements of the specified XMLBean.
+ *
+ * @param xBean an XMLBean that represents an XML element
+ *
+ * @return an array containing all child elements of the specified XMLBean
+ */
+ public static XmlObject[] getChildElements( XmlObject xBean )
+ {
+ return getChildElements( xBean, null );
+ }
+
+ /**
+ * Returns the document XmlBean that is associated with the specified XmlBean.
+ *
+ * @param xBean an XmlBean
+ *
+ * @return the document XmlBean that is associated with the specified XmlBean
+ */
+ public static XmlObject getDocument( XmlObject xBean )
+ {
+ XmlCursor xCursor = xBean.newCursor( );
+ xCursor.toStartDoc( );
+ XmlObject docXBean = xCursor.getObject( );
+ xCursor.dispose( );
+ return docXBean;
+ }
+
+ /**
+ * Returns true if the specified XMLBean represents an XML document, or false if it does not.
+ *
+ * @param xBean an XMLBean
+ *
+ * @return true if the specified XMLBean represents an XML document, or false if it does not
+ */
+ public static boolean isDocument( XmlObject xBean )
+ {
+ return xBean.schemaType( ).isDocumentType( );
+ }
+
+ /**
+ * @param xBean
+ *
+ * @return
+ */
+ public static QName getName( XmlObject xBean )
+ {
+ if ( xBean == null )
+ {
+ throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_PARAM_NOT_ALLOWED ) );
+ }
+
+ SchemaType docSchemaType;
+ if ( isDocument( xBean ) )
+ {
+ docSchemaType = xBean.schemaType( );
+ }
+ else
+ {
+ docSchemaType = xBean.schemaType( ).getOuterType( );
+ }
+
+ QName name;
+ if ( docSchemaType != null )
+ {
+ name = docSchemaType.getDocumentElementName( );
+ }
+ else
+ {
+ XmlCursor xCursor = xBean.newCursor( );
+ name = getName( xCursor );
+ xCursor.dispose( );
+ }
+
+ return name;
+ }
+
+ /**
+ * Note. this method does not dispose of the cursor
+ *
+ * @param xCursor
+ *
+ * @return
+ */
+ public static QName getName( XmlCursor xCursor )
+ {
+ QName name;
+ if ( xCursor.currentTokenType( ).equals( XmlCursor.TokenType.STARTDOC ) )
+ {
+ xCursor.toFirstChild( );
+ name = xCursor.getName( );
+ xCursor.toParent( );
+ }
+ else
+ {
+ name = xCursor.getName( );
+ }
+
+ return name;
+ }
+
+ /**
+ * Returns the root element of the specified document XMLBean. If the specified XMLBean is not a document, the
+ * XMLBean itself is returned.
+ *
+ * @param docXBean a document XMLBean
+ *
+ * @return the root element of the specified document XMLBean, or, if the specified XMLBean is not a document, the
+ * XMLBean itself
+ */
+ public static XmlObject getRootElement( XmlObject docXBean )
+ {
+ XmlObject rootElemXBean;
+ if ( isDocument( docXBean ) )
+ {
+ XmlCursor xCursor = docXBean.newCursor( );
+ if ( xCursor.toFirstChild( ) )
+ {
+ rootElemXBean = xCursor.getObject( );
+ }
+ else
+ {
+ rootElemXBean = null;
+ }
+
+ xCursor.dispose( );
+ }
+ else
+ {
+ rootElemXBean = docXBean;
+ }
+
+ return rootElemXBean;
+ }
+
+ /**
+ * @param xBean
+ * @param value
+ */
+ public static void setValue( XmlObject xBean,
+ String value )
+ {
+ XmlCursor xCursor = xBean.newCursor( );
+ if ( xCursor.isStartdoc( ) )
+ {
+ xCursor.toFirstChild( );
+ }
+
+ xCursor.setTextValue( value );
+ xCursor.dispose( );
+ }
+
+ /**
+ * @param xBean
+ *
+ * @return
+ */
+ public static String getValue( XmlObject xBean )
+ {
+ XmlCursor xCursor = xBean.newCursor( );
+ String value = xCursor.getTextValue( );
+ xCursor.dispose( );
+ return value;
+ }
+
+ /**
+ * @param xBean
+ * @param qName
+ *
+ */
+ public static void setValueAsQName( XmlObject xBean,
+ QName qName )
+ {
+ XmlCursor xCursor = xBean.newCursor( );
+ String prefix = xCursor.prefixForNamespace( qName.getNamespaceURI( ) );
+ String value = prefix + ":" + qName.getLocalPart( );
+ xCursor.setTextValue( value );
+ xCursor.dispose( );
+ }
+
+ /**
+ * @param xBean
+ *
+ * @return
+ */
+ public static QName getValueAsQName( XmlObject xBean )
+ {
+ String value = getValue( xBean );
+ return toQName( value, xBean );
+ }
+
+ /**
+ * Returns a Map keyed on Element QName to a List containing the "Any" XmlObjects types.
+ * <p/>
+ * The way we determine that an element is an Any is by asking for the element property of the schemaType for the
+ * element by the element's QName.
+ *
+ * @param xmlObjectToSearch The XmlObject to find the Any elements in.
+ *
+ * @return Map keyed on Element QName to a List containing the "Any" XmlObjects
+ */
+ public static Map getXmlBeanAnyMap( XmlObject xmlObjectToSearch )
+ {
+ Map qnameToListMap = new HashMap( );
+ XmlCursor xCursor = xmlObjectToSearch.newCursor( );
+ for ( boolean hasNext = xCursor.toFirstChild( ); hasNext; hasNext = xCursor.toNextSibling( ) )
+ {
+ XmlObject siblingXmlObject = xCursor.getObject( );
+ QName siblingXmlObjectQname = getName( siblingXmlObject );
+
+ // TODO (low priority): should this be tested against the original bean?
+ //if it contains the ElementProperty, then it is not an Any
+ if ( siblingXmlObject.schemaType( ).getElementProperty( siblingXmlObjectQname ) != null )
+ {
+ continue;
+ }
+
+ //check to see if we have a xmlObjectList to add to for this QName
+ List xmlObjectList = (List) qnameToListMap.get( siblingXmlObjectQname );
+
+ if ( xmlObjectList == null )
+ {
+ xmlObjectList = new ArrayList( );
+ }
+
+ xmlObjectList.add( siblingXmlObject );
+ qnameToListMap.put( siblingXmlObjectQname, xmlObjectList );
+ }
+
+ xCursor.dispose( );
+
+ return qnameToListMap;
+ }
+
+ /**
+ * Adds a copy of the XmlBean <code>newChild</code> as the last child
+ * of the XmlBean <code>parent</code>.
+ *
+ * @param parent the XmlBean to be added to; must represent an element or a document
+ * @param newChild the XmlBean to be added; must represent an element or a document
+ */
+ public static XmlObject addChildElement( XmlObject parent,
+ XmlObject newChild )
+ {
+ parent = getRootElement( parent );
+ Node parentNode = parent.getDomNode( );
+ Node newChildNode = newChild.newDomNode( ); // no need to use newDomNode() because importNode() will make a copy
+ if ( newChildNode.getNodeType( ) == Node.DOCUMENT_NODE )
+ {
+ newChildNode = ( (Document) newChildNode ).getDocumentElement( );
+ }
+
+ newChildNode = parentNode.getOwnerDocument( ).importNode( newChildNode, true ); //
+ parentNode.appendChild( newChildNode );
+
+ // get a ref to the XmlObject corresponding to the child we've just added...
+ XmlCursor cursor = parent.newCursor( );
+ cursor.toLastChild( );
+ newChild = cursor.getObject( );
+ cursor.dispose( );
+ return newChild;
+ }
+
+ /**
+ * Creates a new XmlBean named <code>name</code> and adds it as the
+ * last child of the XmlBean <code>parent</code>.
+ *
+ * @param parent the XmlBean to be added to; must represent an element or a document
+ * @param name the name of the new XmlBean to be added
+ */
+ public static XmlObject addChildElement( XmlObject parent,
+ QName name )
+ {
+ parent = getRootElement( parent );
+ XmlCursor parentCursor = parent.newCursor( );
+ if ( parentCursor.toLastChild( ) ) // has children
+ {
+ parentCursor.toEndToken( );
+ parentCursor.toNextToken( );
+ }
+ else // childless
+ {
+ parentCursor.toEndToken( );
+ }
+
+ parentCursor.insertElement( name );
+ parentCursor.toPrevSibling( );
+ XmlObject newChild = parentCursor.getObject( );
+ parentCursor.dispose( );
+ return newChild;
+ }
+
+ /**
+ * Makes and returns a copy of the specified XMLBean.
+ *
+ * @param srcXBean the XMLBean to be copied
+ *
+ * @return a copy of the specified XMLBean
+ */
+ public static XmlObject copyXmlBean( XmlObject srcXBean )
+ {
+ try
+ {
+ return XmlObject.Factory.parse( srcXBean.xmlText( new XmlOptions( ).setSaveOuter( ) ) );
+ }
+ catch ( XmlException xe )
+ {
+ throw new RuntimeException( xe );
+ }
+
+ /*XmlCursor srcCursor = srcXBean.newCursor( );
+
+ // create an object of the appropriate type to copy to
+ XmlObject destXBean = XmlObject.Factory.newInstance( new XmlOptions( ).setDocumentType( srcXBean.schemaType() ) );
+ XmlCursor destCursor = destXBean.newCursor( );
+
+ // move into the document
+ destCursor.toNextToken( );
+
+ // copy the xml into the new document
+ srcCursor.copyXml( destCursor );
+
+ // clean up our cursors
+ destCursor.dispose( );
+ srcCursor.dispose( );
+
+ return destXBean;*/
+ }
+
+ /**
+ * Makes and returns a copy of the specified XMLBean array.
+ *
+ * @param srcXBeans the array of XMLBeans to be copied
+ *
+ * @return a copy of the specified XMLBean array
+ */
+ public static XmlObject[] copyXmlBeans( XmlObject[] srcXBeans )
+ {
+ if ( srcXBeans == null )
+ {
+ return null;
+ }
+
+ XmlObject[] destXBeans = new XmlObject[srcXBeans.length];
+
+ for ( int i = 0; i < srcXBeans.length; i++ )
+ {
+ destXBeans[i] = copyXmlBean( srcXBeans[i] );
+ }
+
+ return destXBeans;
+ }
+
+ /**
+ * Removes the specifed XMLBean from its parent element.
+ *
+ * @param xBean an XMLBean
+ */
+ public static void remove( XmlObject xBean )
+ {
+ XmlCursor xCursor = xBean.newCursor( );
+ xCursor.removeXml( );
+
+ xCursor.dispose( );
+ }
+
+ /**
+ * Removes all child elements, with the specified name, from the specified XMLBean.
+ *
+ * @param xBean an XMLBean
+ *
+ * @return true if all child elements, with the specified name, were successfully removed
+ */
+ public static boolean removeChildElements( XmlObject xBean,
+ QName name )
+ {
+ boolean succeeded = true;
+ xBean = getRootElement( xBean );
+ XmlCursor xCursor = xBean.newCursor( );
+ for ( boolean hasNext = xCursor.toFirstChild( ); hasNext; hasNext = xCursor.toNextSibling( ) )
+ {
+ if ( ( name == null ) || getName( xCursor ).equals( name ) )
+ {
+ succeeded = succeeded && xCursor.removeXml( );
+ }
+ }
+
+ xCursor.dispose( );
+ return succeeded;
+ }
+
+ /**
+ * Removes all child elements of the specified XMLBean.
+ *
+ * @param xBean an XMLBean
+ *
+ * @return true if all child elements were successfully removed
+ */
+ public static boolean removeChildElements( XmlObject xBean )
+ {
+ return removeChildElements( xBean, null );
+ }
+
+ /**
+ * @param xBean
+ *
+ * @return
+ *
+ * @throws Exception
+ */
+ public static SOAPElement toSOAPElement( XmlObject xBean )
+ throws Exception
+ {
+ XmlOptions xSaveOpts =
+ new XmlOptions( ).setSaveOuter( ).setSavePrettyPrint( ).setSavePrettyPrintIndent( 2 );
+ Node domNode = xBean.newDomNode( xSaveOpts );
+ Element domElem = null;
+ if ( domNode instanceof Document )
+ {
+ domElem = ( (Document) domNode ).getDocumentElement( );
+ }
+ else if ( domNode instanceof DocumentFragment )
+ {
+ NodeList childNodes = domNode.getChildNodes( );
+ for ( int i = 0; i < childNodes.getLength( ); i++ )
+ {
+ if ( childNodes.item( i ).getNodeType( ) == Node.ELEMENT_NODE )
+ {
+ domElem = (Element) childNodes.item( i );
+ break;
+ }
+ }
+ }
+
+ return SaajUtils.toSOAPElement( domElem );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param elems DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ public static SOAPElement[] toSOAPElementArray( final XmlObject[] elems )
+ throws Exception
+ {
+ SOAPElement[] soapElems = new SOAPElement[elems.length];
+
+ for ( int i = 0; i < elems.length; i++ )
+ {
+ soapElems[i] = toSOAPElement( elems[i] );
+ }
+
+ return soapElems;
+ }
+
+ /**
+ * If possible, converts the specified object to an XMLBean.
+ *
+ * @param obj an object
+ *
+ * @return an XMLBean, or null if the parameter is null
+ *
+ * @throws Exception if the object cannot be converted to an XMLBean
+ */
+ public static XmlObject toXmlObject( Object obj )
+ throws Exception
+ {
+ XmlObject xBean;
+
+ if ( obj == null )
+ {
+ return null;
+ }
+
+ if ( obj instanceof XmlObject )
+ {
+ xBean = (XmlObject) obj;
+ }
+ else if ( obj instanceof SOAPElement )
+ {
+ // !!!NOTE!!! It is critical to do parse( obj.toString() ) here, instead of parse( (Node)obj ),
+ // because Axis 1.2's DOM impl (MessageElement) strips off all attributes, including
+ // namespace decls! (TODO: file an Axis bug for the aforementioned issue)
+ xBean = XmlObject.Factory.parse( obj.toString( ) );
+ }
+ else if ( obj instanceof Node )
+ {
+ xBean = XmlObject.Factory.parse( (Node) obj );
+ }
+ else if ( obj instanceof String )
+ {
+ xBean = XmlObject.Factory.parse( (String) obj );
+ }
+ else if ( obj instanceof InputStream )
+ {
+ xBean = XmlObject.Factory.parse( (InputStream) obj );
+ }
+ else if ( obj instanceof Reader )
+ {
+ xBean = XmlObject.Factory.parse( (Reader) obj );
+ }
+ else if ( obj instanceof File )
+ {
+ xBean = XmlObject.Factory.parse( (File) obj );
+ }
+ else if ( obj instanceof URL )
+ {
+ xBean = XmlObject.Factory.parse( (URL) obj );
+ }
+ else
+ {
+ throw new IllegalArgumentException( MSG.getMessage( Keys.PARAM_MUST_BE_TYPE ) + " "
+ + obj.getClass( ).getName( ) );
+ }
+
+ return xBean;
+ }
+
+ /**
+ * Creates a new XMLBean element with the specified name.
+ *
+ * @param elemName the element name
+ *
+ * @return a new XMLBean element with the specified name
+ */
+ public XmlObject newInstance( QName elemName )
+ {
+ XmlObject xBean = XmlObject.Factory.newInstance( );
+ XmlCursor xCursor = xBean.newCursor( );
+ xCursor.setName( elemName );
+ xCursor.dispose( );
+ return xBean;
+ }
+
+ private static QName toQName( String value,
+ XmlObject xBean )
+ {
+ int colonIndex = value.indexOf( ':' );
+ String nsURI;
+ if ( colonIndex != -1 )
+ {
+ String prefix = value.substring( 0, colonIndex );
+ XmlCursor xCursor = xBean.newCursor( );
+ nsURI = xCursor.namespaceForPrefix( prefix );
+ if ( nsURI == null )
+ {
+ throw new RuntimeException( "No namespace is associated with prefix '" + prefix + "'" );
+ }
+
+ xCursor.dispose( );
+ }
+ else
+ {
+ nsURI = "";
+ }
+
+ String localName = value.substring( colonIndex + 1 );
+ return new QName( nsURI, localName );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlConstants.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlConstants.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlConstants.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlConstants.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,335 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.ws.util;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author Ian P. Springer (Hewlett-Packard Company)
+ */
+public interface XmlConstants
+{
+ /* ========================= Namespace URIs and Prefixes ========================== */
+
+ /**
+ * Prefix representing default XML Namespace.
+ */
+ String NSPREFIX_DEFAULT = "";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String NSPREFIX_SCHEMA_XSD = "xsd";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String NSPREFIX_SCHEMA_XSI = "xsi";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String NSPREFIX_XML = "xml";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String NSPREFIX_XMLNS = "xmlns";
+
+ /**
+ * XML-Schema NS-URI and Prefix.
+ */
+ String NSURI_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
+
+ /**
+ * XML-Schema-Instance NS-URI and Prefix.
+ */
+ String NSURI_SCHEMA_XSI = "http://www.w3.org/2001/XMLSchema-instance";
+
+ /**
+ * XML NS-URI and Prefix.
+ */
+ String NSURI_XML = "http://www.w3.org/XML/1998/namespace";
+
+ /**
+ * XML-Namespace NS-URI and Prefix.
+ */
+ String NSURI_XMLNS = "http://www.w3.org/2000/xmlns/";
+
+ /**
+ * standard XML prolog
+ */
+ String XML_PROLOG = "<?xml version=\"1.0\"?>";
+
+ /* ============================ Type Names ============================= */
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_STRING = new QName( NSURI_SCHEMA_XSD, "string" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_BOOLEAN = new QName( NSURI_SCHEMA_XSD, "boolean" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_DOUBLE = new QName( NSURI_SCHEMA_XSD, "double" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_FLOAT = new QName( NSURI_SCHEMA_XSD, "float" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_INT = new QName( NSURI_SCHEMA_XSD, "int" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_INTEGER = new QName( NSURI_SCHEMA_XSD, "integer" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_LONG = new QName( NSURI_SCHEMA_XSD, "long" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_SHORT = new QName( NSURI_SCHEMA_XSD, "short" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_BYTE = new QName( NSURI_SCHEMA_XSD, "byte" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_DECIMAL = new QName( NSURI_SCHEMA_XSD, "decimal" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_BASE64 = new QName( NSURI_SCHEMA_XSD, "base64Binary" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_HEXBIN = new QName( NSURI_SCHEMA_XSD, "hexBinary" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_ANYSIMPLETYPE = new QName( NSURI_SCHEMA_XSD, "anySimpleType" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_ANYTYPE = new QName( NSURI_SCHEMA_XSD, "anyType" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_ANY = new QName( NSURI_SCHEMA_XSD, "any" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_QNAME = new QName( NSURI_SCHEMA_XSD, "QName" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_DATETIME = new QName( NSURI_SCHEMA_XSD, "dateTime" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_DATE = new QName( NSURI_SCHEMA_XSD, "date" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_TIME = new QName( NSURI_SCHEMA_XSD, "time" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NORMALIZEDSTRING = new QName( NSURI_SCHEMA_XSD, "normalizedString" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_TOKEN = new QName( NSURI_SCHEMA_XSD, "token" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_UNSIGNEDLONG = new QName( NSURI_SCHEMA_XSD, "unsignedLong" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_UNSIGNEDINT = new QName( NSURI_SCHEMA_XSD, "unsignedInt" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_UNSIGNEDSHORT = new QName( NSURI_SCHEMA_XSD, "unsignedShort" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_UNSIGNEDBYTE = new QName( NSURI_SCHEMA_XSD, "unsignedByte" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_POSITIVEINTEGER = new QName( NSURI_SCHEMA_XSD, "positiveInteger" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NEGATIVEINTEGER = new QName( NSURI_SCHEMA_XSD, "negativeInteger" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NONNEGATIVEINTEGER = new QName( NSURI_SCHEMA_XSD, "nonNegativeInteger" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NONPOSITIVEINTEGER = new QName( NSURI_SCHEMA_XSD, "nonPositiveInteger" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_YEARMONTH = new QName( NSURI_SCHEMA_XSD, "gYearMonth" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_MONTHDAY = new QName( NSURI_SCHEMA_XSD, "gMonthDay" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_YEAR = new QName( NSURI_SCHEMA_XSD, "gYear" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_MONTH = new QName( NSURI_SCHEMA_XSD, "gMonth" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_DAY = new QName( NSURI_SCHEMA_XSD, "gDay" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_DURATION = new QName( NSURI_SCHEMA_XSD, "duration" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NAME = new QName( NSURI_SCHEMA_XSD, "Name" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NCNAME = new QName( NSURI_SCHEMA_XSD, "NCName" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NMTOKEN = new QName( NSURI_SCHEMA_XSD, "NMTOKEN" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NMTOKENS = new QName( NSURI_SCHEMA_XSD, "NMTOKENS" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_NOTATION = new QName( NSURI_SCHEMA_XSD, "NOTATION" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_ENTITY = new QName( NSURI_SCHEMA_XSD, "ENTITY" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_ENTITIES = new QName( NSURI_SCHEMA_XSD, "ENTITIES" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_IDREF = new QName( NSURI_SCHEMA_XSD, "IDREF" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_IDREFS = new QName( NSURI_SCHEMA_XSD, "IDREFS" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_ANYURI = new QName( NSURI_SCHEMA_XSD, "anyURI" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_LANGUAGE = new QName( NSURI_SCHEMA_XSD, "language" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_ID = new QName( NSURI_SCHEMA_XSD, "ID" );
+
+ /* ========================= Elements and Attribute Names ========================== */
+
+ /**
+ * DOCUMENT_ME
+ */
+ QName XSD_SCHEMA = new QName( NSURI_SCHEMA_XSD, "schema" );
+
+ /**
+ * DOCUMENT_ME
+ */
+ String XSD_ATTRIB_IMPORT = "import";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String XSD_ATTRIB_INCLUDE = "include";
+
+ /**
+ * DOCUMENT_ME
+ */
+ String XSD_ATTRIB_SCHEMALOCATION = "schemaLocation";
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org