1 4 5 9 10 64 65 package org.openlaszlo.remote.soap.encoding; 66 67 import org.openlaszlo.iv.flash.api.action.Actions; 68 import org.openlaszlo.iv.flash.api.action.Program; 69 import org.openlaszlo.iv.flash.util.FlashBuffer; 70 import java.io.CharArrayWriter ; 71 import javax.xml.namespace.QName ; 72 import org.apache.axis.message.MessageElement; 73 import org.apache.axis.encoding.DeserializerImpl; 74 import org.apache.axis.encoding.DeserializationContext; 75 import org.apache.axis.message.SOAPHandler; 76 import org.apache.axis.utils.Messages; 77 import org.apache.log4j.Logger; 78 import org.xml.sax.Attributes ; 79 import org.xml.sax.SAXException ; 80 import java.math.BigInteger ; 81 import java.math.BigDecimal ; 82 83 import org.apache.axis.Message; 84 import org.apache.axis.MessageContext; 85 import javax.xml.soap.SOAPMessage ; 86 87 88 public class SWFSimpleDeserializer extends DeserializerImpl 90 { 91 public static Logger mLogger = 92 Logger.getLogger(SWFSimpleDeserializer.class); 93 94 static int BUFSIZE = 8192; 95 96 private final CharArrayWriter val = new CharArrayWriter (); 97 98 public static final Boolean TRUE = new Boolean (true); 99 public static final Boolean FALSE = new Boolean (false); 100 101 public QName xmlType; 102 public Class javaType; 103 104 public SWFSimpleDeserializer(Class javaType, QName xmlType) { 105 this.xmlType = xmlType; 106 this.javaType = javaType; 107 } 108 109 public void characters(char [] chars, int start, int end) 110 throws SAXException { 111 val.write(chars,start,end); 112 } 113 114 public void onEndElement(String namespace, String localName, 115 DeserializationContext context) 116 throws SAXException { 117 118 if ("".equals(namespace)) { 124 if ( "faultstring".equals(localName) || 125 "faultactor".equals(localName) ) { 126 value = val.toString(); 127 return; 128 } 129 } 130 131 Program program = new Program( new FlashBuffer(BUFSIZE) ); 132 133 if (isNil) { 135 program.push((Object )null); 136 value = program; 137 return; 138 } 139 140 String source = val.toString(); 141 try { 142 if ( javaType == int.class || javaType == Integer .class) { 143 program.push(Integer.parseInt(source)); 144 } else if (javaType == long.class || javaType == Long .class) { 145 int n = Long.valueOf(source).intValue(); 147 program.push(n); 148 } else if (javaType == short.class || javaType == Short .class) { 149 int n = Short.valueOf(source).intValue(); 151 program.push(n); 152 } else if (javaType == byte.class || javaType == Byte .class) { 153 int n = Byte.valueOf(source).intValue(); 155 program.push(n); 156 } else if (javaType == BigInteger .class) { 157 int n = BigInteger.valueOf(Long.parseLong(source)).intValue(); 159 program.push(n); 160 } else if (javaType == BigDecimal .class) { 161 int n = BigDecimal.valueOf(Long.parseLong(source)).intValue(); 163 program.push(n); 164 } else if (javaType == boolean.class || javaType == Boolean .class) { 165 switch (source.charAt(0)) { 166 case '0': case 'f': case 'F': 167 program.push(FALSE); 168 break; 169 case '1': case 't': case 'T': 170 program.push(TRUE); 171 break; 172 default: 173 program.push(TRUE); 174 break; 175 } 176 } else if (javaType == float.class || javaType == Float .class) { 177 if (source.equals("NaN")) { 178 program.push(Float.NaN); 179 } else if (source.equals("INF")) { 180 program.push(Float.POSITIVE_INFINITY); 181 } else if (source.equals("-INF")) { 182 program.push(Float.NEGATIVE_INFINITY); 183 } else { 184 program.push(Float.parseFloat(source)); 185 } 186 } else if (javaType == double.class || javaType == Double .class) { 187 if (source.equals("NaN")) { 188 program.push(new Double (Double.NaN)); 189 } else if (source.equals("INF")) { 190 program.push(new Double (Double.POSITIVE_INFINITY)); 191 } else if (source.equals("-INF")) { 192 program.push(new Double (Double.NEGATIVE_INFINITY)); 193 } else { 194 program.push(Double.valueOf(source)); 195 } 196 } else if (javaType == String .class) { 197 program.push(source); 199 } else { 200 mLogger.warn("treating " + javaType + " like string: " + source); 202 program.push(source); 203 } 204 } catch (Exception e) { 205 mLogger.error("Exception", e); 206 throw new SAXException (e.getMessage()); 207 } 208 209 value = program; 210 } 211 212 215 public SOAPHandler onStartChild(String namespace, String localName, 216 String prefix, Attributes attributes, 217 DeserializationContext context) 218 throws SAXException { 219 throw new SAXException (Messages.getMessage("cantHandle00", 220 "SimpleDeserializer")); 221 } 222 } 223 | Popular Tags |