KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > remote > soap > encoding > SWFArrayDeserializer


1 /* *****************************************************************************
2  * SWFArrayDeserializer.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6  * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7  * Use is subject to license terms. *
8  * J_LZ_COPYRIGHT_END *********************************************************/

9
10 /*
11  * Copyright 2001-2004 The Apache Software Foundation.
12  *
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */

25
26 package org.openlaszlo.remote.soap.encoding;
27
28 import org.apache.axis.encoding.DeserializationContext;
29 import org.apache.axis.encoding.ser.ArrayDeserializer;
30 import org.apache.axis.message.SOAPHandler;
31 import org.openlaszlo.iv.flash.util.FlashBuffer;
32 import org.openlaszlo.iv.flash.api.action.Actions;
33 import org.openlaszlo.iv.flash.api.action.Program;
34 import java.util.ArrayList JavaDoc;
35 import org.apache.log4j.Logger;
36 import org.xml.sax.Attributes JavaDoc;
37 import org.xml.sax.SAXException JavaDoc;
38
39 public class SWFArrayDeserializer extends ArrayDeserializer
40 {
41     public static Logger mLogger =
42         Logger.getLogger(SWFArrayDeserializer.class);
43
44     // array item tag to use (in LFC, see valueToElement() in
45
// data/LzDataElement.as)
46
String JavaDoc mItemTag = null;
47
48     static int BUFSIZE = 8192;
49
50
51     /**
52      * onStartChild is called on each child element.
53      * @param namespace is the namespace of the child element
54      * @param localName is the local name of the child element
55      * @param prefix is the prefix used on the name of the child element
56      * @param attributes are the attributes of the child element
57      * @param context is the deserialization context.
58      * @return is a Deserializer to use to deserialize a child (must be
59      * a derived class of SOAPHandler) or null if no deserialization should
60      * be performed.
61      */

62     public SOAPHandler onStartChild(String JavaDoc namespace,
63                                     String JavaDoc localName,
64                                     String JavaDoc prefix,
65                                     Attributes JavaDoc attributes,
66                                     DeserializationContext context)
67         throws SAXException JavaDoc {
68
69         if (mItemTag == null) mItemTag = localName;
70
71         return super.onStartChild(namespace, localName, prefix, attributes, context);
72
73     }
74
75
76     /**
77      * When valueComplete() is invoked on the array,
78      * first convert the array value into the expected array.
79      * Then call super.valueComplete() to inform referents
80      * that the array value is ready.
81      **/

82     public void valueComplete() throws SAXException JavaDoc
83     {
84         if (componentsReady()) {
85             try {
86                 ArrayList JavaDoc list = (ArrayList JavaDoc)value;
87                 FlashBuffer fbuf = new FlashBuffer(BUFSIZE);
88                 int i=list.size();
89                 while (--i >= 0) {
90                     fbuf.writeFOB( ( (Program)list.get(i) ).body());
91                 }
92                 Program program = new Program(fbuf);
93                 program.push(list.size());
94                 fbuf.writeByte(Actions.InitArray);
95
96                if (mItemTag != null) {
97                    program.body().writeByte(Actions.PushDuplicate);
98                    program.push("__LZtag"); // __LZtag (array item tag)
99
program.push(mItemTag);
100                    program.body().writeByte(Actions.SetMember);
101                }
102
103                 value = program;
104             } catch (RuntimeException JavaDoc e) {
105                 // We must ignore exceptions from convert for Arrays with null - why?
106
}
107         }
108         super.valueComplete();
109     }
110 }
111
Popular Tags