Revision: 2433
          http://vexi.svn.sourceforge.net/vexi/?rev=2433&view=rev
Author:   mkpg2
Date:     2007-10-11 19:45:21 -0700 (Thu, 11 Oct 2007)

Log Message:
-----------
Development.
   - redone much of org.vexi.core.Resources.java
   - http post for org.ibexj.js.Fountain.HTTP
   - reorganised tests
   

Modified Paths:
--------------
    trunk/core/org.ibex.js/src/org/ibex/js/Fountain.java
    trunk/core/org.ibex.js/src/org/ibex/js/JSFunction.java
    trunk/core/org.ibex.js/src_junit/test/js/TestJS.java
    trunk/core/org.ibex.js/src_junit/test/js/exec/TestExec.java
    trunk/core/org.ibex.js/src_junit/test/js/parse/TestParse.java

Added Paths:
-----------
    trunk/core/org.ibex.js/src_junit/org/ibex/js/TestClasses.java

Modified: trunk/core/org.ibex.js/src/org/ibex/js/Fountain.java
===================================================================
--- trunk/core/org.ibex.js/src/org/ibex/js/Fountain.java        2007-10-12 
02:45:03 UTC (rev 2432)
+++ trunk/core/org.ibex.js/src/org/ibex/js/Fountain.java        2007-10-12 
02:45:21 UTC (rev 2433)
@@ -5,6 +5,7 @@
 package org.ibex.js;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -30,6 +31,10 @@
  *   Fountain for an InputStream, and each InputStream you get back will
  *   be totally independent of the others (ie separate stream position
  *   and state) although they draw from the same data source.
+ *   
+ *   NOTES
+ *   coerceToString for at least File and HTTP returns a canonical url, 
+ *   used to construct filename when cached
  */
 public abstract class Fountain extends JS.Obj implements JS.Cloneable, 
