1 57 58 package org.apache.soap.util.xml; 59 60 import com.ibm.xmi.job.*; 61 import java.io.*; 62 import java.util.*; 63 import org.apache.soap.util.Bean; 64 import org.w3c.dom.*; 65 import org.apache.soap.rpc.SOAPContext; 66 67 72 public class XMIDeserializer implements Deserializer 73 { 74 75 static String XMIheader = "<?xml version='1.0' encoding='UTF-8'?><XMI xmi.version='1.1' timestamp='timestamp temporarily ommitted'><XMI.header><XMI.documentation><XMI.exporter>Java Object Bridge (JOB)</XMI.exporter><XMI.exporterVersion>0.9</XMI.exporterVersion></XMI.documentation></XMI.header><XMI.content>"; 76 77 static String XMIend = "</XMI.content></XMI>"; 78 79 public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src, 80 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 81 throws IllegalArgumentException 82 83 { 84 88 90 String xmlString = DOMWriter.nodeToString(src); 91 String document = XMIheader + xmlString + XMIend; 92 byte[] bytes = document.getBytes(); 93 ByteArrayInputStream bs = new ByteArrayInputStream(bytes); 94 95 com.ibm.xmi.framework.WriterFactory.setInline(true); 96 Collection objects = Job.readObjects(bs); 97 98 try{ 99 bs.close(); 100 }catch(IOException e){ 101 e.printStackTrace(System.err); 102 } 103 104 105 Iterator it = objects.iterator(); 106 107 Object o; 108 if( it.hasNext() ) 110 return new Bean((o=it.next()).getClass(), o); 111 else 112 throw new IllegalArgumentException ("Unable to unmarshall XMI-encoded " + 113 "object."); 114 115 } 116 117 } 118 | Popular Tags |