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/07/12 19:37:15 UTC

svn commit: r421341 - /webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/

Author: danj
Date: Wed Jul 12 10:37:15 2006
New Revision: 421341

URL: http://svn.apache.org/viewvc?rev=421341&view=rev
Log:
Updated these classes to reflect changes between WSRMD 2004 draft and WSRMD CD 01. Also added 
two new classes to represent the new "metadata resource" concept that is present in CD 01; one 
is the capability that exposes and EPR to the metadata resource,  the other is for the metadata 
resource itself.


Added:
    webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataResource.java
    webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleResourceMetadataCapability.java
    webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java
Modified:
    webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/Messages.properties
    webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java
    webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java

Modified: 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=421341&r1=421340&r2=421341&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/Messages.properties (original)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/Messages.properties Wed Jul 12 10:37:15 2006
@@ -1,5 +1,5 @@
 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.
+NoPropertyName = There is a wsrmd:Property in the RMD that has no 'name' 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'.
@@ -8,7 +8,14 @@
 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.
+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.
+NoDescriptorInterface = There is a wsrmd:MetadataDescriptor in the RMD that has no 'interface' attribute. This attribute is an xsd:QName that links back to the WSDL portType.
+NoDescriptorWSDLLocation = There is a wsrmd:MetadataDescriptor in the RMD that has no 'wsdlLocation' attribute. This attribute is a set of two xsd:anyURI that contains the WSDL target namespace and WSDL location (path), separated by a space.
+InvalidWSDLLocation = There is a wsrmd:MetadataDescriptor in the RMD that has an invalid 'wsdlLocation' attribute. This attribute should be a set of two xsd:anyURI that contains the WSDL target namespace and WSDL location (path), separated by a space. The value you provided was 'XXX'.
 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.
+IncompleteMetadataAttributes = The resource's WSDL does not have complete WS-RMD attributes in its portType, so Muse cannot tell if an RMD is meant to be applied or not. To fix this situation, make sure the portType references both the wsrmd:Descriptor and the wsrmd:DescriptorLocation attributes, or none at all.
+DescriptorNotFound = The RMD file XXX does not have a MetadataDescriptor whose 'name' attribute is 'XXX'.
+NoMetadataResource = There is no resource that implements the WS-RF MetadataResource capability defined in muse.xml. In order to use and read from a metadata resource, an application must expose a resource with the capability org.apache.muse.ws.resource.metadata.MetadataResource; this resource will represent the metadata descriptor for the resource.
+FoundMetadataResource = Successfully found the MetadataResource endpoint at 'XXX'. All metadata resources will be managed by this endpoint.

Modified: 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=421341&r1=421340&r2=421341&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java (original)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java Wed Jul 12 10:37:15 2006
@@ -22,14 +22,15 @@
 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.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.metadata.WsrmdConstants;
 
@@ -44,25 +45,25 @@
  * 
  */
 
-class PropertyMetadata
+class PropertyMetadata implements XmlSerializable
 {
     //
     // 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;
+    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;    
+    public static final int MUTABLE = 5; 
     
     //
     // extra (non-standard) metadata values defined by the application
@@ -70,11 +71,6 @@
     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;
@@ -90,17 +86,24 @@
     private QName _qname = null;
     
     //
+    // The initial values for this property - all instances of the resource 
+    // should have these values for the property after initialization. If 
+    // the property is mutable, the values may be deleted after that time.
+    //
+    private Collection _initialValues = 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;
+    private Collection _staticValues = null;
     
     //
     // The valid values for this property - if this is empty, all values 
     // are allowed
     //
-    private Set _validValues = null;
+    private Collection _validValues = null;
     
     //
     // The lower-bound of the valid value range (or null, if there is no 
@@ -132,28 +135,32 @@
         //
         // the path QName maps to a WS-RP property definition
         //
-        String path = property.getAttribute(WsrmdConstants.PATH);
+        String nameString = property.getAttribute(WsrmdConstants.NAME);
         
-        if (path == null || path.length() == 0)
-            throw new RuntimeException(_MESSAGES.get("NoPropertyPath"));
+        if (nameString == null || nameString.length() == 0)
+            throw new RuntimeException(_MESSAGES.get("NoPropertyName"));
         
-        _qname = XmlUtils.parseQName(path, property);
+        _qname = XmlUtils.parseQName(nameString, 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 };
+            Object[] filler = { _qname };
             String message = _MESSAGES.get("ConstantButNotReadOnly", filler);
             throw new IllegalStateException(message);
         }
         
         //
