Hi Bill,

   I've implemented two more methods with their associated unit tests.
I've attached the two patch files.

-Simeon
Index: 
C:/Eclipse/eclipse_3.1/workspace/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
===================================================================
--- 
C:/Eclipse/eclipse_3.1/workspace/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
  (revision 265542)
+++ 
C:/Eclipse/eclipse_3.1/workspace/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
  (working copy)
@@ -21,9 +21,13 @@
 import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Vector;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,19 +39,38 @@
 import org.apache.ws.client.muse.client.impl.stubs.ServiceStub;
 import org.apache.ws.muws.v1_0.capability.IdentityCapability;
 import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlDocumentProperties;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.soap.Node;
+import org.apache.xmlbeans.impl.soap.SOAPElement;
+import org.apache.xmlbeans.impl.soap.SOAPElementFactory;
+import org.apache.xmlbeans.impl.soap.SOAPException;
+//import org.apache.xmlbeans.impl.soap.Text;
 import org.apache.xmlbeans.impl.values.XmlAnyUriImpl;
 import org.apache.xmlbeans.impl.values.XmlDoubleImpl;
 import org.apache.xmlbeans.impl.values.XmlIntImpl;
 import org.apache.xmlbeans.impl.values.XmlStringImpl;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetMultipleResourcePropertiesDocument;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyDocument;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesDocument;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesDocument;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesResponseDocument;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesResponseDocument;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.UpdateType;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetMultipleResourcePropertiesDocument.GetMultipleResourceProperties;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesDocument.QueryResourceProperties;
-import 
org.oasisOpen.docs.wsrf.x2004.x11.wsrfWSResourceProperties12Draft05.GetResourcePropertyDocumentDocument1;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesDocument.SetResourceProperties;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.GetMultipleResourcePropertiesDocumentImpl;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.GetMultipleResourcePropertiesResponseDocumentImpl;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.GetResourcePropertyDocumentImpl;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.QueryResourcePropertiesDocumentImpl;
+import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.QueryResourcePropertiesDocumentImpl.QueryResourcePropertiesImpl;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
 import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
 
 public class ManageableResourceImpl {
@@ -253,6 +276,201 @@
                return (QName[]) infoList.toArray(new QName[0]);
        }
 
