You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by ip...@apache.org on 2005/07/26 20:02:44 UTC

svn commit: r225364 - in /webservices/muse/trunk/src: examples/filesystem/src/java/org/apache/ws/resource/example/filesystem/FilesystemResource.java java/org/apache/ws/muws/MuwsUtils.java java/org/apache/ws/muws/ResourceIdResourcePropertyCallback.java

Author: ips
Date: Tue Jul 26 11:02:37 2005
New Revision: 225364

URL: http://svn.apache.org/viewcvs?rev=225364&view=rev
Log:
added a standardized callback that can be used to initialize the ResourceId prop based on a resource's ID field

Added:
    webservices/muse/trunk/src/java/org/apache/ws/muws/ResourceIdResourcePropertyCallback.java
Modified:
    webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/filesystem/FilesystemResource.java
    webservices/muse/trunk/src/java/org/apache/ws/muws/MuwsUtils.java

Modified: webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/filesystem/FilesystemResource.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/filesystem/FilesystemResource.java?rev=225364&r1=225363&r2=225364&view=diff
==============================================================================
--- webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/filesystem/FilesystemResource.java (original)
+++ webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/filesystem/FilesystemResource.java Tue Jul 26 11:02:37 2005
@@ -3,7 +3,7 @@
 import example.filesystem.callback.OperationalStatusCallback;
 import org.apache.axis.message.addressing.Constants;
 import org.apache.ws.addressing.XmlBeansEndpointReference;
-import org.apache.ws.muws.MuwsUtils;
+import org.apache.ws.muws.ResourceIdResourcePropertyCallback;
 import org.apache.ws.muws.v1_0.MuwsConstants;
 import org.apache.ws.muws.v1_0.capability.IdentityCapability;
 import org.apache.ws.muws.v1_0.capability.ManageabilityCharacteristicsCapability;
@@ -82,7 +82,7 @@
         }
         catch ( Exception e )
         {
-            throw new RuntimeException( "Failed to add MUWS capability topics to topic set.", e );
+            throw new RuntimeException( "Failed to add MUWS capability topics to topic set of " + this.getClass().getName() + " resource with ID " + getID() + ".", e );
         }
 
         org.apache.ws.resource.properties.ResourcePropertySet resourcePropertySet = getResourcePropertySet();
@@ -146,10 +146,8 @@
              */
             // init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ResourceId resource property
             resourceProperty = resourcePropertySet.get( FilesystemPropertyQNames.RESOURCEID );
-            org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ResourceIdDocument prop_resourceid = org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ResourceIdDocument.Factory.newInstance();
-            prop_resourceid.setResourceId( MuwsUtils.toURI( getID() ).toString() );
-            resourceProperty.add( prop_resourceid );
-            resourceProperty.addChangeListener( identityCapabilityTopic ); // add for property-value-changed management events
+            resourceProperty.setCallback( new ResourceIdResourcePropertyCallback( this ) );
+            // NOTE: it's not necessary to add a property change listener, since the ResourceId prop is immutable
 
             // init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ManageabilityCapability resource property
             resourceProperty = resourcePropertySet.get( FilesystemPropertyQNames.MANAGEABILITYCAPABILITY );
@@ -170,8 +168,7 @@
             ManageabilityCapabilityDocument relationshipsCapabilityPropElem = ManageabilityCapabilityDocument.Factory.newInstance();
             relationshipsCapabilityPropElem.setManageabilityCapability( RelationshipsCapability.URI );
             resourceProperty.add( relationshipsCapabilityPropElem );
-
-            resourceProperty.addChangeListener( manageabilityCharacteristicsCapabilityTopic ); // add for property-value-changed management events
+            // NOTE: it's not necessary to add a property change listener, since the ManageabilityCapability prop is immutable
 
             // init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd}OperationalStatus resource property
             resourceProperty = resourcePropertySet.get( FilesystemPropertyQNames.OPERATIONALSTATUS );

Modified: webservices/muse/trunk/src/java/org/apache/ws/muws/MuwsUtils.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/java/org/apache/ws/muws/MuwsUtils.java?rev=225364&r1=225363&r2=225364&view=diff
==============================================================================
--- webservices/muse/trunk/src/java/org/apache/ws/muws/MuwsUtils.java (original)
+++ webservices/muse/trunk/src/java/org/apache/ws/muws/MuwsUtils.java Tue Jul 26 11:02:37 2005
@@ -8,12 +8,9 @@
 import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
 import org.apache.ws.resource.properties.ResourcePropertySet;
 
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLEncoder;
-import java.io.UnsupportedEncodingException;
-
 /**
+ * A set of utility methods to aid in initializing MUWS manageable resources.
+ *
  * @author Sal Campana
  */
 public class MuwsUtils
@@ -49,44 +46,6 @@
         topic.addTopic( RelationshipsCapability.SUBTOPIC_NAME_RELATIONSHIP_CREATED );
         topic.addTopic( RelationshipsCapability.SUBTOPIC_NAME_RELATIONSHIP_DELETED );
         return topicSet.addTopicSpace( topicSpace );