+        // initial value set (optional)
+        //
+        _initialValues = parseInitialValues(property);
+        
+        //
         // static value set (optional)
         //
         _staticValues = parseStaticValues(property);
@@ -193,6 +200,11 @@
         return (String)_extendedMetadata.get(elementName);
     }
     
+    public Collection getInitialValues()
+    {
+        return Collections.unmodifiableCollection(_initialValues);
+    }
+    
     public String getLowerBound()
     {
         return _valueLowerBound;
@@ -203,10 +215,26 @@
         return _modifiability;
     }
     
+    public String getModifiabilityString()
+    {
+        return _modifiability == READ_ONLY ? WsrmdConstants.READ_ONLY : WsrmdConstants.READ_WRITE;
+    }
+    
     public int getMutability()
     {
         return _mutability;
     }
+    
+    public String getMutabilityString()
+    {
+        if (_modifiability == CONSTANT)
+            return WsrmdConstants.CONSTANT;
+        
+        else if (_modifiability == APPENDABLE)
+            return WsrmdConstants.APPENDABLE;
+        
+        return WsrmdConstants.MUTABLE;
+    }
 
     public QName getPropertyName()
     {
@@ -215,7 +243,7 @@
     
     public Collection getStaticValues()
     {
-        return Collections.unmodifiableSet(_staticValues);
+        return Collections.unmodifiableCollection(_staticValues);
     }
     
     public String getUpperBound()
@@ -225,10 +253,10 @@
     
     public Collection getValidValues()
     {
-        return Collections.unmodifiableSet(_validValues);
+        return Collections.unmodifiableCollection(_validValues);
     }
     
-    private boolean isElementInSet(Set setOfValues, Object value)
+    private boolean isElementInCollection(Collection setOfValues, Object value)
     {        
         //
         // complex type values will be XML fragments. in order to have 
@@ -273,14 +301,14 @@
         return false;
     }
     
-    public boolean isStaticValue(Object value)
+    public boolean isInitialValue(Object value)
     {
-        return isElementInSet(_staticValues, value);
+        return isElementInCollection(_initialValues, value);
     }
     
-    public boolean isSubscribable()
+    public boolean isStaticValue(Object value)
     {
-        return _isSubscribable;
+        return isElementInCollection(_staticValues, value);
     }
     
     public boolean isValidValue(Object value)
@@ -291,12 +319,12 @@
         if (_validValues.isEmpty())
             return true;
         
-        return isElementInSet(_validValues, value);
+        return isElementInCollection(_validValues, value);
     }
     
-    private Set parseElementSet(Element property, QName qname)
+    private Collection parseElementCollection(Element property, QName qname)
     {
-        Set values = new HashSet();
+        Collection values = new HashSet();
         
         Element valuesXML = XmlUtils.getElement(property, qname);
         
@@ -339,6 +367,11 @@
         return extended;
     }
     
+    private Collection parseInitialValues(Element property)
+    {
+        return parseElementCollection(property, WsrmdConstants.INITIAL_VALUES_QNAME);
+    }
+    
     private int parseModifiability(Element property)
     {
         String value = property.getAttribute(WsrmdConstants.MODIFIABILITY);
@@ -355,8 +388,8 @@
         else if (value.equals(WsrmdConstants.READ_WRITE))
             return READ_WRITE;
         
-        String path = property.getAttribute(WsrmdConstants.PATH);
-        Object[] filler = { path, value };
+        String name = property.getAttribute(WsrmdConstants.NAME);
+        Object[] filler = { name, value };
         throw new RuntimeException(_MESSAGES.get("InvalidModifiability", filler));
     }
 
@@ -379,31 +412,61 @@
         else if (value.equals(WsrmdConstants.MUTABLE))
             return MUTABLE;
 
-        String path = property.getAttribute(WsrmdConstants.PATH);
-        Object[] filler = { path, value };
+        String name = property.getAttribute(WsrmdConstants.NAME);
+        Object[] filler = { name, value };
         throw new RuntimeException(_MESSAGES.get("InvalidMutability", filler));
     }
     
-    private Set parseStaticValues(Element property)
+    private Collection parseStaticValues(Element property)
+    {
+        return parseElementCollection(property, WsrmdConstants.STATIC_VALUES_QNAME);
+    }
+    
+    private Collection parseValidValues(Element property)
     {
-        return parseElementSet(property, WsrmdConstants.STATIC_VALUES_QNAME);
+        return parseElementCollection(property, WsrmdConstants.VALID_VALUES_QNAME);
     }
 
