KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > encoding > ser > VectorDeserializer


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.encoding.ser;
57
58 import org.jboss.axis.encoding.DeserializationContext;
59 import org.jboss.axis.encoding.Deserializer;
60 import org.jboss.axis.encoding.DeserializerImpl;
61 import org.jboss.axis.encoding.DeserializerTarget;
62 import org.jboss.axis.message.SOAPHandler;
63 import org.jboss.axis.utils.Messages;
64 import org.jboss.logging.Logger;
65 import org.xml.sax.Attributes JavaDoc;
66 import org.xml.sax.SAXException JavaDoc;
67
68 import javax.xml.namespace.QName JavaDoc;
69 import java.util.Vector JavaDoc;
70
71 /**
72  * Deserializer for SOAP Vectors for compatibility with SOAP 2.2.
73  *
74  * @author Carsten Ziegeler (cziegeler@apache.org)
75  * Modified by @author Rich scheuerle <scheu@us.ibm.com>
76  */

77 public class VectorDeserializer extends DeserializerImpl
78 {
79    private static Logger log = Logger.getLogger(VectorDeserializer.class.getName());
80
81    public int curIndex = 0;
82
83    /**
84     * This method is invoked after startElement when the element requires
85     * deserialization (i.e. the element is not an href and the value is not nil.)
86     * <p/>
87     * Simply creates
88     *
89     * @param namespace is the namespace of the element
90     * @param localName is the name of the element
91     * @param prefix is the prefix of the element
92     * @param attributes are the attributes on the element...used to get the type
93     * @param context is the DeserializationContext
94     */

95    public void onStartElement(String JavaDoc namespace, String JavaDoc localName,
96                               String JavaDoc prefix, Attributes JavaDoc attributes,
97                               DeserializationContext context)
98            throws SAXException JavaDoc
99    {
100       if (log.isDebugEnabled())
101       {
102          log.debug("Enter: VectorDeserializer::startElement()");
103       }
104
105       if (context.isNil(attributes))
106       {
107          return;
108       }
109
110       // Create a vector to hold the deserialized values.
111
setValue(new java.util.Vector JavaDoc());
112
113       if (log.isDebugEnabled())
114       {
115          log.debug("Exit: VectorDeserializer::startElement()");
116       }
117    }
118
119    /**
120     * onStartChild is called on each child element.
121     *
122     * @param namespace is the namespace of the child element
123     * @param localName is the local name of the child element
124     * @param prefix is the prefix used on the name of the child element
125     * @param attributes are the attributes of the child element
126     * @param context is the deserialization context.
127     * @return is a Deserializer to use to deserialize a child (must be
128     * a derived class of SOAPHandler) or null if no deserialization should
129     * be performed.
130     */

131    public SOAPHandler onStartChild(String JavaDoc namespace,
132                                    String JavaDoc localName,
133                                    String JavaDoc prefix,
134                                    Attributes JavaDoc attributes,
135                                    DeserializationContext context)
136            throws SAXException JavaDoc
137    {
138       if (log.isDebugEnabled())
139       {
140          log.debug("Enter: VectorDeserializer::onStartChild()");
141       }
142
143       if (attributes == null)
144          throw new SAXException JavaDoc(Messages.getMessage("noType01"));
145
146       // If the xsi:nil attribute, set the value to null and return since
147
// there is nothing to deserialize.
148
if (context.isNil(attributes))
149       {
150          setChildValue(null, new Integer JavaDoc(curIndex++));
151          return null;
152       }
153
154       // Get the type
155
QName JavaDoc itemType = context.getTypeFromAttributes(namespace,
156               localName,
157               attributes);
158       // Get the deserializer
159
Deserializer dSer = null;
160       if (itemType != null)
161       {
162          dSer = context.getDeserializerForType(itemType);
163       }
164       if (dSer == null)
165       {
166          dSer = new DeserializerImpl();
167       }
168
169       // When the value is deserialized, inform us.
170
// Need to pass the index because multi-ref stuff may
171
// result in the values being deserialized in a different order.
172
dSer.registerValueTarget(new DeserializerTarget(this, new Integer JavaDoc(curIndex)));
173       curIndex++;
174
175       if (log.isDebugEnabled())
176       {
177          log.debug("Exit: VectorDeserializer::onStartChild()");
178       }
179
180       // Let the framework know that we aren't complete until this guy
181
// is complete.
182
addChildDeserializer(dSer);
183
184       return (SOAPHandler)dSer;
185    }
186
187    /**
188     * The registerValueTarget code above causes this set function to be invoked when
189     * each value is known.
190     *
191     * @param value is the value of an element
192     * @param hint is an Integer containing the index
193     */

194    public void setChildValue(Object JavaDoc value, Object JavaDoc hint) throws SAXException JavaDoc
195    {
196       if (log.isDebugEnabled())
197       {
198          log.debug(Messages.getMessage("gotValue00", "VectorDeserializer", "" + value));
199       }
200       int offset = ((Integer JavaDoc)hint).intValue();
201       Vector JavaDoc v = (Vector JavaDoc)this.value;
202
203       // If the vector is too small, grow it
204
if (offset >= v.size())
205       {
206          v.setSize(offset + 1);
207       }
208       v.setElementAt(value, offset);
209    }
210 }
211
Popular Tags