-    }
-
-    /**
-     * Converts the specified resource identifier into a URI that can be used as the value
-     * for the MUWS ResourceId property.
-     *
-     * @param resourceId a resource identifier
-     *
-     * @return URI that can be used as the value for the MUWS ResourceId property
-     */ 
-    public static URI toURI( Object resourceId )
-    {
-        String idString = null;
-        try
-        {
-            idString = URLEncoder.encode( String.valueOf( resourceId ), "UTF-8" );
-        }
-        catch ( UnsupportedEncodingException uee )
-        {
-            throw new IllegalStateException( uee.getLocalizedMessage() );
-        }
-        URI idURI;
-        try
-        {
-            idURI = new URI( idString );
-        }
-        catch ( URISyntaxException urise )
-        {
-            try
-            {
-                idURI = new URI( "urn:" + idString );
-            }
-            catch ( URISyntaxException urise2 )
-            {
-                throw new IllegalStateException( urise2.getLocalizedMessage() );
-            }
-        }
-        return idURI;
     }
 
 }

Added: webservices/muse/trunk/src/java/org/apache/ws/muws/ResourceIdResourcePropertyCallback.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/java/org/apache/ws/muws/ResourceIdResourcePropertyCallback.java?rev=225364&view=auto
==============================================================================
--- webservices/muse/trunk/src/java/org/apache/ws/muws/ResourceIdResourcePropertyCallback.java (added)
+++ webservices/muse/trunk/src/java/org/apache/ws/muws/ResourceIdResourcePropertyCallback.java Tue Jul 26 11:02:37 2005
@@ -0,0 +1,126 @@
+/*=============================================================================*
+ *  Copyright 2005 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.muws;
+
+import org.apache.ws.muws.v1_0.capability.IdentityCapability;
+import org.apache.ws.resource.Resource;
+import org.apache.ws.resource.properties.ResourceProperty;
+import org.apache.ws.resource.properties.ResourcePropertyCallback;
+import org.apache.ws.resource.properties.impl.CallbackFailedException;
+import org.apache.ws.addressing.uuid.UUIdGeneratorFactory;
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ResourceIdDocument;
+
+import javax.xml.namespace.QName;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLEncoder;
+
+/**
+ * A callback for the MUWS ResourceId resource property.
+ */
+public class ResourceIdResourcePropertyCallback implements ResourcePropertyCallback
+{
+
+    private Resource m_resource;
+
+    /**
+     * Creates a new {@link ResourceIdResourcePropertyCallback} for the specified MUWS manageable resource.
+     *
+     * @param resource a MUWS manageable resource
+     */
+    public ResourceIdResourcePropertyCallback( Resource resource )
+    {
+        m_resource = resource;
+    }
+
+    /**
+     * @param prop the MUWS ResourceId resource property
+     *
+     * @return the MUWS ResourceId resource property
+     *
+     * @throws CallbackFailedException
+     */
+    public ResourceProperty refreshProperty( ResourceProperty prop ) throws CallbackFailedException
+    {
+        if ( prop.isEmpty() )  // ResourceId prop is immutable, so it only needs to be set once
+        {
+            QName propName = prop.getMetaData().getName();
+            if ( !propName.equals( IdentityCapability.PROP_NAME_RESOURCE_ID ) )
+            {
+                throw new IllegalArgumentException( "Unsupported property: " + propName );
+            }
+            URI idURI = toURI( m_resource.getID() );
+            ResourceIdDocument propElem = ResourceIdDocument.Factory.newInstance();
+            propElem.setResourceId( idURI.toString() );
+            prop.add( propElem );
+        }
+        return prop;
+    }
+
+    /**
+     * Converts the specified resource identifier into a globally unique URI that can
+     * be used as the value for the MUWS ResourceId property.
+     *
+     * @param resourceId a resource identifier
+     *
+     * @return URI that can be used as the value for the MUWS ResourceId property
+     */
+    protected static URI toURI( Object resourceId )
+    {
+        try
+        {
+            return new URI( String.valueOf( resourceId ) );
+        }
+        catch ( URISyntaxException urise )
+        {
+            // resource identifier is not already a URI - convert it to one...
+        }
+        String idString;
+        if ( resourceId != null )
+        {
+            idString = resourceId.toString();
+            // URL-encode the id in case it contains any unsafe characters
+            try
+            {
+                idString = URLEncoder.encode( idString, "UTF-8" );
+            }
+            catch ( UnsupportedEncodingException uee )
+            {
+                // will never happen - all JDKs support UTF-8
+                throw new IllegalStateException( uee.getLocalizedMessage() );
+            }
+        }
+        else
+        {
+            idString = "SINGLETON";
+        }
+        return URI.create( getBaseURI() + "/" + idString );
+    }
+
+    /**
+     * Returns the base URI to which {@link #toURI} will append a stringified version
+     * of a resource identifier.
+     *
+     * @return the base URI to which {@link #toURI} will append a stringified version
+     *         of a resource identifier
+     */
+    protected static String getBaseURI()
+    {
+        return "urn:" + UUIdGeneratorFactory.createUUIdGenerator().generateUUId();
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org