Deals with the new micro Oracle; handles remote schemas and tagproceesors via URLs.

valetto [2001-11-14 04:43:55]
Deals with the new micro Oracle; handles remote schemas and tagproceesors via URLs.
Also, substantially cleaned up code.
Filename
MPUtil.java
ParserThread.java
SienaListenerThread.java
SienaTest.java
SubParser.java
gwExample.xml
gwExample2.xml
diff --git a/MPUtil.java b/MPUtil.java
index 9be604d..367f1b0 100644
--- a/MPUtil.java
+++ b/MPUtil.java
@@ -4,6 +4,9 @@ import java.text.DateFormat;
 import java.util.*;
 import java.io.*;
 import java.net.URL;
+import java.net.MalformedURLException;
+import java.net.HttpURLConnection;
+import siena.*;

 // import oracle.xml.parser.schema.*;
 // import oracle.xml.parser.v2.*;
@@ -13,7 +16,11 @@ import org.xml.sax.helpers.*;
 /** Various static utility methods for metaparser.
   *
   * $Log$
-  * Revision 2.5  2001-04-18 19:49:50  png3
+  * Revision 2.6  2001-11-14 04:43:55  valetto
+  * Deals with the new micro Oracle; handles remote schemas and tagproceesors via URLs.
+  * Also, substantially cleaned up code.
+  *
+  * Revision 2.5  2001/04/18 19:49:50  png3
   * modified synchronization method for worklet arrival.  I thought incorrectly
   * that wait()-ing on an object released _all_ of its locks
   *
@@ -51,69 +58,17 @@ class MPUtil {
     return ("(" + l.getLineNumber() + ":"
     	+ l.getColumnNumber() + ")");
   }
+
+  public static String extractModuleNameFromEvent (Notification n) {
+  		AttributeValue attr = n.getAttribute("TPModule");
+  		return attr.stringValue();
+	}

-  /** pulls module name out of oracle response XML */
-  // TODO: integrate with other logging...
-  public static String extractModuleName(String s) {
-    final String fn = "MPU_extractModuleName: ";
-    final String startTag = "<module";
-    final String endTok = "</module>";
-    int startIdx = s.indexOf(startTag);
-    startIdx = s.indexOf(">", startIdx);
-    int endIdx = s.indexOf(endTok, startIdx);
-    String result = s.substring(startIdx + 1, endIdx);
-    System.err.println(fn+"Expected Module Name:\n" + result);
-    return result;
-  }
-
-  /** pulls subschema out of oracle response XML */
-  // TODO: integrate with other logging...
-  public static void extractSchema(String s) {
-    final String fn = "MPU_extractSchema: ";
-    final String startTag = "<subschema>";
-    final String endTag = "</subschema>";
-    int startIdx = s.indexOf(startTag)+startTag.length();
-    int endIdx = s.indexOf(endTag, startIdx);
-    String result = s.substring(startIdx, endIdx);
-    System.err.println(fn+"extracted schema String:\n" + result);
-
-    // StringReader sr = new StringReader(result);
-    // XMLSchema schema = null;
-    try {
-      FileWriter schema = new FileWriter("schema.xsd");
-      schema.write(result);
-      schema.close();
-      // URL base = new URL("http://www.w3.org/1999/XMLSchema-instance");
-      // XSDBuilder b = new XSDBuilder();
-      // schema = (XMLSchema)b.build(sr, base);
-    } catch (Exception e) {
-      System.err.println(fn+"error while building schema");
-      System.err.println(e);
-      return;
-    }
-  }
-
-  // got this from Oracle, but I think it's been superseded
-  // by the built-in toURL() method of File
-  /*
-  static URL fileToURL(String fname) {
-
-    File file = new File(fname);
-
-    String path = file.getAbsolutePath();
-    String fSep = System.getProperty("file.separator");
-
-    if ((fSep != null) && (fSep.length() == 1)) {
-      path = path.replace(fSep.charAt(0), '/');
-    }
-    if ((path.length() > 0) && (path.charAt(0) != '/')) {
-      path = '/' + path;
-    }
-    try {
-      return new URL("file", null, path);
-    } catch (java.net.MalformedURLException e) {
-      throw new Error("unexpected MalformedURLException");
-    }
-  }
-  */
+	public static String extractSchemaURLFromEvent (Notification n) {
+		String schemaURLValue;
+		AttributeValue attr = n.getAttribute("Value");
+    	schemaURLValue = attr.stringValue();
+    	return schemaURLValue;
+	}
+
 }
