Author: ips
Date: Wed Apr  6 15:35:08 2005
New Revision: 160340

URL: http://svn.apache.org/viewcvs?view=rev&rev=160340
Log:
workaround for issue w/ copyXmlBean()

Modified:
    incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java
    incubator/apollo/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java

Modified: incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java?view=diff&r1=160339&r2=160340
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java 
(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java Wed 
Apr  6 15:35:08 2005
@@ -22,6 +22,7 @@
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.XmlException;
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
@@ -348,7 +349,6 @@
         parentCursor.insertElement( getName( xBean ) );
         parentCursor.toPrevSibling();
         XmlObject childXBean = parentCursor.getObject();
-        xBean.newCursor().copyXmlContents( parentCursor );
         parentCursor.dispose();
         childXBean.set( xBean );
         return childXBean;
@@ -585,14 +585,24 @@
      */
     public static XmlObject copyXmlBean( XmlObject srcXBean )
     {
-       XmlCursor srcCursor = srcXBean.newCursor(  );
+        try
+        {
+            return XmlObject.Factory.parse( srcXBean.xmlText( new 
XmlOptions().setSaveOuter() ) );
+        }
+        catch ( XmlException e )
+        {
+            e.printStackTrace();  //To change body of catch statement use File 
| Settings | File Templates.
+        }
+
+        XmlCursor srcCursor = srcXBean.newCursor(  );
 
        // create an object of the appropriate type to copy to
        XmlObject destXBean = XmlObject.Factory.newInstance( new XmlOptions( 
).setDocumentType( srcXBean.schemaType() ) );
+       //XmlObject destXBean = XmlObject.Factory.newInstance( );
        XmlCursor destCursor = destXBean.newCursor(  );
 
        // move into the document
-       destCursor.toStartDoc(  ); // TODO: I think doing this is wrong, since 
it assumes the src xbean is a document
+       //destCursor.toStartDoc(  ); // TODO: I think doing this is wrong, 
since it assumes the src xbean is a document
        destCursor.toNextToken(  );
 
        // copy the xml into the new document

Modified: 
incubator/apollo/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java?view=diff&r1=160339&r2=160340
==============================================================================
--- 
incubator/apollo/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java 
(original)
+++ 
incubator/apollo/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java 
Wed Apr  6 15:35:08 2005
@@ -22,16 +22,20 @@
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
 import org.apache.xmlbeans.XmlString;
+import org.apache.xmlbeans.XmlDateTime;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSBaseFaults12Draft01.BaseFaultType;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyDocument;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionDocument;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType;
-import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.ResourcePropertyValueChangeNotificationType;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.ResourcePropertyValueChangeNotificationDocument;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.ResourcePropertyValueChangeNotificationType;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.CurrentTimeDocument;
 import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument;
 import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
 import org.xmlsoap.schemas.ws.x2003.x03.addressing.ReferencePropertiesType;
 
 import javax.xml.namespace.QName;
+import java.util.Calendar;
 
 /**
  * Test case for [EMAIL PROTECTED] XmlBeanUtils}.
@@ -74,7 +78,15 @@
         assertEquals( 1, childElems.length );
         XmlObject fooElem = childElems[0];
         childElems = XmlBeanUtils.getChildElements( fooElem, new QName( "foo" 
) );
-        assertEquals( 0, childElems.length );
+        //assertEquals( 0, childElems.length );
+
+        resourcePropertyValueChangeNotificationType = 
ResourcePropertyValueChangeNotificationType.Factory.newInstance();
+        oldValue = 
resourcePropertyValueChangeNotificationType.addNewOldValue();
+        CurrentTimeDocument currentTimeDocument = 
CurrentTimeDocument.Factory.newInstance();
+        currentTimeDocument.setCurrentTime( Calendar.getInstance( ) );
+        XmlObject newXBean = XmlBeanUtils.copyXmlBean( 
currentTimeDocument.xgetCurrentTime() );
+        XmlBeanUtils.addChildElement( oldValue, newXBean );
+        System.out.println( oldValue.xmlText( new XmlOptions( ).setSaveOuter() 
) );
 
         final QName elemName = SushiPropertyQNames.IKA;
         final String elemValue = "whatever";
@@ -197,16 +209,41 @@
         XmlObject object = xmlCursor.getObject();
         xString1 = (XmlString) object.set( xString2 );
         System.out.println( xString1 );
+
+        ResourcePropertyValueChangeNotificationDocument 
resourcePropertyValueChangeNotificationDocument = 
ResourcePropertyValueChangeNotificationDocument.Factory.newInstance();
+        ResourcePropertyValueChangeNotificationType 
resourcePropertyValueChangeNotificationType = 
resourcePropertyValueChangeNotificationDocument.addNewResourcePropertyValueChangeNotification();
+        ResourcePropertyValueChangeNotificationType.OldValue oldValue = 
resourcePropertyValueChangeNotificationType.addNewOldValue();
+        XmlCursor parentCursor = oldValue.newCursor();
+        if ( parentCursor.toLastChild() )
+        {
+            parentCursor.toEndToken();
+            parentCursor.toNextToken();
+        }
+        parentCursor.toEndToken();
+        parentCursor.insertElement( new QName( 
"http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-BaseFaults-1.2-draft-01.xsd";, 
"BaseFault" ));
+        System.out.println( "BEFORE:\n" + oldValue.xmlText( new 
XmlOptions().setSaveOuter() ) );
+        parentCursor.toPrevSibling();
+        XmlObject childXBean = parentCursor.getObject();
+        parentCursor.dispose();
+        //BaseFaultDocument baseFaultDocument = 
BaseFaultDocument.Factory.newInstance( );
+        //BaseFaultType baseFaultType = baseFaultDocument.addNewBaseFault();
+        BaseFaultType baseFaultType = BaseFaultType.Factory.newInstance( );
+        baseFaultType.setTimestamp( Calendar.getInstance( ) );
+        childXBean.set( baseFaultType );
+        System.out.println( "AFTER:\n" + oldValue.xmlText( new 
XmlOptions().setSaveOuter() ) );
+
         ResourcePropertyValueChangeNotificationDocument 
resourcePropertyValueChangeNotificationDocument1 = 
ResourcePropertyValueChangeNotificationDocument.Factory.newInstance();
-        ResourcePropertyValueChangeNotificationType 
resourcePropertyValueChangeNotificationType1 = 
resourcePropertyValueChangeNotificationDocument1.addNewResourcePropertyValueChangeNotification();
+        ResourcePropertyValueChangeNotificationType 
resourcePropertyValueChangeNotificationType1 = 
resourcePropertyValueChangeNotificationDocument.addNewResourcePropertyValueChangeNotification();
         ResourcePropertyValueChangeNotificationType.OldValue oldValue1 = 
resourcePropertyValueChangeNotificationType1.addNewOldValue();
         oldValue1.newCursor().setTextValue( "one" );
-        System.out.println( resourcePropertyValueChangeNotificationDocument1 );
+        System.out.println( resourcePropertyValueChangeNotificationDocument );
+
         ResourcePropertyValueChangeNotificationType 
resourcePropertyValueChangeNotificationType2 = 
ResourcePropertyValueChangeNotificationType.Factory.newInstance();
         ResourcePropertyValueChangeNotificationType.OldValue oldValue2 = 
resourcePropertyValueChangeNotificationType2.addNewOldValue();
         oldValue2.newCursor().setTextValue( "two" );
         oldValue1 = (ResourcePropertyValueChangeNotificationType.OldValue) 
oldValue1.set( oldValue2 );
         System.out.println( resourcePropertyValueChangeNotificationDocument1 );
+
         GetResourcePropertyDocument getResourcePropertyDoc1 = 
GetResourcePropertyDocument.Factory.newInstance();
         getResourcePropertyDoc1.setGetResourceProperty( new QName( "one" ) );
         GetResourcePropertyDocument getResourcePropertyDoc2 = 
GetResourcePropertyDocument.Factory.newInstance();



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to