You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by wi...@apache.org on 2005/08/31 20:22:28 UTC
svn commit: r265542 - in /webservices/muse/trunk/src/examples/client/src:
java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
Author: wire
Date: Wed Aug 31 11:22:23 2005
New Revision: 265542
URL: http://svn.apache.org/viewcvs?rev=265542&view=rev
Log: (empty)
Modified:
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
Modified: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java?rev=265542&r1=265541&r2=265542&view=diff
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java (original)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java Wed Aug 31 11:22:23 2005
@@ -21,6 +21,7 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.Vector;
import javax.xml.namespace.QName;
@@ -33,13 +34,19 @@
import org.apache.ws.client.muse.client.impl.stubs.ResourceStub;
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.XmlException;
import org.apache.xmlbeans.XmlObject;
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.QueryExpressionType;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesResponseDocument;
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.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
@@ -181,6 +188,24 @@
"Server returned either an unrecognizable response or no String type was returned as a response.");
}
+ /*
+ * Returns a specific property value as an integer.
+ */
+ public int getPropertyAsInt(QName propertyName) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
+ LOG.info("getting property value "+propertyName+" from " + this.epr.getAddress());
+ XmlObject[] parts = rs.getResourceProperty(propertyName);
+ for (int i = 0; i < parts.length; i++) {
+ XmlObject xmlObject = parts[i];
+ if (xmlObject instanceof XmlIntImpl) {
+ XmlIntImpl childElement = (XmlIntImpl) xmlObject;
+ int value = childElement.getIntValue();
+ return value;
+ }
+ }
+ throw new UnexpectedServerResponseException(
+ "Server returned either an unrecognizable response or no String type was returned as a response.");
+ }
+
/* Returns a specific property value as a untyped property as XMLObject[]. For clients
* preferring to parse pure XML.
*
@@ -190,14 +215,42 @@
XmlObject[] parts = rs.getResourceProperty(propertyName);
return parts;
}
-
- public PropertyInfoImpl[] getPropertyInfo() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
- GetMultipleResourcePropertiesDocument grpDocument = GetMultipleResourcePropertiesDocument.Factory.newInstance();
- GetMultipleResourceProperties multi = grpDocument.addNewGetMultipleResourceProperties();
-
+ /**
+ * Returns a list of QNames of valid wsrf properties for this resource.
+ * <b>Note:</b> this operation may not be supported by this resource.
+ * A resource must implement QueryResourceProperties for this method to work.
+ * @return
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws XmlException
+ * @throws UnexpectedServerResponseException
+ */
+ public QName[] getPropertyQNames() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
+ QueryResourcePropertiesDocument queryDocument = QueryResourcePropertiesDocument.Factory.newInstance();
+ QueryResourceProperties query = queryDocument.addNewQueryResourceProperties();
+ QueryExpressionType expression = query.addNewQueryExpression();
+ expression.setDialect("http://www.w3.org/TR/1999/REC-xpath-19991116");
+ XmlCursor cursor = expression.newCursor();
+ cursor.setTextValue("/");
+ cursor.dispose();
- XmlObject parts = rs.sendRequest(grpDocument,"http://getresourcepropertydocument","M");
- return null;
+ XmlObject parts = rs.sendRequest(queryDocument,"http://queryresourcepropertydocument","M");
+ if(!(parts instanceof QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse))
+ throw new UnexpectedServerResponseException("Expected QueryResourcePropertiesResponseDocument but received "+parts.getClass().getName());
+ QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse response=(QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse)parts;
+ cursor=response.newCursor();
+ cursor.toChild(0);
+ cursor.toFirstChild();
+ XmlAnyUriImpl obj = (XmlAnyUriImpl)cursor.getObject();
+ Vector infoList = new Vector(20);
+ QName propName=cursor.getName();
+ infoList.add(propName);
+ while(cursor.toNextSibling()){
+ propName=cursor.getName();
+ infoList.add(propName);
+ }
+ cursor.dispose();
+ return (QName[]) infoList.toArray(new QName[0]);
}
// public XmlObject[] getMetric(QName testmetric) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
Modified: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java?rev=265542&r1=265541&r2=265542&view=diff
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java (original)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java Wed Aug 31 11:22:23 2005
@@ -5,6 +5,8 @@
import java.net.URISyntaxException;
import java.net.URL;
+import javax.xml.namespace.QName;
+
import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
import org.apache.ws.client.muse.client.impl.stubs.FaultException;
import org.apache.ws.service.testresource.TestResourcePropertyQNames;
@@ -100,8 +102,20 @@
}
- public void testGetAllPropertyInfo() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
- PropertyInfoImpl[] infoArry= testImpl.getPropertyInfo();
+ /**
+ * 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 testGetPropertyNames() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+ QName[] infoArry= testImpl.getPropertyQNames();
+ assertNotNull(infoArry);
+ assertEquals(17,infoArry.length);
}
/**
@@ -115,7 +129,7 @@
*
*/
// public void testMetricValue() throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
-// XmlObject[] propValue=testImpl.getMetric(TestResourcePropertyQNames.TESTMETRIC);
+// XmlObject[] propValue=testImpl.getMetricInfo(TestResourcePropertyQNames.TESTMETRIC);
// System.out.println();
// }