KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > jmx > adaptor > AttributeDeser


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 // $Id: AttributeDeser.java,v 1.5.6.1 2005/03/02 14:19:54 tdiesler Exp $
9

10 package org.jboss.net.jmx.adaptor;
11
12 import org.jboss.axis.encoding.DeserializationContext;
13 import org.jboss.axis.encoding.Deserializer;
14 import org.jboss.axis.encoding.DeserializerImpl;
15 import org.jboss.axis.encoding.Target;
16 import org.jboss.axis.encoding.TypeMapping;
17 import org.jboss.axis.message.SOAPHandler;
18 import org.xml.sax.Attributes JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20
21 import javax.management.Attribute JavaDoc;
22 import javax.xml.namespace.QName JavaDoc;
23
24 /**
25  * An <code>AttributeDeser</code> is be used to deserialize
26  * Attribute objects using the <code>SOAP-ENC</code>
27  * encoding style.<p>
28  * @since 26.04.03
29  * @author <a HREF="mailto:a_taherkordi@users.sourceforge.net">Alireza Taherkordi</a>
30  * @author <a HREF="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>
31  * @version $Revision: 1.5.6.1 $
32  */

33 public class AttributeDeser extends DeserializerImpl
34 {
35
36    //
37
// Attributes
38
//
39

40    protected String JavaDoc attributeName;
41    protected Object JavaDoc attributeValue;
42    protected QName JavaDoc xmlType;
43
44    //
45
// Constructors
46
//
47

48    public AttributeDeser(Class JavaDoc javaClass, QName JavaDoc xmlType)
49    {
50       this.xmlType = xmlType;
51    }
52
53    /** we can already defer the attribute name */
54    public void onStartElement(String JavaDoc namespace,
55                               String JavaDoc localName,
56                               String JavaDoc qName,
57                               Attributes JavaDoc attributes,
58                               DeserializationContext context)
59            throws SAXException JavaDoc
60    {
61       attributeName = attributes.getValue("", "name");
62    }
63
64    /** dispatch to the deserializer for the value element */
65    public SOAPHandler onStartChild(String JavaDoc namespace,
66                                    String JavaDoc localName,
67                                    String JavaDoc prefix,
68                                    Attributes JavaDoc attributes,
69                                    DeserializationContext context)
70            throws SAXException JavaDoc
71    {
72       if (localName.equals("value") && namespace.equals(""))
73       {
74          QName JavaDoc qn =
75                  context.getTypeFromAttributes(namespace, localName, attributes);
76          // get the deserializer
77
Deserializer dSer = context.getDeserializerForType(qn);
78          // If no deserializer, use the base DeserializerImpl.
79
// There may not be enough information yet to choose the
80
// specific deserializer.
81
if (dSer == null)
82          {
83             dSer = new DeserializerImpl();
84             // determine a default type for this child element
85
TypeMapping tm = context.getTypeMapping();
86             dSer.setDefaultType(tm.getTypeQName(Object JavaDoc.class));
87             dSer.registerValueTarget(new AttributeValueTarget());
88          }
89          return (SOAPHandler)dSer;
90       }
91       else
92       {
93          return null;
94       }
95    }
96
97    /**
98     * Append any characters to the value. This method is defined by
99     * Deserializer.
100     */

101    public void onEndElement(String JavaDoc namespace,
102                             String JavaDoc localName,
103                             DeserializationContext context)
104            throws SAXException JavaDoc
105    {
106       if (isNil)
107       {
108          value = null;
109          return;
110       }
111
112       value = new Attribute JavaDoc(attributeName, attributeValue);
113    }
114
115    //
116
// Inner classes
117
//
118

119    protected class AttributeValueTarget implements Target
120    {
121       public void set(Object JavaDoc value) throws SAXException JavaDoc
122       {
123          attributeValue = value;
124       }
125    }
126
127 }
128
Popular Tags