Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package clojure.velocity;
- import org.apache.velocity.util.introspection.UberspectImpl;
- import org.apache.velocity.util.introspection.VelPropertyGet;
- import org.apache.velocity.util.introspection.Info;
- import org.apache.velocity.runtime.parser.node.AbstractExecutor;
- import clojure.lang.APersistentMap;
- import clojure.lang.Keyword;
- import java.lang.reflect.InvocationTargetException;
- public class ClojureUberspectImpl extends UberspectImpl {
- @Override
- public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception {
- if (obj instanceof APersistentMap) {
- final APersistentMap map = (APersistentMap)obj;
- final Keyword key = Keyword.intern(null, identifier);
- return new VelGetterImpl(new AbstractExecutor() {
- public Object execute(Object o) throws IllegalAccessException, InvocationTargetException {
- return map.get(key);
- }
- });
- } else {
- return super.getPropertyGet(obj, identifier, i);
- }
- }
- }
Add Comment
Please, Sign In to add comment