You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by wg...@apache.org on 2005/10/15 08:32:34 UTC

svn commit: r321297 - in /jakarta/velocity/core/trunk/src/java/org/apache/velocity: app/Velocity.java app/VelocityEngine.java runtime/RuntimeInstance.java runtime/RuntimeServices.java runtime/RuntimeSingleton.java

Author: wglass
Date: Fri Oct 14 23:32:31 2005
New Revision: 321297

URL: http://svn.apache.org/viewcvs?rev=321297&view=rev
Log:
Throw more user-friendly exception when init() has not been called (as opposed to arbitrary NPE's from deep in the code)

Modified:
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeSingleton.java

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java?rev=321297&r1=321296&r2=321297&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java Fri Oct 14 23:32:31 2005
@@ -207,6 +207,14 @@
         throws ParseErrorException, MethodInvocationException,
             ResourceNotFoundException, IOException
     {
+        /**
+         * Check to see the engine was initialized.
+         */
+        if (!RuntimeSingleton.isInitialized()) 
+        {
+            throw new IllegalStateException ("Cannot evaluate string as Velocity has not been initialized.");
+        }
+        
         /*
          *  first, parse - convert ParseException if thrown
          */

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java?rev=321297&r1=321296&r2=321297&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java Fri Oct 14 23:32:31 2005
@@ -241,6 +241,14 @@
         throws ParseErrorException, MethodInvocationException,
             ResourceNotFoundException, IOException
     {
+        /**
+         * Check to see the engine was initialized.
+         */
+        if (!ri.isInitialized()) 
+        {
+            throw new IllegalStateException ("Cannot evaluate string as Velocity has not been initialized.");
+        }
+        
         /*
          *  first, parse - convert ParseException if thrown
          */
@@ -284,6 +292,15 @@
         throws ParseErrorException, MethodInvocationException,
             ResourceNotFoundException,IOException
     {
+
+        /**
+         * Check to see the engine was initialized.
+         */
+        if (!ri.isInitialized()) 
+        {
+            throw new IllegalStateException ("Cannot evaluate string as Velocity has not been initialized.");
+        }
+                
         SimpleNode nodeTree = null;
 
         try
@@ -448,6 +465,14 @@
                                       Context context, Writer writer )
         throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception
     {
+        /**
+         * Check to see the engine was initialized.
+         */
+        if (!ri.isInitialized()) 
+        {
+            throw new IllegalStateException ("Cannot merge template as Velocity has not been initialized.");
+        }
+        
         Template template = ri.getTemplate(templateName, encoding);
 
         if ( template == null )
@@ -478,6 +503,14 @@
     public Template getTemplate(String name)
         throws ResourceNotFoundException, ParseErrorException, Exception
     {
+        /**
+         * Check to see the engine was initialized.
+         */
+        if (!ri.isInitialized()) 
+        {
+            throw new IllegalStateException ("Cannot get template as Velocity has not been initialized.");
+        }
+        
         return ri.getTemplate( name );
     }
 

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=321297&r1=321296&r2=321297&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java Fri Oct 14 23:32:31 2005
@@ -246,7 +246,15 @@
         }
     }
 
-
+    /**
+     * Returns true if the RuntimeInstance has been successfully initialized.
+     * @return
+     */
+    public boolean isInitialized()
+    {
+        return initialized;
+    }
+    
     /**
      *  Gets the classname for the Uberspect introspection package and
      *  instantiates an instance.

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java?rev=321297&r1=321296&r2=321297&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java Fri Oct 14 23:32:31 2005
@@ -353,4 +353,11 @@
      * implemenation.
      */
     public Introspector getIntrospector();
+    
+    /**
+     * Returns true if the RuntimeInstance has been successfully initialized.
+     * @return
+     */
+    public boolean isInitialized();
+
 }

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeSingleton.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeSingleton.java?rev=321297&r1=321296&r2=321297&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeSingleton.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeSingleton.java Fri Oct 14 23:32:31 2005
@@ -26,7 +26,6 @@
 import org.apache.velocity.exception.ResourceNotFoundException;
 import org.apache.velocity.runtime.directive.Directive;
 import org.apache.velocity.runtime.parser.ParseException;
-import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.node.SimpleNode;
 import org.apache.velocity.runtime.resource.ContentResource;
 import org.apache.velocity.util.introspection.Introspector;
@@ -106,6 +105,15 @@
         throws Exception
     {
         ri.init();
+    }
+
+    /**
+     * Returns true if the RuntimeSingleton has been successfully initialized.
+     * @return
+     */
+    public static boolean isInitialized()
+    {
+        return ri.isInitialized();
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org