Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package clojure.velocity;
  2.  
  3. import org.apache.velocity.util.introspection.UberspectImpl;
  4. import org.apache.velocity.util.introspection.VelPropertyGet;
  5. import org.apache.velocity.util.introspection.Info;
  6. import org.apache.velocity.runtime.parser.node.AbstractExecutor;
  7. import clojure.lang.APersistentMap;
  8. import clojure.lang.Keyword;
  9.  
  10. import java.lang.reflect.InvocationTargetException;
  11.  
  12. public class ClojureUberspectImpl extends UberspectImpl {
  13.  
  14. @Override
  15. public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception {
  16. if (obj instanceof APersistentMap) {
  17. final APersistentMap map = (APersistentMap)obj;
  18. final Keyword key = Keyword.intern(null, identifier);
  19. return new VelGetterImpl(new AbstractExecutor() {
  20. public Object execute(Object o) throws IllegalAccessException, InvocationTargetException {
  21. return map.get(key);
  22. }
  23. });
  24. } else {
  25. return super.getPropertyGet(obj, identifier, i);
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment