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/02/01 00:14:43 UTC

svn commit: r502035 - in /webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl: SimpleResourcePropertyCollection.java WsrpUtils.java

Author: danj
Date: Wed Jan 31 15:14:41 2007
New Revision: 502035

URL: http://svn.apache.org/viewvc?view=rev&rev=502035
Log:
Fix for MUSE-188 - two new convenience methods for serializing single objects in addition to arrays.

Modified:
    webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/SimpleResourcePropertyCollection.java
    webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/WsrpUtils.java

Modified: webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/SimpleResourcePropertyCollection.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/SimpleResourcePropertyCollection.java?view=diff&rev=502035&r1=502034&r2=502035
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/SimpleResourcePropertyCollection.java (original)
+++ webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/SimpleResourcePropertyCollection.java Wed Jan 31 15:14:41 2007
@@ -32,8 +32,10 @@
 import org.apache.muse.util.messages.MessagesFactory;
 import org.apache.muse.util.xml.XmlUtils;
 import org.apache.muse.util.xml.XsdUtils;
+import org.apache.muse.ws.addressing.soap.SoapFault;
 import org.apache.muse.ws.resource.WsResourceCapability;
 import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.ext.faults.SerializationErrorFault;
 import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
 import org.apache.muse.ws.resource.metadata.faults.MetadataValidationFault;
 import org.apache.muse.ws.resource.metadata.impl.ExternalChangeApprover;
@@ -539,7 +541,16 @@
         throws BaseFault
     {
         Element[] properties = getResourceProperty(qname);
-        return WsrpUtils.convertToObjects(properties, type);
+        
+        try
+        {
+            return WsrpUtils.convertToObjects(properties, type);
+        }
+        
+        catch (SoapFault fault)
+        {
+            throw new SerializationErrorFault(fault);
+        }
     }
     
     public synchronized Collection getPropertyNames()

Modified: webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/WsrpUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/WsrpUtils.java?view=diff&rev=502035&r1=502034&r2=502035
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/WsrpUtils.java (original)
+++ webservices/muse/trunk/modules/muse-wsrf-impl/src/org/apache/muse/ws/resource/properties/impl/WsrpUtils.java Wed Jan 31 15:14:41 2007
@@ -29,8 +29,6 @@
 import org.apache.muse.util.messages.MessagesFactory;
 import org.apache.muse.util.xml.XmlUtils;
 import org.apache.muse.ws.addressing.soap.SoapFault;
-import org.apache.muse.ws.resource.basefaults.BaseFault;
-import org.apache.muse.ws.resource.ext.faults.SerializationErrorFault;
 import org.apache.muse.ws.resource.properties.WsrpConstants;
 import org.apache.muse.ws.wsdl.WsdlUtils;
 
@@ -48,6 +46,38 @@
     // Used to lookup all exception messages
     //
     private static Messages _MESSAGES = MessagesFactory.get(WsrpUtils.class);
+
+    /**
+     * 
+     * Uses one of Muse's registered Serializers to convert the given object 
+     * into an XML element.
+     *
+     * @param property
+     *        The property value to serialize.
+     * 
+     * @param type
+     *        The type whose registered Serializer will be used to parse 
+     *        the property value.
+     * 
+     * @param qname
+     *        The QName of the XML element that will represent the 
+     *        property value.
+     * 
+     * @return The POJO representation of the given property value.
+     * 
+     * @throws SoapFault
+     *         <ul>
+     *         <li>If the value could not be serialized.</li>
+     *         </ul>
+     *
+     */
+    public static Element convertToElement(Object property, Class type, QName qname)
+        throws SoapFault
+    {
+        SerializerRegistry registry = SerializerRegistry.getInstance();
+        Serializer ser = registry.getSerializer(type);        
+        return ser.toXML(property, qname);
+    }
     
     /**
      * 
@@ -76,9 +106,7 @@
      *         </ul>
      *
      */
-    public static Element[] convertToElements(Object[] properties, 
-                                              Class type, 
-                                              QName qname)
+    public static Element[] convertToElements(Object[] properties, Class type, QName qname)
         throws SoapFault
     {
         SerializerRegistry registry = SerializerRegistry.getInstance();
@@ -93,6 +121,34 @@
 
     /**
      * 
+     * Uses one of Muse's registered Serializers to convert the given Element 
+     * into an instance of the given type.
+     *
+     * @param property
+     *        The property value to deserialize.
+     * 
+     * @param type
+     *        The type whose registered Serializer will be used to parse 
+     *        the property value.
+     * 
+     * @return The POJO representation of the given property value.
+     * 
+     * @throws SoapFault
+     *         <ul>
+     *         <li>If the value could not be deserialized.</li>
+     *         </ul>
+     *
+     */
+    public static Object convertToObject(Element property, Class type)
+        throws SoapFault
+    {
+        SerializerRegistry registry = SerializerRegistry.getInstance();
+        Serializer deser = registry.getSerializer(type);
+        return deser.fromXML(property);
+    }
+
+    /**
+     * 
      * Uses Muse's registered Serializers to convert the given Elements 
      * into instances of the given type.
      *
@@ -108,30 +164,22 @@
      *         The order of the objects will be the same as the order of the 
      *         values.
      * 
-     * @throws BaseFault
+     * @throws SoapFault
      *         <ul>
      *         <li>If any of the values could not be deserialized.</li>
      *         </ul>
      *
      */
     public static Object convertToObjects(Element[] properties, Class type)
-        throws BaseFault
+        throws SoapFault
     {
         SerializerRegistry registry = SerializerRegistry.getInstance();
         Serializer deser = registry.getSerializer(type);
         
         Object objects = Array.newInstance(type, properties.length);
         
-        try
-        {
-            for (int n = 0; n < properties.length; ++n)
-                Array.set(objects, n, deser.fromXML(properties[n]));
-        }
-        
-        catch (SoapFault fault)
-        {
-            throw new SerializationErrorFault(fault);
-        }
+        for (int n = 0; n < properties.length; ++n)
+            Array.set(objects, n, deser.fromXML(properties[n]));
         
         return objects;
     }



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