Revision: 1941
          http://svn.sourceforge.net/vexi/?rev=1941&view=rev
Author:   mkpg2
Date:     2007-07-07 09:57:13 -0700 (Sat, 07 Jul 2007)

Log Message:
-----------
Fix. Parse exceptions during apply were not handled.
Made the way exceptions processing templates are handled consistent, it always 
results in throwing a JSExn.

Modified Paths:
--------------
    core/trunk/org.vexi.core/src/org/vexi/core/Blessing.java
    core/trunk/org.vexi.core/src/org/vexi/core/Template.java
    core/trunk/org.vexi.core/src/org/vexi/core/TemplateBuilder.java

Modified: core/trunk/org.vexi.core/src/org/vexi/core/Blessing.java
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/Blessing.java    2007-07-07 
16:33:41 UTC (rev 1940)
+++ core/trunk/org.vexi.core/src/org/vexi/core/Blessing.java    2007-07-07 
16:57:13 UTC (rev 1941)
@@ -91,47 +91,17 @@
         return getStatic(new Template(vexi, JSU.toString(parentkey)));
     }
     JS getStatic(Template unresolved) throws JSExn {
-        try {
-            if (t == null) {
-               // Otherwise we recurse infinitely.
-               if(initializing)
-                       throw new JSExn("Accessing template during its own 
initialization");
-               initializing = true;
-                // FEATURE: Might want to handle the ".t" part better
-                JS res = parent.get(JSU.S(JSU.toString(parentkey) + ".t"));
-                t = TemplateBuilder.build(unresolved, res);
-                initializing = false;
-            }
-            return t != null ? t.getStatic(): null;
+        if (t == null) {
+               // Otherwise we recurse infinitely.
+               if(initializing)
+                       throw new JSExn("Accessing template during its own 
initialization");
+               initializing = true;
+            // FEATURE: Might want to handle the ".t" part better
+            JS res = parent.get(JSU.S(JSU.toString(parentkey) + ".t"));
+            t = TemplateBuilder.build(unresolved, res);
+            initializing = false;
         }
-        // TODO - make it consistent. Should JSExn be thrown out in some cases
-        // and not others. Probably should either always throw a JSExn, or 
always
-        // return null. Typically there are three stages when executing a 
template file
-        // Parse -> Run Static -> Apply. If you fix an error in parse, but 
there is still
-        // an error in the other 2 stages then currently something that may be 
part working
-        // (i.e. displays, but just a ui:box for offending template) will 
appear to get
-        // worse with the fix -> i.e. nothing displays.
-        // So to make things consistent we can either
-        //  1. Always make applies catch exceptions (and just return 
ui:box's), this
-        //     will include when they are done dynamically.
-        //  2. Always make source exceptions throw JSExns (i.e. each of the 
catchs
-        //     below should ultimately throw an exception)
-        //  3. Perhaps consider dynamically applied, and applied in a template
-        //     differently. If applying in js, you can always choose to catch. 
-        //     This is not the case if the template is referenced in the XML.
-        catch(JSExn e){
-               //Log.uError("[INIT ERROR]", "JSExn thrown during execution of 
the static part");
-               //Log.uError("[INIT ERROR]", e);
-               throw e;
-        }
-        catch(SourceException e){
-               Log.uError(e.getMessageSig(), e.getWhere() + "\n- "+ 
e.getMessage());
-               Log.debug(this, e);
-        }
-        catch (Exception e) {
-            Log.error(this, e);
-        }
-        return null;
+        return t != null ? t.getStatic(): null;
     }
     
     private String description() {

Modified: core/trunk/org.vexi.core/src/org/vexi/core/Template.java
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/Template.java    2007-07-07 
16:33:41 UTC (rev 1940)
+++ core/trunk/org.vexi.core/src/org/vexi/core/Template.java    2007-07-07 
16:57:13 UTC (rev 1941)
@@ -15,8 +15,8 @@
 import org.ibex.util.Basket;
 import org.ibex.util.Tree;
 import org.ibex.util.Vec;
-import org.ibex.util.XML;
 
+
 /**
  *  Encapsulates a template node 
  *  <p>

Modified: core/trunk/org.vexi.core/src/org/vexi/core/TemplateBuilder.java
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/TemplateBuilder.java     
2007-07-07 16:33:41 UTC (rev 1940)
+++ core/trunk/org.vexi.core/src/org/vexi/core/TemplateBuilder.java     
2007-07-07 16:57:13 UTC (rev 1941)
@@ -30,7 +30,7 @@
                TemplateBuilder.instance = instance;
        }
        
-       public static Template build(Template unresolved, JS s) throws 
IOException, JSExn, XML.Exn {
+       public static Template build(Template unresolved, JS s) throws JSExn {
                if(instance==null) instance = new TemplateBuilder();
        return instance.new TemplateHelper(unresolved, s).t;
     }
@@ -39,11 +39,22 @@
         for (int i=0; nLines > i; i++) content.append('\n');
     }
        
-       static JS parseScript(StringBuffer content, int content_start,  String 
sourceName, GlobalsChecker parserParam) throws IOException {
-        if (content == null) return null;
-        String contentString = content.toString();
-        if (contentString.trim().length() > 0) return 
Parser.fromReader(sourceName, content_start, new StringReader(contentString), 
parserParam);
-        return null;
+       static JS parseScript(StringBuffer content, int content_start,  String 
sourceName, GlobalsChecker parserParam) throws JSExn {
+               try{
+                       if (content == null) return null;
+                       String contentString = content.toString();
+                       if (contentString.trim().length() > 0) return 
Parser.fromReader(sourceName, content_start, new StringReader(contentString), 
parserParam);
+                       return null;
+               }
+               catch(SourceException e){
+                       Log.uError(e.getMessageSig(), e.getWhere() + "\n- "+ 
e.getMessage());
+                       // FEATURE create JSExn constructor that takes a 
SourceException - 
+               // and so pass on more information as exception properties.
+               throw new JSExn("Could not parse script, " + sourceName + ":" + 
content_start);
+               }catch (Exception e) {
+                       Log.error(Template.class, e);
+                       throw new JSExn("Unexpected error when parsing, " + 
sourceName + ":" + content_start);
+               }
     }
     
     private static final int STATE_INITIAL = 0;
@@ -73,7 +84,7 @@
         CodeBlock cb = null;
         int meta = 0;
 
-        public TemplateHelper(Template unresolved, JS s) throws XML.Exn, 
IOException, JSExn {
+        public TemplateHelper(Template unresolved, JS s) throws JSExn {
                try{
                        this.unresolved = unresolved;
                        InputStream is = JSU.getInputStream(s);
@@ -94,7 +105,13 @@
                        // XML class is not aware of the name of the source,
                        // so we add it here
                        e.setSourceName(sourceName());
-                       throw e;
+                       Log.uError(e.getMessageSig(), e.getWhere() + "\n- "+ 
e.getMessage());
+                       // FEATURE create JSExn constructor that takes a 
SourceException - 
+                       // and so pass on more information as exception 
properties.
+                       throw new JSExn("Could not parse xml, " + sourceName());
+               }catch(Exception e){
+                       Log.error(TemplateHelper.class, e);
+                       throw new JSExn("Unexpected error when parsing, " + 
sourceName());
                }
         }
 


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 DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to