KickJava   Java API By Example, From Geeks To Geeks.

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


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: ObjectInstanceDeser.java,v 1.4.8.1 2005/03/02 14:19:55 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.DeserializerTarget;
16 import org.jboss.axis.message.SOAPHandler;
17 import org.xml.sax.Attributes JavaDoc;
18 import org.xml.sax.SAXException JavaDoc;
19
20 import javax.management.ObjectInstance JavaDoc;
21 import javax.management.ObjectName JavaDoc;
22 import javax.xml.namespace.QName JavaDoc;
23
24 /**
25  * An <code>ObjectInstanceDeser</code> is be used to deserialize
26  * ObjectInstance using the <code>SOAP-ENC</code>
27  * encoding style.<p>
28  *
29  * @author <a HREF="mailto:a_taherkordi@users.sourceforge.net">Alireza Taherkordi</a>
30  * @version $Revision: 1.4.8.1 $
31  */

32 public class ObjectInstanceDeser extends DeserializerImpl
33 {
34
35    ObjectName JavaDoc objectName;
36    String JavaDoc className;
37
38    public void onStartElement(String JavaDoc namespace,
39                               String JavaDoc localName,
40                               String JavaDoc prefix,
41                               Attributes JavaDoc attributes,
42                               DeserializationContext context)
43            throws SAXException JavaDoc
44    {
45
46       if (context.isNil(attributes))
47       {
48          return;
49       }
50
51       //nothing to do
52

53    }
54
55    public SOAPHandler onStartChild(String JavaDoc namespace,
56                                    String JavaDoc localName,
57                                    String JavaDoc prefix,
58                                    Attributes JavaDoc attributes,
59                                    DeserializationContext context)
60            throws SAXException JavaDoc
61    {
62
63       // Get the type
64
QName JavaDoc itemType =
65               context.getTypeFromAttributes(namespace, localName, attributes);
66       // Get the deserializer
67
Deserializer dSer = null;
68       if (itemType != null)
69       {
70          dSer = context.getDeserializerForType(itemType);
71       }
72       if (dSer == null)
73       {
74          dSer = new DeserializerImpl();
75       }
76
77       // When the value is deserialized, inform us.
78
// Need to pass the localName as a hint
79
dSer.registerValueTarget(new DeserializerTarget(this, localName));
80
81       addChildDeserializer(dSer);
82
83       return (SOAPHandler)dSer;
84    }
85
86    public void setChildValue(Object JavaDoc value, Object JavaDoc hint) throws SAXException JavaDoc
87    {
88       if (hint.equals("className"))
89          className = (String JavaDoc)value;
90       else if (hint.equals("objectName"))
91          objectName = (ObjectName JavaDoc)value;
92
93    }
94
95    public void onEndElement(String JavaDoc s,
96                             String JavaDoc s1,
97                             DeserializationContext deserializationcontext)
98    {
99       try
100       {
101          super.value = new ObjectInstance JavaDoc(objectName, className);
102       }
103       catch (Exception JavaDoc exception)
104       {
105          exception.printStackTrace();
106       }
107    }
108
109 }
110
Popular Tags