Author: scamp
Date: Mon Aug 1 11:11:09 2005
New Revision: 226850
URL: http://svn.apache.org/viewcvs?rev=226850&view=rev
Log: (empty)
Removed:
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/examples/filesystem/src/java/org/apache/ws/resource/example/host/HostResource.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=226850&r1=226849&r2=226850&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
Mon Aug 1 11:11:09 2005
@@ -1,5 +1,6 @@
package org.apache.ws.resource.example.filesystem;
+import org.apache.ws.muws.MuwsUtils;
/**
@@ -124,8 +125,7 @@
* MUWS-defined properties.
*/
// init the
{http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ResourceId
resource property
- resourceProperty = resourcePropertySet.get(
FilesystemPropertyQNames.RESOURCEID );
- resourceProperty.setCallback( new
org.apache.ws.muws.ResourceIdResourcePropertyCallback( this ) );
+ MuwsUtils.initResourceIdProperty(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
@@ -164,6 +164,7 @@
relationshipType = prop_relationship.addNewRelationship();
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.RelationshipTypeType
relationshipTypeType = relationshipType.addNewType();
org.apache.ws.util.XmlBeanUtils.addChildElement(
relationshipTypeType, new javax.xml.namespace.QName( "http://myns.com/",
"ContainedBy", "myns" ) );
+
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.RelationshipParticipantType
relationshipParticipantType = relationshipType.addNewParticipant();
org.apache.ws.resource.properties.ResourceProperty resourceIdProp
= resourcePropertySet.get( FilesystemPropertyQNames.RESOURCEID );
Modified:
webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/host/HostResource.java
URL:
http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/host/HostResource.java?rev=226850&r1=226849&r2=226850&view=diff
==============================================================================
---
webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/host/HostResource.java
(original)
+++
webservices/muse/trunk/src/examples/filesystem/src/java/org/apache/ws/resource/example/host/HostResource.java
Mon Aug 1 11:11:09 2005
@@ -1,6 +1,8 @@
package org.apache.ws.resource.example.host;
+import org.apache.ws.muws.MuwsUtils;
+
/**
* A Host WS-Resource.
* <p />
@@ -31,12 +33,9 @@
try{
- // init the
{http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ResourceId
resource property
- resourceProperty = resourcePropertySet.get(
HostPropertyQNames.RESOURCEID );
- resourceProperty.setCallback( new
org.apache.ws.muws.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}ResourceId
resource property
+ MuwsUtils.initResourceIdProperty(this);
+ // NOTE: it's not necessary to add a property change listener,
since the ResourceId prop is immutable
}
catch (Exception e)
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=226850&r1=226849&r2=226850&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 Mon Aug
1 11:11:09 2005
@@ -1,12 +1,25 @@
package org.apache.ws.muws;
+import org.apache.commons.id.IdentifierUtils;
+import org.apache.commons.id.uuid.UUID;
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.RelationshipsCapability;
import org.apache.ws.notification.topics.Topic;
import org.apache.ws.notification.topics.TopicSpace;
import org.apache.ws.notification.topics.TopicSpaceSet;
import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
+import org.apache.ws.resource.properties.ResourceProperty;
import org.apache.ws.resource.properties.ResourcePropertySet;
+import org.apache.ws.resource.Resource;
+import org.apache.ws.resource.PropertiesResource;
+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 set of utility methods to aid in initializing MUWS manageable resources.
@@ -22,13 +35,13 @@
*
* @param propSet
*/
- public static void updateRelationshipResourceProperty( ResourcePropertySet
propSet, org.apache.ws.notification.base.NotificationProducerResource
notifResource )
+ public static void updateRelationshipResourceProperty(ResourcePropertySet
propSet, org.apache.ws.notification.base.NotificationProducerResource
notifResource)
{
- if ( propSet.get(
org.apache.ws.muws.v1_0.capability.RelationshipsCapability.PROP_NAME_RELATIONSHIP
) != null )
+ if
(propSet.get(org.apache.ws.muws.v1_0.capability.RelationshipsCapability.PROP_NAME_RELATIONSHIP)
!= null)
{
- org.apache.ws.muws.v1_0.impl.XmlBeansRelationshipResourceProperty
relationshipResourceProperty = new
org.apache.ws.muws.v1_0.impl.XmlBeansRelationshipResourceProperty(
propSet.getMetaData().getPropertyMetaData(
org.apache.ws.muws.v1_0.capability.RelationshipsCapability.PROP_NAME_RELATIONSHIP
),
-
(org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet) propSet,
notifResource );
- (
(org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet) propSet
).set( relationshipResourceProperty );
+ org.apache.ws.muws.v1_0.impl.XmlBeansRelationshipResourceProperty
relationshipResourceProperty = new
org.apache.ws.muws.v1_0.impl.XmlBeansRelationshipResourceProperty(propSet.getMetaData().getPropertyMetaData(org.apache.ws.muws.v1_0.capability.RelationshipsCapability.PROP_NAME_RELATIONSHIP),
+
(org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet) propSet,
notifResource);
+
((org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet)
propSet).set(relationshipResourceProperty);
}
}
@@ -36,15 +49,97 @@
* Adds the MUWS RelationshipCreated/Deleted topics to the specified topic
set.
*
* @param topicSet
+ */
+ public static TopicSpace addRelationshipTopics(TopicSpaceSet topicSet)
+ {
+ TopicSpace topicSpace = new
TopicSpaceImpl(MuwsConstants.NSURI_MUWS_PART2_TOPICS);
+ Topic topic = topicSpace.addTopic(RelationshipsCapability.TOPIC_NAME);
+
topic.addTopic(RelationshipsCapability.SUBTOPIC_NAME_RELATIONSHIP_CREATED);
+
topic.addTopic(RelationshipsCapability.SUBTOPIC_NAME_RELATIONSHIP_DELETED);
+ return topicSet.addTopicSpace(topicSpace);
+ }
+
+ /**
+ * Utility method for initializing the MUWS Identity ResourceId property.
*
+ * @param resource The resource to add the property to.
*/
- public static TopicSpace addRelationshipTopics( TopicSpaceSet topicSet )
+ public static void initResourceIdProperty(Resource resource)
{
- TopicSpace topicSpace = new TopicSpaceImpl(
MuwsConstants.NSURI_MUWS_PART2_TOPICS );
- Topic topic = topicSpace.addTopic( RelationshipsCapability.TOPIC_NAME
);
- topic.addTopic(
RelationshipsCapability.SUBTOPIC_NAME_RELATIONSHIP_CREATED );
- topic.addTopic(
RelationshipsCapability.SUBTOPIC_NAME_RELATIONSHIP_DELETED );
- return topicSet.addTopicSpace( topicSpace );
+ if (resource instanceof PropertiesResource)
+ {
+ ResourceProperty resourceProperty =
((PropertiesResource)resource).getResourcePropertySet().get(IdentityCapability.PROP_NAME_RESOURCE_ID);
+ if (resourceProperty != null)
+ {
+ if (resourceProperty.isEmpty()) // ResourceId prop is
immutable, so it only needs to be set once
+ {
+ URI idURI = toURI(resource.getID());
+ ResourceIdDocument propElem =
ResourceIdDocument.Factory.newInstance();
+ propElem.setResourceId(idURI.toString());
+ resourceProperty.add(propElem);
+ }
+ }
+ }
}
+
+ /**
+ * 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
+ */
+ private 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 [EMAIL PROTECTED] #toURI} will append a
stringified version
+ * of a resource identifier. The default implementation returns a URN
representation
+ * of a v4 UUID.
+ *
+ * @return the base URI to which [EMAIL PROTECTED] #toURI} will append a
stringified version
+ * of a resource identifier
+ */
+ private static String getBaseURI()
+ {
+ try
+ {
+ return ((UUID)
IdentifierUtils.UUID_VERSION_FOUR_GENERATOR.nextIdentifier()).toUrn();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to generate UUID.", e);
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]