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 [21/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/XmlUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/XmlUtils.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,294 @@
+/*=============================================================================*
+ *  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.axis.utils.XMLUtils;
+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.Element;
+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 java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * LOG-DONE
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.5 $
+ */
+public class XmlUtils
+{
+   private static Log LOG = LogFactory.getLog( XmlUtils.class.getName(  ) );
+
+   /** DOCUMENT_ME */
+   public static final Messages          MSG   = MessagesImpl.getInstance(  );
+   private static DocumentBuilderFactory s_dbf = getDOMFactory(  );
+
+   /**
+    * Get an empty new Document
+    *
+    * @return Document
+    *
+    * @throws ParserConfigurationException if construction problems occur
+    */
+   public static Document newDocument(  )
+   throws ParserConfigurationException
+   {
+      synchronized ( s_dbf )
+      {
+         return s_dbf.newDocumentBuilder(  ).newDocument(  );
+      }
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param inp DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws ParserConfigurationException DOCUMENT_ME
+    * @throws SAXException                 DOCUMENT_ME
+    * @throws IOException                  DOCUMENT_ME
+    */
+   public static Document newDocument( InputSource inp )
+   throws ParserConfigurationException, 
+          SAXException, 
+          IOException
+   {
+      DocumentBuilder db;
+
+      synchronized ( s_dbf )
+      {
+         db = s_dbf.newDocumentBuilder(  );
+      }
+
+      db.setErrorHandler( new XMLUtils.ParserErrorHandler(  ) );
+      return db.parse( inp );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param inp DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws ParserConfigurationException DOCUMENT_ME
+    * @throws SAXException                 DOCUMENT_ME
+    * @throws IOException                  DOCUMENT_ME
+    */
+   public static Document newDocument( InputStream inp )
+   throws ParserConfigurationException, 
+          SAXException, 
+          IOException
+   {
+      return newDocument( new InputSource( inp ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param uri DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws ParserConfigurationException DOCUMENT_ME
+    * @throws SAXException                 DOCUMENT_ME
+    * @throws IOException                  DOCUMENT_ME
+    */
+   public static Document newDocument( String uri )
+   throws ParserConfigurationException, 
+          SAXException, 
+          IOException
+   {
+      // call the authenticated version as there might be
+      // username/password info embeded in the uri.
+      return newDocument( uri, null, null );
+   }
+
+   /**
+    * Create a new document from the given URI, use the username and password if the URI requires authentication.
+    */
+   public static Document newDocument( String uri,
+                                       String username,
+                                       String password )
+   throws ParserConfigurationException, 
+          SAXException, 
+          IOException
+   {
+      InputSource ins = getInputSourceFromURI( uri, username, password );
+
+      Document    doc = null;
+
+      try
+      {
+         doc = newDocument( ins );
+      }
+      finally
+      {
+         if ( ins.getByteStream(  ) != null )
+         {
+            ins.getByteStream(  ).close(  );
+         }
+         else if ( ins.getCharacterStream(  ) != null )
+         {
+            ins.getCharacterStream(  ).close(  );
+         }
+      }
+
+      return doc;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param doc DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public static String toString( Document doc )
+   {
+      return XMLUtils.DocumentToString( doc );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param element DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public static String toString( Element element )
+   {
+      return XMLUtils.ElementToString( element );
+   }
+
+   private static DocumentBuilderFactory getDOMFactory(  )
+   {
+      DocumentBuilderFactory dbf;
+
+      try
+      {
+         dbf = DocumentBuilderFactory.newInstance(  );
+         dbf.setNamespaceAware( true );
+      }
+      catch ( Exception e )
+      {
+         LOG.error( "", e );
+         dbf = null;
+      }
+
+      return ( dbf );
+   }
+
+   /**
+    * Utility to get the bytes at a protected uri
+    * <p/>
+    * This will retrieve the URL if a username and password are provided. The java.net.URL class does not do Basic
+    * Authentication, so we have to do it manually in this routine.
+    * <p/>
+    * If no username is provided, we create an InputSource from the uri and let the InputSource go fetch the contents.
+    *
+    * @param uri      the resource to get
+    * @param username basic auth username
+    * @param password basic auth password
+    */
+   private static InputSource getInputSourceFromURI( String uri,
+                                                     String username,
+                                                     String password )
+   throws IOException
+   {
+      URL wsdlurl = null;
+      LOG.debug( MSG.getMessage( Keys.INPUT_SRC_FRM_URI, uri, username, password ) );
+      try
+      {
+         wsdlurl = new URL( uri );
+      }
+      catch ( MalformedURLException e )
+      {
+         // we can't process it, it might be a 'simple' foo.wsdl
+         // let InputSource deal with it
+         return new InputSource( uri );
+      }
+
+      // if no authentication, just let InputSource deal with it
+      if ( ( username == null ) && ( wsdlurl.getUserInfo(  ) == null ) )
+      {
+         return new InputSource( uri );
+      }
+
+      // if this is not an HTTP{S} url, let InputSource deal with it
+      if ( !wsdlurl.getProtocol(  ).startsWith( "http" ) )
+      {
+         return new InputSource( uri );
+      }
+
+      URLConnection connection = wsdlurl.openConnection(  );
+
+      // Does this work for https???
+      if ( !( connection instanceof HttpURLConnection ) )
+      {
+         // can't do http with this URL, let InputSource deal with it
+         return new InputSource( uri );
+      }
+
+      HttpURLConnection uconn    = (HttpURLConnection) connection;
+      String            userinfo = wsdlurl.getUserInfo(  );
+      uconn.setRequestMethod( "GET" );
+      uconn.setAllowUserInteraction( false );
+      uconn.setDefaultUseCaches( false );
+      uconn.setDoInput( true );
+      uconn.setDoOutput( false );
+      uconn.setInstanceFollowRedirects( true );
+      uconn.setUseCaches( false );
+
+      // username/password info in the URL overrides passed in values
+      String auth = null;
+
+      if ( userinfo != null )
+      {
+         auth = userinfo;
+      }
+      else if ( username != null )
+      {
+         auth = ( password == null ) ? username : ( username + ":" + password );
+      }
+
+      if ( auth != null )
+      {
+         uconn.setRequestProperty( "Authorization",
+                                   "Basic " + XMLUtils.base64encode( auth.getBytes( XMLUtils.getEncoding(  ) ) ) );
+      }
+
+      uconn.connect(  );
+
+      return new InputSource( uconn.getInputStream(  ) );
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/ant/FileTask.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/ant/FileTask.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/ant/FileTask.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/ant/FileTask.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,108 @@
+/*=============================================================================*
+ *  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.ant;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.ws.util.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.i18n.MessagesImpl;
+import java.io.File;
+
+/**
+ * LOG-DONE
+ * Defines a property with a path value, allowing a base dir to be specified
+ * for expanding the path if it is relative.
+ *
+ * @author Ian P. Springer (Hewlett-Packard Company)
+ */
+public class FileTask
+   extends Task
+{
+   /** DOCUMENT_ME */
+   public static final Messages MSG        = MessagesImpl.getInstance(  );
+   private String               m_property;
+   private File                 m_location;
+   private File                 m_baseDir;
+
+   /**
+    * If the specified location is relative, this directory will be used as
+    * the base directory when expanding the location to an absolute path.
+    * If the baseDir attribute is not specified, the project's basedir
+    * (i.e. ${basedir}) will be used.
+    *
+    * @param baseDir used as the base directory when expanding the location
+    *                to an absolute path
+    */
+   public void setBaseDir( File baseDir )
+   {
+      m_baseDir = baseDir;
+   }
+
+   /**
+    * A filesystem path - may be absolute or relative. If relative it will be
+    * expanded. NOTE: The parameter is a String and not a File to prevent
+    * Ant from resolving relative files based on the project basedir.
+    *
+    * @param location a filesystem path - may be absolute or relative
+    */
+   public void setLocation( String location )
+   {
+      m_location = new File( location );
+   }
+
+   /**
+    * Sets the name of the property to set.
+    *
+    * @param property the name of the property to set
+    */
+   public void setProperty( String property )
+   {
+      m_property = property;
+   }
+
+   /**
+    * @see {@link org.apache.tools.ant.Task#execute()}
+    */
+   public void execute(  )
+   throws BuildException
+   {
+      if ( getProject(  ) == null )
+      {
+         throw new IllegalStateException( MSG.getMessage( Keys.PRJ_NOT_SET ) );
+      }
+
+      if ( m_property == null )
+      {
+         throw new BuildException( MSG.getMessage( Keys.MST_SPECIFY_PROP_NAME ) );
+      }
+
+      if ( m_location == null )
+      {
+         throw new BuildException( MSG.getMessage( Keys.MST_SPECIFY_LOCATION ) );
+      }
+
+      if ( !m_location.isAbsolute(  ) )
+      {
+         m_baseDir     = ( m_baseDir != null ) ? m_baseDir : getProject(  ).getBaseDir(  );
+         m_location    = new File( m_baseDir,
+                                   m_location.getPath(  ) );
+      }
+
+      getProject(  ).setNewProperty( m_property,
+                                     m_location.getAbsolutePath(  ) );
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/helper/Dom2SaajConverter.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/helper/Dom2SaajConverter.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/helper/Dom2SaajConverter.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/helper/Dom2SaajConverter.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,270 @@
+/*=============================================================================*
+ *  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.helper;
+
+import org.apache.ws.util.NameUtils;
+import org.apache.ws.util.XmlConstants;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.NodeList;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+
+/**
+ * LOG-DONE
+ *
+ * @author Ian P. Springer
+ */
+public class Dom2SaajConverter
+{
+   private SOAPFactory m_soap_factory;
+
+   /**
+    * Creates a new {@link Dom2SaajConverter} object.
+    *
+    * @throws SOAPException DOCUMENT_ME
+    */
+   public Dom2SaajConverter(  )
+   throws SOAPException
+   {
+      m_soap_factory = SOAPFactory.newInstance(  );
+   }
+
+   /**
+    * 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 DetailEntry addDetailEntry( Detail  detail,
+                                      Element domElem )
+   throws SOAPException
+   {
+      if ( domElem == null )
+      {
+         return null;
+      }
+
+      DetailEntry detailEntry;
+      if ( domElem instanceof DetailEntry )
+      {
+         detailEntry = (DetailEntry) domElem;
+      }
+      else
+      {
+         detailEntry =
+            detail.addDetailEntry( m_soap_factory.createName( domElem.getLocalName(  ),
+                                                              getPrefix( domElem ),
+                                                              getNamespaceURI( domElem ) ) );
+         buildSOAPElement( domElem, detailEntry );
+      }
+
+      return detailEntry;
+   }
+
+   /**
+    * Converts a DOM {@link org.w3c.dom.Element} to a SAAJ {@link javax.xml.soap.SOAPElement}.
+    *
+    * @param domElem a DOM {@link org.w3c.dom.Element}
+    *
+    * @return a {@link javax.xml.soap.SOAPElement}
+    *
+    * @throws javax.xml.soap.SOAPException
+    */
+   public SOAPElement toSOAPElement( Element domElem )
+   throws SOAPException
+   {
+      if ( domElem == null )
+      {
+         return null;
+      }
+
+      SOAPElement soapElem;
+      if ( domElem instanceof SOAPElement )
+      {
+         soapElem = (SOAPElement) domElem;
+      }
+      else
+      {
+         soapElem =
+            m_soap_factory.createElement( domElem.getLocalName(  ),
+                                          getPrefix( domElem ),
+                                          getNamespaceURI( domElem ) );
+
+         buildSOAPElement( domElem, soapElem );
+      }
+
+      return ( soapElem );
+   }
+
+   /**
+    * @param attrib
+    *
+    * @return
+    */
+   private static boolean isNamespaceDeclarationAttrib( org.w3c.dom.Node attrib )
+   {
+      String prefix = attrib.getPrefix(  );
+      String ns_uri = attrib.getNamespaceURI(  );
+
+      return ( ( ( prefix != null ) && prefix.equals( XmlConstants.NSPREFIX_XMLNS ) )
+             || ( ( ns_uri != null ) && ns_uri.equals( XmlConstants.NSURI_XMLNS ) ) )
+             && !attrib.getLocalName(  ).equals( XmlConstants.NSPREFIX_XMLNS );
+   }
+
+   /**
+    * @param node
+    *
+    * @return
+    */
+   private static String getNamespaceURI( org.w3c.dom.Node node )
+   {
+      String ns_uri = node.getNamespaceURI(  );
+
+      return ( ( ns_uri != null ) ? ns_uri : "" );
+   }
+
+   /**
+    * @param node
+    *
+    * @return
+    */
+   private static String getPrefix( org.w3c.dom.Node node )
+   {
+      String prefix = node.getPrefix(  );
+
+      return ( ( prefix != null ) ? prefix : NameUtils.getNamespacePrefix( node.getNamespaceURI(  ) ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param soap_elem DOCUMENT_ME
+    * @param elem      DOCUMENT_ME
+    *
+    * @throws SOAPException DOCUMENT_ME
+    */
+   private SOAPElement addAttributes( SOAPElement soap_elem,
+                                      Element     elem )
+   throws SOAPException
+   {
+      NamedNodeMap attribs = elem.getAttributes(  );
+
+      for ( int i = 0; i < attribs.getLength(  ); i++ )
+      {
+         org.w3c.dom.Node attrib = attribs.item( i );
+
+         if ( isNamespaceDeclarationAttrib( attrib ) )
+         {
+            soap_elem.addNamespaceDeclaration( attrib.getLocalName(  ),
+                                               attrib.getNodeValue(  ) );
+         }
+         else
+         {
+            if ( hasPrefix( soap_elem ) && attrib.getLocalName(  ).equals( XmlConstants.NSPREFIX_XMLNS ) )
+            {
+               // don't add an xmlns="..." attribute if the element has a prefix
+               continue;
+            }
+
+            Name attrib_pqname =
+               m_soap_factory.createName( attrib.getLocalName(  ),
+                                          attrib.getPrefix(  ),
+                                          attrib.getNamespaceURI(  ) );
+
+            soap_elem.addAttribute( attrib_pqname,
+                                    attrib.getNodeValue(  ) );
+         }
+      }
+
+      return ( soap_elem );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param soap_elem DOCUMENT_ME
+    * @param elem      DOCUMENT_ME
+    *
+    * @throws SOAPException DOCUMENT_ME
+    */
+   private SOAPElement addChildren( SOAPElement soap_elem,
+                                    Element     elem )
+   throws SOAPException
+   {
+      NodeList children = elem.getChildNodes(  );
+
+      for ( int i = 0; i < children.getLength(  ); i++ )
+      {
+         org.w3c.dom.Node node      = children.item( i );
+         short            node_type = node.getNodeType(  );
+
+         if ( node_type == org.w3c.dom.Node.ELEMENT_NODE )
+         {
+            SOAPElement new_elem =
+               soap_elem.addChildElement( node.getLocalName(  ),
+                                          getPrefix( node ),
+                                          getNamespaceURI( node ) );
+
+            buildSOAPElement( (Element) node, new_elem );
+         }
+         else if ( node_type == org.w3c.dom.Node.TEXT_NODE )
+         {
+            soap_elem.addTextNode( node.getNodeValue(  ) );
+         }
+      }
+
+      return ( soap_elem );
+   }
+
+   /**
+    * Workhorse method for {@link Dom2SaajConverter#toSOAPElement} - calls itself recursively.
+    *
+    * @param elem      the DOM element to be converted
+    * @param soap_elem the SAAJ SOAP element being built
+    *
+    * @throws SOAPException
+    */
+   private SOAPElement buildSOAPElement( Element     elem,
+                                         SOAPElement soap_elem )
+   throws SOAPException
+   {
+      return ( addChildren( addAttributes( soap_elem, elem ),
+                            elem ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param soap_elem DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   private static boolean hasPrefix( SOAPElement soap_elem )
+   {
+      String prefix = soap_elem.getElementName(  ).getPrefix(  );
+
+      return ( ( prefix != null ) && !prefix.equals( XmlConstants.NSPREFIX_DEFAULT ) );
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/helper/Saaj2StringConverter.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/helper/Saaj2StringConverter.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/helper/Saaj2StringConverter.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/helper/Saaj2StringConverter.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,811 @@
+/*=============================================================================*
+ *  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.helper;
+
+import org.apache.ws.util.XmlConstants;
+import org.apache.ws.util.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.i18n.MessagesImpl;
+import javax.xml.soap.Name;
+import javax.xml.soap.Node;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.Text;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**       LOG-DONE
+ * @author Ian P. Springer (Hewlett-Packard Company)
+ */
+public class Saaj2StringConverter
+{
+   /** DOCUMENT_ME */
+   public static final Messages MSG = MessagesImpl.getInstance(  );
+
+   /**
+    * Whitespace string to use for indentation in {@link #toString( javax.xml.soap.Node )}.
+    */
+   private static final String DEFAULT_NODE_INDENT_STRING = "  ";
+
+   /**
+    * The string to use for each indent (may only contain spaces or tabs).
+    */
+   private String m_indent_str = DEFAULT_NODE_INDENT_STRING;
+
+   /**
+    * 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 soap_elem a SAAJ {@link SOAPElement}
+    *
+    * @return a list containing the children of the specified {@link SOAPElement}
+    */
+   public static List getChildNodes( SOAPElement soap_elem )
+   {
+      List     elem_children = new ArrayList(  );
+      List     text_children = new ArrayList(  );
+      Iterator node_iter     = soap_elem.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 );
+   }
+
+   /**
+    * @param soap_elem
+    * @param ns_uri
+    *
+    * @return
+    */
+   public static String getDeclaredPrefix( SOAPElement soap_elem,
+                                           String      ns_uri )
+   {
+      Iterator prefixes = soap_elem.getNamespacePrefixes(  );
+
+      while ( prefixes.hasNext(  ) )
+      {
+         String prefix = (String) prefixes.next(  );
+
+         if ( soap_elem.getNamespaceURI( prefix ).equals( ns_uri ) )
+         {
+            return ( prefix );
+         }
+      }
+
+      return ( null );
+   }
+
+   /**
+    * Sets the indent string.
+    *
+    * @param indent_str the indent string to use; if null, indenting will be disabled
+    */
+   public void setIndentString( String indent_str )
+   {
+      m_indent_str = indent_str;
+   }
+
+   /**
+    * Gets the indent string.
+    *
+    * @return the indent string being used; if null, indenting is disabled
+    */
+   public String getIndentString(  )
+   {
+      return m_indent_str;
+   }
+
+   /**
+    * 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 ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param soap_text DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws SOAPException DOCUMENT_ME
+    */
+   public static String getValue( Text soap_text )
+   throws SOAPException
+   {
+      if ( soap_text == null )
+      {
+         throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_PARAM_NOT_ALLOWED ) );
+      }
+
+      String value = soap_text.getValue(  );
+
+      if ( value == null )
+      {
+         value = soap_text.toString(  );
+      }
+
+      if ( value == null )
+      {
+         throw new SOAPException( MSG.getMessage( Keys.NULL_VALUE ) );
+      }
+
+      return ( value );
+   }
+
+   /**
+    * Returns true if the specified string is non-null and does not equal ""; otherwise returns false.
+    *
+    * @param str a string
+    *
+    * @return true if the specified string is non-null and does not equal ""; otherwise false
+    */
+   public static boolean hasNonEmptyValue( String str )
+   {
+      return ( ( str != null ) && !str.equals( "" ) );
+   }
+
+   /**
+    * Returns a string representation of the specified {@link javax.xml.soap.Node}.
+    *
+    * @param soap_node a SAAJ SOAP node
+    *
+    * @return a string represntation of the SOAP node
+    *
+    * @throws SOAPException
+    */
+   public String toString( Node soap_node )
+   throws SOAPException
+   {
+      return ( buildSOAPNodeStringBuffer( new StringBuffer(  ),
+                                          soap_node,
+                                          soap_node,
+                                          0 ).toString(  ) );
+   }
+
+   /**
+    * @param soap_elem a SOAP element
+    *
+    * @return an Iterator of the element's children
+    */
+   private static Iterator getChildren( SOAPElement soap_elem )
+   {
+      List children = null;
+
+      // NOTE (ips, 08/12/03): the below block is a workaround for a bug in AXIS 1.1...
+      if ( soap_elem instanceof SOAPEnvelope && false )
+      {
+         children = getEnvelopeChildren( soap_elem );
+      }
+
+      if ( ( children == null ) || children.isEmpty(  ) )
+      {
+         children = getChildNodes( soap_elem );
+      }
+
+      return ( children.iterator(  ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param current_soap_node DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   private static boolean isElement( Node current_soap_node )
+   {
+      return !( current_soap_node instanceof Text );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param soap_elem DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   private static List getEnvelopeChildren( SOAPElement soap_elem )
+   {
+      List children;
+
+      children = new ArrayList(  );
+
+      SOAPEnvelope soap_env = (SOAPEnvelope) soap_elem;
+      SOAPHeader   header = null;
+      SOAPBody     body   = null;
+
+      try
+      {
+         header    = soap_env.getHeader(  );
+         body      = soap_env.getBody(  );
+      }
+      catch ( SOAPException soape )
+      {
+         //LOG.warn( ResourceKeys.MSG.getMsg( ResourceKeys.EX_FAILED_TO_GET_SOAP_BODY, soape ) );
+      }
+
+      if ( ( header != null ) && ( body != null ) )
+      {
+         children.add( header );
+         children.add( body );
+      }
+
+      return children;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param pqname         DOCUMENT_ME
+    * @param root_soap_elem DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   private static String getPrefix( Name        pqname,
+                                    SOAPElement root_soap_elem )
+   {
+      String prefix = pqname.getPrefix(  );
+
+      if ( ( prefix != null ) && !prefix.equals( "" ) )
+      {
+         return ( prefix );
+      }
+
+      return ( recursiveGetPrefix( pqname, root_soap_elem ) );
+   }
+
+   /**
+    * @param child
+    * @param ns_uri
+    *
+    * @return
+    */
+   private static String getPrefix( SOAPElement child,
+                                    String      ns_uri )
+   {
+      if ( child == null )
+      {
+         //throw new IllegalArgumentException( ResourceKeys.MSG.getMsg( ResourceKeys.EX_SOAP_ELEM_NULL ) );
+      }
+
+      String prefix;
+
+      if ( Node.TEXT_NODE == child.getNodeType(  ) )
+      {
+         return null;
+      }
+
+      Name child_name = child.getElementName(  );
+
+      if ( child_name == null )
+      {
+         return null;
+      }
+
+      String child_uri = child_name.getURI(  );
+
+      if ( child_uri == null )
+      {
+         return null;
+      }
+
+      if ( ns_uri == null )
+      {
+         return null;
+      }
+
+      if ( child_uri.equals( ns_uri ) )
+      {
+         prefix = child.getElementName(  ).getPrefix(  );
+
+         if ( ( prefix != null ) && !prefix.equals( "" ) )
+         {
+            return ( prefix );
+         }
+      }
+
+      prefix = getDeclaredPrefix( child, ns_uri );
+
+      if ( ( prefix != null ) && !prefix.equals( "" ) )
+      {
+         return ( prefix );
+      }
+
+      return ( null );
+   }
+
+   /**
+    * Constructs a string representation of the specified SAAJ {@link Name}.
+    *
+    * @param pqname a prefixed qname
+    *
+    * @return a string representation of the prefixed qname
+    */
+   private static String nameToString( Name pqname )
+   {
+      if ( pqname == null )
+      {
+         //LOG.debug( ResourceKeys.MSG.getMsg( ResourceKeys.EX_PASSED_IN_NAME_OBJ_NULL ) );
+         return ( "" );
+      }
+
+      String prefix     = pqname.getPrefix(  );
+      String local_name = pqname.getLocalName(  );
+
+      if ( ( local_name == null ) || local_name.equals( "" ) )
+      {
+         //LOG.debug( ResourceKeys.MSG.getMsg( ResourceKeys.EX_PASSED_IN_NAME_OBJ_NULL_LOCAL ) );
+         if ( ( ( prefix != null ) && !prefix.equals( "" ) ) )
+         {
+            // NOTE (ips): This is a workaround for a bug in AXIS 1.1's MessageElement.getNamespacePrefixes()
+            return ( prefix );
+         }
+
+         return ( "" );
+      }
+
+      StringBuffer buf = new StringBuffer(  );
+
+      if ( ( prefix != null ) && !prefix.equals( "" ) )
+      {
+         buf.append( prefix );
+         buf.append( ":" );
+      }
+
+      buf.append( local_name );
+
+      return ( buf.toString(  ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param buf       DOCUMENT_ME
+    * @param soap_elem DOCUMENT_ME
+    * @param depth     DOCUMENT_ME
+    */
+   private void appendAttributes( StringBuffer buf,
+                                  SOAPElement  soap_elem,
+                                  int          depth )
+   {
+      appendXmlnsAttributeIfNoPrefix( buf, soap_elem, depth );
+
+      Iterator iter = soap_elem.getAllAttributes(  );
+
+      while ( iter.hasNext(  ) )
+      {
+         Name attrib_pqname = (Name) iter.next(  );
+
+         // skip all xmlns:foo attributes (e.g. xmlns:xs="urn:schema")
+         if ( ( attrib_pqname.getPrefix(  ) != null )
+              && attrib_pqname.getPrefix(  ).equals( XmlConstants.NSPREFIX_XMLNS ) )
+         {
+            continue;
+         }
+
+         // skip the xmlns attribute (e.g. xmlns="urn:default")
+         if ( ( attrib_pqname.getLocalName(  ) != null )
+              && attrib_pqname.getLocalName(  ).equals( XmlConstants.NSPREFIX_XMLNS ) )
+         {
+            continue;
+         }
+
+         appendAttribute( buf,
+                          nameToString( attrib_pqname ),
+                          soap_elem.getAttributeValue( attrib_pqname ),
+                          depth );
+
+         if ( ( ( attrib_pqname.getURI(  ) != null ) && !( "".equals( attrib_pqname.getURI(  ) ) ) )
+              && ( ( attrib_pqname.getPrefix(  ) != null ) && !( "".equals( attrib_pqname.getPrefix(  ) ) ) )
+              && ( soap_elem.getNamespaceURI( attrib_pqname.getPrefix(  ) ) == null ) )
+         {
+            appendNamespaceDeclarationAttribute( buf, attrib_pqname, depth );
+         }
+      }
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param buf       DOCUMENT_ME
+    * @param elem_name DOCUMENT_ME
+    * @param depth     DOCUMENT_ME
+    */
+   private void appendElementOpener( StringBuffer buf,
+                                     String       elem_name,
+                                     int          depth )
+   {
+      appendIndentSpaces( buf, depth );
+      buf.append( "<" );
+      buf.append( elem_name );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param buf DOCUMENT_ME
+    */
+   private static void appendEmptyElementCloser( StringBuffer buf )
+   {
+      buf.append( " />\n" );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param buf       DOCUMENT_ME
+    * @param elem_name DOCUMENT_ME
+    * @param depth     DOCUMENT_ME
+    */
+   private void appendClosingElement( StringBuffer buf,
+                                      String       elem_name,
+                                      int          depth )
+   {
+      appendIndentSpaces( buf, depth );
+      buf.append( "</" );
+      buf.append( elem_name );
+      buf.append( ">\n" );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param buf DOCUMENT_ME
+    */
+   private static void appendElementCloser( StringBuffer buf )
+   {
+      buf.append( ">\n" );
+   }
+
+   /**
+    * @param buf
+    * @param attrib_name
+    * @param attrib_value
+    */
+   private void appendAttribute( StringBuffer buf,
+                                 String       attrib_name,
+                                 String       attrib_value,
+                                 int          depth )
+   {
+      buf.append( "\n" );
+      appendIndentSpaces( buf, depth );
+      buf.append( attrib_name );
+      buf.append( "=\"" );
+      buf.append( attrib_value );
+      buf.append( "\"" );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param buf      DOCUMENT_ME
+    * @param children DOCUMENT_ME
+    * @param depth    DOCUMENT_ME
+    */
+   private void appendChildren( StringBuffer buf,
+                                Iterator     children,
+                                SOAPElement  root_soap_elem,
+                                int          depth )
+   throws SOAPException
+   {
+      while ( children.hasNext(  ) )
+      {
+         Node child = (Node) children.next(  );
+
+         buildSOAPNodeStringBuffer( buf, root_soap_elem, child, depth );
+      }
+   }
+
+   /**
+    * @param buf
+    * @param depth
+    */
+   private void appendIndentSpaces( StringBuffer buf,
+                                    int          depth )
+   {
+      if ( m_indent_str != null )
+      {
+         buf.append( org.apache.commons.lang.StringUtils.repeat( m_indent_str, depth ) );
+      }
+   }
+
+   /**
+    * Append an namespace declaration attribute of the form xmlns:prefix=nsuri.
+    *
+    * @param buf       the {@link StringBuffer} to be appended to
+    * @param ns_pqname a {@link Name} containing the namespace URI and prefix to be appended; note that the localname
+    *                  portion of ns_pqname is ignored
+    * @param depth     the current indentation depth
+    */
+   private void appendNamespaceDeclarationAttribute( StringBuffer buf,
+                                                     Name         ns_pqname,
+                                                     int          depth )
+   {
+      if ( ns_pqname.getPrefix(  ).equals( XmlConstants.NSPREFIX_XMLNS ) )
+      {
+         //LOG.debug( "The prefix \"xmlns\" cannot be bound to any namespace explicitly. Skipping..." );
+         return;
+      }
+
+      if ( ns_pqname.getURI(  ).equals( XmlConstants.NSURI_XMLNS ) )
+      {
+         //LOG.debug( "The namespace for \"xmlns\" cannot be bound to any prefix explicitly. Skipping..." );
+         return;
+      }
+
+      String xmlns_prefix = XmlConstants.NSPREFIX_XMLNS;
+
+      // if prefix was not the "default" prefix (xmlns:BLAH="xxx" vs. xmlns="xxx")
+      if ( hasNonEmptyValue( ns_pqname.getPrefix(  ) ) )
+      {
+         xmlns_prefix += ( ":" + ns_pqname.getPrefix(  ) );
+      }
+
+      appendAttribute( buf,
+                       xmlns_prefix,
+                       ns_pqname.getURI(  ),
+                       depth );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param buf   DOCUMENT_ME
+    * @param elem  DOCUMENT_ME
+    * @param depth DOCUMENT_ME
+    */
+   private void appendTextNode( StringBuffer buf,
+                                Node         elem,
+                                int          depth )
+   throws SOAPException
+   {
+      Text text = (Text) elem;
+
+      appendIndentSpaces( buf, depth );
+      buf.append( getValue( text ) );
+      buf.append( "\n" );
+   }
+
+   /**
+    * @param buf
+    * @param soap_elem
+    * @param depth
+    */
+   private void appendXmlnsAttributeIfNoPrefix( StringBuffer buf,
+                                                SOAPElement  soap_elem,
+                                                int          depth )
+   {
+      Name elem_pqname = soap_elem.getElementName(  );
+
+      if ( ( elem_pqname.getPrefix(  ) == null ) && ( elem_pqname.getURI(  ) != null ) )
+      {
+         appendAttribute( buf,
+                          XmlConstants.NSPREFIX_XMLNS,
+                          elem_pqname.getURI(  ),
+                          depth );
+      }
+   }
+
+   /**
+    * @param buf       string buffer to append to
+    * @param soap_elem a SOAP element; may not be null
+    * @param depth     current recursion depth
+    */
+   private void appendXmlnsAttributes( StringBuffer buf,
+                                       SOAPElement  soap_elem,
+                                       int          depth )
+   {
+      Iterator prefixes             = soap_elem.getNamespacePrefixes(  );
+      Set      encountered_prefixes = new HashSet(  );
+
+      Name     name = soap_elem.getElementName(  );
+
+      if ( hasNonEmptyValue( name.getPrefix(  ) ) && hasNonEmptyValue( name.getURI(  ) ) )
+      {
+         encountered_prefixes.add( name.getPrefix(  ) );
+         appendNamespaceDeclarationAttribute( buf, name, depth );
+      }
+
+      while ( prefixes.hasNext(  ) )
+      {
+         String prefix = (String) prefixes.next(  );
+
+         if ( encountered_prefixes.contains( prefix ) )
+         {
+            // duplicate prefix - skip it...
+            continue;
+         }
+
+         encountered_prefixes.add( prefix );
+
+         try
+         {
+            Name ns_pqname =
+               SOAPFactory.newInstance(  ).createName( "",
+                                                       prefix,
+                                                       soap_elem.getNamespaceURI( prefix ) );
+
+            appendNamespaceDeclarationAttribute( buf, ns_pqname, depth );
+         }
+         catch ( SOAPException soape )
+         {
+            //LOG.error( ResourceKeys.MSG.getMsg( ResourceKeys.METHOD_FAILED, "SOAPFactory.createName()" ),soape );
+         }
+      }
+   }
+
+   /**
+    * Workhorse method for {@link #toString(javax.xml.soap.Node)} - calls itself recursively.
+    *
+    * @param buf               StringBuffer used to build up the string representation
+    * @param current_soap_node a SAAJ SOAP node
+    * @param depth             the current tree depth (used for indenting)
+    */
+   private StringBuffer buildSOAPNodeStringBuffer( StringBuffer buf,
+                                                   Node         root_soap_node,
+                                                   Node         current_soap_node,
+                                                   int          depth )
+   throws SOAPException
+   {
+      if ( isElement( current_soap_node ) )
+      {
+         SOAPElement soap_elem   = (SOAPElement) current_soap_node;
+         Name        elem_pqname = null;
+
+         try
+         {
+            elem_pqname = soap_elem.getElementName(  );
+         }
+         catch ( RuntimeException re )
+         {
+            //LOG.error( ResourceKeys.MSG.getMsg( ResourceKeys.METHOD_FAILED, "SOAPElement.getElementName()" ) );
+         }
+
+         String elem_name = nameToString( elem_pqname );
+
+         if ( ( elem_pqname.getPrefix(  ) == null ) || elem_pqname.getPrefix(  ).equals( "" ) )
+         {
+            String prefix = getPrefix( elem_pqname, (SOAPElement) root_soap_node );
+
+            if ( prefix != null )
+            {
+               elem_name = prefix + ":" + elem_name;
+            }
+         }
+
+         appendElementOpener( buf, elem_name, depth );
+         appendXmlnsAttributes( buf, soap_elem, depth + 1 );
+         appendAttributes( buf, soap_elem, depth + 1 );
+
+         Iterator children = getChildren( soap_elem );
+
+         if ( children != null )
+         {
+            appendElementCloser( buf );
+            appendChildren( buf, children, (SOAPElement) root_soap_node, depth + 1 );
+            appendClosingElement( buf, elem_name, depth );
+         }
+         else
+         {
+            if ( hasNonEmptyValue( soap_elem ) )
+            {
+               appendElementCloser( buf );
+               appendTextNode( buf, soap_elem, depth + 1 );
+               appendClosingElement( buf, elem_name, depth );
+            }
+            else
+            {
+               appendEmptyElementCloser( buf );
+            }
+         }
+      }
+      else
+      {
+         appendTextNode( buf, current_soap_node, depth );
+      }
+
+      return ( buf );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param soap_elem DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   private static boolean hasNonEmptyValue( SOAPElement soap_elem )
+   {
+      return ( soap_elem.getValue(  ) != null ) && !soap_elem.getValue(  ).trim(  ).equals( "" );
+   }
+
+   /**
+    * @param pqname
+    * @param current_soap_elem
+    *
+    * @return
+    */
+   private static String recursiveGetPrefix( Name        pqname,
+                                             SOAPElement current_soap_elem )
+   {
+      String prefix = getPrefix( current_soap_elem,
+                                 pqname.getURI(  ) );
+
+      if ( ( prefix != null ) && !prefix.equals( "" ) )
+      {
+         return ( prefix );
+      }
+
+      Iterator children = current_soap_elem.getChildElements(  );
+
+      while ( children.hasNext(  ) )
+      {
+         Object obj_child = children.next(  );
+
+         if ( !( obj_child instanceof SOAPElement ) )
+         {
+            continue;
+         }
+
+         SOAPElement child = (SOAPElement) obj_child;
+
+         prefix = getPrefix( child,
+                             pqname.getURI(  ) );
+
+         if ( ( prefix != null ) && !prefix.equals( "" ) )
+         {
+            break;
+         }
+
+         prefix = recursiveGetPrefix( pqname, child );
+
+         if ( ( prefix != null ) && !prefix.equals( "" ) )
+         {
+            break;
+         }
+      }
+
+      return ( prefix );
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/AbstractMessages.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/AbstractMessages.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/AbstractMessages.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/AbstractMessages.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,389 @@
+/*=============================================================================*
+ *  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.i18n;
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Each project should implement this abstract class.
+ *
+ * @author Ian P. Springer
+ */
+public abstract class AbstractMessages
+   implements Messages
+{
+   /** DOCUMENT_ME */
+   private static final String DEFAULT_RESOURCE_NAME = "resource";
+
+   /** DOCUMENT_ME */
+   private static final Locale LOCALE = null;
+
+   /** DOCUMENT_ME */
+   private static final String ROOT_PROJECT_NAME = "org.apache.ws";
+
+   /** DOCUMENT_ME */
+   private static final String ROOT_PACKAGE_NAME = "org.apache.ws.util.i18n";
+
+   /** DOCUMENT_ME */
+   private static final ResourceBundle ROOT_RESOURCE_BUNDLE =
+      ProjectResourceBundle.getBundle( ROOT_PROJECT_NAME,
+                                       ROOT_PACKAGE_NAME,
+                                       DEFAULT_RESOURCE_NAME,
+                                       LOCALE,
+                                       AbstractMessages.class.getClassLoader(  ),
+                                       null );
+   private MessageBundle               m_messageBundle;
+
+   /**
+    * Creates a new {@link AbstractMessages} object.
+    */
+   protected AbstractMessages(  )
+   {
+      this( DEFAULT_RESOURCE_NAME );
+   }
+
+   /**
+    * Creates a new {@link AbstractMessages} object.
+    *
+    * @param resourceName DOCUMENT_ME
+    */
+   protected AbstractMessages( final String resourceName )
+   {
+      m_messageBundle =
+         new MessageBundle( getProjectPackageName(  ),
+                            getResourcePackageName(  ),
+                            resourceName,
+                            LOCALE,
+                            this.getClass(  ).getClassLoader(  ),
+                            ROOT_RESOURCE_BUNDLE );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             String arg0 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key, arg0 );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             Object arg0 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key,
+                                         String.valueOf( arg0 ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    * @param arg1 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             String arg0,
+                             String arg1 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key, arg0, arg1 );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    * @param arg1 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             Object arg0,
+                             Object arg1 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key,
+                                         String.valueOf( arg0 ),
+                                         String.valueOf( arg1 ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    * @param arg1 DOCUMENT_ME
+    * @param arg2 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             String arg0,
+                             String arg1,
+                             String arg2 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key, arg0, arg1, arg2 );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    * @param arg1 DOCUMENT_ME
+    * @param arg2 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             Object arg0,
+                             Object arg1,
+                             Object arg2 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key,
+                                         String.valueOf( arg0 ),
+                                         String.valueOf( arg1 ),
+                                         String.valueOf( arg2 ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    * @param arg1 DOCUMENT_ME
+    * @param arg2 DOCUMENT_ME
+    * @param arg3 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             String arg0,
+                             String arg1,
+                             String arg2,
+                             String arg3 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key, arg0, arg1, arg2, arg3 );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    * @param arg1 DOCUMENT_ME
+    * @param arg2 DOCUMENT_ME
+    * @param arg3 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             Object arg0,
+                             Object arg1,
+                             Object arg2,
+                             Object arg3 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key,
+                                         String.valueOf( arg0 ),
+                                         String.valueOf( arg1 ),
+                                         String.valueOf( arg2 ),
+                                         String.valueOf( arg3 ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    * @param arg1 DOCUMENT_ME
+    * @param arg2 DOCUMENT_ME
+    * @param arg3 DOCUMENT_ME
+    * @param arg4 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             String arg0,
+                             String arg1,
+                             String arg2,
+                             String arg3,
+                             String arg4 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key, arg0, arg1, arg2, arg3, arg4 );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param arg0 DOCUMENT_ME
+    * @param arg1 DOCUMENT_ME
+    * @param arg2 DOCUMENT_ME
+    * @param arg3 DOCUMENT_ME
+    * @param arg4 DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String key,
+                             Object arg0,
+                             Object arg1,
+                             Object arg2,
+                             Object arg3,
+                             Object arg4 )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key,
+                                         String.valueOf( arg0 ),
+                                         String.valueOf( arg1 ),
+                                         String.valueOf( arg2 ),
+                                         String.valueOf( arg3 ),
+                                         String.valueOf( arg4 ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    * @param args DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   public String getMessage( String   key,
+                             String[] args )
+   throws MissingResourceException
+   {
+      return m_messageBundle.getMessage( key, args );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String toString(  )
+   {
+      return "i18n messages for project " + getProjectPackageName(  );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   protected abstract String getProjectPackageName(  );
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   protected abstract String getResourcePackageName(  );
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   protected MessageBundle getMessageBundle(  )
+   {
+      return m_messageBundle;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param name DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   protected static final String getPackage( String name )
+   {
+      return name.substring( 0,
+                             name.lastIndexOf( '.' ) ).intern(  );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   protected ResourceBundle getResourceBundle(  )
+   {
+      return m_messageBundle.getResourceBundle(  );
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/Keys.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/Keys.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/Keys.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/Keys.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,231 @@
+/*=============================================================================*
+ *  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.i18n;
+
+
+/**
+ * i18n message keys and messages for the {@link org.apache.ws.util} package
+ * and all its subpackages.
+ *
+ * @author Ian P. Springer
+ */
+public interface Keys
+{
+   /**
+    * @msg Getting an InputSource from the URI: {0} using username: {1} and password: {2}
+    */
+   String INPUT_SRC_FRM_URI = "INPUT_SRC_FRM_URI";
+
+   /**
+    * @msg Null parameter not allowed.
+    */
+   String NULL_PARAM_NOT_ALLOWED = "NULL_PARAM_NOT_ALLOWED";
+
+   /**
+    * @msg Parameter must be an instance of one of the following types: XmlObject, Node, String, InputStream, Reader, File, or URL
+    */
+   String PARAM_MUST_BE_TYPE = "PARAM_MUST_BE_TYPE";
+
+   /**
+    * @msg  parameter may not be null
+    */
+   String PARAM_MAY_NOT_BE_NULL = "PARAM_MAY_NOT_BE_NULL";
+
+   /**
+    * @msg text node has null value
+    */
+   String TEXT_NODE_IS_NULL = "TEXT_NODE_IS_NULL";
+
+   /**
+    * @msg Building a prefix for the namespace: {0}
+    */
+   String BLD_PREFIX_FOR_NAMESPC = "BLD_PREFIX_FOR_NAMESPC";
+
+   /**
+    * @msg Creating a Name from localpart: {0} prefix: {1} uri: {2}
+    */
+   String CREATING_NAME = "CREATING_NAME";
+
+   /**
+    * @msg Converting QName to Name.  QName: {0}
+    */
+   String CONVRT_QNAME_TO_NAME = "CONVRT_QNAME_TO_NAME";
+
+   /**
+    * @msg Converting Name to QName.  Name: {0}
+    */
+   String CONVRT_NAME_TO_QNAME = "CONVRT_NAME_TO_QNAME";
+
+   /**
+    * @msg Attempting to load xml string: {0} into a DOM.
+    */
+   String LOAD_XML_STRING = "LOAD_XML_STRING";
+
+   /**
+    * @msg InputStream parameter must not be null.
+    */
+   String INPUTSTRM_MST_NOT_B_NULL = "INPUTSTRM_MST_NOT_B_NULL";
+
+   /**
+    * @msg OutputStream parameter must not be null.
+    */
+   String OUTSTRM_MST_NOT_B_NULL = "OUTSTRM_MST_NOT_B_NULL";
+
+   /**
+    * @msg Attempting to copy an InputStream to the file: {0}
+    */
+   String COPY_OUTPUTSTRM_TO_FILE = "COPY_OUTPUTSTRM_TO_FILE";
+
+   /**
+    * @msg copy
+    */
+   String COPY = "COPY";
+
+   /**
+    * @msg Failed to copy input stream to {0}.  Rename of temporary file {1} failed.
+    */
+   String FAILED_TO_COPY_INPUTSTRM = "FAILED_TO_COPY_INPUTSTRM";
+
+   /**
+    * @msg Attempting to copy the file: {0} to the file: {1}
+    */
+   String ATTMPT_COPY_FILE_TO_FILE = "ATTMPT_COPY_FILE_TO_FILE";
+
+   /**
+    * @msg Failed to copy {0} to {1} Cause: {2}
+    */
+   String FAILED_TO_CPY_FILE_TO_FILE = "FAILED_TO_CPY_FILE_TO_FILE";
+
+   /**
+    * @msg Attempting to delete directory: {0}
+    */
+   String ATTMPT_DEL_DIR = "ATTMPT_DEL_DIR";
+
+   /**
+    * @msg Attempting to convert a String to an InputStream. String: {0}
+    */
+   String ATTMPT_CNVRT_STRING_TO_INPTSTRM = "ATTMPT_CNVRT_STRING_TO_INPTSTRM";
+
+   /**
+    * @msg Work object cannot be null.
+    */
+   String NULL_WORK = "NULL_WORK";
+
+   /**
+    * @msg Setting WorkManager maxPoolSize to: {0}
+    */
+   String WRK_MGR_POOL_SIZE = "WRK_MGR_POOL_SIZE";
+
+   /**
+    * @msg Creating WorkManager with maxPoolSize: {0}
+    */
+   String CREATE_WRK_MGR_POOL_SZE = "CREATE_WRK_MGR_POOL_SZE";
+
+   /**
+    * @msg Cancelling.
+    */
+   String CANCELLING = "CANCELLING";
+
+   /**
+    * @msg Setting pool size to: {0}
+    */
+   String SET_POOL_SIZE = "SET_POOL_SIZE";
+
+   /**
+    * @msg Resuming.
+    */
+   String RESUMING = "RESUMING";
+
+   /**
+    * @msg Stopping.
+    */
+   String STOPPING = "STOPPING";
+
+   /**
+    * @msg Suspending.
+    */
+   String SUSPENDING = "SUSPENDING";
+
+   /**
+    * @msg Removing task: {0}
+    */
+   String REMOVING_TASK = "REMOVING_TASK";
+
+   /**
+    * @msg The serviceURL attribute is required.
+    */
+   String SRVC_URL_REQ = "SRVC_URL_REQ";
+
+   /**
+    * @msg The requestFile attribute is required.
+    */
+   String RQST_FILE_REQ = "RQST_FILE_REQ";
+
+   /**
+    * @msg SOAP request failed with HTTP status: {0} {1}
+    */
+   String SOAP_REQ_FAILED_HTTP_STATUS = "SOAP_REQ_FAILED_HTTP_STATUS";
+
+   /**
+    * @msg  Usage:  java {0} http://serviceURL soapEnvelope.xml [SOAPAction]
+    */
+   String SOAPCLIENT_USAGE = "SOAPCLIENT_USAGE";
+
+   /**
+    * @msg  SOAPAction is optional.
+    */
+   String SOAPACITON_OPTIONAL = "SOAPACITON_OPTIONAL";
+
+   /**
+    * @msg Getting Lock for key: {0}
+    */
+   String GET_LOCK_FOR_KEY = "GET_LOCK_FOR_KEY";
+
+   /**
+    * @msg Removing Lock for key: {0}
+    */
+   String REMOVING_LCK_FOR_KEY = "REMOVING_LCK_FOR_KEY";
+
+   /**
+    * @msg Acquiring lock.
+    */
+   String ACQUIRE_LCK = "ACQUIRE_LCK";
+
+   /**
+    * @msg Releasing lock.
+    */
+   String RELEASE_LCK = "RELEASE_LCK";
+
+   /**
+    * @msg project has not been set
+    */
+   String PRJ_NOT_SET = "PRJ_NOT_SET";
+
+   /**
+    * @msg You must specify a property name.
+    */
+   String MST_SPECIFY_PROP_NAME = "MST_SPECIFY_PROP_NAME";
+
+   /**
+    * @msg You must specify a location.
+    */
+   String MST_SPECIFY_LOCATION = "MST_SPECIFY_LOCATION";
+
+   /**
+    * @msg value is null
+    */
+   String NULL_VALUE = "NULL_VALUE";
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/MessageBundle.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/MessageBundle.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/MessageBundle.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/MessageBundle.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,258 @@
+/*=============================================================================*
+ *  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.i18n;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Accept parameters for ProjectResourceBundle,
+ * but defer object instantiation (and therefore
+ * resource bundle loading) until required.
+ *
+ * @author Richard A. Sitze (rsitze@us.ibm.com)
+ * @author Karl Moss (kmoss@macromedia.com)
+ * @author Glen Daniels (gdaniels@apache.org)
+ */
+public class MessageBundle
+{
+   private final ClassLoader     m_classLoader;
+   private final Locale          m_locale;
+   private ProjectResourceBundle m_resourceBundle = null;
+   private final ResourceBundle  m_parent;
+   private final String          m_packageName;
+   private final String          m_projectName;
+   private final String          m_resourceName;
+   private boolean               m_loaded;
+
+   /**
+    * Construct a new ExtendMessages
+    */
+   public MessageBundle( String         projectName,
+                         String         packageName,
+                         String         resourceName,
+                         Locale         locale,
+                         ClassLoader    classLoader,
+                         ResourceBundle parent )
+   throws MissingResourceException
+   {
+      this.m_projectName     = projectName;
+      this.m_packageName     = packageName;
+      this.m_resourceName    = resourceName;
+      this.m_locale          = locale;
+      this.m_classLoader     = classLoader;
+      this.m_parent          = parent;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public final ProjectResourceBundle getResourceBundle(  )
+   {
+      if ( !m_loaded )
+      {
+         m_resourceBundle =
+            ProjectResourceBundle.getBundle( m_projectName, m_packageName, m_resourceName, m_locale,
+                                             m_classLoader, m_parent );
+         m_loaded = true;
+      }
+
+      return m_resourceBundle;
+   }
+
+   /**
+    * Gets a string message from the resource bundle for the given key
+    *
+    * @param key The resource key
+    *
+    * @return The message
+    */
+   public String getMessage( String key )
+   throws MissingResourceException
+   {
+      return getMessage( key, (String[]) null );
+   }
+
+   /**
+    * <p>Gets a string message from the resource bundle for the given key. The message may contain variables that will
+    * be substituted with the given arguments. Variables have the format:</p> <dir> This message has two variables: {0}
+    * and {1} </dir>
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    *
+    * @return The message
+    */
+   public String getMessage( String key,
+                             String arg0 )
+   throws MissingResourceException
+   {
+      return getMessage( key,
+                         new String[]
+                         {
+                            arg0
+                         } );
+   }
+
+   /**
+    * <p>Gets a string message from the resource bundle for the given key. The message may contain variables that will
+    * be substituted with the given arguments. Variables have the format:</p> <dir> This message has two variables: {0}
+    * and {1} </dir>
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    *
+    * @return The message
+    */
+   public String getMessage( String key,
+                             String arg0,
+                             String arg1 )
+   throws MissingResourceException
+   {
+      return getMessage( key,
+                         new String[]
+                         {
+                            arg0,
+                            arg1
+                         } );
+   }
+
+   /**
+    * <p>Gets a string message from the resource bundle for the given key. The message may contain variables that will
+    * be substituted with the given arguments. Variables have the format:</p> <dir> This message has two variables: {0}
+    * and {1} </dir>
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    *
+    * @return The message
+    */
+   public String getMessage( String key,
+                             String arg0,
+                             String arg1,
+                             String arg2 )
+   throws MissingResourceException
+   {
+      return getMessage( key,
+                         new String[]
+                         {
+                            arg0,
+                            arg1,
+                            arg2
+                         } );
+   }
+
+   /**
+    * <p>Gets a string message from the resource bundle for the given key. The message may contain variables that will
+    * be substituted with the given arguments. Variables have the format:</p> <dir> This message has two variables: {0}
+    * and {1} </dir>
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    * @param arg3 The argument to place in variable {3}
+    *
+    * @return The message
+    */
+   public String getMessage( String key,
+                             String arg0,
+                             String arg1,
+                             String arg2,
+                             String arg3 )
+   throws MissingResourceException
+   {
+      return getMessage( key,
+                         new String[]
+                         {
+                            arg0,
+                            arg1,
+                            arg2,
+                            arg3
+                         } );
+   }
+
+   /**
+    * <p>Gets a string message from the resource bundle for the given key. The message may contain variables that will
+    * be substituted with the given arguments. Variables have the format:</p> <dir> This message has two variables: {0}
+    * and {1} </dir>
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    * @param arg3 The argument to place in variable {3}
+    * @param arg4 The argument to place in variable {4}
+    *
+    * @return The message
+    */
+   public String getMessage( String key,
+                             String arg0,
+                             String arg1,
+                             String arg2,
+                             String arg3,
+                             String arg4 )
+   throws MissingResourceException
+   {
+      return getMessage( key,
+                         new String[]
+                         {
+                            arg0,
+                            arg1,
+                            arg2,
+                            arg3,
+                            arg4
+                         } );
+   }
+
+   /**
+    * <p>Gets a string message from the resource bundle for the given key. The message may contain variables that will
+    * be substituted with the given arguments. Variables have the format:</p> <dir> This message has two variables: {0}
+    * and {1} </dir>
+    *
+    * @param key   The resource key
+    * @param array An array of objects to place in corresponding variables
+    *
+    * @return The message
+    */
+   public String getMessage( String   key,
+                             String[] array )
+   throws MissingResourceException
+   {
+      String msg = null;
+
+      if ( getResourceBundle(  ) != null )
+      {
+         msg = getResourceBundle(  ).getString( key );
+      }
+
+      if ( msg == null )
+      {
+         throw new MissingResourceException( "Cannot find resource key \"" + key + "\" in base name "
+                                             + getResourceBundle(  ).getResourceName(  ),
+                                             getResourceBundle(  ).getResourceName(  ), key );
+      }
+
+      return MessageFormat.format( msg, array );
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/Messages.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/Messages.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/Messages.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/Messages.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,232 @@
+/*=============================================================================*
+ *  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.i18n;
+
+import java.util.MissingResourceException;
+
+/**
+ * Provides methods for retrieving i18n messages.
+ *
+ * @author Ian P. Springer <ia...@hp.com>
+ */
+public interface Messages
+{
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key The resource key
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      String arg0 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      Object arg0 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      String arg0,
+                      String arg1 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      Object arg0,
+                      Object arg1 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      String arg0,
+                      String arg1,
+                      String arg2 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      Object arg0,
+                      Object arg1,
+                      Object arg2 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    * @param arg3 The argument to place in variable {3}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      String arg0,
+                      String arg1,
+                      String arg2,
+                      String arg3 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    * @param arg3 The argument to place in variable {3}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      Object arg0,
+                      Object arg1,
+                      Object arg2,
+                      Object arg3 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    * @param arg3 The argument to place in variable {3}
+    * @param arg4 The argument to place in variable {4}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      String arg0,
+                      String arg1,
+                      String arg2,
+                      String arg3,
+                      String arg4 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param arg0 The argument to place in variable {0}
+    * @param arg1 The argument to place in variable {1}
+    * @param arg2 The argument to place in variable {2}
+    * @param arg3 The argument to place in variable {3}
+    * @param arg4 The argument to place in variable {4}
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String key,
+                      Object arg0,
+                      Object arg1,
+                      Object arg2,
+                      Object arg3,
+                      Object arg4 )
+   throws MissingResourceException;
+
+   /**
+    * Get a message from resource.properties from the package of the given object.
+    *
+    * @param key  The resource key
+    * @param args An array of objects to place in corresponding variables
+    *
+    * @return The formatted message
+    *
+    * @throws MissingResourceException
+    */
+   String getMessage( String   key,
+                      String[] args )
+   throws MissingResourceException;
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/MessagesImpl.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/MessagesImpl.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/MessagesImpl.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/MessagesImpl.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,64 @@
+/*=============================================================================*
+ *  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.i18n;
+
+
+/**
+ * Singleton used by all classes below the {@link org.apache.ws.util} package
+ * for retrieving i18n messages.
+ *
+ * @author Ian P. Springer
+ */
+public class MessagesImpl
+   extends AbstractMessages
+{
+   /** DOCUMENT_ME */
+   public static final String PROJECT_PACKAGE_NAME = "org.apache.ws.util";
+
+   /** DOCUMENT_ME */
+   public static final String RESOURCE_PACKAGE_NAME = "org.apache.ws.util.i18n";
+   private static Messages    s_ourInstance = new MessagesImpl(  );
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public static Messages getInstance(  )
+   {
+      return s_ourInstance;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   protected String getProjectPackageName(  )
+   {
+      return PROJECT_PACKAGE_NAME;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   protected String getResourcePackageName(  )
+   {
+      return RESOURCE_PACKAGE_NAME;
+   }
+}
\ 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