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 18:05:31 UTC

svn commit: r306789 - in /webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime: ./ Lifetime.java LifetimeEnabledResourceImpl.java

Author: wire
Date: Thu Oct  6 09:05:29 2005
New Revision: 306789

URL: http://svn.apache.org/viewcvs?rev=306789&view=rev
Log:
adding LifetimeResource components.

Added:
    webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/
    webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/Lifetime.java
    webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImpl.java

Added: webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/Lifetime.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/Lifetime.java?rev=306789&view=auto
==============================================================================
--- webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/Lifetime.java (added)
+++ webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/Lifetime.java Thu Oct  6 09:05:29 2005
@@ -0,0 +1,65 @@
+/*=============================================================================*
+ *  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.client.muse.client.impl.lifetime;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
+import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.xmlbeans.XmlDateTime;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+
+public interface Lifetime {
+
+	/** 
+	 * This method causes the immediate destruction of this stateful WS-Resource.
+	 * <b>Note:</b> this operation may not be supported by this resource.
+	 * A resource must implement Destroy for this method to work.
+	 * @return
+	 * @throws FaultException 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 * @throws FaultException
+	 * @throws URISyntaxException
+	 * @throws IOException
+	 * @throws XmlException
+	 * @throws UnexpectedServerResponseException
+	 */
+	public abstract XmlObject[] destroyResourceImmediately()
+			throws URISyntaxException, IOException, XmlException,
+			UnexpectedServerResponseException, FaultException;
+
+	public abstract XmlDateTime getCurrentTime(QName requestedProperty)
+			throws URISyntaxException, IOException, XmlException,
+			UnexpectedServerResponseException, FaultException;
+
+	public abstract XmlDateTime getTerminationTime(QName requestedProperty)
+			throws URISyntaxException, IOException, XmlException,
+			UnexpectedServerResponseException, FaultException;
+
+	public abstract XmlObject[] setTerminationTime(XmlDateTime instanceOfTime)
+			throws URISyntaxException, IOException, XmlException,
+			UnexpectedServerResponseException, FaultException;
+
+}
\ No newline at end of file

