001: /* *****************************************************************************
002: * SWFArrayDeserializer.java
003: * ****************************************************************************/
004:
005: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006: * Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved. *
007: * Use is subject to license terms. *
008: * J_LZ_COPYRIGHT_END *********************************************************/
009:
010: /*
011: * Copyright 2001-2007 The Apache Software Foundation.
012: *
013: * Licensed under the Apache License, Version 2.0 (the "License");
014: * you may not use this file except in compliance with the License.
015: * You may obtain a copy of the License at
016: *
017: * http://www.apache.org/licenses/LICENSE-2.0
018: *
019: * Unless required by applicable law or agreed to in writing, software
020: * distributed under the License is distributed on an "AS IS" BASIS,
021: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
022: * See the License for the specific language governing permissions and
023: * limitations under the License.
024: */
025:
026: package org.openlaszlo.remote.swf.soap.encoding;
027:
028: import org.apache.axis.encoding.DeserializationContext;
029: import org.apache.axis.encoding.ser.ArrayDeserializer;
030: import org.apache.axis.message.SOAPHandler;
031: import org.openlaszlo.iv.flash.util.FlashBuffer;
032: import org.openlaszlo.iv.flash.api.action.Actions;
033: import org.openlaszlo.iv.flash.api.action.Program;
034: import java.util.ArrayList;
035: import org.apache.log4j.Logger;
036: import org.xml.sax.Attributes;
037: import org.xml.sax.SAXException;
038:
039: public class SWFArrayDeserializer extends ArrayDeserializer {
040: public static Logger mLogger = Logger
041: .getLogger(SWFArrayDeserializer.class);
042:
043: // array item tag to use (in LFC, see valueToElement() in
044: // data/LzDataElement.as)
045: String mItemTag = null;
046:
047: static int BUFSIZE = 8192;
048:
049: /**
050: * onStartChild is called on each child element.
051: * @param namespace is the namespace of the child element
052: * @param localName is the local name of the child element
053: * @param prefix is the prefix used on the name of the child element
054: * @param attributes are the attributes of the child element
055: * @param context is the deserialization context.
056: * @return is a Deserializer to use to deserialize a child (must be
057: * a derived class of SOAPHandler) or null if no deserialization should
058: * be performed.
059: */
060: public SOAPHandler onStartChild(String namespace, String localName,
061: String prefix, Attributes attributes,
062: DeserializationContext context) throws SAXException {
063:
064: if (mItemTag == null)
065: mItemTag = localName;
066:
067: return super .onStartChild(namespace, localName, prefix,
068: attributes, context);
069:
070: }
071:
072: /**
073: * When valueComplete() is invoked on the array,
074: * first convert the array value into the expected array.
075: * Then call super.valueComplete() to inform referents
076: * that the array value is ready.
077: **/
078: public void valueComplete() throws SAXException {
079: if (componentsReady()) {
080: try {
081: ArrayList list = (ArrayList) value;
082: FlashBuffer fbuf = new FlashBuffer(BUFSIZE);
083: int i = list.size();
084: while (--i >= 0) {
085: fbuf.writeFOB(((Program) list.get(i)).body());
086: }
087: Program program = new Program(fbuf);
088: program.push(list.size());
089: fbuf.writeByte(Actions.InitArray);
090:
091: if (mItemTag != null) {
092: program.body().writeByte(Actions.PushDuplicate);
093: program.push("__LZtag"); // __LZtag (array item tag)
094: program.push(mItemTag);
095: program.body().writeByte(Actions.SetMember);
096: }
097:
098: value = program;
099: } catch (RuntimeException e) {
100: // We must ignore exceptions from convert for Arrays with null - why?
101: }
102: }
103: super.valueComplete();
104: }
105: }
|