Constants {
 
@@ -43,7 +48,7 @@
 
     // streams are "sealed" by default to prevent accidental object leakage
     private Cache getCache = new Cache(100, true);
-    
+
     public final JS get(JS key) throws JSExn {
         JS ret = (JS)getCache.get(key);
         if (ret == null) getCache.put(key, ret = _get(key));
@@ -69,11 +74,14 @@
     
     // Perform any caching (Fountain.Multi calls this on its 
     // constituent streams so that it can cache everything up
-    // front).
+    // front). REMARK - do we need this? can't we just make sure
+    // everything is cached before creating the multiple. What
+    // are the advantages of lazily caching like this
     public void cache(JS principal) throws IOException{};
 
     // Info about the stream (lastModified, contentLength, url ...)
-    public JS getInfo() throws IOException {   return new JS.Obj(); }
+    // HACK - optionally takes the stream for HTTP to avoid making two calls
+    public JS getInfo() throws IOException { return new JS.Obj();}
     
     public JS call(JS method, JS[] args) throws JSExn {
        if("info".equals(JSU.toString(method))){
@@ -104,30 +112,56 @@
     /** HTTP or HTTPS resource */
     public static class HTTP extends Fountain{
         private String url;
-        public String coerceToString() { return "HTTP:" + url; }
-        public HTTP(String url) { while (url.endsWith("/")) url = 
url.substring(0, url.length() - 1); this.url = url; }
+        private HTTPInputStream lastResponse;
+        private org.ibex.net.HTTP http(){ return new org.ibex.net.HTTP(url);}
+        public String coerceToString() { return url; }
+        public HTTP(String url) { 
+               while (url.endsWith("/")) url = url.substring(0, url.length() - 
1);
+               this.url = url;
+        }
         public JS _get(JS key) throws JSExn { return new HTTP(url + "/" + 
JSU.toString(key)); }
         public JS getInfo() throws IOException {
                JS.Obj r = new JS.Obj();
-               // FIXME FIXME - use HTTP HEAD (not HTTP head)
-               HTTPInputStream his = (HTTPInputStream) new 
org.ibex.net.HTTP(url).HEAD(null, null);
+               // FIXME - this cast can break (if stream is zipped)
+               // remember the stream (we only want it here for its properties)
+               lastResponse = (HTTPInputStream) http().GET(null, null);
                try {
-                       r.put(SC_lastModified, JSU.S(his.getLastModified()));
-                       r.put(SC_length, JSU.N(his.getLength()));
+                       r.put(SC_lastModified, 
JSU.S(lastResponse.getLastModified()));
+                       r.put(SC_length, JSU.N(lastResponse.getLength()));
                        r.put(SC_name, JSU.S(url));
                }catch(JSExn e){
                        // only supported by Java 6
                        //throw new IOException(e);
                        throw new IOException(e.getMessage());
-               } finally{
-                               his.close();
-                       }
+               }
+               return r;
+        }
+        //public String getCacheKey(Vec path) throws NotCacheableException { 
return url; }
+        public InputStream getInputStream() throws IOException { 
+               if(lastResponse!=null) 
+                       try{ return lastResponse;}
+                       finally{lastResponse=null;}
+               return http().GET(null, null); }
+        /*public InputStream getHeadInputStream() throws IOException { 
+               try{return http.HEAD(null, null);}
+               // if the server doesn't support HTTP/HEAD fallback to get
+               catch(HTTPException e){return http.GET(null, null);}
+        }*/
+        public OutputStream getOutputStream() throws IOException { 
+               // ALL WRONG
+               // HACK - we need a way to retrieve the output stream
+               // from the http post
+               ByteArrayOutputStream r = new ByteArrayOutputStream(){
+                       public void close() throws IOException {
+                               String s = new String(toByteArray());
+                               // HACK - hardcode mime type
+                               lastResponse= (HTTPInputStream) 
http().POST("test/xml", s, null, null);
+                       }
+               };
+               // we write \r \n which ends the header
+               r.write(new byte[]{13,10});
                return r;
         }
-        //public String getCacheKey(Vec path) throws NotCacheableException { 
return url; }
-        public InputStream getInputStream() throws IOException { return new 
org.ibex.net.HTTP(url).GET(null, null); }
-        public InputStream getHeadInputStream() throws IOException { return 
new org.ibex.net.HTTP(url).HEAD(null, null); }
-        
     }
 
     /** byte arrays */
@@ -144,9 +178,11 @@
     public static class File extends Fountain {
         private String path;
         private boolean writeable;
-        public File(String path) { this(path,true); }
-        public File(String path, boolean writeable) { this.path = path; 
this.writeable = writeable;}
-        public String coerceToString() { return "File:" + path; }
+        public File(String path) throws JSExn { this(path,true); }
+        public File(String path, boolean writeable) throws JSExn { 
+               try{this.path = new 
java.io.File(path).getCanonicalPath();}catch(IOException e){throw new 
JSExn(e.getMessage());} 
+               this.writeable = writeable;}
+        public String coerceToString() { return "file://"+path; }
         public String getCacheKey() throws NotCacheableException { throw new 
NotCacheableException(); /* already on disk */ }
         public InputStream getInputStream() throws IOException { 
                try{return new FileInputStream(path);
@@ -342,9 +378,7 @@
         public ProgressWatcher(JS principal, Fountain watchee) throws 
IOException, JSExn { 
                this.principal = principal; this.watchee = watchee;
                
-               JS info = getInfo();
-               //      detirmine the callback rate 
-               callbackRate = JSU.toInt(info.get(SC_length))/100;
+
                
                // get traps
                startTrap = wtrap(SC_start);
@@ -359,9 +393,14 @@
         
         public InputStream getInputStream() throws IOException {
                try{
+                       InputStream is = watchee.getInputStream();
+                       if(startTrap==null && progressTrap==null) return is;
+               JS info = getInfo();
+                       //      detirmine the callback rate 
+               callbackRate = JSU.toInt(info.get(SC_length))/100;
                        if(startTrap!=null) 
Thread.runInNew(startTrap.function(), new JS[]{info});
 
-                       return new FilterInputStream(watchee.getInputStream()) {
+                       return new FilterInputStream(is) {
                                private int bytesDownloaded = 0;
                                private int bytesSinceCallback = 0;
                                public int read() throws IOException {
@@ -400,7 +439,7 @@
         // and call functions on watchee directly like that.
         private JS info = null;
         public JS getInfo() throws IOException {
-               if(info==null)info = watchee.getInfo();
+               if(info==null) info = watchee.getInfo();
                return info;
         }
     }
@@ -430,6 +469,11 @@
     }
     */
     public Keys keys() throws JSExn {
+       return keys(this);
+    }
+    // REMARK - uses principal here. This may well get 
+    // pushed up to the JS interface itself.
+    public Keys keys(JS principal) throws JSExn {
        try {
                        final Set s = getKeyCache();
                return new Keys(this){

Modified: trunk/core/org.ibex.js/src/org/ibex/js/JSFunction.java
===================================================================
--- trunk/core/org.ibex.js/src/org/ibex/js/JSFunction.java      2007-10-12 
02:45:03 UTC (rev 2432)
+++ trunk/core/org.ibex.js/src/org/ibex/js/JSFunction.java      2007-10-12 
02:45:21 UTC (rev 2433)
@@ -130,7 +130,7 @@
     } 
 
     public String coerceToString() {
-       return "function$" + Integer.toHexString(hashCode());
+       return "function:"+definedAt()+ "$" + Integer.toHexString(hashCode());
     }
 
        /*public boolean checkEndsWell() {

Added: trunk/core/org.ibex.js/src_junit/org/ibex/js/TestClasses.java
===================================================================
--- trunk/core/org.ibex.js/src_junit/org/ibex/js/TestClasses.java               
                (rev 0)
+++ trunk/core/org.ibex.js/src_junit/org/ibex/js/TestClasses.java       
2007-10-12 02:45:21 UTC (rev 2433)
@@ -0,0 +1,14 @@
+package org.ibex.js;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import test.Util;
+
+public class TestClasses extends TestCase{
+       static public Test suite() {
+               TestSuite suite = Util.newTestSuite(TestClasses.class);
+               suite.addTest(Util.suiteJava(TestFountainKeys.class));
+               return suite;
+       }
+}


Property changes on: 
trunk/core/org.ibex.js/src_junit/org/ibex/js/TestClasses.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/core/org.ibex.js/src_junit/test/js/TestJS.java
===================================================================
--- trunk/core/org.ibex.js/src_junit/test/js/TestJS.java        2007-10-12 
02:45:03 UTC (rev 2432)
+++ trunk/core/org.ibex.js/src_junit/test/js/TestJS.java        2007-10-12 
02:45:21 UTC (rev 2433)
@@ -5,6 +5,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.ibex.js.TestClasses;
 import org.ibex.util.Log;
 
 import test.Util;
@@ -21,7 +22,8 @@
                Util.changeLogLevel(Log.WARN);
        TestSuite suite = Util.newTestSuite(TestJS.class);
        suite.addTest(TestExec.suite());
-       suite.addTestSuite(TestParse.class);
+       suite.addTest(Util.suiteJava(TestParse.class));
+       suite.addTest(TestClasses.suite());
        return suite;
     }
 }

Modified: trunk/core/org.ibex.js/src_junit/test/js/exec/TestExec.java
===================================================================
--- trunk/core/org.ibex.js/src_junit/test/js/exec/TestExec.java 2007-10-12 
02:45:03 UTC (rev 2432)
+++ trunk/core/org.ibex.js/src_junit/test/js/exec/TestExec.java 2007-10-12 
02:45:21 UTC (rev 2433)
@@ -8,7 +8,6 @@
 import org.ibex.util.Log;
 
 import test.Util;
-import test.js.parse.TestParse;
 
 public class TestExec {
        

Modified: trunk/core/org.ibex.js/src_junit/test/js/parse/TestParse.java
===================================================================
--- trunk/core/org.ibex.js/src_junit/test/js/parse/TestParse.java       
2007-10-12 02:45:03 UTC (rev 2432)
+++ trunk/core/org.ibex.js/src_junit/test/js/parse/TestParse.java       
2007-10-12 02:45:21 UTC (rev 2433)
@@ -72,7 +72,7 @@
        
        public void testUnterminatedStatement() throws Exception {
                try{
-                       JS f = parseFile("unterminated_statement.js");
+                       parseFile("unterminated_statement.js");
                }catch(JSExn e){
                        assertTrue(e.getMessage().endsWith("3"));
                }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to