package axis_parse;

import java.io.*;
import javax.xml.namespace.QName;
import org.apache.axis.message.*;
import org.apache.axis.*;
import org.apache.axis.server.AxisServer;
import org.apache.*;
import org.apache.axis.message.*;
import org.apache.axis.encoding.*;
import org.xml.sax.InputSource;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class test {
  public test(){
  }

     public static void main(String[] args) {
       try{
         String filename = "D:/honghong/jb_projects/axis_parse/e2.xml";
         InputStream in = new java.io.FileInputStream(filename);
         test t = new test();
         Object result = t.deserializeFromInputStream(in, new QName("http://www.opengis.net/xls",""), Class.forName("axis_parse.XLS"));
System.out.println(result.getClass().getName());
       }catch(Exception e){
System.out.println("******* exception: "+e.getMessage());
       }
     }

  public static Object deserializeFromInputStream(InputStream is, QName
qname, Class clazz) throws Exception, AxisFault {

    // Wrap the InputStream up into a SOAP Body and Envelope since the parser
    // expects a SOAP Envelope
    SOAPEnvelope env1 = new SOAPEnvelope();
    env1.addBodyElement(new SOAPBodyElement(is));

    return deserializeFromSOAPReader(new BufferedReader(new StringReader(env1.toString())),
                                              qname,
                                              clazz);
  }

  public static Object deserializeFromSOAPReader(Reader reader, QName
qname, Class clazz) throws Exception, AxisFault {

    MessageContext msgContext = new MessageContext(new AxisServer());

    DeserializationContext dser = new DeserializationContextImpl(
        new InputSource(reader), msgContext,
org.apache.axis.Message.REQUEST);

    // parse the InputSource
    dser.parse();

    SOAPEnvelope env = dser.getEnvelope();
    RPCElement rpcElem = (RPCElement)env.getFirstBody();
    Object result = rpcElem.getValueAsType(qname, clazz);
    return result;
  }

}