+       /* Takes a list of QNames that constitute the requested list of 
properties to retrieve.
+        * Returns XmlObject instances as there is not guarantee that we'll 
receive anything more specific,
+        *   therefore just returning fragments.
+        */
+       public XmlObject[] getMultipleResourceProperties(QName[] 
requestedValues) throws URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException {
+
+               //Create MultipleResourceProperties document
+               GetMultipleResourcePropertiesDocument gmpDoc = 
GetMultipleResourcePropertiesDocument.Factory.newInstance();
+
+               //Build the query to be included in that document
+               GetMultipleResourceProperties query = 
gmpDoc.addNewGetMultipleResourceProperties();
+
+               //Iterate through QName[] to add each property
+               for (int i = 0; i < requestedValues.length; i++) {
+                       query.addResourceProperty(requestedValues[i]);
+               }
+               
+               //Now send the request
+       XmlObject parts = 
rs.sendRequest(gmpDoc,"http://getmultipleresourcepropertydocument","M";);
+       
+       if(!(parts instanceof 
GetMultipleResourcePropertiesResponseDocumentImpl.GetMultipleResourcePropertiesResponseImpl))
+               throw new UnexpectedServerResponseException("Expected 
GetMultipleResourcePropertiesResponseDocumentImpl but received 
"+parts.getClass().getName());
+
+       //type cast and walk the array to extract the responses
+       
GetMultipleResourcePropertiesResponseDocumentImpl.GetMultipleResourcePropertiesResponseImpl
 response = 
(GetMultipleResourcePropertiesResponseDocumentImpl.GetMultipleResourcePropertiesResponseImpl)parts;
+       
+       //Create cursor to walk through the response.
+       XmlCursor cursor = response.newCursor();
+        cursor.toChild(0);
+        cursor.toFirstChild();
+
+       XmlObject obj = cursor.getObject();
+       Vector infoList = new Vector(20);
+       
+       //extract the first XmlObject
+       XmlObject prop=cursor.getObject();
+       infoList.add(prop);
+       
+       //walk the sibling list to extract all objects
+       while(cursor.toNextSibling()){
+               prop=cursor.getObject();
+           infoList.add(prop);
+       }
+       cursor.dispose();
+       
+               return (XmlObject[]) infoList.toArray(new XmlObject[0]);
+       }
+
+//     //Spec method.
+//     public XmlObject getResourcePropertyDocument() throws 
URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException {
+////   public XmlObject[] getResourcePropertyDocument() throws 
URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException {
+//
+//             //Create GetResourcePropertyDocument document
+//             GetResourcePropertyDocument resPropDoc = 
GetResourcePropertyDocument.Factory.newInstance();
+////           GetMultipleResourcePropertiesDocument gmpDoc = 
GetMultipleResourcePropertiesDocument.Factory.newInstance();
+//
+//             //Build the query to be included in that document
+////           XmlDocumentProperties query = resPropDoc.documentProperties();
+////           XmlDocumentProperties query = resPropDoc.();
+////           GetMultipleResourceProperties query = 
gmpDoc.addNewGetMultipleResourceProperties();
+//             
+//             //Now send the request
+//             XmlObject parts = rs.sendRequest(resPropDoc,
+//                             
"http://docs.oasis-open.org/wsrf/rpw-1/GetResourcePropertyDocument/GetResourcePropertyDocumentRequest","M";);
+////           XmlObject parts = 
rs.sendRequest(resPropDoc,"http://getresourcepropertydocument","M";);
+////       XmlObject parts = 
rs.sendRequest(gmpDoc,"http://getmultipleresourcepropertydocument","M";);
+//
+//             if(!(parts instanceof GetResourcePropertyDocumentImpl))
+//                     throw new UnexpectedServerResponseException("Expected 
GetResourcePropertyDocumentImpl but received "+parts.getClass().getName());     
  
+////       if(!(parts instanceof 
GetMultipleResourcePropertiesResponseDocumentImpl.GetMultipleResourcePropertiesResponseImpl))
+////           throw new UnexpectedServerResponseException("Expected 
GetMultipleResourcePropertiesResponseDocumentImpl but received 
"+parts.getClass().getName());
+//
+//       //type cast and walk the array to extract the responses
+//             GetResourcePropertyDocumentImpl response = 
(GetResourcePropertyDocumentImpl)parts;
+////       
GetMultipleResourcePropertiesResponseDocumentImpl.GetMultipleResourcePropertiesResponseImpl
 response = 