-    private boolean parseSubscribability(Element property)
+    public Element toXML()
     {
-        String value = property.getAttribute(WsrmdConstants.SUBSCRIBABILITY);
-        
-        //
-        // default value is 'true'
-        //
-        if (value == null || value.length() == 0)
-            return true;
-        
-        return Boolean.valueOf(value).booleanValue();
+        return toXML(XmlUtils.EMPTY_DOC);
     }
-    
-    private Set parseValidValues(Element property)
+
+    public Element toXML(Document doc)
     {
-        return parseElementSet(property, WsrmdConstants.VALID_VALUES_QNAME);
+        Element root = XmlUtils.createElement(doc, WsrmdConstants.PROPERTY_QNAME);
+        
+        QName qname = getPropertyName();
+        root.setAttribute(WsrmdConstants.NAME, XmlUtils.toString(qname));
+        XmlUtils.setNamespaceAttribute(root, qname.getPrefix(), qname.getNamespaceURI());
+        
+        root.setAttribute(WsrmdConstants.MODIFIABILITY, getModifiabilityString());        
+        root.setAttribute(WsrmdConstants.MUTABILITY, getMutabilityString());
+        
+        Element initialValues = XmlUtils.createElement(doc, WsrmdConstants.INITIAL_VALUES_QNAME);
+        Element staticValues = XmlUtils.createElement(doc, WsrmdConstants.STATIC_VALUES_QNAME);
+        Element validValues = XmlUtils.createElement(doc, WsrmdConstants.VALID_VALUES_QNAME);
+        
+        Element[] values = new Element[]{ initialValues, staticValues, validValues };
+        Collection[] instances = new Collection[] { getInitialValues(), getStaticValues(), getValidValues() };
+        
+        for (int n = 0; n < values.length; ++n)
+        {
+            if (instances[n].isEmpty())
+                continue;
+            
+            root.appendChild(values[n]);
+            
+            Iterator i = instances[n].iterator();
+            
+            while (i.hasNext())
+            {
+                Element next = (Element)i.next();
+                next = (Element)doc.importNode(next, true);
+                values[n].appendChild(next);
+            }
+        }
+        
+        return root;
     }
 }

Modified: 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=421341&r1=421340&r2=421341&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java (original)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java Wed Jul 12 10:37:15 2006
@@ -16,13 +16,16 @@
 
 package org.apache.muse.ws.resource.metadata.impl;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import org.apache.muse.util.messages.Messages;
@@ -49,18 +52,22 @@
     // 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();
 
