UUIDSerializer.java
01 /*
02  *
03  * Licensed to the Apache Software Foundation (ASF) under one
04  * or more contributor license agreements.  See the NOTICE file
05  * distributed with this work for additional information
06  * regarding copyright ownership.  The ASF licenses this file
07  * to you under the Apache License, Version 2.0 (the
08  * "License"); you may not use this file except in compliance
09  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 package org.apache.qpid.management.wsdm.muse.serializer;
22 
23 import java.util.UUID;
24 
25 import javax.xml.namespace.QName;
26 
27 import org.apache.muse.core.serializer.Serializer;
28 import org.apache.muse.util.xml.XmlUtils;
29 import org.apache.muse.ws.addressing.soap.SoapFault;
30 import org.w3c.dom.Element;
31 
32 /**
33  * Implementation of Muse Serializer for UUID type.
34  *  
35  @author Andrea Gazzarini
36  */
37 public class UUIDSerializer implements Serializer 
38 {  
39   /**
40    * Return a UUID representation of the given xml element.
41    
42    @param xml the element to unmarshal.
43    @throws SoapFault when the unmarshalling fails.
44    */  
45   public Object fromXML(Element elementDatathrows SoapFault 
46   {
47     return UUID.fromString(elementData.getTextContent());
48   }
49 
50   /**
51    * Returns the java type associated to this class.
52    
53    @return the java type associated to this class.
54    */
55   public Class<?> getSerializableType() 
56   {
57     return UUID.class;
58   }
59 
60   /**
61    * Return an xml representation of the given UUID with the given name.
62    
63    @param object the UUID to marshal.
64    @param qname the qualified (xml) name of the object to use in xml representation.
65    @return the xml representation of the UUID.
66    @throws SoapFault when the marshalling fails.
67    */
68   public Element toXML(Object obj, QName qnamethrows SoapFault 
69   {
70     return XmlUtils.createElement(qname, String.valueOf(obj));
71   }
72 }