(GetMultipleResourcePropertiesResponseDocumentImpl.GetMultipleResourcePropertiesResponseImpl)parts;
+//       
+//       //Create cursor to walk through the response.
+//       XmlCursor cursor = response.newCursor();
+//        cursor.toChild(0);
+//        cursor.toFirstChild();
+//
+////       XmlObject obj = cursor.getObject();
+////       Vector infoList = new Vector(20);
+//       
+//       //extract the first XmlObject
+//       XmlObject prop=cursor.getObject();
+////       infoList.add(prop);
+////       
+////       //walk the sibling list to extract all objects
+////       while(cursor.toNextSibling()){
+////           prop=cursor.getObject();
+////           infoList.add(prop);
+////       }
+//       cursor.dispose();
+//       
+//       return prop;
+////           return (XmlObject[]) infoList.toArray(new XmlObject[0]);
+//     }
+
+       /* Takes an XPath query and a dialect, and returns the results as an 
XMLObject[].
+        * Operation returns a subset of the ResourceProperties or an XPath 
operation on 
+        * the same. 
+        */
+       public XmlObject[] queryResourceProperties(String xpathExp, String 
xpthDialect) throws URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException {
+
+               //build the query document
+               QueryResourcePropertiesDocument queryDocument = 
QueryResourcePropertiesDocument.Factory.newInstance();
+               //add the query properties component
+               QueryResourceProperties query = 
queryDocument.addNewQueryResourceProperties();
+               //add the query expression
+               QueryExpressionType expression = query.addNewQueryExpression();
+                //set the specific dialect to use
+                
expression.setDialect("http://www.w3.org/TR/1999/REC-xpath-19991116";);
+                //Manipulate the xml 
+                XmlCursor cursor = expression.newCursor();
+                //insert the xpath component
+                cursor.setTextValue(xpathExp);
+                cursor.dispose();
+               
+       XmlObject parts = 
rs.sendRequest(queryDocument,"http://queryresourcepropertydocument","M";);
+       if(!(parts instanceof 
QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse))
+               throw new UnexpectedServerResponseException("Expected 
QueryResourcePropertiesResponseDocument but received 
"+parts.getClass().getName());
+       
+       //cast to response
+       QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse 
response=(QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse)parts;
+
+       //navigate the document to retrieve all the properties
+       cursor=response.newCursor();
+       cursor.toChild(0);
+       cursor.toFirstChild();
+       
+       //store all encountered responses
+       Vector infoList = new Vector(20);
+       XmlObject propValue=cursor.getObject();
+       infoList.add(propValue);
+       
+       //for numerous response components
+       while(cursor.toNextSibling()){
+                       propValue=cursor.getObject();
+            infoList.add(propValue);
+       }
+       cursor.dispose();
+       
+       //build the response
+       return (XmlObject[]) infoList.toArray(new XmlObject[0]);
+       }
+
+
+       public boolean updatePropertyWithDouble(QName price, double newVal) 
throws URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException {
+               boolean success = false;
+
+               //build the change document
+               SetResourcePropertiesDocument queryDocument = 
SetResourcePropertiesDocument.Factory.newInstance();
+               //add the set properties component
+               SetResourceProperties query = 
queryDocument.addNewSetResourceProperties();
+               //add the update expression
+               UpdateType modification = query.addNewUpdate();
+                //Manipulate the xml 
+                XmlCursor cursor = modification.newCursor();
+                //Now begin to add each update element
+                  //tmp string conversion?
+                  String txt = String.valueOf(newVal);
+//                System.out.println("Val:"+cursor.getName());
+//                modification.
+////              cursor.
+                  cursor.insertElementWithText(price,txt);
+                  cursor.dispose();
+                
+       XmlObject parts = 
rs.sendRequest(queryDocument,"http://updateresourcepropertydocument","M";);
+       if(!(parts instanceof SetResourcePropertiesResponseDocument))
+               throw new UnexpectedServerResponseException("Expected 
SetResourcePropertiesResponseDocument but received 
"+parts.getClass().getName());
+       
+       //cast to response
+       SetResourcePropertiesResponseDocument 
response=(SetResourcePropertiesResponseDocument)parts;
+
+       //navigate the document to retrieve all the properties
+       cursor=response.newCursor();
+       cursor.toChild(0);
+       cursor.toFirstChild();
+       
+       //store all encountered responses
+       Vector infoList = new Vector(20);
+       XmlObject propValue=cursor.getObject();
+       infoList.add(propValue);
+       
+       //for numerous response components
+       while(cursor.toNextSibling()){
+                       propValue=cursor.getObject();
+            infoList.add(propValue);
+       }
+       cursor.dispose();
+               
+               return success;
+       }
+
 //     public XmlObject[] getMetric(QName testmetric) throws FaultException, 
URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException {
 //             LOG.info("getting Metric value  "+testmetric+" from " + 
this.epr.getAddress()); 
 //             XmlObject[] parts = rs.getResourceProperty(testmetric);
Index: 
C:/Eclipse/eclipse_3.1/workspace/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
===================================================================
--- 
C:/Eclipse/eclipse_3.1/workspace/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
      (revision 265558)
+++ 
C:/Eclipse/eclipse_3.1/workspace/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
      (working copy)
@@ -99,7 +99,23 @@
                XmlObject[] 
propValue=testImpl.getProperty(TestResourcePropertyQNames.PRICE);
                assertNotNull(propValue);
                assertTrue(propValue.length==1);
+               
+       }
 
+       /**
+        * Objective: Get a property value returned as a string.  
+        * @throws UnexpectedServerResponseException 
+        * @throws XmlException 
+        * @throws IOException 
+        * @throws URISyntaxException 
+        * @throws FaultException 
+        *
+        */
+       public void testGetPropertyAsString() throws FaultException, 
URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException{
+               String 
propValue=String.valueOf(testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE));
+               assertNotNull(propValue);
+               assertTrue(propValue.length()>0);
+
        }
        
        /**
@@ -116,15 +132,36 @@
                QName[] infoArry= testImpl.getPropertyQNames();
                assertNotNull(infoArry);
                assertEquals(16,infoArry.length);
+               
        }
-       
-//     public void testGetMultipleResourceProperties(){
-//             QName[] infoArry= testImpl.getMultipleResourceProperties();
-//             assertNotNull(infoArry);
-//             assertEquals(16,infoArry.length);
-//     
-//     }
 
+       // DONE: GetMultipleresourceProperties  
+       public void testGetMultipleResourceProperties() throws 
URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException{
+               //define list of requested resouces as QName array
+               QName[] requestedResourceProperties = new QName[3];
+               //populate array.
+               requestedResourceProperties[0] = 
TestResourcePropertyQNames.NAME;   
+               requestedResourceProperties[1] = 
TestResourcePropertyQNames.PRICE;   
+               requestedResourceProperties[2] = 
TestResourcePropertyQNames.RESOURCEID;   
+               
+               XmlObject[] resourceArry= 
testImpl.getMultipleResourceProperties(requestedResourceProperties);
+               assertNotNull(resourceArry);
+               
+               //DONE: test for 3 returned resource properties.
+               assertTrue("Incorrect number of XML fragments 
returned!",(resourceArry.length==requestedResourceProperties.length));
+                       
+               //DONE: check that queried resources are actually returned
+                String name ="UnitTestResource";
+                String price = "0.99";
+                String resId ="rn:0001";
+                assertTrue("Expected resource not found.",
+                                resourceArry[0].toString().indexOf(name)>-1);
+                assertTrue("Expected resource not found.",
+                                resourceArry[1].toString().indexOf(price)>-1);
+                assertTrue("Expected resource not found.",
+                                resourceArry[2].toString().indexOf(resId)>-1);
+       }
+
        /**
         * Objective: Request a metric called test metric. Confirm readability
         * of all metric metadata.
@@ -144,11 +181,143 @@
 //             fail("Try writting an actual test.");
 //     }
        
-       // TODO Support QueryResourceProperties
+       // TODO Provide Complete support for primitive type getting
        
-       // TODO GetMultipleresourceProperties
+       // TODO Resolve the best way to support getting metrics
        
-       //Next try the tests
+       // TODO Implement Capabilities
        
-       // Next try the create and destroys.
+       // TODO Implement Commonly Supported Properties
+       
+       // DONE: Beginning support for QueryResourceProperties
+       /**
+        * Objective: Query resource properties with an XPath expression using 
+        * a specific XPath dialect. 
+        * @throws UnexpectedServerResponseException 
+        * @throws XmlException 
+        * @throws IOException 
+        * @throws URISyntaxException 
+        * @throws UnexpectedServerResponseException 
+        * @throws XmlException 
+        * @throws IOException 
+        * @throws URISyntaxException 
+        * @throws FaultException 
+        *
+        */     
+    public void testQueryResourceProperties() throws URISyntaxException, 
IOException, XmlException, UnexpectedServerResponseException{
+
+       //DONE: figure out how to specify a supported dialect.  Start with 
xpath 1.0 and xpath 2.0
+               String dialect1 = 
"http://www.w3.org/TR/1999/REC-xpath-19991116";;
+               String dialect2 = 
"http://www.w3.org/TR/2003/WD-xpath20-20031112";;
+               
+               //test a select all query
+       String xpathExpression = "*";
+       XmlObject[] resourceProps = 
testImpl.queryResourceProperties(xpathExpression,dialect1);
+       assertNotNull(resourceProps);
+       assertEquals(16,resourceProps.length);
+
+               //test a boolean query
+       xpathExpression = "boolean(/*/Price=0.99)";
+       resourceProps = 
testImpl.queryResourceProperties(xpathExpression,dialect1);
+       assertNotNull(resourceProps);
+       assertEquals(1,resourceProps.length);
+
+       //DONE: rinse and repeat with the second dialect.
+               //test a select all query
+       xpathExpression = "*";
+       resourceProps = 
testImpl.queryResourceProperties(xpathExpression,dialect2);
+       assertNotNull(resourceProps);
+       assertEquals(17,resourceProps.length);
+
+               //test a boolean query
+       xpathExpression = "boolean(/*/Price=0.99)";
+       resourceProps = 
testImpl.queryResourceProperties(xpathExpression,dialect2);
+       assertNotNull(resourceProps);
+       assertEquals(1,resourceProps.length);
+       
+    }
+
+       /**
+        * Objective: Query resource properties with an XPath expression using 
+        * a specific XPath dialect. 
+        * @throws UnexpectedServerResponseException 
+        * @throws XmlException 
+        * @throws IOException 
+        * @throws URISyntaxException 
+        * @throws UnexpectedServerResponseException 
+        * @throws XmlException 
+        * @throws IOException 
+        * @throws URISyntaxException 
+        * @throws FaultException 
+        * @throws FaultException 
+        *
+        */     
+    public void testSetResourceProperties() throws URISyntaxException, 
IOException, XmlException, UnexpectedServerResponseException, FaultException{
+               
+               //test that a simple update operation works.
+                //retrieve and existing property
+                double 
propValue=testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE);
+                double newVal = (propValue - .2); 
+                //change that property
+                
testImpl.updatePropertyWithDouble(TestResourcePropertyQNames.PRICE,newVal);
+                
+                //make sure that it's changed
+               
+               //test that insert works
+                //make call for one that doesn't exist
+                //create it
+                //verify it
+               
+               //Now delete that previously created property
+               
+               //now carry out update, delete and insert in one call.
+                //verify that those values were successfully changed.
+               
+       
+    }    
+    
+       // TODO Support for setting properties
+       
+       // TODO Calling Operations on Resources
+       
+       // TODO Next try the create and destroys.
+       
+       // TODO Notifications
+       
+    //TODO: getResourcePropertyDocument
+    /**
+     * Objective: Request a list of property qnames and make sure it is 
+     * of the expected length. 
+     * @throws UnexpectedServerResponseException 
+     * @throws XmlException 
+     * @throws IOException 
+     * @throws URISyntaxException 
+     * @throws FaultException 
+     *
+     */
+//    public void NotImplemented_testGetResourcePropertyDocument() throws 
URISyntaxException, IOException, XmlException, 
UnexpectedServerResponseException{
+//     XmlObject resPropDoc= testImpl.getResourcePropertyDocument();
+//     assertNotNull(resPropDoc);
+//     //TODO: test content returned
+////   assertEquals(1,resPropDoc.length);
+//    }
+
+    //TODO: testQueryExpressionDialect
+       /**
+        * Objective: Request a list of property qnames and make sure it is 
+        * of the expected length. 
+        * @throws UnexpectedServerResponseException 
+        * @throws XmlException 
+        * @throws IOException 
+        * @throws URISyntaxException 
+        * @throws FaultException 
+        *
+        */
+//     public void testQueryExpressionDialect() throws URISyntaxException, 
IOException, XmlException, UnexpectedServerResponseException{
+////           XmlObject resPropDoc= testImpl.queryExpressionDialect();
+////           assertNotNull(resPropDoc);
+//             //TODO: test content returned
+////           assertEquals(1,resPropDoc.length);
+//     }
+       
 }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to