You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2016/09/12 12:31:32 UTC

svn commit: r1760348 - in /velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime: RuntimeConstants.java RuntimeInstance.java

Author: cbrisson
Date: Mon Sep 12 12:31:32 2016
New Revision: 1760348

URL: http://svn.apache.org/viewvc?rev=1760348&view=rev
Log:
add a resource.manager.instance property

Modified:
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java?rev=1760348&r1=1760347&r2=1760348&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java Mon Sep 12 12:31:32 2016
@@ -115,7 +115,16 @@ public interface RuntimeConstants
      * ----------------------------------------------------------------------
      */
 
-    /**  */
+    /**
+     * The <code>resource.manager.instance</code> property specifies an existing instance of a
+     * {@link org.apache.velocity.runtime.resource.ResourceManager} implementation to use
+     */
+    String RESOURCE_MANAGER_INSTANCE = "resource.manager.instance";
+
+    /**
+    * The <code>resource.manager.class</code> property specifies the name of the
+    * {@link org.apache.velocity.runtime.resource.ResourceManager} implementation to use.
+    */
     String RESOURCE_MANAGER_CLASS = "resource.manager.class";
 
     /**

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=1760348&r1=1760347&r2=1760348&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java Mon Sep 12 12:31:32 2016
@@ -752,9 +752,24 @@ public class RuntimeInstance implements
         /*
          * Which resource manager?
          */
+        Object inst = getProperty(RuntimeConstants.RESOURCE_MANAGER_INSTANCE);
         String rm = getString(RuntimeConstants.RESOURCE_MANAGER_CLASS);
 
-        if (rm != null && rm.length() > 0)
+        if (inst != null)
+        {
+            if (ResourceManager.class.isAssignableFrom(inst.getClass()))
+            {
+                resourceManager = (ResourceManager)inst;
+                resourceManager.initialize(this);
+            }
+            else
+            {
+                String msg = inst.getClass().getName() + " object set as resource.manager.instance is not a valid org.apache.velocity.runtime.resource.ResourceManager.";
+                log.error(msg);
+                throw new VelocityException(msg);
+            }
+        }
+        else if (rm != null && rm.length() > 0)
         {
             /*
              *  if something was specified, then make one.
@@ -795,8 +810,8 @@ public class RuntimeInstance implements
             }
 
             resourceManager = (ResourceManager) o;
-
             resourceManager.initialize(this);
+            setProperty(RESOURCE_MANAGER_INSTANCE, resourceManager);
          }
          else
          {
@@ -804,7 +819,7 @@ public class RuntimeInstance implements
              *  someone screwed up.  Lets not fool around...
              */
 
-            String err = "It appears that no class was specified as the"
+            String err = "It appears that no class or instance was specified as the"
             + " ResourceManager.  Please ensure that all configuration"
             + " information is correct.";