diff --git a/ParserThread.java b/ParserThread.java
index 6384174..24d5c9d 100644
--- a/ParserThread.java
+++ b/ParserThread.java
@@ -1,13 +1,9 @@
 package psl.metaparser;

-// import oracle.xml.parser.schema.*;
-// import oracle.xml.parser.v2.*;
 import org.xml.sax.*;
 import org.xml.sax.helpers.*;
 import org.apache.xerces.parsers.*;

-// import psl.worklets2.wvm.*;
-// import psl.worklets2.worklets.*;
 import psl.worklets.*;
 import psl.codetransfer.*;
 import psl.kx.*;
@@ -24,7 +20,11 @@ import psl.tagprocessor.TagProcessor;
   * Spawns Validators/SubParsers to validate subcomponents.
   *
   * $Log$
-  * Revision 2.12  2001-06-02 19:35:33  png3
+  * Revision 2.13  2001-11-14 04:43:55  valetto
+  * Deals with the new micro Oracle; handles remote schemas and tagproceesors via URLs.
+  * Also, substantially cleaned up code.
+  *
+  * Revision 2.12  2001/06/02 19:35:33  png3
   * various pre-demo tweaks
   *
   * Revision 2.11  2001/04/18 20:12:29  png3
@@ -74,16 +74,12 @@ class ParserThread extends DefaultHandler
   boolean debug = false;
   int depth = 0;

-  // Demo temp
-  // WVM wvm = null;
   String moduleName = null;

-  // for SmartEventSchema
-  // XMLSchema se = null;
-
   Stack valStack = null;
   Validator currentVal = null;
   boolean spawnParser = false;
+  String currentHint = null;

   private final String source = "psl.metaparser.ParserThread";
   String requestID = null;
@@ -122,24 +118,9 @@ class ParserThread extends DefaultHandler
     }

     valStack = new Stack();
-    /*
-    String seSchema = Metaparser.getSESchema();
-    if (debug) dbg.println(fn+"reading in schema " + seSchema); // debug
-    try {
-      File f = new File(seSchema);
-      URL seURL = f.toURL();
-      XSDBuilder b = new XSDBuilder();
-      se = (XMLSchema)b.build(seURL);
-    } catch (Exception e) {
-      log.println(fn+"error while building schema");
-      log.println(e);
-      return;
-    }
-    */
-
+
     Hashtable ht = new Hashtable();
     SAXParser p = new SAXParser();
