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 da...@apache.org on 2006/06/16 00:17:07 UTC
svn commit: r414694 [4/7] - in /webservices/muse/trunk/modules/muse-wsrf: ./
src-api/ src-api/org/ src-api/org/apache/ src-api/org/apache/muse/
src-api/org/apache/muse/ws/ src-api/org/apache/muse/ws/resource/
src-api/org/apache/muse/ws/resource/basefau...
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/impl/SimpleWsResource.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/impl/SimpleWsResource.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/impl/SimpleWsResource.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/impl/SimpleWsResource.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,148 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.SimpleResource;
+import org.apache.muse.ws.resource.WsResource;
+import org.apache.muse.ws.resource.metadata.OpenMetadataDescriptor;
+import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
+import org.apache.muse.ws.resource.properties.ResourcePropertyCollection;
+import org.apache.muse.ws.resource.properties.impl.SimpleResourcePropertyCollection;
+import org.apache.muse.ws.resource.properties.impl.WsrpUtils;
+import org.apache.muse.ws.resource.properties.schema.OpenPropertiesSchema;
+import org.apache.muse.ws.resource.properties.schema.ResourcePropertiesSchema;
+import org.apache.muse.ws.resource.properties.schema.impl.SimpleResourcePropertiesSchema;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.wsdl.WsdlUtils;
+
+/**
+ *
+ * SimpleResource is Muse's default implementation of a WS-RF-compliant
+ * resource ({@linkplain WsResource WsResource}). It creates a WSRP
+ * state model using Muse's default
+ * {@linkplain SimpleResourcePropertyCollection WSRP implementation};
+ * the WSRP implementation class can be modified by overriding the
+ * createPropertyCollection() method in this class.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleWsResource extends SimpleResource implements WsResource
+{
+ private ResourcePropertyCollection _properties = null;
+
+ /**
+ *
+ * This method returns the concrete WSRP state model - this is not
+ * the implementation of the WSRP capabilities (which map SOAP
+ * requests to WSRP operations), but it does implement the actual
+ * WSRP operations and does the delegation of read/write requests
+ * to the capabilities defining the properties. It is available no
+ * matter how many of the WSRP capabilites are exposed to remote
+ * clients.
+ * <br><br>
+ * You can replace the default implementation by overriding
+ * this method to instantiate a different concrete class. You would
+ * then specify the name of your new SimpleWsResource sub-class in
+ * muse.xml's <java-resource-class> tag.
+ *
+ * @return An instance of SimpleResourcePropertyCollection.
+ *
+ */
+ protected ResourcePropertyCollection createPropertyCollection()
+ {
+ return new SimpleResourcePropertyCollection();
+ }
+
+ public final ResourcePropertyCollection getPropertyCollection()
+ {
+ return _properties;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ * <br><br>
+ * The SimpleWsResource implementation takes the following steps:
+ * <ol>
+ * <li>Create WSRP state model - createPropertyCollection()</li>
+ * <br>
+ * <li>Create WSRP document schema and apply it to the collection.</li>
+ * <br>
+ * <li>Create WSRP metadata and apply it to the collection.</li>
+ * <br>
+ * <li>Call super.initialize() to initialize capabilities. The
+ * WSRP collection is now available to the capabilities during
+ * their startup cycle.</li>
+ * <br>
+ * <li>Apply metadata by creating components needed to enforce it.</li>
+ * <br>
+ * <li>Validate WSRP document according to schema and metadata.</li>
+ * <br>
+ * </ol>
+ *
+ */
+ public void initialize()
+ throws SoapFault
+ {
+ _properties = createPropertyCollection();
+
+ ResourcePropertiesSchema schema = createPropertiesSchema();
+ _properties.setSchema(schema);
+
+ MetadataDescriptor metadata = createMetadataDescriptor();
+ _properties.setMetadata(metadata);
+
+ super.initialize();
+
+ _properties.applyMetadata();
+
+ _properties.validateSchema();
+ _properties.validateMetadata();
+ }
+
+ protected ResourcePropertiesSchema createPropertiesSchema()
+ {
+ //
+ // get the WSDL, which has the WS-RP definition/schema
+ //
+ String path = getWsdlPath();
+ QName portType = getWsdlPortType();
+ Document wsdl = WsdlUtils.createWSDL(getEnvironment(), path, true);
+ Element wsrpDoc = WsrpUtils.getPropertiesDefinition(wsdl, portType);
+
+ if (wsrpDoc == null) // FIXME: log message at WARNING level
+ return OpenPropertiesSchema.getInstance();
+
+ return new SimpleResourcePropertiesSchema(wsrpDoc);
+ }
+
+ protected MetadataDescriptor createMetadataDescriptor()
+ {
+ //
+ // FIXME: re-finish when WS-RMD spec is a) stable, and b) in
+ // public review (July-ish)
+ //
+ return OpenMetadataDescriptor.getInstance();
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/Messages.properties
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/Messages.properties?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/Messages.properties (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/Messages.properties Thu Jun 15 15:16:59 2006
@@ -0,0 +1,4 @@
+NullRequestElement = The DOM Element with the request's SOAP body is null.
+NullResponseElement = The DOM Element with the response's SOAP body is null.
+NullDocument = The DOM Document needed to create the XML fragment is null.
+InvalidTimeValue = Could not set the wsrl:TerminationTime because the time value - XXX - was invalid. The original error was: XXX
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTime.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTime.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTime.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTime.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,130 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.lifetime.impl;
+
+import java.text.ParseException;
+import java.util.Date;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.util.xml.XmlSerializable;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.util.xml.XsdUtils;
+import org.apache.muse.ws.resource.lifetime.WsrlConstants;
+import org.apache.muse.ws.resource.lifetime.faults.UnableToSetTerminationTimeFault;
+
+/**
+ *
+ * SetTerminationTime is a serializer/deserializer for the WS-ImmediateTermination
+ * SetTerminationTime operation's request content.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SetTerminationTime implements XmlSerializable
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private Messages _MESSAGES = MessagesFactory.get(SetTerminationTime.class);
+
+ //
+ // The new wsrl:TerminationTime (could be null)
+ //
+ private Date _time = null;
+
+ public SetTerminationTime(Date time)
+ {
+ _time = time;
+ }
+
+ public SetTerminationTime(Element request)
+ throws UnableToSetTerminationTimeFault
+ {
+ if (request == null)
+ throw new NullPointerException(_MESSAGES.get("NullRequestElement"));
+
+ boolean isDuration = true;
+ String timeString = XmlUtils.getElementText(request, WsrlConstants.REQUESTED_DURATION_QNAME);
+
+ //
+ // no duration, try dateTime
+ //
+ if (timeString == null)
+ {
+ isDuration = false;
+ timeString = XmlUtils.getElementText(request, WsrlConstants.REQUESTED_TIME_QNAME);
+ }
+
+ //
+ // the time could be null - this means there is no
+ // scheduled termination any more
+ //
+ if (timeString != null)
+ {
+ try
+ {
+ if (isDuration)
+ {
+ Date rightNow = new Date();
+ long duration = XsdUtils.getDuration(timeString);
+ long theFuture = rightNow.getTime() + duration;
+ _time = new Date(theFuture);
+ }
+
+ else
+ _time = XsdUtils.getLocalTime(timeString);
+ }
+
+ catch (ParseException error)
+ {
+ Object[] filler = { timeString, error.getMessage() };
+ throw new UnableToSetTerminationTimeFault(_MESSAGES.get("InvalidTimeValue", filler));
+ }
+ }
+ }
+
+ public Date getTerminationTime()
+ {
+ return _time;
+ }
+
+ public String toString()
+ {
+ return XmlUtils.toString(toXML(), false);
+ }
+
+ public Element toXML()
+ {
+ return toXML(XmlUtils.EMPTY_DOC);
+ }
+
+ public Element toXML(Document doc)
+ {
+ if (doc == null)
+ throw new NullPointerException(_MESSAGES.get("NullDocument"));
+
+ Element root = XmlUtils.createElement(doc, WsrlConstants.SET_TERMINATION_QNAME);
+ XmlUtils.setElement(root, WsrlConstants.REQUESTED_TIME_QNAME, getTerminationTime());
+
+ return root;
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTimeHandler.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTimeHandler.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTimeHandler.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTimeHandler.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,58 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.lifetime.impl;
+
+import java.util.Date;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.routing.AbstractMessageHandler;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.resource.lifetime.WsrlConstants;
+
+/**
+ *
+ * SetTerminationTimeHandler is the parser for the WS-ImmediateTermination
+ * SetTerminationTime operation.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ * @see org.apache.muse.ws.resource.lifetime.ImmediateTermination
+ *
+ */
+
+public class SetTerminationTimeHandler extends AbstractMessageHandler
+{
+ public SetTerminationTimeHandler()
+ {
+ super(WsrlConstants.SET_TERMINATION_QNAME);
+ }
+
+ public Object[] fromXML(Element xml)
+ throws SoapFault
+ {
+ SetTerminationTime request = new SetTerminationTime(xml);
+ return new Object[]{ request.getTerminationTime() };
+ }
+
+ public Element toXML(Object result)
+ {
+ SetTerminationTimeResponse response =
+ new SetTerminationTimeResponse((Date)result);
+ return response.toXML();
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTimeResponse.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTimeResponse.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTimeResponse.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SetTerminationTimeResponse.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,124 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.lifetime.impl;
+
+import java.text.ParseException;
+import java.util.Date;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.lifetime.WsrlConstants;
+import org.apache.muse.util.xml.XmlSerializable;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.util.xml.XsdUtils;
+
+/**
+ *
+ * SetTerminationTimeResponse is a serializer/deserializer for the
+ * WS-ImmediateTermination SetTerminationTime operation's response content.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SetTerminationTimeResponse implements XmlSerializable
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private Messages _MESSAGES =
+ MessagesFactory.get(SetTerminationTimeResponse.class);
+
+ //
+ // The wsrl:CurrentTime
+ //
+ private Date _currentTime = null;
+
+ //
+ // The resource's new wsrl:TerminationTime (could be null)
+ //
+ private Date _terminationTime = null;
+
+ public SetTerminationTimeResponse(Date termination)
+ {
+ _currentTime = new Date();
+ _terminationTime = termination;
+ }
+
+ public SetTerminationTimeResponse(Element xml)
+ throws ParseException
+ {
+ if (xml == null)
+ throw new NullPointerException(_MESSAGES.get("NullResponseElement"));
+
+ //
+ // current time on the RESOURCE (DON'T use 'new Date()')
+ //
+ QName qname = WsrlConstants.CURRENT_TIME_QNAME;
+ String timeString = XmlUtils.getElementText(xml, qname);
+ _currentTime = XsdUtils.getLocalTime(timeString);
+
+ //
+ // termination time that was just set
+ //
+ qname = WsrlConstants.NEW_TIME_QNAME;
+ timeString = XmlUtils.getElementText(xml, qname);
+
+ //
+ // if the termination was cancelled, there won't be a value
+ //
+ if (timeString != null)
+ _terminationTime = XsdUtils.getLocalTime(timeString);
+ }
+
+ public Date getCurrentTime()
+ {
+ return _currentTime;
+ }
+
+ public Date getTerminationTime()
+ {
+ return _terminationTime;
+ }
+
+ public String toString()
+ {
+ return XmlUtils.toString(toXML(), false);
+ }
+
+ public Element toXML()
+ {
+ return toXML(XmlUtils.EMPTY_DOC);
+ }
+
+ public Element toXML(Document doc)
+ {
+ if (doc == null)
+ throw new NullPointerException(_MESSAGES.get("NullDocument"));
+
+ Element root = XmlUtils.createElement(doc, WsrlConstants.SET_TERMINATION_RESPONSE_QNAME);
+ XmlUtils.setElement(root, WsrlConstants.NEW_TIME_QNAME, getTerminationTime());
+ XmlUtils.setElement(root, WsrlConstants.CURRENT_TIME_QNAME, getCurrentTime());
+
+ return root;
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SimpleImmediateTermination.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SimpleImmediateTermination.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SimpleImmediateTermination.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SimpleImmediateTermination.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,41 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.lifetime.impl;
+
+import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
+import org.apache.muse.ws.resource.lifetime.ImmediateTermination;
+import org.apache.muse.ws.resource.lifetime.faults.ResourceNotDestroyedFault;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+
+
+public class SimpleImmediateTermination
+ extends AbstractWsResourceCapability implements ImmediateTermination
+{
+ public synchronized void destroy()
+ throws ResourceNotDestroyedFault
+ {
+ try
+ {
+ getResource().shutdown();
+ }
+
+ catch (SoapFault fault)
+ {
+ throw new ResourceNotDestroyedFault(fault);
+ }
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SimpleScheduledTermination.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SimpleScheduledTermination.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SimpleScheduledTermination.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/lifetime/impl/SimpleScheduledTermination.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,166 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.lifetime.impl;
+
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.TimerTask;
+
+import javax.xml.namespace.QName;
+
+import org.apache.muse.core.routing.MessageHandler;
+import org.apache.muse.util.LoggingUtils;
+import org.apache.muse.util.ReflectUtils;
+import org.apache.muse.util.Timer;
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.WsResource;
+import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
+import org.apache.muse.ws.resource.lifetime.ImmediateTermination;
+import org.apache.muse.ws.resource.lifetime.ScheduledTermination;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+
+/**
+ *
+ * SimpleScheduledTermination is Muse's default implementation of WS-RL for
+ * WS-RF and manageable resources. It uses Java's built in timing mechanism
+ * to manage scheduled terminations. This class does not provide any actual
+ * resource shutdown operations - it only removes the resource's visibility
+ * to internal and external clients. Resource classes that leverage this
+ * implementation should call this class' destroy() before doing their own
+ * shutdown tasks.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleScheduledTermination
+ extends AbstractWsResourceCapability implements ScheduledTermination
+{
+ //
+ // Used to lookup all exception messages
+ //
+ protected static Messages _MESSAGES =
+ MessagesFactory.get(SimpleScheduledTermination.class);
+
+ private Timer _terminationTimer = null;
+
+ protected MessageHandler createSetTerminationTimeHandler()
+ {
+ MessageHandler handler = new SetTerminationTimeHandler();
+
+ Method method = ReflectUtils.getFirstMethod(getClass(), "setTerminationTime");
+ handler.setMethod(method);
+
+ return handler;
+ }
+
+ public QName[] getPropertyNames()
+ {
+ return PROPERTIES;
+ }
+
+ public void initialize()
+ throws SoapFault
+ {
+ super.initialize();
+
+ //
+ // create the timer that can be used for acting on the
+ // termination time, but don't start it
+ //
+ TimerTask scheduledDestruction = new DestroyTimerTask(getWsResource());
+ _terminationTimer = new Timer(scheduledDestruction);
+
+ setMessageHandler(createSetTerminationTimeHandler());
+ }
+
+ public Date getCurrentTime()
+ {
+ return new Date();
+ }
+
+ public Date getTerminationTime()
+ {
+ return _terminationTimer.getScheduledTime();
+ }
+
+ public Date setTerminationTime(Date time)
+ {
+ if (time == null)
+ _terminationTimer.cancel();
+
+ else if (_terminationTimer.getScheduledTime() == null)
+ _terminationTimer.schedule(time);
+
+ else
+ _terminationTimer.reschedule(time);
+
+ return time;
+ }
+
+ public void shutdown()
+ throws SoapFault
+ {
+ _terminationTimer.cancel();
+ super.shutdown();
+ }
+
+ /**
+ *
+ * DestroyTimerTask is a simple {@linkplain TimerTask TimerTask} that invokes
+ * a resource's WS-RL Destroy operation. It does not perform any the actual
+ * destruction or cleanup tasks.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ * @see ImmediateTermination#destroy
+ *
+ */
+ class DestroyTimerTask extends TimerTask
+ {
+ private WsResource _resource = null;
+
+ public DestroyTimerTask(WsResource resource)
+ {
+ _resource = resource;
+ }
+
+ /**
+ *
+ * Invokes the resource's WS-RL Destroy operation.
+ *
+ */
+ public void run()
+ {
+ try
+ {
+ _resource.shutdown();
+ }
+
+ catch (SoapFault fault)
+ {
+ //
+ // If the resource destructor fails, there's not much
+ // we can do - there is no caller to report back to,
+ // so we just log the info
+ //
+ LoggingUtils.logError(_resource.getLog(), fault);
+ }
+ }
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ExternalChangeApprover.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ExternalChangeApprover.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ExternalChangeApprover.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ExternalChangeApprover.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,111 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.metadata.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.properties.listeners.AbstractChangeApprover;
+import org.apache.muse.ws.resource.properties.listeners.PropertyChangeApprover;
+import org.apache.muse.ws.resource.properties.set.faults.UnableToModifyResourcePropertyFault;
+
+/**
+ *
+ * ExternalChangeApprover is a
+ * {@linkplain PropertyChangeApprover PropertyChangeApprover} that throws an
+ * exception if an external client tries to change a read-only property. This
+ * approver can enforce behavior such as read-only, mutable properties
+ * (properties that a user cannot change but which change on their own or
+ * through side effects); it also allows programmers to prevent the
+ * modification of properties through the generic WS-RP SetResourceProperties.
+ * <br><br>
+ * In this class, the concept of "read-only" is meant to imply external
+ * privileges - it may be the case that internal components can modify the
+ * property in order to reflect its actual value. An example of such a
+ * scenario would be free disk space - a user cannot just change the amount
+ * of free disk space directly, but it will change on its own as a result of
+ * operations on the file system.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class ExternalChangeApprover extends AbstractChangeApprover
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES =
+ MessagesFactory.get(ExternalChangeApprover.class);
+
+ //
+ // True if the property is read-only for EXTERNAL clients
+ //
+ private boolean _isReadOnly;
+
+ /**
+ *
+ * Creates a new approver for the property with the given name. The
+ * approver will throw an exception if the second parameter is "true"
+ * and the change request comes from an external client.
+ *
+ * @param qname
+ * The name of the property to monitor.
+ *
+ * @param isReadOnly
+ * True if the property cannot be modified by external clients.
+ *
+ * @see AbstractChangeApprover#AbstractChangeApprover(QName)
+ *
+ */
+ public ExternalChangeApprover(QName qname, boolean isReadOnly)
+ {
+ super(qname);
+ _isReadOnly = isReadOnly;
+ }
+
+ /**
+ *
+ * @return True if the property being monitored cannot be changed by
+ * external clients.
+ *
+ */
+ public boolean isReadOnly()
+ {
+ return _isReadOnly;
+ }
+
+ /**
+ *
+ * Throws an exception if the property is read-only <b>and</b> the given
+ * security token does not match the one held by the approver.
+ *
+ */
+ public void validateChange(Element oldValue, Element newValue, Object token)
+ throws BaseFault
+ {
+ if (isReadOnly() && !isSecure(token))
+ {
+ Object[] filler = { getPropertyName() };
+ throw new UnableToModifyResourcePropertyFault(_MESSAGES.get("NoExternalChanges", filler));
+ }
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/InsertOnlyApprover.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/InsertOnlyApprover.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/InsertOnlyApprover.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/InsertOnlyApprover.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,78 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.metadata.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.properties.listeners.AbstractChangeApprover;
+import org.apache.muse.ws.resource.properties.listeners.PropertyChangeApprover;
+import org.apache.muse.ws.resource.properties.set.faults.UnableToModifyResourcePropertyFault;
+
+/**
+ *
+ * InsertOnlyApprover is a
+ * {@linkplain PropertyChangeApprover PropertyChangeApprover} that throws an
+ * exception if a request tries to perform a WS-RP Delete or Update on a
+ * property. In this case, the property is not immutable (since we can insert
+ * new instances of it), but the property <em>instances</em> are.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class InsertOnlyApprover extends AbstractChangeApprover
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES = MessagesFactory.get(InsertOnlyApprover.class);
+
+ /**
+ *
+ * @see AbstractChangeApprover#AbstractChangeApprover(QName)
+ *
+ */
+ public InsertOnlyApprover(QName qname)
+ {
+ super(qname);
+ }
+
+ /**
+ *
+ * Throws an exception if the first parameter is not null (signifying
+ * an update or deletion of an existing property).
+ *
+ */
+ public void validateChange(Element oldValue, Element newValue, Object token)
+ throws BaseFault
+ {
+ //
+ // if an old value exists, it means we're updating that old value
+ // or deleting it - BAD
+ //
+ if (oldValue != null)
+ {
+ Object[] filler = { getPropertyName() };
+ throw new UnableToModifyResourcePropertyFault(_MESSAGES.get("InsertOnly", filler));
+ }
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/Messages.properties
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/Messages.properties?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/Messages.properties (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/Messages.properties Thu Jun 15 15:16:59 2006
@@ -0,0 +1,14 @@
+NullPropertyElement = The DOM Element with the property definition is null.
+NoPropertyPath = There is a wsrmd:Property in the RMD that has no path attribute. This attribute is required to map the property to one defined in the WS-ResourceProperties schema; the attribute value should be the qualified name of one of those properties.
+ConstantButNotReadOnly = The wsrmd:Property with path 'XXX' is constant but not read-only - this is impossible. If a value is constant, it cannot be written to, so the modifiability of the property must be read-only.
+InvalidModifiability = The wsrmd:Property with the path 'XXX' has an invalid modifiability attribute value: XXX. The accepted modifiability values are 'read-only' and 'read-write'.
+InvalidMutability = The wsrmd:Property with the path 'XXX' has an invalid mutability attribute value: XXX. The accepted mutability values are 'constant', 'appendable', and 'mutable'.
+NullMetadataDocument = The DOM Document with the contents of the .rmd file is null.
+NoTargetNS = The resource metadata document (.rmd file) does not have the required targetNamespace attribute in its root element.
+NullMetadataDescriptor = The MetadataDescriptor is null.
+EmptyTargetNS = The target namespace string passed to setTargetNamespace() is null or empty. Make sure that the target namespace is a valid URI string and is defined in the root element of the RMD.
+NullDescriptorElement = The DOM Element with the MetadataDescriptor definition is null.
+NoDescriptorName = There is a wsrmd:MetadataDescriptor in the RMD that has no name attribute. This attribute is an xsd:NCName that uniquely identifies the descriptor.
+UndefinedProperty = There is no wsrmd:Property defined with the path 'XXX'. You cannot read metadata for a property that does not exist. Use the hasProperty method to determine if a property name is valid.
+NullPropertyMetadata = The PropertyMetadata reference is null.
+NoExternalChanges = The property 'XXX' is not writeable by remote clients. Its value may change over the lifetime of the resource, but it may only be modified by internal components.
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,409 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.metadata.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.resource.metadata.WsrmdConstants;
+
+/**
+ *
+ * PropertyMetadata is an internal class that represents one metadata
+ * definition (for one resource property) in a WS-RMD document definition.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ * @see SimpleMetadataDescriptor
+ *
+ */
+
+class PropertyMetadata
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES = MessagesFactory.get(PropertyMetadata.class);
+
+ //
+ // Modifiability values
+ //
+ public static final int READ_ONLY = 1;
+ public static final int READ_WRITE = 2;
+
+ //
+ // Mutability values
+ //
+ public static final int APPENDABLE = 3;
+ public static final int CONSTANT = 4;
+ public static final int MUTABLE = 5;
+
+ //
+ // extra (non-standard) metadata values defined by the application
+ //
+ private Map _extendedMetadata = null;
+
+ //
+ // The subscribability of the property. The default is true.
+ //
+ private boolean _isSubscribable = true;
+
+ //
+ // The modifiability rule for the property. The default is read-write.
+ //
+ private int _modifiability = READ_WRITE;
+
+ //
+ // The mutability rule for this property. The default is mutable.
+ //
+ private int _mutability = MUTABLE;
+
+ //
+ // The name of the property being defined
+ //
+ private QName _qname = null;
+
+ //
+ // The static values for this property - all instances of the resource
+ // should have these values for the property after initialization. The
+ // values CANNOT be deleted, even if the property is read-write/mutable.
+ //
+ private Set _staticValues = null;
+
+ //
+ // The valid values for this property - if this is empty, all values
+ // are allowed
+ //
+ private Set _validValues = null;
+
+ //
+ // The lower-bound of the valid value range (or null, if there is no
+ // value range). This is in string form, and must be converted to the
+ // appropriate data type by the caller.
+ //
+ private String _valueLowerBound = null;
+
+ //
+ // The upper-bound of the valid value range (or null, if there is no
+ // value range). This is in string form, and must be converted to the
+ // appropriate data type by the caller.
+ //
+ private String _valueUpperBound = null;
+
+ /**
+ *
+ * Creates a new metadata definition from the given XML.
+ *
+ * @param property
+ * The property's metadata definition, in XML form.
+ *
+ */
+ public PropertyMetadata(Element property)
+ {
+ if (property == null)
+ throw new NullPointerException(_MESSAGES.get("NullPropertyElement"));
+
+ //
+ // the path QName maps to a WS-RP property definition
+ //
+ String path = property.getAttribute(WsrmdConstants.PATH);
+
+ if (path == null || path.length() == 0)
+ throw new RuntimeException(_MESSAGES.get("NoPropertyPath"));
+
+ _qname = XmlUtils.parseQName(path, property);
+
+ _modifiability = parseModifiability(property);
+ _mutability = parseMutability(property);
+ _isSubscribable = parseSubscribability(property);
+
+ //
+ // make sure constant properties are also read-only!
+ //
+ if ((_mutability == CONSTANT) && (_modifiability != READ_ONLY))
+ {
+ Object[] filler = { path };
+ String message = _MESSAGES.get("ConstantButNotReadOnly", filler);
+ throw new IllegalStateException(message);
+ }
+
+ //
+ // static value set (optional)
+ //
+ _staticValues = parseStaticValues(property);
+
+ //
+ // valid value set (optional)
+ //
+ _validValues = parseValidValues(property);
+
+ //
+ // valid value range (optional)
+ //
+ Element rangeXML =
+ XmlUtils.getElement(property, WsrmdConstants.VALID_RANGE_QNAME);
+
+ if (rangeXML != null)
+ {
+ _valueLowerBound = rangeXML.getAttribute(WsrmdConstants.LOWER_BOUND);
+ _valueUpperBound = rangeXML.getAttribute(WsrmdConstants.UPPER_BOUND);
+
+ //
+ // for consistency, if there was no bound, we want the value
+ // to be null
+ //
+ if (_valueLowerBound != null && _valueLowerBound.length() == 0)
+ _valueLowerBound = null;
+
+ if (_valueUpperBound != null && _valueUpperBound.length() == 0)
+ _valueUpperBound = null;
+ }
+
+ _extendedMetadata = parseExtendedMetadata(property);
+ }
+
+ public String getExtendedMetadata(QName elementName)
+ {
+ return (String)_extendedMetadata.get(elementName);
+ }
+
+ public String getLowerBound()
+ {
+ return _valueLowerBound;
+ }
+
+ public int getModifiability()
+ {
+ return _modifiability;
+ }
+
+ public int getMutability()
+ {
+ return _mutability;
+ }
+
+ public QName getPropertyName()
+ {
+ return _qname;
+ }
+
+ public Collection getStaticValues()
+ {
+ return Collections.unmodifiableSet(_staticValues);
+ }
+
+ public String getUpperBound()
+ {
+ return _valueUpperBound;
+ }
+
+ public Collection getValidValues()
+ {
+ return Collections.unmodifiableSet(_validValues);
+ }
+
+ private boolean isElementInSet(Set setOfValues, Object value)
+ {
+ //
+ // complex type values will be XML fragments. in order to have
+ // a simple equality check, we create an XML instance of the
+ // value being tested and compare it to the XML fragments in the
+ // value set:
+ //
+
+ //
+ // 1. create XML instance of the value being tested. for complex
+ // types, the value is already XML; for simple types we build:
+ //
+ // <PropertyName>value</PropertyName>
+ //
+ Element valueXML = null;
+
+ if (value instanceof Element)
+ valueXML = (Element)value;
+
+ else
+ {
+ QName qname = getPropertyName();
+ valueXML = XmlUtils.createElement(XmlUtils.EMPTY_DOC, qname, value);
+ }
+
+ //
+ // 2. compare the XML fragments
+ //
+ Iterator i = setOfValues.iterator();
+
+ while (i.hasNext())
+ {
+ Element next = (Element)i.next();
+
+ if (XmlUtils.equals(next, valueXML))
+ return true;
+ }
+
+ //
+ // 3. no matches - invalid
+ //
+ return false;
+ }
+
+ public boolean isStaticValue(Object value)
+ {
+ return isElementInSet(_staticValues, value);
+ }
+
+ public boolean isSubscribable()
+ {
+ return _isSubscribable;
+ }
+
+ public boolean isValidValue(Object value)
+ {
+ //
+ // if no valid values were specified, it means ANY value is ok
+ //
+ if (_validValues.isEmpty())
+ return true;
+
+ return isElementInSet(_validValues, value);
+ }
+
+ private Set parseElementSet(Element property, QName qname)
+ {
+ Set values = new HashSet();
+
+ Element valuesXML = XmlUtils.getElement(property, qname);
+
+ if (valuesXML != null)
+ {
+ //
+ // we store the values as XML fragments - we will need
+ // these to do simple validation later. converting the
+ // values to non-XML would serve no purpose, and would
+ // require much more complexity
+ //
+ Element[] children = XmlUtils.getAllElements(valuesXML);
+
+ for (int n = 0; n < children.length; ++n)
+ values.add(children[n]);
+ }
+
+ return values;
+ }
+
+ private Map parseExtendedMetadata(Element property)
+ {
+ Map extended = new HashMap();
+
+ Element[] children = XmlUtils.getAllElements(property);
+
+ for (int n = 0; n < children.length; ++n)
+ {
+ QName qname = XmlUtils.getElementQName(children[n]);
+
+ if (!qname.equals(WsrmdConstants.VALID_VALUES_QNAME) &&
+ !qname.equals(WsrmdConstants.VALID_RANGE_QNAME) &&
+ !qname.equals(WsrmdConstants.STATIC_VALUES_QNAME))
+ {
+ String value = XmlUtils.extractText(children[n]);
+ extended.put(qname, value);
+ }
+ }
+
+ return extended;
+ }
+
+ private int parseModifiability(Element property)
+ {
+ String value = property.getAttribute(WsrmdConstants.MODIFIABILITY);
+
+ //
+ // default value is 'read-write'
+ //
+ if (value == null || value.length() == 0)
+ return READ_WRITE;
+
+ if (value.equals(WsrmdConstants.READ_ONLY))
+ return READ_ONLY;
+
+ else if (value.equals(WsrmdConstants.READ_WRITE))
+ return READ_WRITE;
+
+ String path = property.getAttribute(WsrmdConstants.PATH);
+ Object[] filler = { path, value };
+ throw new RuntimeException(_MESSAGES.get("InvalidModifiability", filler));
+ }
+
+ private int parseMutability(Element property)
+ {
+ String value = property.getAttribute(WsrmdConstants.MUTABILITY);
+
+ //
+ // default value is 'mutable'
+ //
+ if (value == null || value.length() == 0)
+ return MUTABLE;
+
+ if (value.equals(WsrmdConstants.APPENDABLE))
+ return APPENDABLE;
+
+ else if (value.equals(WsrmdConstants.CONSTANT))
+ return CONSTANT;
+
+ else if (value.equals(WsrmdConstants.MUTABLE))
+ return MUTABLE;
+
+ String path = property.getAttribute(WsrmdConstants.PATH);
+ Object[] filler = { path, value };
+ throw new RuntimeException(_MESSAGES.get("InvalidMutability", filler));
+ }
+
+ private Set parseStaticValues(Element property)
+ {
+ return parseElementSet(property, WsrmdConstants.STATIC_VALUES_QNAME);
+ }
+
+ private boolean parseSubscribability(Element property)
+ {
+ String value = property.getAttribute(WsrmdConstants.SUBSCRIBABILITY);
+
+ //
+ // default value is 'true'
+ //
+ if (value == null || value.length() == 0)
+ return true;
+
+ return Boolean.valueOf(value).booleanValue();
+ }
+
+ private Set parseValidValues(Element property)
+ {
+ return parseElementSet(property, WsrmdConstants.VALID_VALUES_QNAME);
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ReadOnlyApprover.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ReadOnlyApprover.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ReadOnlyApprover.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ReadOnlyApprover.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,71 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.metadata.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.properties.listeners.AbstractChangeApprover;
+import org.apache.muse.ws.resource.properties.listeners.PropertyChangeApprover;
+import org.apache.muse.ws.resource.properties.set.faults.UnableToModifyResourcePropertyFault;
+
+/**
+ *
+ * ReadOnlyApprover is a {@linkplain PropertyChangeApprover PropertyChangeApprover}
+ * that prevents modifications to read-only properties. It throws an exception for
+ * any and all attempts to change a property.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class ReadOnlyApprover extends AbstractChangeApprover
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES = MessagesFactory.get(ReadOnlyApprover.class);
+
+ /**
+ *
+ * @see AbstractChangeApprover#AbstractChangeApprover(QName)
+ *
+ */
+ public ReadOnlyApprover(QName qname)
+ {
+ super(qname);
+ }
+
+ /**
+ *
+ * <b>Always</b> throws an exception - <b>no</b> changes are allowed for
+ * read-only properties.
+ *
+ */
+ public void validateChange(Element oldValue, Element newValue, Object token)
+ throws BaseFault
+ {
+ //
+ // any change = BAD
+ //
+ throw new UnableToModifyResourcePropertyFault(_MESSAGES.get("ReadOnly", new Object[]{ getPropertyName() }));
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,226 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.metadata.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
+import org.apache.muse.ws.resource.metadata.WsrmdConstants;
+import org.apache.muse.ws.resource.properties.impl.WsrpUtils;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.util.xml.XmlUtils;
+
+/**
+ *
+ * SimpleMetadataDescriptor is Muse's default implementation of the RMD
+ * parsing and evaluation stage. It stores a simple lookup table of property
+ * names and metadata.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleMetadataDescriptor implements MetadataDescriptor
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES = MessagesFactory.get(SimpleMetadataDescriptor.class);
+
+ //
+ // The (unique) name of the descriptor - this maps to the name attribute
+ // in the XML definition
+ //
+ private String _name = null;
+
+ //
+ // All of the wsrmd:Property definitions, according to paths (a QName)
+ //
+ private Map _propertiesByQName = new HashMap();
+
+ /**
+ *
+ * Creates a new RMD metadata descriptor from the given XML definition.
+ *
+ * @param xml
+ * The XML representation of the descriptor.
+ *
+ */
+ public SimpleMetadataDescriptor(Element xml)
+ {
+ if (xml == null)
+ throw new NullPointerException(_MESSAGES.get("NullDescriptorElement"));
+
+ //
+ // the (unique) name - this is required
+ //
+ _name = xml.getAttribute(WsrmdConstants.NAME);
+
+ if (_name == null || _name.length() == 0)
+ throw new RuntimeException(_MESSAGES.get("NoDescriptorName"));
+
+ //
+ // parse all properties (there may be zero)
+ //
+ Element[] properties = XmlUtils.getElements(xml, WsrmdConstants.PROPERTY_QNAME);
+
+ for (int n = 0; n < properties.length; ++n)
+ {
+ PropertyMetadata metadata = new PropertyMetadata(properties[n]);
+ _propertiesByQName.put(metadata.getPropertyName(), metadata);
+ }
+ }
+
+ public boolean canDelete(QName propertyQName)
+ {
+ //
+ // deletion requires mutability (AND isReadOnlyExternal() == false)
+ //
+ PropertyMetadata property = getProperty(propertyQName);
+ return property.getMutability() == PropertyMetadata.MUTABLE;
+ }
+
+ public boolean canInsert(QName propertyQName)
+ {
+ //
+ // insert requires write permission and partial mutability (AND
+ // isReadOnlyExternal() == false)
+ //
+ int mutability = getProperty(propertyQName).getMutability();
+
+ return mutability == PropertyMetadata.APPENDABLE ||
+ mutability == PropertyMetadata.MUTABLE;
+ }
+
+ public boolean canSubscribe(QName propertyQName)
+ {
+ return getProperty(propertyQName).isSubscribable();
+ }
+
+ public boolean canUpdate(QName propertyQName)
+ {
+ //
+ // update requires write permission and full mutability (AND
+ // isReadOnlyExternal() == false)
+ //
+ PropertyMetadata property = getProperty(propertyQName);
+ return property.getMutability() == PropertyMetadata.MUTABLE;
+ }
+
+ private Object convertToObjects(Collection values, Class type)
+ throws SoapFault
+ {
+ Element[] asArray = new Element[values.size()];
+ asArray = (Element[])values.toArray(asArray);
+
+ return WsrpUtils.convertToObjects(asArray, type);
+ }
+
+ public String getExtendedMetadata(QName propertyQName, QName elementName)
+ {
+ return getProperty(propertyQName).getExtendedMetadata(elementName);
+ }
+
+ public String getLowerBound(QName propertyQName)
+ {
+ return getProperty(propertyQName).getLowerBound();
+ }
+
+ public String getName()
+ {
+ return _name;
+ }
+
+ private PropertyMetadata getProperty(QName propertyQName)
+ {
+ PropertyMetadata property =
+ (PropertyMetadata)_propertiesByQName.get(propertyQName);
+
+ if (property == null)
+ {
+ Object[] filler = { propertyQName };
+ throw new RuntimeException(_MESSAGES.get("UndefinedProperty", filler));
+ }
+
+ return property;
+ }
+
+ public Collection getPropertyNames()
+ {
+ return Collections.unmodifiableSet(_propertiesByQName.keySet());
+ }
+
+ public Collection getStaticValues(QName propertyQName)
+ {
+ return getProperty(propertyQName).getStaticValues();
+ }
+
+ public Object getStaticValues(QName propertyQName, Class javaType)
+ throws SoapFault
+ {
+ Collection values = getProperty(propertyQName).getStaticValues();
+ return convertToObjects(values, javaType);
+ }
+
+ public String getUpperBound(QName propertyQName)
+ {
+ return getProperty(propertyQName).getUpperBound();
+ }
+
+ public Collection getValidValues(QName propertyQName)
+ {
+ return getProperty(propertyQName).getValidValues();
+ }
+
+ public Object getValidValues(QName propertyQName, Class javaType)
+ throws SoapFault
+ {
+ Collection values = getProperty(propertyQName).getValidValues();
+ return convertToObjects(values, javaType);
+ }
+
+ public boolean hasProperty(QName propertyQName)
+ {
+ return _propertiesByQName.containsKey(propertyQName);
+ }
+
+ public boolean isReadOnlyExternal(QName propertyQName)
+ {
+ PropertyMetadata property = getProperty(propertyQName);
+ return property.getModifiability() == PropertyMetadata.READ_ONLY;
+ }
+
+ public boolean isStaticValue(QName propertyQName, Object value)
+ {
+ return getProperty(propertyQName).isStaticValue(value);
+ }
+
+ public boolean isValidValue(QName propertyQName, Object value)
+ {
+ PropertyMetadata property = getProperty(propertyQName);
+ return property.isValidValue(value);
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/StaticValuesApprover.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/StaticValuesApprover.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/StaticValuesApprover.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/StaticValuesApprover.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,103 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.metadata.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
+import org.apache.muse.ws.resource.properties.listeners.AbstractChangeApprover;
+import org.apache.muse.ws.resource.properties.listeners.PropertyChangeApprover;
+import org.apache.muse.ws.resource.properties.set.faults.UnableToModifyResourcePropertyFault;
+
+/**
+ *
+ * StaticValuesApprover is a
+ * {@linkplain PropertyChangeApprover PropertyChangeApprover} that throws an
+ * exception if a caller tries to delete a property instance whose value is
+ * defined in the WS-RMD document's StaticValues section. If a property's
+ * metadata defines static values, those values must be in the WS-RP document
+ * for the entire resource lifecycle.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class StaticValuesApprover extends AbstractChangeApprover
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES =
+ MessagesFactory.get(StaticValuesApprover.class);
+
+ //
+ // The RMD with the static values of the properties
+ //
+ private MetadataDescriptor _metadata = null;
+
+ /**
+ *
+ * Creates a new approver for the property with the given name and RMD.
+ *
+ * @param qname
+ * The QName of the property to monitor.
+ *
+ * @param metadata
+ * The RMD descriptor with the metadata for the property.
+ *
+ * @see AbstractChangeApprover#AbstractChangeApprover(QName)
+ *
+ */
+ public StaticValuesApprover(QName qname, MetadataDescriptor metadata)
+ {
+ super(qname);
+
+ if (metadata == null)
+ throw new NullPointerException(_MESSAGES.get("NullMetadataDescriptor"));
+
+ _metadata = metadata;
+ }
+
+ /**
+ *
+ * Throws an exception if the second parameter is null (signifying a
+ * deletion) and the current property value is one of the static values
+ * defined in the RMD.
+ *
+ */
+ public void validateChange(Element oldValue, Element newValue, Object token)
+ throws BaseFault
+ {
+ QName qname = getPropertyName();
+
+ //
+ // IF we're deleting AND the value is a StaticValue, disallow it
+ //
+ if ((oldValue != null && newValue == null) &&
+ _metadata.isStaticValue(qname, oldValue))
+ {
+ Object[] filler = { qname, XmlUtils.toString(oldValue, false) };
+ throw new UnableToModifyResourcePropertyFault(_MESSAGES.get("DeletingStaticValue", filler));
+ }
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ValidValuesApprover.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ValidValuesApprover.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ValidValuesApprover.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/ValidValuesApprover.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,104 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.metadata.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
+import org.apache.muse.ws.resource.properties.listeners.AbstractChangeApprover;
+import org.apache.muse.ws.resource.properties.listeners.PropertyChangeApprover;
+import org.apache.muse.ws.resource.properties.set.faults.UnableToModifyResourcePropertyFault;
+
+/**
+ *
+ * ValidValuesApprover is a
+ * {@linkplain PropertyChangeApprover PropertyChangeApprover} that throws
+ * an exception if a caller tries to insert or update a property instance
+ * with a value that is not defined in the WS-RMD document's ValidValues
+ * section. If a property's metadata defines valid values, those are the only
+ * values it may have; if not, any value is acceptable.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class ValidValuesApprover extends AbstractChangeApprover
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES =
+ MessagesFactory.get(ValidValuesApprover.class);
+
+ //
+ // The RMD with the valid values of the properties
+ //
+ private MetadataDescriptor _metadata = null;
+
+ /**
+ *
+ * Creates a new approver for the property with the given name and RMD.
+ *
+ * @param qname
+ * The QName of the property to monitor.
+ *
+ * @param metadata
+ * The RMD descriptor with the metadata for the property.
+ *
+ * @see AbstractChangeApprover#AbstractChangeApprover(QName)
+ *
+ */
+ public ValidValuesApprover(QName qname, MetadataDescriptor metadata)
+ {
+ super(qname);
+
+ if (metadata == null)
+ throw new NullPointerException(_MESSAGES.get("NullMetadataDescriptor"));
+
+ _metadata = metadata;
+ }
+
+ /**
+ *
+ * Throws an exception if the the second parameter is not null (signifying
+ * an insertion or update) and is not one of the valid values defined in
+ * the RMD.
+ *
+ */
+ public void validateChange(Element oldValue, Element newValue, Object token)
+ throws BaseFault
+ {
+ QName qname = getPropertyName();
+
+ //
+ // assuming it's not a deletion (null), check the value. if there
+ // are no ValidValues defined, this should still work according to
+ // the MetadataDescriptor interface.
+ //
+ if (newValue != null && !_metadata.isValidValue(qname, newValue))
+ {
+ Object[] filler = { qname, XmlUtils.toString(newValue, false) };
+ throw new UnableToModifyResourcePropertyFault(_MESSAGES.get("InvalidValue", filler));
+ }
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetDocumentHandler.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetDocumentHandler.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetDocumentHandler.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetDocumentHandler.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,60 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.properties.get.impl;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.muse.core.routing.AbstractMessageHandler;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.resource.properties.WsrpConstants;
+
+/**
+ *
+ * GetDocumentHandler is the parser for the WS-ResourceProperties
+ * GetResourcePropertyDocument operation.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class GetDocumentHandler extends AbstractMessageHandler
+{
+ public GetDocumentHandler()
+ {
+ super(WsrpConstants.GET_DOCUMENT_QNAME);
+ }
+
+ public Object[] fromXML(Element xml)
+ {
+ return EMPTY_REQUEST;
+ }
+
+ public Element toXML(Object result)
+ {
+ Element resultXML = (Element)result;
+ Document doc = resultXML.getOwnerDocument();
+
+ Node parent = resultXML.getParentNode();
+
+ if (parent != null)
+ parent.removeChild(resultXML);
+
+ return XmlUtils.createElement(doc, WsrpConstants.GET_DOCUMENT_RESPONSE_QNAME, resultXML, false);
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetHandler.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetHandler.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetHandler.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetHandler.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,53 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.properties.get.impl;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.routing.AbstractMessageHandler;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.resource.properties.WsrpConstants;
+
+/**
+ *
+ * GetHandler is the parser for the WS-ResourceProperties GetResourceProperty
+ * operation.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class GetHandler extends AbstractMessageHandler
+{
+ public GetHandler()
+ {
+ super(WsrpConstants.GET_QNAME);
+ }
+
+ public Object[] fromXML(Element xml)
+ throws SoapFault
+ {
+ GetRequest request = new GetRequest(xml);
+ return new Object[]{ request.getQName() };
+ }
+
+ public Element toXML(Object result)
+ {
+ GetResponse get = new GetResponse((Element[])result);
+ return get.toXML();
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleHandler.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleHandler.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleHandler.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleHandler.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,53 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.properties.get.impl;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.routing.AbstractMessageHandler;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.resource.properties.WsrpConstants;
+
+/**
+ *
+ * GetMultipleHandler is the parser for the WS-ResourceProperties
+ * GetMultipleResourceProperties operation.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class GetMultipleHandler extends AbstractMessageHandler
+{
+ public GetMultipleHandler()
+ {
+ super(WsrpConstants.GET_MULTIPLE_QNAME);
+ }
+
+ public Object[] fromXML(Element xml)
+ throws SoapFault
+ {
+ GetMultipleRequest request = new GetMultipleRequest(xml);
+ return new Object[]{ request.getQNames() };
+ }
+
+ public Element toXML(Object result)
+ {
+ GetMultipleResponse get = new GetMultipleResponse((Element[])result);
+ return get.toXML();
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleRequest.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleRequest.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleRequest.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleRequest.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,132 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.properties.get.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.util.xml.XmlSerializable;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.resource.ext.faults.InvalidMessageFormatFault;
+import org.apache.muse.ws.resource.properties.WsrpConstants;
+
+/**
+ *
+ * GetMultipleRequest is a serializer/deserializer for the WS-ResourceProperties
+ * GetMultipleResourceProperties operation's request content.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class GetMultipleRequest implements XmlSerializable
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES = MessagesFactory.get(GetMultipleRequest.class);
+
+ //
+ // The names of the properties to retrieve
+ //
+ private QName[] _qnames = null;
+
+ public GetMultipleRequest(QName[] qnames)
+ {
+ if (qnames == null)
+ throw new NullPointerException(_MESSAGES.get("NullQNameArray"));
+
+ for (int n = 0; n < qnames.length; ++n)
+ {
+ if (qnames[n] == null)
+ {
+ Object[] filler = { new Integer(n) };
+ throw new NullPointerException(_MESSAGES.get("NullQNameN", filler));
+ }
+ }
+
+ _qnames = qnames;
+ }
+
+ public GetMultipleRequest(Element request)
+ throws InvalidMessageFormatFault
+ {
+ if (request == null)
+ throw new NullPointerException(_MESSAGES.get("NullRequestElement"));
+
+ //
+ // load the property QNames from the ResourceProperty elements...
+ //
+ QName qname = WsrpConstants.PROPERTY_QNAME;
+ Element[] properties = XmlUtils.getElements(request, qname);
+
+ if (properties.length == 0)
+ throw new InvalidMessageFormatFault(_MESSAGES.get("NoPropertiesInGet"));
+
+ _qnames = new QName[properties.length];
+
+ for (int n = 0; n < properties.length; ++n)
+ {
+ _qnames[n] = XmlUtils.getQName(properties[n]);
+
+ if (_qnames[n] == null)
+ {
+ Object[] filler = { new Integer(n) };
+ throw new InvalidMessageFormatFault(_MESSAGES.get("NullPropertyN", filler));
+ }
+ }
+ }
+
+ public QName[] getQNames()
+ {
+ return _qnames;
+ }
+
+ public String toString()
+ {
+ return XmlUtils.toString(toXML(), false);
+ }
+
+ public Element toXML()
+ {
+ return toXML(XmlUtils.EMPTY_DOC);
+ }
+
+ public Element toXML(Document doc)
+ {
+ if (doc == null)
+ throw new NullPointerException(_MESSAGES.get("NullDocument"));
+
+ QName qname = WsrpConstants.GET_MULTIPLE_QNAME;
+ Element root = XmlUtils.createElement(doc, qname);
+
+ qname = WsrpConstants.PROPERTY_QNAME;
+ QName[] qnames = getQNames();
+
+ for (int n = 0; n < qnames.length; ++n)
+ {
+ Element property = XmlUtils.createElement(doc, qname, qnames[n]);
+ root.appendChild(property);
+ }
+
+ return root;
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleResponse.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleResponse.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleResponse.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/properties/get/impl/GetMultipleResponse.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,118 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.properties.get.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.properties.WsrpConstants;
+import org.apache.muse.util.xml.XmlSerializable;
+import org.apache.muse.util.xml.XmlUtils;
+
+/**
+ *
+ * GetMultipleResponse is a serializer/deserializer for the WS-ResourceProperties
+ * GetMultipleResourceProperties operation's response content.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class GetMultipleResponse implements XmlSerializable
+{
+ //
+ // Used to lookup all exception messages
+ //
+ private static Messages _MESSAGES = MessagesFactory.get(GetMultipleResponse.class);
+
+ //
+ // The property instances retrieved for a GetMultipleResourceProperties
+ // request. This may be empty.
+ //
+ private Element[] _properties = null;
+
+ public GetMultipleResponse(Element[] properties)
+ {
+ if (properties == null)
+ throw new NullPointerException(_MESSAGES.get("NullElementArray"));
+
+ for (int n = 0; n < properties.length; ++n)
+ {
+ if (properties[n] == null)
+ {
+ Object[] filler = { new Integer(n) };
+ throw new NullPointerException(_MESSAGES.get("NullInstanceN", filler));
+ }
+ }
+
+ _properties = properties;
+ }
+
+ public int getNumberOfProperties()
+ {
+ return _properties.length;
+ }
+
+ public Element[] getProperties()
+ {
+ return _properties;
+ }
+
+ public Element getProperty(int index)
+ {
+ return _properties[index];
+ }
+
+ public QName getPropertyName(int index)
+ {
+ return XmlUtils.getElementQName(getProperty(index));
+ }
+
+ public boolean isEmpty()
+ {
+ return _properties.length == 0;
+ }
+
+ public String toString()
+ {
+ return XmlUtils.toString(toXML(), false);
+ }
+
+ public Element toXML()
+ {
+ return toXML(XmlUtils.EMPTY_DOC);
+ }
+
+ public Element toXML(Document doc)
+ {
+ QName qname = WsrpConstants.GET_MULTIPLE_RESPONSE_QNAME;
+ Element root = XmlUtils.createElement(doc, qname);
+
+ for (int n = 0; n < _properties.length; ++n)
+ {
+ Node property = doc.importNode(_properties[n], true);
+ root.appendChild(property);
+ }
+
+ return root;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org