Something is screwed up about the list-server or SMTP forwarding...
I sent this and another mail on friday, but I did not seem to
reach the list. I got responses from the list of later emails
but never from this one.
Here it is again...
-------- Original Message --------
Subject: [PATCH] ASTReference.setValue to handle Maps
Date: Fri, 12 Jan 2001 15:39:17 +0100
From: Christoph Reck <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
The following patch enhances ASTReference.setValue to handle Maps.
There might be a more elegant way to do it (e.g. doing the instanceof
beforehand. But this way it has no performace impact if this feature
is not used (on the LHS of a #set directive).
---------------------------------------------------------------------------
---
Apache-Velocity-20010109/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
Wed Jan 3 06:27:37 2001
+++ Apache-Velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
+ Tue Jan 9 11:55:12 2001
@@ -273,9 +273,6 @@
}
}
- Object[] args = { value };
- Class[] params = { value.getClass() };
-
/*
* This catches the last phase of setting a property
* if we catch an exception we know that something
@@ -284,17 +281,36 @@
* not a method of $provider.
*/
+ String identifyer = jjtGetChild(children - 1).getFirstToken().image;
try
{
+ Object[] args = { value };
+ Class[] params = { value.getClass() };
+
Class c = result.getClass();
- Method m = c.getMethod("set" + jjtGetChild(children -
1).getFirstToken().image, params);
+ Method m = c.getMethod("set" + identifyer, params);
m.invoke(result, args);
}
catch (Exception e)
{
+ if (result instanceof Map)
+ {
+ try
+ {
+ ((Map) result).put(identifyer, value);
+ }
+ catch (Exception ex)
+ {
+ Runtime.error(new ReferenceException("reference put : template =
+" + context.getCurrentTemplateName(),
this));
+ return false;
+ }
+ }
+ else
+ {
Runtime.error(new ReferenceException("reference set : template = " +
context.getCurrentTemplateName(), this));
return false;
}
+ }
return true;
}
---------------------------------------------------------------------------
BTW. note that many files (like the CVS version of this one) have spaces
after the lines. I'm doing a `diff -wu` to suppress noise above. It would
be good to cleanup the files from this. JBuilder has an option that
strips leading spaces from the lines.
:) Christoph