+    private QName _wsdlInterface = null;
+
+    private String _wsdlLocation = null;
+    
     /**
      * 
      * Creates a new RMD metadata descriptor from the given XML definition.
@@ -81,6 +88,31 @@
 
         if (_name == null || _name.length() == 0)
             throw new RuntimeException(_MESSAGES.get("NoDescriptorName"));
+        
+        String interfaceString = xml.getAttribute(WsrmdConstants.INTERFACE);
+
+        if (interfaceString == null || interfaceString.length() == 0)
+            throw new RuntimeException(_MESSAGES.get("NoDescriptorInterface"));
+        
+        _wsdlInterface = XmlUtils.parseQName(interfaceString, xml);
+        
+        String uriList = xml.getAttribute(WsrmdConstants.WSDL_LOCATION);
+
+        if (uriList == null || uriList.length() == 0)
+            throw new RuntimeException(_MESSAGES.get("NoDescriptorWSDLLocation"));
+        
+        //
+        // the list is a two-URI set of { WSDL targetNS, WSDL location }
+        //
+        String[] values = uriList.split(" ");
+        
+        if (values.length != 2)
+        {
+            Object[] filler = { uriList };
+            throw new RuntimeException(_MESSAGES.get("InvalidWSDLLocation", filler));
+        }
+            
+        _wsdlLocation = values[1];  // ignore values[0] - it's just the targetNS
 
         //
         // parse all properties (there may be zero)
@@ -115,11 +147,6 @@
                mutability == PropertyMetadata.MUTABLE;
     }
 
-    public boolean canSubscribe(QName propertyQName)
-    {
-        return getProperty(propertyQName).isSubscribable();
-    }
-
     public boolean canUpdate(QName propertyQName)
     {
         //
@@ -130,13 +157,19 @@
         return property.getMutability() == PropertyMetadata.MUTABLE;
     }
 
-    private Object convertToObjects(Collection values, Class type)
+    private Collection convertToObjects(Collection values, Class type)
         throws SoapFault
     {
         Element[] asArray = new Element[values.size()];
         asArray = (Element[])values.toArray(asArray);
-
-        return WsrpUtils.convertToObjects(asArray, type);
+        
+        //
+        // we can return a List instead of a Set (HashSet) because 
+        // the collection will be iterated over by calling code, not 
+        // used for internal lookups
+        //
+        Object[] objects = (Object[])WsrpUtils.convertToObjects(asArray, type);
+        return Arrays.asList(objects);
     }
 
     public String getExtendedMetadata(QName propertyQName, QName elementName)
@@ -144,6 +177,23 @@
         return getProperty(propertyQName).getExtendedMetadata(elementName);
     }
 
+    public Collection getInitialValues(QName propertyQName)
+    {
+        return getProperty(propertyQName).getInitialValues();
+    }
+
+    public Collection getInitialValues(QName propertyQName, Class javaType)
+        throws SoapFault
+    {
+        Collection values = getProperty(propertyQName).getInitialValues();
+        return convertToObjects(values, javaType);
+    }
+
+    public QName getInterface()
+    {
+        return _wsdlInterface;
+    }
+
     public String getLowerBound(QName propertyQName)
     {
         return getProperty(propertyQName).getLowerBound();
@@ -156,8 +206,7 @@
 
     private PropertyMetadata getProperty(QName propertyQName)
     {
-        PropertyMetadata property = 
-            (PropertyMetadata)_propertiesByQName.get(propertyQName);
+        PropertyMetadata property = (PropertyMetadata)_propertiesByQName.get(propertyQName);
 
         if (property == null)
         {
@@ -178,7 +227,7 @@
         return getProperty(propertyQName).getStaticValues();
     }
 
-    public Object getStaticValues(QName propertyQName, Class javaType)
+    public Collection getStaticValues(QName propertyQName, Class javaType)
         throws SoapFault
     {
         Collection values = getProperty(propertyQName).getStaticValues();
@@ -195,18 +244,28 @@
         return getProperty(propertyQName).getValidValues();
     }
 
-    public Object getValidValues(QName propertyQName, Class javaType)
+    public Collection getValidValues(QName propertyQName, Class javaType)
         throws SoapFault
     {
         Collection values = getProperty(propertyQName).getValidValues();
         return convertToObjects(values, javaType);
     }
 
+    public String getWsdlLocation()
+    {
+        return _wsdlLocation;
+    }
+
     public boolean hasProperty(QName propertyQName)
     {
         return _propertiesByQName.containsKey(propertyQName);
     }
 
+    public boolean isInitialValue(QName propertyQName, Object value)
+    {
+        return getProperty(propertyQName).isInitialValue(value);
+    }
+
     public boolean isReadOnlyExternal(QName propertyQName)
     {
         PropertyMetadata property = getProperty(propertyQName);
@@ -220,7 +279,38 @@
 
     public boolean isValidValue(QName propertyQName, Object value)
     {
-        PropertyMetadata property = getProperty(propertyQName);
-        return property.isValidValue(value);
+        return getProperty(propertyQName).isValidValue(value);
+    }
+
+    public Element toXML()
+    {
+        return toXML(XmlUtils.EMPTY_DOC);
+    }
+
+    public Element toXML(Document doc)
+    {
+        Element root = XmlUtils.createElement(doc, WsrmdConstants.DESCRIPTOR_QNAME);
+        
+        root.setAttribute(WsrmdConstants.NAME, getName());
+        root.setAttribute(WsrmdConstants.INTERFACE, XmlUtils.toString(getInterface()));
+        
+        //
+        // HACK: the namespace that is the first token of this attribute value 
+        //       is incorrect - it should be the target NS of the WSDL file, 
+        //       but I don't want to re-load the WSDL file just to get that 
+        //       value, and I don't think it's going to be used
+        //
+        root.setAttribute(WsrmdConstants.WSDL_LOCATION, WsrmdConstants.NAMESPACE_URI + ' ' + getWsdlLocation());
+        
+        Iterator i = getPropertyNames().iterator();
+        
+        while (i.hasNext())
+        {
+            PropertyMetadata property = getProperty((QName)i.next());
+            Element propertyXML = property.toXML(doc);
+            root.appendChild(propertyXML);
+        }
+        
+        return root;
     }
 }

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataResource.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataResource.java?rev=421341&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataResource.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataResource.java Wed Jul 12 10:37:15 2006
@@ -0,0 +1,54 @@
+/*=============================================================================*
+ *  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.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
+import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
+import org.apache.muse.ws.resource.metadata.MetadataResource;
+
+/**
+ * 
+ * SimpleMetadataResource is Muse's default implementation of the capability 
+ * used by WSRF resources that are WS-RMD "metadata resources" - that is, they 
+ * function solely to expose the metadata of other WS-resource types.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleMetadataResource 
+    extends AbstractWsResourceCapability implements MetadataResource
+{
+    private MetadataDescriptor _rmd = null;
+
+    public MetadataDescriptor getMetadataDescriptor()
+    {
+        return _rmd;
+    }
+    
+    public QName[] getPropertyNames()
+    {
+        return PROPERTIES;
+    }
+
+    public void setMetadataDescriptor(MetadataDescriptor rmd)
+    {
+        _rmd = rmd;
+    }
+}

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleResourceMetadataCapability.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleResourceMetadataCapability.java?rev=421341&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleResourceMetadataCapability.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/SimpleResourceMetadataCapability.java Wed Jul 12 10:37:15 2006
@@ -0,0 +1,101 @@
+/*=============================================================================*
+ *  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.apache.muse.core.Resource;
+import org.apache.muse.core.ResourceManager;
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
+import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
+import org.apache.muse.ws.resource.metadata.MetadataResource;
+import org.apache.muse.ws.resource.metadata.ResourceMetadataCapability;
+import org.apache.muse.ws.resource.metadata.WsrmdConstants;
+
+/**
+ * 
+ * SimpleResourceMetadataCapability is Muse's default implementation of the WSRF 
+ * capability that exposes the wsrmd:MetadataDescriptorReference property and 
+ * creates a metadata resource that can be used to query metadata values.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleResourceMetadataCapability 
+    extends AbstractWsResourceCapability implements ResourceMetadataCapability
+{
+    //
+    // Used to look up all exception messages
+    //
+    private static Messages _MESSAGES = MessagesFactory.get(SimpleResourceMetadataCapability.class);
+    
+    private EndpointReference _metadataEPR = null;
+    
+    public EndpointReference getMetadataDescriptorReference()
+    {
+        return _metadataEPR;
+    }
+    
+    public QName[] getPropertyNames()
+    {
+        return PROPERTIES;
+    }
+    
+    public void initialize() 
+        throws SoapFault
+    {
+        super.initialize();
+
+        //
+        // make sure we're exposing the "metadata resource" endpoint so that 
+        // clients can read the descriptor property
+        //
+        Resource owner = getWsResource();
+        ResourceManager manager = owner.getResourceManager();
+        String metadataPath = manager.getResourceContextPath(MetadataResource.class);
+
+        if (metadataPath == null)
+            throw new RuntimeException(_MESSAGES.get("NoMetadataResource"));
+        
+        getLog().info(_MESSAGES.get("FoundMetadataResource", new Object[]{ metadataPath }));
+        
+        //
+        // create an instance of the metadata resource type and keep a reference 
+        // to the EPR for the MetadataDescriptorReference property
+        //
+        Resource metadataResource = manager.createResource(metadataPath);
+        _metadataEPR = metadataResource.getEndpointReference();
+        
+        //
+        // store our descriptor in the metadata resource's WSRP doc
+        //
+        MetadataResource rmdCap = (MetadataResource)metadataResource.getCapability(WsrmdConstants.METADATA_RESOURCE_URI);
+        MetadataDescriptor rmd = getWsResource().getPropertyCollection().getMetadata();
+        rmdCap.setMetadataDescriptor(rmd);
+        
+        //
+        // initialize and expose the metadata resource to clients
+        //
+        metadataResource.initialize();
+        manager.addResource(_metadataEPR, metadataResource);
+    }
+}

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java?rev=421341&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java Wed Jul 12 10:37:15 2006
@@ -0,0 +1,42 @@
+/*=============================================================================*
+ *  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 org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.resource.metadata.WsrmdConstants;
+
+public class WsrmdUtils
+{
+    public static Element getMetadataDescriptor(Document rmd, String name)
+    {
+        Element root = XmlUtils.getFirstElement(rmd);  // wsrmd:Definitions
+        Element[] descriptors = XmlUtils.getElements(root, WsrmdConstants.DESCRIPTOR_QNAME);
+        
+        for (int n = 0; n < descriptors.length; ++n)
+        {
+            String nextAttr = descriptors[n].getAttribute(WsrmdConstants.NAME);
+            
+            if (nextAttr != null && nextAttr.equals(name))
+                return descriptors[n];
+        }
+        
+        return null;
+    }
+}



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