Added: webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImpl.java?rev=306789&view=auto
==============================================================================
--- webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImpl.java (added)
+++ webservices/muse/trunk/client/src/java/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImpl.java Thu Oct  6 09:05:29 2005
@@ -0,0 +1,207 @@
+/*=============================================================================*
+ *  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.client.muse.client.impl.lifetime;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Calendar;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.addressing.EndpointReference;
+import org.apache.ws.client.muse.client.impl.ManageableResourceImpl;
+import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
+import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.ws.service.testresource.TestResourcePropertyQNames;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlDateTime;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+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.SetTerminationTimeDocument.SetTerminationTime;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.impl.SetTerminationTimeResponseDocumentImpl;
+import org.xmlsoap.schemas.soap.envelope.impl.FaultImpl;
+
+public class LifetimeEnabledResourceImpl extends ManageableResourceImpl implements Lifetime {
+
+	public LifetimeEnabledResourceImpl(EndpointReference epr)
+	throws MalformedURLException {
+	super(epr);
+	}
+	
+	public LifetimeEnabledResourceImpl(URL url) throws MalformedURLException,
+		XmlException, IOException {
+	super(url);
+	}
+	
+	public LifetimeEnabledResourceImpl(String txt) throws MalformedURLException,
+		XmlException, IOException {
+	super(txt);
+	}	
+	
+	/* (non-Javadoc)
+	 * @see org.apache.ws.client.muse.client.impl.lifetime.Lifetime#destroyResourceImmediately()
+	 */	
+	public XmlObject[] destroyResourceImmediately() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
+	   //build the destroy document
+	   DestroyDocument destroyDocument = DestroyDocument.Factory.newInstance();
+	   destroyDocument.addNewDestroy();
+	   
+	   XmlObject parts = rs.sendRequest(destroyDocument,"http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceLifetime/Destroy");
+       if(parts instanceof FaultImpl)
+          	throw new FaultException(parts.toString());
+       if(!(parts instanceof DestroyResponseDocument.DestroyResponse))
+    	   throw new UnexpectedServerResponseException("Expected DestroyResponseDocument but received "+parts.getClass().getName());
+
+       //cast to response
+       DestroyResponseDocument.DestroyResponse response=(DestroyResponseDocument.DestroyResponse)parts;
+
+       //navigate the document to retrieve all the properties
+       XmlCursor cursor = null;
+       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 String getCurrentTimeAsString(QName requestedProperty) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
+		String timeOnResource = "";
+		
+		XmlDateTime time = getCurrentTime(requestedProperty);
+		timeOnResource = time.getStringValue();
+		
+		return timeOnResource;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.ws.client.muse.client.impl.lifetime.Lifetime#getCurrentTime(javax.xml.namespace.QName)
+	 */
+	public XmlDateTime getCurrentTime(QName requestedProperty) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
+		//retrieve as XMLDateTime
+		XmlDateTime time = getPropertyAsDateTime(requestedProperty);
+		return time;
+	}
+
+	public String getTerminationTimeAsString(QName requestedProperty) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
+		String timeOnResource = "";
+		XmlDateTime time = getCurrentTime(requestedProperty);
+		timeOnResource = time.getStringValue();
+		return timeOnResource;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.ws.client.muse.client.impl.lifetime.Lifetime#getTerminationTime(javax.xml.namespace.QName)
+	 */
+	public XmlDateTime getTerminationTime(QName requestedProperty) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
+		 //retrieve as XMLDateTime
+		 XmlDateTime time = getPropertyAsDateTime(requestedProperty);
+		return time;
+	}
+
+	/**This is a convenience method that allows the user to simply specify 
+	 * the number of milliseconds from whatever time exists on the server, after
+	 * which to schedule termination for this resource. 
+	 * The specification does not attempt to guarantee client-server time synchronization.
+	 * This method simply queries the CurrentTime and then adds the number of milliseconds
+	 * entered to the scheduledTerminationTime.  
+	 * When using this method or any other destroy or scheduled destruction methods consider 
+	 * transport latency times for the destruction request/response interchange.  
+	 * @return XMLObject[]
+	 * @throws FaultException 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 */
+	public XmlObject[] scheduleTerminationInNMilliSeconds(long timeFromNow, QName currentTimeProperty) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
+		XmlObject[] response = null;
+//		XmlDateTime currentServerTime = getCurrentTime(TestResourcePropertyQNames.CURRENTTIME2);
+		XmlDateTime currentServerTime = getCurrentTime(currentTimeProperty);
+	   	long current = currentServerTime.getCalendarValue().getTimeInMillis();
+	   	  //build new XmlDateTime to schedule TimeOfDeath(TOD)
+	   	  XmlDateTime tod = XmlDateTime.Factory.newInstance();
+	   	   Calendar instance = Calendar.getInstance();
+           instance.setTimeInMillis(current+timeFromNow);
+           tod.setCalendarValue(instance);
+           
+	   	  //issue the Scheduled death request
+	   	  response = setTerminationTime(tod);
+		
+		return response;
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.ws.client.muse.client.impl.lifetime.Lifetime#setTerminationTime(org.apache.xmlbeans.XmlDateTime)
+	 */
+	public XmlObject[] setTerminationTime(XmlDateTime instanceOfTime) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException {
+		   //build the SetTerminationTime document
+		   SetTerminationTimeDocument terminationScheduleDocument = SetTerminationTimeDocument.Factory.newInstance();
+		   SetTerminationTime tTime = terminationScheduleDocument.addNewSetTerminationTime();
+		   tTime.setRequestedTerminationTime(instanceOfTime.getCalendarValue());
+		   
+		   XmlObject parts = rs.sendRequest(terminationScheduleDocument,"http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceLifetime/SetTerminationTime");
+	       if(parts instanceof FaultImpl)
+	          	throw new FaultException(parts.toString());
+	       if(!(parts instanceof SetTerminationTimeResponseDocumentImpl.SetTerminationTimeResponseImpl))
+	    	   throw new UnexpectedServerResponseException("Expected SetTerminationTimeResponseDocumentImpl but received "+parts.getClass().getName());
+
+	       //cast to response
+	       SetTerminationTimeResponseDocumentImpl.SetTerminationTimeResponseImpl response=
+	    	   (SetTerminationTimeResponseDocumentImpl.SetTerminationTimeResponseImpl)parts;
+
+	       //navigate the document to retrieve all the properties
+	       XmlCursor cursor = null;
+	       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]);
+	}
+}