-    // p.setValidationMode(XMLParser.NONVALIDATING);
     p.setContentHandler(this);
     p.setErrorHandler(this);
     try {
@@ -170,39 +151,14 @@ class ParserThread extends DefaultHandler
       if (moduleName != null) {

 	prDbg(fn+"module "+moduleName+" should be coming");  // debug
-	// DemoTemp
-	prDbg(fn+"waiting for worklet arrival:" + MPUtil.timestamp());
-	Thread.currentThread().sleep(1000);
-	prDbg(fn+"worklet arrived:" + MPUtil.timestamp());
-
-	/*
-        synchronized (_wklArrivals) {
-	  if (_wklArrivals.containsKey(requestID)) {
-	    prDbg(fn+"worklet had already arrived:"+
-	    	(Date)_wklArrivals.get(requestID));
-	  } else {
-	    // Object lockObj = new Object();
-	    //_wklArrivals.put(requestID, lockObj);
-	    prDbg(fn+"waiting for worklet arrival:" + MPUtil.timestamp());
-	    Date d = null;
-	    while (true) {
-	      _wklArrivals.wait();
-	      d = (Date) _wklArrivals.get(requestID);
-	      if (d != null) break;
-	    }
-	    prDbg(fn+"worklet arrived:" + d);
-	  }
-	}
-	*/
-
+
 	try {
 	// Let Simin work his magic
-	  URL[] jarPath = new URL[]{new URL("file://"+moduleName)};
-	  URLClassLoader loader = new URLClassLoader(jarPath);
+	  URL[] jarPath = new URL[]{new URL(moduleName)};
+	  URLClassLoader loader = new URLClassLoader(jarPath); // this can remote tagprocessor modules
 	  Class cls = Class.forName
 	      ("psl.tagprocessor.TagProcessorImpl", true, loader);
-
-	  // System.out.println("Working with " + xmlDoc);
+
 	  XMLReader reader = XMLReaderFactory.createXMLReader
 	  ("org.apache.xerces.parsers.SAXParser");
 	  try {
@@ -217,9 +173,14 @@ class ParserThread extends DefaultHandler
 	    return;
 	  }
 	  TagProcessor tp = (TagProcessor) cls.newInstance();
-	  //tp.setJarPath("file:");
-	  //tp.setResource(jarPath[0].getPath());
-	  tp.setResource(moduleName);
+
+	  /* PEPPO: this requires that a .jar is downloaded locally
+	     and accessed via filename
+	  */
+	  //tp.setResource(moduleName);
+
+	  /* PEPPO new - attempts to use remote .jar via its URL */
+	  tp.setResource(new URL(moduleName));
 	  tp.init(ht);
 	  reader.setContentHandler(tp.getContentHandler());
 	  dbg.println(fn+"TagProcessor about to parse");
@@ -251,10 +212,6 @@ class ParserThread extends DefaultHandler
       e.printStackTrace();
       return;
     }
-    prDbg(fn+"shutting down wvm");
-    // don't shutdown if Demo temp
-    // wvm.shutdown();
-
     if (debug) dbg.println(fn+"Done parsing");
   }

@@ -285,7 +242,7 @@ class ParserThread extends DefaultHandler
             throws SAXException {

     final String fn = "PT_startElement: ";
-    String oracleResp = null;
+    Notification oracleResp = null;

     prDbg(fn+MPUtil.printLoc(loc) + ":" + qName);
     for (int i = 0; i < atts.getLength(); i++) {
@@ -302,12 +259,6 @@ class ParserThread extends DefaultHandler
       // retrieve subparser
       requestID = String.valueOf(System.currentTimeMillis());

-      // Demo temp
-      // prDbg(fn+"creating new WVM("+slt.hostname+","+requestID+")");
-      System.out.println("WVM created");
-      // Demo temp
-      // wvm = new WVM(this, slt.hostname, requestID);
-
       Notification n = new Notification();
       n.putAttribute("Hostname", slt.hostname);
       n.putAttribute("Source", source);
@@ -316,14 +267,11 @@ class ParserThread extends DefaultHandler
       // changed to MPQuery for Oracle compatibility
       n.putAttribute("Type", "MPQuery");
       n.putAttribute("MPQuery", MPUtil.makeQuery(qName));
+      // PEPPO: added to send pre-selected hint to Oracle about what tag processor to use
+      if (currentHint != null)
+      	n.putAttribute("useHint", currentHint);
       prDbg(fn+"sending request to Oracle:" + n);
-      try {
-	// DemoTemp
-	prDbg(fn+"going to sleep: " + MPUtil.timestamp());
-	Thread.currentThread().sleep(1000);
-	prDbg(fn+"awake again: " + MPUtil.timestamp());
-	moduleName="tagprocessor.jar";
-      /*
+      try {
 	slt.publish(n);
 	Object lockObj = new Object();
 	Metaparser.waitList.put(requestID, lockObj);
@@ -332,23 +280,22 @@ class ParserThread extends DefaultHandler
 	  lockObj.wait();
 	}
 	prDbg(fn+"awake again: " + MPUtil.timestamp());
-	// hash entry now has the XML string
-	oracleResp = (String)Metaparser.waitList.get(requestID);
-	prDbg(fn+"retrieved OResp of:"+oracleResp);
-	// XMLSchema subSchema = MPUtil.extractSchema(oracleResp);
-	MPUtil.extractSchema(oracleResp);
-	moduleName = MPUtil.extractModuleName(oracleResp);
-	*/
+	// hash entry now has the Event returned by the Oracle
+	oracleResp = (Notification)Metaparser.waitList.get(requestID);
+	prDbg(fn+"retrieved OResp of:"+oracleResp.toString());
+	String schemaURL = MPUtil.extractSchemaURLFromEvent(oracleResp);
+	moduleName = MPUtil.extractModuleNameFromEvent(oracleResp);

 	// we have a new schema.  parse it out, suck it in...
 	currentVal = new Validator(xml, new PipedWriter(),
 	  "SubValid" + instNr, debug, loc);
 	currentVal.send("<?xml version='1.0' encoding='UTF-8'?>");
-	// mega-hack -- defies description
-	// extracted XML is sitting in file schema.xsd
+	/* PEPPO: uses the URL of the schema to specify to the validator
+	   the schema into the fabricated xml header
+	*/
 	currentVal.send("<"+qName+
 		" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
-  		" xsi:noNamespaceSchemaLocation='schema.xsd'>");
+  		" xsi:noNamespaceSchemaLocation='" + schemaURL +"'>");
       } catch (Exception e) {
 	prLog(fn+"Exception with Oracle communication: " + e);
 	e.printStackTrace();
@@ -359,6 +306,7 @@ class ParserThread extends DefaultHandler
       currentVal.setDepth(depth);
       currentVal.setElement(qName);
       spawnParser = false;
+      currentHint = null;
     }

     // finally, spit out this tag
@@ -422,6 +370,7 @@ class ParserThread extends DefaultHandler

   public void processingInstruction(String target, String data)
           throws SAXException {
+
     final String fn = "PT PI: ";
     prDbg(fn+"ProcessingInstruction:" + target + " " + data);
     if (target.toLowerCase().equals("flexml")) {
@@ -448,6 +397,13 @@ class ParserThread extends DefaultHandler
 	      --depth;
 	    }
 	  }
+	  else if (piaName.toLowerCase().equals("microhint")){
+	  	currentHint = piaVal.toLowerCase();
+	  	++depth;
+	    prDbg(fn+"*** found Oracle hint: " + currentHint + " ***");
+	    --depth;
+	}
+
 	}
       }
       depth -= 2;
