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/10/06 21:16:31 UTC
svn commit: r306857 -
/webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
Author: wire
Date: Thu Oct 6 12:16:26 2005
New Revision: 306857
URL: http://svn.apache.org/viewcvs?rev=306857&view=rev
Log:
Removed almost all code here to base this class on wsrf impl
Modified:
webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
Modified: webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java?rev=306857&r1=306856&r2=306857&view=diff
==============================================================================
--- webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java (original)
+++ webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java Thu Oct 6 12:16:26 2005
@@ -16,713 +16,28 @@
*/
package org.apache.ws.client.muse.client.impl;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
-import java.net.URISyntaxException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Iterator;
-import java.util.List;
-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;
import org.apache.ws.addressing.EndpointReference;
-import org.apache.ws.addressing.XmlBeansEndpointReference;
-import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
-import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
-import org.apache.ws.client.muse.client.impl.stubs.ResourceStub;
-import org.apache.ws.client.muse.client.impl.stubs.ServiceStub;
-import org.apache.ws.client.muse.client.impl.wsrf.InsertOrUpdateRequest;
-import org.apache.ws.client.muse.client.impl.wsrf.SetPropertiesRequestImpl;
-import org.apache.ws.client.muse.client.model.PropertiesList;
-import org.apache.ws.muws.v1_0.capability.IdentityCapability;
-import org.apache.ws.service.testresource.TestResourcePropertyQNames;
-import org.apache.ws.util.XmlBeanUtils;
-import org.apache.xmlbeans.XmlCursor;
-import org.apache.xmlbeans.XmlDateTime;
-import org.apache.xmlbeans.XmlDocumentProperties;
+import org.apache.ws.client.muse.client.impl.properties.ResourcePropertiesImpl;
import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.impl.regex.ParseException;
-import org.apache.xmlbeans.impl.soap.Node;
-import org.apache.xmlbeans.impl.soap.SOAPElement;
-import org.apache.xmlbeans.impl.soap.SOAPException;
-import org.apache.xmlbeans.impl.values.XmlAnyUriImpl;
-import org.apache.xmlbeans.impl.values.XmlBooleanImpl;
-import org.apache.xmlbeans.impl.values.XmlDateTimeImpl;
-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.wsrfWSResourceLifetime12Draft01.CurrentTimeDocument;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.DestroyDocument;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.DestroyResponseDocument;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.SetTerminationTimeDocument;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.SetTerminationTimeResponseDocument;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.SetTerminationTimeDocument.SetTerminationTime;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.impl.DestroyDocumentImpl;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.impl.DestroyResponseDocumentImpl;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.impl.SetTerminationTimeResponseDocumentImpl;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.DeleteType;
-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.InsertType;
-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.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.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.SetResourcePropertiesResponseDocumentImpl;
-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.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.SetResourcePropertiesResponseDocumentImpl;
-import org.xmlsoap.schemas.soap.envelope.impl.FaultImpl;
-import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
-
-public class ManageableResourceImpl {
-
- protected EndpointReference epr;
-
- protected ResourceStub rs;
-
- protected ServiceStub ss;
-
- private static Log LOG = LogFactory.getLog(ManageableResourceImpl.class);
-
- /**
- * Creates a ManageableResource from a class that implements
- * EndpointReference.
- *
- * @param epr
- * @throws MalformedURLException
- */
- public ManageableResourceImpl(EndpointReference epr)
- throws MalformedURLException {
- super();
- this.epr = epr;
- this.rs = new ResourceStub(epr);
- this.ss = new ServiceStub(new URL(epr.getAddress()));
- }
-
- /**
- * Creates a MangeableResource from an EPR persisted to a URL.
- *
- * @param url
- * @throws MalformedURLException
- * @throws XmlException
- * @throws IOException
- */
- public ManageableResourceImpl(URL url) throws MalformedURLException,
- XmlException, IOException {
- this(getEprFromUrl(url));
- }
-
- /**
- * Creates a MangeableResource from an Sting based text.
- *
- * @param url
- * @throws MalformedURLException
- * @throws XmlException
- * @throws IOException
- */
- public ManageableResourceImpl(String txt) throws MalformedURLException,
- XmlException, IOException {
- this(getEprFromXmlText(txt));
- }
-
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getId()
- */
- public String getId() throws FaultException,
- UnexpectedServerResponseException, URISyntaxException, IOException,
- XmlException {
- LOG.info("Calling getId on " + this.epr.getAddress());
- XmlObject[] parts = rs
- .getResourceProperty(IdentityCapability.PROP_NAME_RESOURCE_ID);
- for (int i = 0; i < parts.length; i++) {
- XmlObject xmlObject = parts[i];
- if (xmlObject instanceof XmlAnyUriImpl) {
- XmlAnyUriImpl childElement = (XmlAnyUriImpl) xmlObject;
- String value = childElement.getStringValue();
-
- // Remove any namespace contained in the id.
- if (value.indexOf(':') > -1) {
- return value.split(":")[1];
- }
- return value;
- }
- }
- throw new UnexpectedServerResponseException(
- "Server returned either an unrecognizable response or no response at all");
- }
-
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsString(javax.xml.namespace.QName)
- */
- public String getPropertyAsString(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 XmlStringImpl) {
- XmlStringImpl childElement = (XmlStringImpl) xmlObject;
- String value = childElement.getStringValue();
- return value;
- }
- }
- throw new UnexpectedServerResponseException(
- "Server returned either an unrecognizable response or no String type was returned as a response.");
- }
-
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getEpr()
- */
- public EndpointReference getEpr() {
- return epr;
- }
-
- public static EndpointReference getEprFromUrl(URL url) throws XmlException,
- IOException {
- LOG.debug("Connecting to URL for EPR: " + url.toString());
- EndpointReferenceDocument eprd = (EndpointReferenceDocument) XmlObject.Factory
- .parse(url);
- return new XmlBeansEndpointReference(eprd.getEndpointReference());
- }
-
- public static EndpointReference getEprFromXmlText(String txt)
- throws XmlException, IOException {
- LOG.debug("Parsing text for EPR: " + txt);
- ByteArrayInputStream stream = new ByteArrayInputStream(txt.getBytes());
- EndpointReferenceDocument eprd = (EndpointReferenceDocument) XmlObject.Factory
- .parse(stream);
- return new XmlBeansEndpointReference(eprd.getEndpointReference());
- }
-
- /* Returns a specific property value as a double.
- *
- */
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsDouble(javax.xml.namespace.QName)
- */
- public double getPropertyAsDouble(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 XmlDoubleImpl) {
- XmlDoubleImpl childElement = (XmlDoubleImpl) xmlObject;
- double value = childElement.getDoubleValue();
- 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 an integer.
- */
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsInt(javax.xml.namespace.QName)
- */
- 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 an XmlDateTime object.
- */
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsBoolean(javax.xml.namespace.QName)
- */
- public XmlDateTime getPropertyAsDateTime(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 XmlDateTimeImpl) {
- XmlDateTimeImpl childElement = (XmlDateTimeImpl) xmlObject;
- return childElement;
- }
- }
- throw new UnexpectedServerResponseException(
- "Server returned either an unrecognizable response or no boolean type was returned as a response.");
- }
-
- /*
- * Returns a specific property value as a bolean.
- */
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsBoolean(javax.xml.namespace.QName)
- */
- public boolean getPropertyAsBoolean(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 XmlBooleanImpl) {
- XmlBooleanImpl childElement = (XmlBooleanImpl) xmlObject;
- boolean value = childElement.getBooleanValue();
- return value;
- }
- }
- throw new UnexpectedServerResponseException(
- "Server returned either an unrecognizable response or no boolean type was returned as a response.");
- }
+public class ManageableResourceImpl extends ResourcePropertiesImpl {
- /* Returns a specific property value as a untyped property as XMLObject[]. For clients
- * preferring to parse pure XML.
- *
- */
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getProperty(javax.xml.namespace.QName)
- */
- public XmlObject[] getProperty(QName propertyName) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
- LOG.info("getting property value "+propertyName+" from " + this.epr.getAddress());
- XmlObject[] parts = rs.getResourceProperty(propertyName);
- return parts;
+ public ManageableResourceImpl(String txt) throws MalformedURLException, XmlException, IOException {
+ super(txt);
}
- /* (non-Javadoc)
- * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyQNames()
- */
- public QName[] getPropertyQNames() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
- 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(queryDocument,"http://queryresourcepropertydocument");
-
- 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();
- 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 ManageableResourceImpl(EndpointReference epr) throws MalformedURLException {
+ super(epr);
}
- /* 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, FaultException {
-
- //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");
-
- 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]);
+ public ManageableResourceImpl(URL url) throws MalformedURLException, XmlException, IOException {
+ super(url);
}
-// //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, FaultException {
-
- //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");
- expression.setDialect(xpthDialect.trim());
- //Manipulate the xml
- XmlCursor cursor = expression.newCursor();
- //insert the xpath component
- cursor.setTextValue(xpathExp);
- cursor.dispose();
-
- XmlObject parts = rs.sendRequest(queryDocument,"http://queryresourcepropertydocument");
- if(parts instanceof FaultImpl)
- throw new FaultException(parts.toString());
- 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]);
- }
-
- private boolean updateProperty(QName property, String[] updates) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
- boolean success;
- //update that property
- SetPropertiesRequestImpl setRequest = new SetPropertiesRequestImpl();
- boolean completed =setRequest.addUpdateRequest(property,updates);
- setProperties(setRequest);
- success = true;
- return success;
- }
-
- public void updateProperty(QName property, XmlObject update) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
- String xmlText;
- XmlOptions opts = new XmlOptions();
- opts.setSaveOuter();
- opts.setSavePrettyPrint();
- xmlText=update.xmlText(opts);
- updateProperty(property,xmlText);
- }
-
- public void updateProperty(QName property, double newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] updates = {String.valueOf(newValue)};
- updateProperty(property, updates);
- }
- public void updateProperty(QName property, int newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] updates = {String.valueOf(newValue)};
- updateProperty(property, updates);
- }
- public void updateProperty(QName property, float newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] updates = {String.valueOf(newValue)};
- updateProperty(property, updates);
- }
- public void updateProperty(QName property, String newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] updates = {newValue};
- updateProperty(property, updates);
- }
- public void updateProperty(QName property, boolean newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] updates = {String.valueOf(newValue)};
- updateProperty(property, updates);
- }
-
- private void insertProperty(QName property, String[] updates) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
- boolean success;
- //insert that property
- SetPropertiesRequestImpl setRequest = new SetPropertiesRequestImpl();
- boolean completed =setRequest.addInsertRequest(property,updates);
- setProperties(setRequest);
- success = true;
- }
-
- public void insertProperty(QName property, double newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] inserts = {String.valueOf(newValue)};
- insertProperty(property, inserts);
- }
- public void insertProperty(QName property, int newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] inserts = {String.valueOf(newValue)};
- insertProperty(property, inserts);
- }
- public void insertProperty(QName property, float newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] inserts = {String.valueOf(newValue)};
- insertProperty(property, inserts);
- }
- public void insertProperty(QName property, String newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] inserts = {newValue};
- insertProperty(property, inserts);
- }
- public void insertProperty(QName property, boolean newValue) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- String[] inserts = {String.valueOf(newValue)};
- insertProperty(property, inserts);
- }
-
- public void deleteProperty(QName propertyToDelete) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
- boolean success = false;
- //delete that property
- SetPropertiesRequestImpl setRequest = new SetPropertiesRequestImpl();
- boolean completed =setRequest.addDeleteRequest(propertyToDelete);
- setProperties(setRequest);
- }
-
- /* updateProperties takes a SetPropertiesRequest instance which defines
- * Insert, Update and Delete requests and the order in which they were made.
- */
- public XmlObject setProperties(PropertiesList modificationList) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
-
- //build the SetResourceProperties document
- SetResourcePropertiesDocument setPropsDocument =
- SetResourcePropertiesDocument.Factory.newInstance();
- //add the set properties component
- SetResourceProperties request = setPropsDocument.addNewSetResourceProperties();
- XmlCursor cursor = null;
-
- //iterate through the SetPropertiesRequest to populate the SetResourcePropertiesDocument
- for (int i = 0; i < modificationList.getAllResourcesIndex(); i++) {
-
- //Retrieve the current object
- Object resMod = modificationList.getAllSetResourceRequests().get(i);
-
- if (resMod instanceof QName) { //Then this is a delete request
- QName deleteParameter = (QName) resMod;
- //Then create the xml for the delete
- DeleteType delete =request.addNewDelete();
- delete.setResourceProperty(deleteParameter);
- }
- else{//then is an insert or update request
- InsertOrUpdateRequest custRequest = (InsertOrUpdateRequest)resMod;
- if(custRequest.isInsert()){//then generate xml for insert
- //is an insert request. Building appropriate xml
- //add the insert expression
- InsertType modification = request.addNewInsert();
- //Manipulate the xml
- cursor = modification.newCursor();
-
- //add all update parameters to the current node
- addItemsToNode(custRequest.getProperty(),cursor,custRequest.getPropetyValues());
- }
- else{//is an update request. Building appropriate xml
- //add the update expression
- UpdateType modification = request.addNewUpdate();
- //Manipulate the xml
- cursor = modification.newCursor();
-
- //add all update parameters to the current node
- addItemsToNode(custRequest.getProperty(),cursor,custRequest.getPropetyValues());
- }
- }
- }
-
- validateXmlBean(setPropsDocument);
-
- XmlObject parts = rs.sendRequest(setPropsDocument,"http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceProperties/SetResourceProperties");
- if(parts instanceof FaultImpl)
- throw new FaultException(parts.toString());
- if(!(parts instanceof SetResourcePropertiesResponseDocumentImpl.SetResourcePropertiesResponseImpl))
- throw new UnexpectedServerResponseException("Expected SetResourcePropertiesResponseDocumentImpl but received "+parts.getClass().getName());
-
- //cast to response
- SetResourcePropertiesResponseDocumentImpl.SetResourcePropertiesResponseImpl response
- =(SetResourcePropertiesResponseDocumentImpl.SetResourcePropertiesResponseImpl)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 propValue;
- }
-
- /* AddItemsToNode: this method takes: XmlCursor, QName[] and String[].
- * adds an element for each corresponding QName and String value for each property.
- */
- private void addItemsToNode(QName propQname, XmlCursor cursor, String[] propList) throws IllegalArgumentException {
- //store away reference to original cursor location
- XmlCursor origCursorLocation = cursor.newCursor();
-
- //For each property value encountered, create sub nodes
- for (int i = 0; i < propList.length; i++) {
- XmlCursor listCursorPosition = origCursorLocation.newCursor();
- cursor = origCursorLocation.newCursor();
- //Create a new node
- cursor.insertElementWithText(propQname,propList[i]);
- cursor.toParent();
-
- cursor.toChild(propQname);
- //move the cursor positioning
- listCursorPosition.toNextToken();
- //stitch the node into new location
- cursor.copyXml(listCursorPosition);
- //remove the original node
- cursor.removeXml();
- //clean up
- cursor.dispose();
- listCursorPosition.dispose();
- }
- }
-
-// 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);
-// if(parts==null||parts.length==0){
-// throw new UnexpectedServerResponseException(
-// "Server returned no metric values in response.");
-// }
-//
-// XmlObject part = parts[0];
-// part.changeType();
-//
-// return parts;
-// }
-
- public static void validateXmlBean(XmlObject requestXBean) throws ParseException{
- XmlOptions validateOptions = new XmlOptions( );
- List errorList = new ArrayList( );
- validateOptions.setErrorListener( errorList );
- boolean isValid = requestXBean.validate( validateOptions );
- if ( !isValid )
- {
- QName bodyElemName = XmlBeanUtils.getName( requestXBean );
- StringBuffer strBuf = new StringBuffer( "Request body element " );
- strBuf.append( bodyElemName);
- strBuf.append( " is not valid as per its schema: \n\n" );
- for ( int i = 0; i < errorList.size( ); i++ )
- {
- strBuf.append( "\t\t" );
- strBuf.append( i + 1 );
- strBuf.append( ") " );
- strBuf.append( errorList.get( i ) );
- strBuf.append( "\n" );
- }
-
- strBuf.append( "\n" );
- throw new ParseException(
- strBuf.toString( ),0 );
- }
-
- }
-
- //helper method to create SetPropertiesRequest instance
- public PropertiesList createNewSetPropertiesRequest(){
- return new SetPropertiesRequestImpl();
- }
}