package tutorial.sample31;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.rpc.JAXRPCException;


public class HelloWorldService{

  private static final String xml = "<some><valid/><xml/><data/></some>";

  public Document helloDom(){

    Document doc;

    try{
      doc = getDocument();
    }catch( SAXException e ){
      throw new JAXRPCException( "Failed to parse", e );
    }catch( ParserConfigurationException e ){
      throw new JAXRPCException( "Failed to parse", e );
    }catch( IOException e ){
      throw new JAXRPCException( "Failed to parse", e );
    }
    
    System.out.println("The dom on the server is[");
    weblogic.xml.babel.stream.DOMInputStream.printNode((Node) doc);
    System.out.println("]");

    return doc;
  }



  private Document getDocument() 
    throws SAXException, ParserConfigurationException, IOException{

      ByteArrayInputStream bis = new ByteArrayInputStream( xml.getBytes() );

      DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = fact.newDocumentBuilder();
      Document doc = db.parse(new InputSource(bis));

    return doc;
  }

}

