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 2007/01/12 19:41:49 UTC
svn commit: r495682 - in
/webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl:
Messages.properties PropertyMetadata.java SimpleMetadataDescriptor.java
WsrmdUtils.java
Author: danj
Date: Fri Jan 12 10:41:48 2007
New Revision: 495682
URL: http://svn.apache.org/viewvc?view=rev&rev=495682
Log:
Fix for MUSE-179 - made MetadataDescriptor objects mutable, but w/o making it possible to create non-compliant RMD docs.
WsrmdUtils contains a convenience method for turning one MetadataDescriptor object into a complete RMD MetadataDocument.
Modified:
webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/Messages.properties
webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java
webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java
webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java
Modified: webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/Messages.properties
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/Messages.properties?view=diff&rev=495682&r1=495681&r2=495682
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/Messages.properties (original)
+++ webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/Messages.properties Fri Jan 12 10:41:48 2007
@@ -1,4 +1,3 @@
-#Wed Aug 16 21:49:58 EDT 2006
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'.
DeletingStaticValue=Could not delete a value for the property 'XXX' because it is static. The static value was\: XXX
InvalidMutability=The wsrmd\:Property with the path 'XXX' has an invalid mutability attribute value\: XXX. The accepted mutability values are 'constant', 'appendable', and 'mutable'.
@@ -16,3 +15,4 @@
ReadOnly=The metadata for property 'XXX' makes it read-only. It cannot be modified in any way via WS-RP SetResourceProperties.
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.
NullMetadataDescriptor=The MetadataDescriptor is null.
+NullPropertyName=The name for the wsrmd:Property is null.
Modified: webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java?view=diff&rev=495682&r1=495681&r2=495682
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java (original)
+++ webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/PropertyMetadata.java Fri Jan 12 10:41:48 2007
@@ -16,10 +16,10 @@
package org.apache.muse.ws.resource.metadata.impl;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -119,6 +119,63 @@
//
private String _valueUpperBound = null;
+ public PropertyMetadata(QName qname, int modifiability, int mutability)
+ {
+ if (qname == null)
+ throw new NullPointerException(_MESSAGES.get("NullPropertyName"));
+
+ if (modifiability != READ_ONLY && modifiability != READ_WRITE)
+ {
+ Object[] filler = { qname, new Integer(modifiability) };
+ throw new RuntimeException(_MESSAGES.get("InvalidModifiability", filler));
+ }
+
+ if (mutability != CONSTANT && mutability != APPENDABLE && mutability != MUTABLE)
+ {
+ Object[] filler = { qname, new Integer(mutability) };
+ throw new RuntimeException(_MESSAGES.get("InvalidMutability", filler));
+ }
+
+ _qname = qname;
+ _modifiability = modifiability;
+ _mutability = mutability;
+ }
+
+ public PropertyMetadata(QName qname, String modifiability, String mutability)
+ {
+ if (qname == null)
+ throw new NullPointerException(_MESSAGES.get("NullPropertyName"));
+
+ _qname = qname;
+
+ if (modifiability.equalsIgnoreCase(WsrmdConstants.READ_ONLY))
+ _modifiability = READ_ONLY;
+
+ else if (modifiability.equalsIgnoreCase(WsrmdConstants.READ_WRITE))
+ _modifiability = READ_WRITE;
+
+ else
+ {
+ Object[] filler = { _qname, modifiability };
+ throw new RuntimeException(_MESSAGES.get("InvalidModifiability", filler));
+ }
+
+ if (mutability.equalsIgnoreCase(WsrmdConstants.CONSTANT))
+ _mutability = CONSTANT;
+
+ else if (mutability.equalsIgnoreCase(WsrmdConstants.APPENDABLE))
+ _mutability = APPENDABLE;
+
+ else if (mutability.equalsIgnoreCase(WsrmdConstants.MUTABLE))
+ _mutability = MUTABLE;
+
+ else
+ {
+ Object[] filler = { _qname, mutability };
+ throw new RuntimeException(_MESSAGES.get("InvalidMutability", filler));
+ }
+ }
+
/**
*
* Creates a new metadata definition from the given XML.
@@ -173,8 +230,7 @@
//
// valid value range (optional)
//
- Element rangeXML =
- XmlUtils.getElement(property, WsrmdConstants.VALID_RANGE_QNAME);
+ Element rangeXML = XmlUtils.getElement(property, WsrmdConstants.VALID_RANGE_QNAME);
if (rangeXML != null)
{
@@ -324,7 +380,7 @@
private Collection parseElementCollection(Element property, QName qname)
{
- Collection values = new HashSet();
+ Collection values = new ArrayList();
Element valuesXML = XmlUtils.getElement(property, qname);
@@ -355,9 +411,14 @@
{
QName qname = XmlUtils.getElementQName(children[n]);
+ //
+ // 'extended metadata' is any element that isn't the
+ // RMD *Values elements
+ //
if (!qname.equals(WsrmdConstants.VALID_VALUES_QNAME) &&
!qname.equals(WsrmdConstants.VALID_RANGE_QNAME) &&
- !qname.equals(WsrmdConstants.STATIC_VALUES_QNAME))
+ !qname.equals(WsrmdConstants.STATIC_VALUES_QNAME)&&
+ !qname.equals(WsrmdConstants.INITIAL_VALUES_QNAME))
{
String value = XmlUtils.extractText(children[n]);
extended.put(qname, value);
@@ -425,6 +486,36 @@
private Collection parseValidValues(Element property)
{
return parseElementCollection(property, WsrmdConstants.VALID_VALUES_QNAME);
+ }
+
+ public void setExtendedMetadata(QName elementName, String value)
+ {
+ _extendedMetadata.put(elementName, value);
+ }
+
+ public void setInitialValues(Collection values)
+ {
+ _initialValues = new ArrayList(values);
+ }
+
+ public void setLowerBound(String value)
+ {
+ _valueLowerBound = value;
+ }
+
+ public void setStaticValues(Collection values)
+ {
+ _staticValues = new ArrayList(values);
+ }
+
+ public void setUpperBound(String value)
+ {
+ _valueUpperBound = value;
+ }
+
+ public void setValidValues(Collection values)
+ {
+ _validValues = new ArrayList(values);
}
public Element toXML()
Modified: webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java?view=diff&rev=495682&r1=495681&r2=495682
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java (original)
+++ webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/SimpleMetadataDescriptor.java Fri Jan 12 10:41:48 2007
@@ -70,6 +70,19 @@
/**
*
+ * This constructor allows users to create RMD docs programmatically,
+ * adding wsrmd:Property elements one at a time.
+ *
+ */
+ public SimpleMetadataDescriptor(String name, String wsdlLocation, QName wsdlInterface)
+ {
+ _name = name;
+ _wsdlLocation = wsdlLocation;
+ _wsdlInterface = wsdlInterface;
+ }
+
+ /**
+ *
* Creates a new RMD metadata descriptor from the given XML definition.
*
* @param xml
@@ -126,6 +139,15 @@
}
}
+ public void addProperty(QName property, String modifiability, String mutability)
+ {
+ if (hasProperty(property))
+ throw new Error();
+
+ PropertyMetadata metadata = new PropertyMetadata(property, modifiability, mutability);
+ _propertiesByQName.put(metadata.getPropertyName(), metadata);
+ }
+
public boolean canDelete(QName propertyQName)
{
//
@@ -171,6 +193,31 @@
Object[] objects = (Object[])WsrpUtils.convertToObjects(asArray, type);
return Arrays.asList(objects);
}
+
+ private Collection convertToXML(QName property, Collection values)
+ throws SoapFault
+ {
+ Object[] asArray = new Object[values.size()];
+ asArray = values.toArray(asArray);
+
+ Class type = null;
+
+ Iterator i = values.iterator();
+
+ while (type == null && i.hasNext())
+ {
+ Object next = i.next();
+
+ if (next != null)
+ type = next.getClass();
+ }
+
+ if (type == null)
+ type = String.class;
+
+ Element[] xml = WsrpUtils.convertToElements(asArray, type, property);
+ return Arrays.asList(xml);
+ }
public String getExtendedMetadata(QName propertyQName, QName elementName)
{
@@ -280,6 +327,47 @@
public boolean isValidValue(QName propertyQName, Object value)
{
return getProperty(propertyQName).isValidValue(value);
+ }
+
+ public void removeProperty(QName property)
+ {
+ _propertiesByQName.remove(property);
+ }
+
+ public void setExtendedMetadata(QName property, QName elementName, String value)
+ {
+ getProperty(property).setExtendedMetadata(elementName, value);
+ }
+
+ public void setInitialValues(QName property, Collection values)
+ throws SoapFault
+ {
+ values = convertToXML(property, values);
+ getProperty(property).setInitialValues(values);
+ }
+
+ public void setLowerBound(QName property, String value)
+ {
+ getProperty(property).setLowerBound(value);
+ }
+
+ public void setStaticValues(QName property, Collection values)
+ throws SoapFault
+ {
+ values = convertToXML(property, values);
+ getProperty(property).setStaticValues(values);
+ }
+
+ public void setUpperBound(QName property, String value)
+ {
+ getProperty(property).setUpperBound(value);
+ }
+
+ public void setValidValues(QName property, Collection values)
+ throws SoapFault
+ {
+ values = convertToXML(property, values);
+ getProperty(property).setValidValues(values);
}
public Element toXML()
Modified: webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java?view=diff&rev=495682&r1=495681&r2=495682
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java (original)
+++ webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/metadata/impl/WsrmdUtils.java Fri Jan 12 10:41:48 2007
@@ -20,6 +20,7 @@
import org.w3c.dom.Element;
import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
import org.apache.muse.ws.resource.metadata.WsrmdConstants;
/**
@@ -32,6 +33,26 @@
public class WsrmdUtils
{
+ /**
+ *
+ * This method serializes the given descriptor into XML and then wraps
+ * it in a wsrmd:Definitions element so it can be written or published
+ * as a valid WSRMD document.
+ *
+ * @param rmd
+ *
+ * @return The XML for the given MetadataDescriptor, wrapped in a
+ * wsrmd:Definitions element.
+ *
+ */
+ public static Element createMetadataDocument(MetadataDescriptor rmd)
+ {
+ Element root = XmlUtils.createElement(WsrmdConstants.DEFINITIONS_QNAME);
+ Element rmdXML = rmd.toXML();
+ root.appendChild(rmdXML);
+ return root;
+ }
+
/**
*
* @param rmd
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org