package WebFlow.GatewayTest; import WebFlow.*; import WebFlow.submitJob.*; import org.w3c.dom.*; import com.ibm.xml.parser.Parser; import com.ibm.xml.parser.TXDocument; import java.io.FileInputStream; import java.io.PrintWriter; import java.io.File; import java.util.Vector; public class XmlServerImpl extends BeanContextChildSupport implements WebFlow.GatewayTest.XmlServerOperations { String msg_; org.omg.CORBA.Object peer; private Parser parser; private Document doc; public XmlServerImpl(org.omg.CORBA.Object peer, String msg) throws WebFlow.NullPointerException { super(peer); this.peer = peer; msg_ = msg; } public void test() { System.out.println("XmlServer is up"); } public boolean instantiateParser(String FileName) { boolean status = false; try { File infile = new File(FileName); if(infile.exists()) { FileInputStream is = new FileInputStream(FileName); parser = new Parser(FileName); doc = parser.readStream(is); if(parser.getNumberOfErrors() > 0) { System.out.println("Sorry, the xml document has errors"); //System.exit(1); } else { status = true; } } else { System.out.println("Sorry, file "+FileName+" does not exist"); } } catch (Exception e) { System.out.println(e); e.printStackTrace(); } return status; } public void printXML(){ try { ((TXDocument)doc).print(new PrintWriter(System.out)); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } } public void testDOM(){ try { Node root=doc.getDocumentElement(); System.out.println("document: "+root.getNodeName()); printAllTags(root); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } } public String[] getInstalledHosts() { String[] hosts=null; try { Node root=doc.getDocumentElement(); String ApplicationName = ((Element)root).getAttribute("id"); System.out.println("Application Name: "+ApplicationName); Vector tags = getAllTags(root,"target"); int n = tags.size(); int k = 0; for (int i=0; i Node ch1 = findFirstTag(ch,"installed"); // executable or a script to be generated? Node Snode = findFirstTag(ch1,"script"); if(Snode == null) { // construct RSL rsl=""; for(Node ch2 = ch1.getFirstChild(); ch2!=null; ch2 = ch2.getNextSibling()) { if(ch2 instanceof Element) { rsl += ch2.getNodeName()+"="; rsl +=((Element)ch2).getAttribute("file_id")+"; "; } } } else { // there is a script to be generated Node Mnode = findFirstTag(Snode,"module"); if(Mnode != null) { rsl = "script:"; rsl += " name="+((Element)Mnode).getAttribute("name"); rsl += " idl="+((Element)Mnode).getAttribute("idl"); rsl += " class="+((Element)Mnode).getAttribute("class"); } else { System.out.println("something fishy... no module tag"); } } } else { System.out.println("Sorry, this application is not installed " +" on "+hostname); } } } catch (Exception e) { System.out.println(e); e.printStackTrace(); } return rsl; } public String getInstallRSL(String hostname) { String rsl="not ready yet"; return rsl; } private String getAttributeValue(Node node, String tag, String name) { String value=""; for(Node ch = node.getFirstChild(); ch!=null; ch = ch.getNextSibling()) { if(ch instanceof Element) { if(ch.getNodeName().equals(tag)) { value=((Element)ch).getAttribute(name); break; } } } return value; } private Node findFirstTag(Node node, String tag) { Node result=null; for(Node ch = node.getFirstChild(); ch!=null; ch = ch.getNextSibling()) { if(ch instanceof Element) { if(ch.getNodeName().equals(tag)) { result=ch; break; } } } return result; } private Vector getAllTags(Node node, String tag) { Vector result=new Vector(); for(Node ch = node.getFirstChild(); ch!=null; ch = ch.getNextSibling()) { if(ch instanceof Element) { if(ch.getNodeName().equals(tag)) { result.addElement(ch); } } } return result; } private Node findTagWithAttribute(Node node, String tag, String attr, String value) { Node result=null; for(Node ch = node.getFirstChild(); ch!=null; ch = ch.getNextSibling()) { if(ch instanceof Element) { if(ch.getNodeName().equals(tag)) { if( ((Element)ch).getAttribute(attr).equals(value)){ result=ch; break; } } } } return result; } private static void printAllTags(Node node){ for(Node ch = node.getFirstChild(); ch!=null; ch = ch.getNextSibling()) { if(ch instanceof Element) { System.out.println(ch.getNodeName()); NamedNodeMap nnm = ch.getAttributes(); for(int i=0;i