diff --git a/SienaListenerThread.java b/SienaListenerThread.java
index 1c2cb60..de110d4 100644
--- a/SienaListenerThread.java
+++ b/SienaListenerThread.java
@@ -10,7 +10,11 @@ import siena.*;
   * Spawns ParserThreads.
   *
   * $Log$
-  * Revision 2.6  2001-06-02 19:35:33  png3
+  * Revision 2.7  2001-11-14 04:43:55  valetto
+  * Deals with the new micro Oracle; handles remote schemas and tagproceesors via URLs.
+  * Also, substantially cleaned up code.
+  *
+  * Revision 2.6  2001/06/02 19:35:33  png3
   * various pre-demo tweaks
   *
   * Revision 2.5  2001/03/14 08:17:13  png3
@@ -167,7 +171,6 @@ class SienaListenerThread implements Runnable {

   public void handleOracleNotification(Notification n) {
     String reqID = null;
-    String oracleResp = null;
     final String fn="hON: ";

     prDbg(fn+"got Oracle notification" + n);
@@ -176,13 +179,11 @@ class SienaListenerThread implements Runnable {
     // TODO: check for not found
     AttributeValue se = n.getAttribute("MPRequestID");
     reqID = se.stringValue();
-    se = n.getAttribute("Value");
-    oracleResp = se.stringValue();

     Object o = Metaparser.waitList.get(reqID);
     // replace hash entry with oracle xml
-    prDbg(fn+"Hash replace: key="+reqID+"; val="+oracleResp);
-    Metaparser.waitList.put(reqID, oracleResp);
+    prDbg(fn+"Hash replace: key="+reqID+"; val="+n.toString());
+    Metaparser.waitList.put(reqID, n);
     prDbg(fn+"notifying...");
     synchronized(o) {
       // wakey, wakey
diff --git a/SienaTest.java b/SienaTest.java
index 90a412d..41f67af 100644
--- a/SienaTest.java
+++ b/SienaTest.java
@@ -12,7 +12,11 @@ import siena.*;
   * One argument: xml message to include.
   *
   * $Log$
-  * Revision 2.5  2001-04-18 19:49:50  png3
+  * Revision 2.6  2001-11-14 04:43:55  valetto
+  * Deals with the new micro Oracle; handles remote schemas and tagproceesors via URLs.
+  * Also, substantially cleaned up code.
+  *
+  * Revision 2.5  2001/04/18 19:49:50  png3
   * modified synchronization method for worklet arrival.  I thought incorrectly
   * that wait()-ing on an object released _all_ of its locks
   *
@@ -76,12 +80,14 @@ public class SienaTest {
     xml = sb.toString();
     System.err.println("About to parse:\n" + xml+"\n.");

-    Notification n = KXNotification.ProbeKXNotification("Biff-Probe", 666, xml);
-/*
+    Notification n = KXNotification.MetaparserInput("SienaTest", 333, 666, null,xml);
+
+    /*
     n.putAttribute("Source", "EventDistiller");
     n.putAttribute("Type", "DataToMetaParser");
     n.putAttribute("SmartEvent", xml);
-*/
+    */
+
     try {
       hd.publish(n);
     } catch (SienaException se) {
diff --git a/SubParser.java b/SubParser.java
index 1d9f17f..3e61239 100644
--- a/SubParser.java
+++ b/SubParser.java
@@ -10,7 +10,11 @@ import java.util.*;
 /** Validating subordinate parser thread.
   *
   * $Log$
-  * Revision 2.6  2001-06-02 19:35:33  png3
+  * Revision 2.7  2001-11-14 04:43:55  valetto
+  * Deals with the new micro Oracle; handles remote schemas and tagproceesors via URLs.
+  * Also, substantially cleaned up code.
+  *
+  * Revision 2.6  2001/06/02 19:35:33  png3
   * various pre-demo tweaks
   *
   * Revision 2.5  2001/02/05 06:35:16  png3
@@ -176,6 +180,7 @@ public class SubParser extends DefaultHandler implements Runnable {
   public void processingInstruction(String target, String data)
           throws SAXException {

+	String currentHint = null;
     final String fn = inst+"_SP_PI: ";

     v.prDbg(fn+"ProcessingInstruction:" + target + " " + data);
@@ -200,6 +205,13 @@ public class SubParser extends DefaultHandler implements Runnable {
 	      --depth;
 	    }
 	  }
+	  else if (piaName.toLowerCase().equals("microhint")) { // added to handle hint to micro-Oracle
+	  	currentHint = piaVal.toLowerCase();
+	  	++depth;
+	    v.prDbg(fn+"*** found Oracle hint: " + currentHint + " ***");
+	    --depth;
+	}
+
 	}
       }
       depth -= 2;
diff --git a/gwExample.xml b/gwExample.xml
new file mode 100644
index 0000000..6093671
--- /dev/null
+++ b/gwExample.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<smartevent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SmartEventSchema.xsd">
+	<tag>25</tag>
+	<source>
+		<ipAddr>128.59.23.6</ipAddr>
+		<ipPort>0</ipPort>
+	</source>
+	<time>1004547955964</time>
+	<?FleXML type="schemaFrag" name="event" version="1.0" microhint="schema"?>
+	<event>
+		<packager value="null"/>
+		<timestamp value="1004547955854"/>
+		<parameters>
+			<callback type="before"/>
+			<object value="edu.isi.dasher.service.SystemJobPool@ec436"/>
+			<class name="edu.isi.dasher.service.SystemJobPool"/>
+			<method name="jobReported(JobReportEvent)"/>
+			<parameters>
+				<param type="edu.isi.dasher.service.event.JobStatusEvent" value="Wed Oct 31 12:05:55 EST 2001"/>
+				<SERVICE_DYNAMICS>
+					<Service>SearchEngineWrapper(JobNumber=128.59.23.6:1004547955824)</Service>
+					<Status>Running</Status>
+					<Progress>66</Progress>
+				</SERVICE_DYNAMICS>
+			</parameters>
+		</parameters>
+	</event>
+</smartevent>
diff --git a/gwExample2.xml b/gwExample2.xml
new file mode 100644
index 0000000..8072eb9
--- /dev/null
+++ b/gwExample2.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<smartevent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SmartEventSchema.xsd">
+	<tag>25</tag>
+	<source>
+		<ipAddr>128.59.23.6</ipAddr>
+		<ipPort>0</ipPort>
+	</source>
+	<time>1004547955964</time>
+	<?FleXML type="schemaFrag" name="event" version="1.0" microhint="schema"?>
+	<event>
+		<packager value="null"/>
+		<timestamp value="1004547955854"/>
+		<parameters>
+			<callback type="before"/>
+			<object value="edu.isi.dasher.service.SystemJobPool@ec436"/>
+			<class name="edu.isi.dasher.service.SystemJobPool"/>
+			<method name="jobReported(JobReportEvent)"/>
+			<parameters>
+				<param type="edu.isi.dasher.service.event.JobStatusEvent" value="Wed Oct 31 12:05:55 EST 2001"/>
+				<SERVICE_DYNAMICS>
+					<Service>SearchEngineWrapper(JobNumber=128.59.23.6:1004547955824)</Service>
+					<Status>Fooling around</Status>
+					<Progress>66</Progress>
+				</SERVICE_DYNAMICS>
+			</parameters>
+		</parameters>
+	</event>
+</smartevent>