You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-commits@ws.apache.org by sc...@apache.org on 2005/10/20 19:51:37 UTC
svn commit: r326958 [7/9] - in /webservices/wsrf/trunk/src:
examples/filesystem/
examples/filesystem/src/java/org/apache/ws/resource/example/filesystem/
java/org/apache/ws/addressing/ java/org/apache/ws/addressing/handler/
java/org/apache/ws/addressing...
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java Thu Oct 20 10:50:00 2005
@@ -15,18 +15,6 @@
*=============================================================================*/
package org.apache.ws.util;
-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;
-
-import javax.xml.namespace.QName;
-import javax.xml.soap.SOAPElement;
-
import org.apache.ws.util.i18n.Keys;
import org.apache.ws.util.i18n.Messages;
import org.apache.ws.util.i18n.MessagesImpl;
@@ -40,6 +28,16 @@
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.
@@ -49,666 +47,677 @@
*/
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() );
- }
- }
+ private static final Messages MSG = MessagesImpl.getInstance( );
- 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;
- }
-
- /**
- * @param xBean
- */
- public static void setName( XmlObject xBean, QName name )
- {
- if ( xBean == null )
- {
- throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_PARAM_NOT_ALLOWED ) );
- }
- XmlCursor xCursor = xBean.newCursor();
- setName( xCursor, name );
- xCursor.dispose();
- }
-
- /**
- * Note. this method does not dispose of the cursor
- *
- * @param xCursor
- */
- public static void setName( XmlCursor xCursor, QName name )
- {
- if ( xCursor.currentTokenType().equals( XmlCursor.TokenType.STARTDOC ) )
- {
- if ( xCursor.toFirstChild() )
- {
- xCursor.setName( name );
- xCursor.toParent();
- }
- else
- {
- addChildElement( xCursor.getObject(), name );
- }
- }
- else
- {
+ /**
+ * @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
+ */
+ public static void setName( XmlObject xBean,
+ QName name )
+ {
+ if ( xBean == null )
+ {
+ throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_PARAM_NOT_ALLOWED ) );
+ }
+
+ XmlCursor xCursor = xBean.newCursor( );
+ setName( xCursor, name );
+ xCursor.dispose( );
+ }
+
+ /**
+ * Note. this method does not dispose of the cursor
+ *
+ * @param xCursor
+ */
+ public static void setName( XmlCursor xCursor,
+ QName name )
+ {
+ if ( xCursor.currentTokenType( ).equals( XmlCursor.TokenType.STARTDOC ) )
+ {
+ if ( xCursor.toFirstChild( ) )
+ {
xCursor.setName( 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 ) )
+ xCursor.toParent( );
+ }
+ else
+ {
+ addChildElement( xCursor.getObject( ),
+ name );
+ }
+ }
+ else
+ {
+ xCursor.setName( name );
+ }
+ }
+
+ /**
+ * @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;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param elemName DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static XmlObject createElement( QName elemName )
+ {
+ XmlObject xBean = XmlObject.Factory.newInstance( );
+ setName( xBean, elemName );
+ return xBean;
+ }
+
+ /**
+ * 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 );*/
+ Node domNode = xBean.newDomNode( );
+ 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 )
{
- succeeded = succeeded && xCursor.removeXml();
+ domElem = (Element) childNodes.item( i );
+ break;
}
- }
+ }
+ }
- 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 );*/
- Node domNode = xBean.newDomNode( );
- 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 + "'" );
- }
+ return SaajUtils.toSOAPElement( domElem );
+ }
- xCursor.dispose();
- }
- else
- {
- nsURI = "";
- }
-
- String localName = value.substring( colonIndex + 1 );
- return new QName( nsURI, localName );
- }
-
- public static XmlObject createElement( QName elemName )
- {
- XmlObject xBean = XmlObject.Factory.newInstance();
- setName( xBean, elemName );
- return xBean;
- }
+ /**
+ * 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 );
+ }
}
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/ant/FileTask.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/ant/FileTask.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/ant/FileTask.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/ant/FileTask.java Thu Oct 20 10:50:00 2005
@@ -15,13 +15,12 @@
*=============================================================================*/
package org.apache.ws.util.ant;
-import java.io.File;
-
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
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/helper/Dom2SaajConverter.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/helper/Dom2SaajConverter.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/helper/Dom2SaajConverter.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/helper/Dom2SaajConverter.java Thu Oct 20 10:50:00 2005
@@ -15,18 +15,17 @@
*=============================================================================*/
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;
-
-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;
/**
* LOG-DONE
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/helper/Saaj2StringConverter.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/helper/Saaj2StringConverter.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/helper/Saaj2StringConverter.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/helper/Saaj2StringConverter.java Thu Oct 20 10:50:00 2005
@@ -15,12 +15,10 @@
*=============================================================================*/
package org.apache.ws.util.helper;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
+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;
@@ -30,11 +28,11 @@
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.Text;
-
-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 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)
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/i18n/ProjectResourceBundle.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/i18n/ProjectResourceBundle.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/i18n/ProjectResourceBundle.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/i18n/ProjectResourceBundle.java Thu Oct 20 10:50:00 2005
@@ -15,6 +15,8 @@
*=============================================================================*/
package org.apache.ws.util.i18n;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
@@ -22,9 +24,6 @@
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* <p>Wrapper class for resource bundles. Property files are used to store
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/j2ee/WebDDMergeTask.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/j2ee/WebDDMergeTask.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/j2ee/WebDDMergeTask.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/j2ee/WebDDMergeTask.java Thu Oct 20 10:50:00 2005
@@ -1,212 +1,223 @@
-/*=============================================================================*
- * Copyright 2005 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.j2ee;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import noNamespace.ServletMappingType;
-import noNamespace.ServletType;
-import noNamespace.WebAppDocument;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.FileSet;
-import org.apache.xmlbeans.XmlOptions;
-
-/**
- * An Ant task that merges one or more source J2EE web.xml's into a target web.xml.
- */
-public class WebDDMergeTask extends Task
-{
-
- private List m_sourceFiles = new ArrayList();
- private File m_targetFile;
-
- public WebDDMergeTask()
- {
- initContextClassLoader();
- }
-
- /**
- * Adds the specified file to the list of source web.xml's.
- *
- * @param srcFile
- */
- public void setSourceFile( File srcFile )
- {
- m_sourceFiles.add( srcFile );
- }
-
- /**
- * Adds the files in the specified fileset to the list of source web.xml's.
- *
- * @param fileSet DOCUMENT_ME
- */
- public void addConfiguredSourceFiles( FileSet fileSet )
- {
- File baseDir = fileSet.getDir( getProject() );
- DirectoryScanner dirScanner = fileSet.getDirectoryScanner( getProject() );
- String[] includedFiles = dirScanner.getIncludedFiles();
- for ( int i = 0; i < includedFiles.length; i++ )
- {
- m_sourceFiles.add( new File( baseDir, includedFiles[i] ) );
- }
- }
-
- /**
- * Sets the target web.xml (i.e. the web.xml to be merged into).
- *
- * @param targetFile
- */
- public void setTargetFile( File targetFile )
- {
- m_targetFile = targetFile;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @throws org.apache.tools.ant.BuildException
- * DOCUMENT_ME
- */
- public void execute()
- throws BuildException
- {
- if ( m_sourceFiles.isEmpty() )
- {
- throw new BuildException( "No source web.xml files were specified!" );
- }
- try
- {
- System.out.println( "Loading target web-app document from " + m_targetFile + " ..." );
- WebAppDocument targetWebAppDoc = parseWebXmlFile( m_targetFile );
- WebAppDocument.WebApp targetWebApp = targetWebAppDoc.getWebApp();
- for ( int i = 0; i < m_sourceFiles.size(); i++ )
- {
- mergeWebXml( (File) m_sourceFiles.get( i ), targetWebApp );
- }
- saveTargetDocToFile( targetWebAppDoc );
- }
- catch ( Exception e )
- {
- throw new BuildException( e );
- }
- }
-
- private WebAppDocument parseWebXmlFile( File ddFile )
- throws Exception
- {
- XmlOptions loadOptions = new XmlOptions().setLoadStripWhitespace();
- return WebAppDocument.Factory.parse( ddFile, loadOptions );
- }
-
- private void saveTargetDocToFile( WebAppDocument doc )
- throws IOException
- {
- System.out.println( "Saving updated target web-app document to " + m_targetFile + " ..." );
- XmlOptions saveOptions = new XmlOptions().setSavePrettyPrint();
- doc.save( m_targetFile, saveOptions );
- }
-
- private void mergeWebXml( File srcFile, WebAppDocument.WebApp targetWebApp ) throws Exception
- {
- System.out.println( "Merging " + srcFile + " into target web-app document ..." );
- WebAppDocument webAppDoc = parseWebXmlFile( srcFile );
- WebAppDocument.WebApp webApp = webAppDoc.getWebApp();
- mergeServletElements( webApp, targetWebApp );
- mergeServletMappingElements( webApp, targetWebApp );
- }
-
- private void mergeServletElements( WebAppDocument.WebApp webApp, WebAppDocument.WebApp targetWebApp )
- {
- ServletType[] servletArray = webApp.getServletArray();
- ServletType[] targetServletArray = targetWebApp.getServletArray();
- for ( int i = 0; i < servletArray.length; i++ )
- {
- ServletType servlet = servletArray[i];
- String servletName = servlet.getServletName().getStringValue();
- ServletType targetServlet = getServlet( targetServletArray, servletName );
- if ( targetServlet == null )
- {
- targetServlet = targetWebApp.addNewServlet();
- }
- targetServlet.set( servlet );
- }
- }
-
- private void mergeServletMappingElements( WebAppDocument.WebApp webApp, WebAppDocument.WebApp targetWebApp )
- {
- ServletMappingType[] servletMappingArray = webApp.getServletMappingArray();
- ServletMappingType[] targetServletMappingArray = targetWebApp.getServletMappingArray();
- for ( int i = 0; i < servletMappingArray.length; i++ )
- {
- ServletMappingType servletMapping = servletMappingArray[i];
- String servletName = servletMapping.getServletName().getStringValue();
- String urlPattern = servletMapping.getUrlPattern().getStringValue();
- ServletMappingType targetServletMapping = getServletMapping( targetServletMappingArray, servletName,
- urlPattern );
- if ( targetServletMapping == null )
- {
- targetServletMapping = targetWebApp.addNewServletMapping();
- }
- targetServletMapping.set( servletMapping );
- }
- }
-
- private ServletType getServlet( ServletType[] servletArray,
- String servletName )
- {
- ServletType servlet = null;
- for ( int j = 0; j < servletArray.length; j++ )
- {
- if ( servletArray[j].getServletName().getStringValue().equals( servletName ) )
- {
- servlet = servletArray[j];
- break;
- }
- }
- return servlet;
- }
-
- private ServletMappingType getServletMapping( ServletMappingType[] servletMappingArray, String servletName,
- String urlPattern )
- {
- ServletMappingType servletMapping = null;
- for ( int j = 0; j < servletMappingArray.length; j++ )
- {
- if ( servletMappingArray[j].getServletName().getStringValue().equals( servletName ) &&
- servletMappingArray[j].getUrlPattern().getStringValue().equals( urlPattern ) )
- {
- servletMapping = servletMappingArray[j];
- break;
- }
- }
- return servletMapping;
- }
-
- private void initContextClassLoader()
- {
- if ( Thread.currentThread().getContextClassLoader() == null )
- {
- Thread.currentThread().setContextClassLoader( Task.class.getClassLoader() );
- }
- }
-
-}
+/*=============================================================================*
+ * 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.j2ee;
+
+import noNamespace.ServletMappingType;
+import noNamespace.ServletType;
+import noNamespace.WebAppDocument;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.xmlbeans.XmlOptions;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An Ant task that merges one or more source J2EE web.xml's into a target web.xml.
+ */
+public class WebDDMergeTask
+ extends Task
+{
+ private List m_sourceFiles = new ArrayList( );
+ private File m_targetFile;
+
+ /**
+ * Creates a new {@link WebDDMergeTask} object.
+ */
+ public WebDDMergeTask( )
+ {
+ initContextClassLoader( );
+ }
+
+ /**
+ * Adds the specified file to the list of source web.xml's.
+ *
+ * @param srcFile
+ */
+ public void setSourceFile( File srcFile )
+ {
+ m_sourceFiles.add( srcFile );
+ }
+
+ /**
+ * Sets the target web.xml (i.e. the web.xml to be merged into).
+ *
+ * @param targetFile
+ */
+ public void setTargetFile( File targetFile )
+ {
+ m_targetFile = targetFile;
+ }
+
+ /**
+ * Adds the files in the specified fileset to the list of source web.xml's.
+ *
+ * @param fileSet DOCUMENT_ME
+ */
+ public void addConfiguredSourceFiles( FileSet fileSet )
+ {
+ File baseDir = fileSet.getDir( getProject( ) );
+ DirectoryScanner dirScanner = fileSet.getDirectoryScanner( getProject( ) );
+ String[] includedFiles = dirScanner.getIncludedFiles( );
+ for ( int i = 0; i < includedFiles.length; i++ )
+ {
+ m_sourceFiles.add( new File( baseDir, includedFiles[i] ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @throws org.apache.tools.ant.BuildException
+ * DOCUMENT_ME
+ */
+ public void execute( )
+ throws BuildException
+ {
+ if ( m_sourceFiles.isEmpty( ) )
+ {
+ throw new BuildException( "No source web.xml files were specified!" );
+ }
+
+ try
+ {
+ System.out.println( "Loading target web-app document from " + m_targetFile + " ..." );
+ WebAppDocument targetWebAppDoc = parseWebXmlFile( m_targetFile );
+ WebAppDocument.WebApp targetWebApp = targetWebAppDoc.getWebApp( );
+ for ( int i = 0; i < m_sourceFiles.size( ); i++ )
+ {
+ mergeWebXml( (File) m_sourceFiles.get( i ), targetWebApp );
+ }
+
+ saveTargetDocToFile( targetWebAppDoc );
+ }
+ catch ( Exception e )
+ {
+ throw new BuildException( e );
+ }
+ }
+
+ private ServletType getServlet( ServletType[] servletArray,
+ String servletName )
+ {
+ ServletType servlet = null;
+ for ( int j = 0; j < servletArray.length; j++ )
+ {
+ if ( servletArray[j].getServletName( ).getStringValue( ).equals( servletName ) )
+ {
+ servlet = servletArray[j];
+ break;
+ }
+ }
+
+ return servlet;
+ }
+
+ private ServletMappingType getServletMapping( ServletMappingType[] servletMappingArray,
+ String servletName,
+ String urlPattern )
+ {
+ ServletMappingType servletMapping = null;
+ for ( int j = 0; j < servletMappingArray.length; j++ )
+ {
+ if ( servletMappingArray[j].getServletName( ).getStringValue( ).equals( servletName )
+ && servletMappingArray[j].getUrlPattern( ).getStringValue( ).equals( urlPattern ) )
+ {
+ servletMapping = servletMappingArray[j];
+ break;
+ }
+ }
+
+ return servletMapping;
+ }
+
+ private void initContextClassLoader( )
+ {
+ if ( Thread.currentThread( ).getContextClassLoader( ) == null )
+ {
+ Thread.currentThread( ).setContextClassLoader( Task.class.getClassLoader( ) );
+ }
+ }
+
+ private void mergeServletElements( WebAppDocument.WebApp webApp,
+ WebAppDocument.WebApp targetWebApp )
+ {
+ ServletType[] servletArray = webApp.getServletArray( );
+ ServletType[] targetServletArray = targetWebApp.getServletArray( );
+ for ( int i = 0; i < servletArray.length; i++ )
+ {
+ ServletType servlet = servletArray[i];
+ String servletName = servlet.getServletName( ).getStringValue( );
+ ServletType targetServlet = getServlet( targetServletArray, servletName );
+ if ( targetServlet == null )
+ {
+ targetServlet = targetWebApp.addNewServlet( );
+ }
+
+ targetServlet.set( servlet );
+ }
+ }
+
+ private void mergeServletMappingElements( WebAppDocument.WebApp webApp,
+ WebAppDocument.WebApp targetWebApp )
+ {
+ ServletMappingType[] servletMappingArray = webApp.getServletMappingArray( );
+ ServletMappingType[] targetServletMappingArray = targetWebApp.getServletMappingArray( );
+ for ( int i = 0; i < servletMappingArray.length; i++ )
+ {
+ ServletMappingType servletMapping = servletMappingArray[i];
+ String servletName = servletMapping.getServletName( ).getStringValue( );
+ String urlPattern = servletMapping.getUrlPattern( ).getStringValue( );
+ ServletMappingType targetServletMapping =
+ getServletMapping( targetServletMappingArray, servletName, urlPattern );
+ if ( targetServletMapping == null )
+ {
+ targetServletMapping = targetWebApp.addNewServletMapping( );
+ }
+
+ targetServletMapping.set( servletMapping );
+ }
+ }
+
+ private void mergeWebXml( File srcFile,
+ WebAppDocument.WebApp targetWebApp )
+ throws Exception
+ {
+ System.out.println( "Merging " + srcFile + " into target web-app document ..." );
+ WebAppDocument webAppDoc = parseWebXmlFile( srcFile );
+ WebAppDocument.WebApp webApp = webAppDoc.getWebApp( );
+ mergeServletElements( webApp, targetWebApp );
+ mergeServletMappingElements( webApp, targetWebApp );
+ }
+
+ private WebAppDocument parseWebXmlFile( File ddFile )
+ throws Exception
+ {
+ XmlOptions loadOptions = new XmlOptions( ).setLoadStripWhitespace( );
+ return WebAppDocument.Factory.parse( ddFile, loadOptions );
+ }
+
+ private void saveTargetDocToFile( WebAppDocument doc )
+ throws IOException
+ {
+ System.out.println( "Saving updated target web-app document to " + m_targetFile + " ..." );
+ XmlOptions saveOptions = new XmlOptions( ).setSavePrettyPrint( );
+ doc.save( m_targetFile, saveOptions );
+ }
+}
\ No newline at end of file
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/j2ee/WebservicesDDMergeTask.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/j2ee/WebservicesDDMergeTask.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/j2ee/WebservicesDDMergeTask.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/j2ee/WebservicesDDMergeTask.java Thu Oct 20 10:50:00 2005
@@ -1,176 +1,183 @@
-/*=============================================================================*
- * Copyright 2005 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.j2ee;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.FileSet;
-import org.apache.xmlbeans.XmlOptions;
-
-import com.sun.java.xml.ns.j2Ee.WebserviceDescriptionType;
-import com.sun.java.xml.ns.j2Ee.WebservicesDocument;
-import com.sun.java.xml.ns.j2Ee.WebservicesType;
-
-/**
- * An Ant task that merges one or more source J2EE webservices.xml's into a target webservices.xml.
- */
-public class WebservicesDDMergeTask extends Task
-{
-
- private List m_sourceFiles = new ArrayList();
- private File m_targetFile;
-
- public WebservicesDDMergeTask()
- {
- initContextClassLoader();
- }
-
- /**
- * Adds the specified file to the list of source web.xml's.
- *
- * @param srcFile
- */
- public void setSourceFile( File srcFile )
- {
- m_sourceFiles.add( srcFile );
- }
-
- /**
- * Adds the files in the specified fileset to the list of source web.xml's.
- *
- * @param fileSet DOCUMENT_ME
- */
- public void addConfiguredSourceFiles( FileSet fileSet )
- {
- File baseDir = fileSet.getDir( getProject() );
- DirectoryScanner dirScanner = fileSet.getDirectoryScanner( getProject() );
- String[] includedFiles = dirScanner.getIncludedFiles();
- for ( int i = 0; i < includedFiles.length; i++ )
- {
- m_sourceFiles.add( new File( baseDir, includedFiles[i] ) );
- }
- }
-
- /**
- * Sets the target web.xml (i.e. the web.xml to be merged into).
- *
- * @param targetFile
- */
- public void setTargetFile( File targetFile )
- {
- m_targetFile = targetFile;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @throws org.apache.tools.ant.BuildException
- * DOCUMENT_ME
- */
- public void execute()
- throws BuildException
- {
- if ( m_sourceFiles.isEmpty() )
- {
- throw new BuildException( "No source webservices.xml files were specified!" );
- }
- try
- {
- System.out.println( "Loading target webservices document from " + m_targetFile + " ..." );
- WebservicesDocument targetDdDoc = parseWebservicesXmlFile( m_targetFile );
- WebservicesType targetDd = targetDdDoc.getWebservices();
- for ( int i = 0; i < m_sourceFiles.size(); i++ )
- {
- mergeWebservicesDD( (File) m_sourceFiles.get( i ), targetDd );
- }
- saveTargetDocToFile( targetDdDoc );
- }
- catch ( Exception e )
- {
- throw new BuildException( e );
- }
- }
-
- private WebservicesDocument parseWebservicesXmlFile( File ddFile )
- throws Exception
- {
- XmlOptions loadOptions = new XmlOptions().setLoadStripWhitespace();
- return WebservicesDocument.Factory.parse( ddFile, loadOptions );
- }
-
- private void saveTargetDocToFile( WebservicesDocument doc )
- throws IOException
- {
- System.out.println( "Saving updated target webservices document to " + m_targetFile + " ..." );
- XmlOptions saveOptions = new XmlOptions().setSavePrettyPrint();
- doc.save( m_targetFile, saveOptions );
- }
-
- private void mergeWebservicesDD( File srcFile, WebservicesType targetWebservices ) throws Exception
- {
- System.out.println( "Merging " + srcFile + " into target webservices document ..." );
- WebservicesDocument ddDoc = parseWebservicesXmlFile( srcFile );
- WebservicesType dd = ddDoc.getWebservices();
- mergeWebserviceDescriptionElements( dd, targetWebservices );
- }
-
- private void mergeWebserviceDescriptionElements( WebservicesType webservices, WebservicesType targetWebservices )
- {
- WebserviceDescriptionType[] wsDescArray = webservices.getWebserviceDescriptionArray();
- WebserviceDescriptionType[] targetWsDescArray = targetWebservices.getWebserviceDescriptionArray();
- for ( int i = 0; i < wsDescArray.length; i++ )
- {
- WebserviceDescriptionType wsDesc = wsDescArray[i];
- String wsDescName = wsDesc.getWebserviceDescriptionName().getStringValue();
- WebserviceDescriptionType targetWsDesc = getWebserviceDescription( targetWsDescArray, wsDescName );
- if ( targetWsDesc == null )
- {
- targetWsDesc = targetWebservices.addNewWebserviceDescription();
- }
- targetWsDesc.set( wsDesc );
- }
- }
-
- private WebserviceDescriptionType getWebserviceDescription( WebserviceDescriptionType[] wsDescArray,
- String wsDescName )
- {
- WebserviceDescriptionType wsDesc = null;
- for ( int i = 0; i < wsDescArray.length; i++ )
- {
- if ( wsDescArray[i].getWebserviceDescriptionName().getStringValue().equals( wsDescName ) )
- {
- wsDesc = wsDescArray[i];
- break;
- }
- }
- return wsDesc;
- }
-
- private void initContextClassLoader()
- {
- if ( Thread.currentThread().getContextClassLoader() == null )
- {
- Thread.currentThread().setContextClassLoader( Task.class.getClassLoader() );
- }
- }
-
-}
+/*=============================================================================*
+ * 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.j2ee;
+
+import com.sun.java.xml.ns.j2Ee.WebserviceDescriptionType;
+import com.sun.java.xml.ns.j2Ee.WebservicesDocument;
+import com.sun.java.xml.ns.j2Ee.WebservicesType;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.xmlbeans.XmlOptions;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An Ant task that merges one or more source J2EE webservices.xml's into a target webservices.xml.
+ */
+public class WebservicesDDMergeTask
+ extends Task
+{
+ private List m_sourceFiles = new ArrayList( );
+ private File m_targetFile;
+
+ /**
+ * Creates a new {@link WebservicesDDMergeTask} object.
+ */
+ public WebservicesDDMergeTask( )
+ {
+ initContextClassLoader( );
+ }
+
+ /**
+ * Adds the specified file to the list of source web.xml's.
+ *
+ * @param srcFile
+ */
+ public void setSourceFile( File srcFile )
+ {
+ m_sourceFiles.add( srcFile );
+ }
+
+ /**
+ * Sets the target web.xml (i.e. the web.xml to be merged into).
+ *
+ * @param targetFile
+ */
+ public void setTargetFile( File targetFile )
+ {
+ m_targetFile = targetFile;
+ }
+
+ /**
+ * Adds the files in the specified fileset to the list of source web.xml's.
+ *
+ * @param fileSet DOCUMENT_ME
+ */
+ public void addConfiguredSourceFiles( FileSet fileSet )
+ {
+ File baseDir = fileSet.getDir( getProject( ) );
+ DirectoryScanner dirScanner = fileSet.getDirectoryScanner( getProject( ) );
+ String[] includedFiles = dirScanner.getIncludedFiles( );
+ for ( int i = 0; i < includedFiles.length; i++ )
+ {
+ m_sourceFiles.add( new File( baseDir, includedFiles[i] ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @throws org.apache.tools.ant.BuildException
+ * DOCUMENT_ME
+ */
+ public void execute( )
+ throws BuildException
+ {
+ if ( m_sourceFiles.isEmpty( ) )
+ {
+ throw new BuildException( "No source webservices.xml files were specified!" );
+ }
+
+ try
+ {
+ System.out.println( "Loading target webservices document from " + m_targetFile + " ..." );
+ WebservicesDocument targetDdDoc = parseWebservicesXmlFile( m_targetFile );
+ WebservicesType targetDd = targetDdDoc.getWebservices( );
+ for ( int i = 0; i < m_sourceFiles.size( ); i++ )
+ {
+ mergeWebservicesDD( (File) m_sourceFiles.get( i ), targetDd );
+ }
+
+ saveTargetDocToFile( targetDdDoc );
+ }
+ catch ( Exception e )
+ {
+ throw new BuildException( e );
+ }
+ }
+
+ private WebserviceDescriptionType getWebserviceDescription( WebserviceDescriptionType[] wsDescArray,
+ String wsDescName )
+ {
+ WebserviceDescriptionType wsDesc = null;
+ for ( int i = 0; i < wsDescArray.length; i++ )
+ {
+ if ( wsDescArray[i].getWebserviceDescriptionName( ).getStringValue( ).equals( wsDescName ) )
+ {
+ wsDesc = wsDescArray[i];
+ break;
+ }
+ }
+
+ return wsDesc;
+ }
+
+ private void initContextClassLoader( )
+ {
+ if ( Thread.currentThread( ).getContextClassLoader( ) == null )
+ {
+ Thread.currentThread( ).setContextClassLoader( Task.class.getClassLoader( ) );
+ }
+ }
+
+ private void mergeWebserviceDescriptionElements( WebservicesType webservices,
+ WebservicesType targetWebservices )
+ {
+ WebserviceDescriptionType[] wsDescArray = webservices.getWebserviceDescriptionArray( );
+ WebserviceDescriptionType[] targetWsDescArray = targetWebservices.getWebserviceDescriptionArray( );
+ for ( int i = 0; i < wsDescArray.length; i++ )
+ {
+ WebserviceDescriptionType wsDesc = wsDescArray[i];
+ String wsDescName = wsDesc.getWebserviceDescriptionName( ).getStringValue( );
+ WebserviceDescriptionType targetWsDesc = getWebserviceDescription( targetWsDescArray, wsDescName );
+ if ( targetWsDesc == null )
+ {
+ targetWsDesc = targetWebservices.addNewWebserviceDescription( );
+ }
+
+ targetWsDesc.set( wsDesc );
+ }
+ }
+
+ private void mergeWebservicesDD( File srcFile,
+ WebservicesType targetWebservices )
+ throws Exception
+ {
+ System.out.println( "Merging " + srcFile + " into target webservices document ..." );
+ WebservicesDocument ddDoc = parseWebservicesXmlFile( srcFile );
+ WebservicesType dd = ddDoc.getWebservices( );
+ mergeWebserviceDescriptionElements( dd, targetWebservices );
+ }
+
+ private WebservicesDocument parseWebservicesXmlFile( File ddFile )
+ throws Exception
+ {
+ XmlOptions loadOptions = new XmlOptions( ).setLoadStripWhitespace( );
+ return WebservicesDocument.Factory.parse( ddFile, loadOptions );
+ }
+
+ private void saveTargetDocToFile( WebservicesDocument doc )
+ throws IOException
+ {
+ System.out.println( "Saving updated target webservices document to " + m_targetFile + " ..." );
+ XmlOptions saveOptions = new XmlOptions( ).setSavePrettyPrint( );
+ doc.save( m_targetFile, saveOptions );
+ }
+}
\ No newline at end of file
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/BasicBeanFactory.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/BasicBeanFactory.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/BasicBeanFactory.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/BasicBeanFactory.java Thu Oct 20 10:50:00 2005
@@ -15,14 +15,12 @@
*=============================================================================*/
package org.apache.ws.util.jndi;
-import java.util.Hashtable;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.util.Hashtable;
/**
* An extension of the Commons Naming {@link org.apache.naming.factory.BeanFactory}
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/BeanFactory.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/BeanFactory.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/BeanFactory.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/BeanFactory.java Thu Oct 20 10:50:00 2005
@@ -15,15 +15,13 @@
*=============================================================================*/
package org.apache.ws.util.jndi;
-import java.util.Hashtable;
-
+import org.apache.axis.AxisEngine;
+import org.apache.axis.MessageContext;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.security.auth.Subject;
-
-import org.apache.axis.AxisEngine;
-import org.apache.axis.MessageContext;
+import java.util.Hashtable;
/**
* Bean factory.
@@ -72,17 +70,17 @@
SecurityManager securityManager =
SecurityManager.getManager();
- try {
- msgCtx = serviceManager.createMessageContext(serviceName);
- ServiceSecurityConfig.initialize(msgCtx);
- subject = securityManager.getServiceSubject(serviceName);
- } catch (Exception e) {
- NamingException ne =
- new NamingException(i18n.getMessage("beanSecInitFailed"));
- ne.setRootCause(e);
- throw ne;
- }
- }*/
+ try {
+ msgCtx = serviceManager.createMessageContext(serviceName);
+ ServiceSecurityConfig.initialize(msgCtx);
+ subject = securityManager.getServiceSubject(serviceName);
+ } catch (Exception e) {
+ NamingException ne =
+ new NamingException(i18n.getMessage("beanSecInitFailed"));
+ ne.setRootCause(e);
+ throw ne;
+ }
+ }*/
try
{
if ( subject == null )
@@ -142,5 +140,4 @@
// ServiceManager.HelperAxisEngine.setCurrentMessageContext(oldCtx);
}
}
-
}
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/SpringJndiPopulator.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/SpringJndiPopulator.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/SpringJndiPopulator.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/SpringJndiPopulator.java Thu Oct 20 10:50:00 2005
@@ -1,113 +1,122 @@
-/*=============================================================================*
- * Copyright 2005 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.jndi;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameAlreadyBoundException;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.ws.resource.JndiConstants;
-import org.apache.ws.resource.ResourceHome;
-import org.apache.ws.util.spring.SpringBeanObjectFactory;
-import org.springframework.beans.factory.ListableBeanFactory;
-
-/**
- * Provides the ability to populate a JNDI context with the beans from a Spring listable bean factory.
- *
- * @author Ian Springer
- */
-public abstract class SpringJndiPopulator
-{
-
- private static Log LOG = LogFactory.getLog( SpringJndiPopulator.class.getName() );
-
- public static void populateJndi( ListableBeanFactory beanFactory )
- {
- Context resourceContext = getResourceContext();
- String[] beanDefNames = beanFactory.getBeanNamesForType( ResourceHome.class );
- for ( int i = 0; i < beanDefNames.length; i++ )
- {
- String beanDefName = beanDefNames[i];
- ResourceHome resourceHome = (ResourceHome)beanFactory.getBean( beanDefName );
- String portComponentName = resourceHome.getPortComponentName();
- if ( portComponentName == null )
- {
- throw new IllegalStateException( "Bean definition for resource home " + resourceHome.getClass().getName() +
- " does not initialize the 'portComponentName' property." );
- }
- LOG.info( "Binding " + resourceHome.getClass().getName() + " resource home instance to JNDI name '" +
- JndiConstants.CONTEXT_NAME_RESOURCE + "/" + portComponentName + "'..." );
- Reference ref = new Reference( resourceHome.getClass().getName(),
- new StringRefAddr( SpringBeanObjectFactory.ADDR_TYPE_SPRING_BEAN_ID, beanDefName ),
- SpringBeanObjectFactory.class.getName(), null );
- try
- {
- resourceContext.rebind( portComponentName, ref );
- }
- catch ( NamingException ne )
- {
- throw new RuntimeException( ne );
- }
- }
- }
-
- private static Context getResourceContext()
- {
- Context wsrfContext = createContext( getInitialContext(), "wsrf" );
- return createContext( wsrfContext, "resource" );
- }
-
- private static Context getInitialContext()
- {
- Context initialContext;
- try
- {
- initialContext = new InitialContext();
- }
- catch ( NamingException ne )
- {
- throw new RuntimeException( ne );
- }
- return initialContext;
- }
-
- private static Context createContext( Context targetContext, String name )
- {
- try
- {
- Context context;
- try
- {
- context = targetContext.createSubcontext( name );
- }
- catch ( NameAlreadyBoundException nabe )
- {
- context = (Context) targetContext.lookup( name );
- }
- return context;
- }
- catch ( NamingException ne )
- {
- throw new RuntimeException( ne );
- }
- }
-
-}
+/*=============================================================================*
+ * 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.jndi;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.resource.JndiConstants;
+import org.apache.ws.resource.ResourceHome;
+import org.apache.ws.util.spring.SpringBeanObjectFactory;
+import org.springframework.beans.factory.ListableBeanFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+/**
+ * Provides the ability to populate a JNDI context with the beans from a Spring listable bean factory.
+ *
+ * @author Ian Springer
+ */
+public abstract class SpringJndiPopulator
+{
+ private static Log LOG = LogFactory.getLog( SpringJndiPopulator.class.getName( ) );
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param beanFactory DOCUMENT_ME
+ */
+ public static void populateJndi( ListableBeanFactory beanFactory )
+ {
+ Context resourceContext = getResourceContext( );
+ String[] beanDefNames = beanFactory.getBeanNamesForType( ResourceHome.class );
+ for ( int i = 0; i < beanDefNames.length; i++ )
+ {
+ String beanDefName = beanDefNames[i];
+ ResourceHome resourceHome = (ResourceHome) beanFactory.getBean( beanDefName );
+ String portComponentName = resourceHome.getPortComponentName( );
+ if ( portComponentName == null )
+ {
+ throw new IllegalStateException( "Bean definition for resource home "
+ + resourceHome.getClass( ).getName( )
+ + " does not initialize the 'portComponentName' property." );
+ }
+
+ LOG.info( "Binding " + resourceHome.getClass( ).getName( ) + " resource home instance to JNDI name '"
+ + JndiConstants.CONTEXT_NAME_RESOURCE + "/" + portComponentName + "'..." );
+ Reference ref =
+ new Reference( resourceHome.getClass( ).getName( ),
+ new StringRefAddr( SpringBeanObjectFactory.ADDR_TYPE_SPRING_BEAN_ID, beanDefName ),
+ SpringBeanObjectFactory.class.getName( ), null );
+ try
+ {
+ resourceContext.rebind( portComponentName, ref );
+ }
+ catch ( NamingException ne )
+ {
+ throw new RuntimeException( ne );
+ }
+ }
+ }
+
+ private static Context getInitialContext( )
+ {
+ Context initialContext;
+ try
+ {
+ initialContext = new InitialContext( );
+ }
+ catch ( NamingException ne )
+ {
+ throw new RuntimeException( ne );
+ }
+
+ return initialContext;
+ }
+
+ private static Context getResourceContext( )
+ {
+ Context wsrfContext = createContext( getInitialContext( ),
+ "wsrf" );
+ return createContext( wsrfContext, "resource" );
+ }
+
+ private static Context createContext( Context targetContext,
+ String name )
+ {
+ try
+ {
+ Context context;
+ try
+ {
+ context = targetContext.createSubcontext( name );
+ }
+ catch ( NameAlreadyBoundException nabe )
+ {
+ context = (Context) targetContext.lookup( name );
+ }
+
+ return context;
+ }
+ catch ( NamingException ne )
+ {
+ throw new RuntimeException( ne );
+ }
+ }
+}
\ No newline at end of file