@SuppressWarnings({"rawtypes", "unchecked"}) @Override public Object get(Object context, String name) throws EvaluationException { if (context == null) { return null; } ContextAccessor accessor = getAccessor(context); if (accessor == null) { throw new EvaluationException("No accessor for: " + context); } return accessor.get(context, name); }
public ContextAccessor<?> getAccessor(Object object) { if (object == null) { return null; } else if (!classAccessors.containsKey(object.getClass())) { ContextAccessor<?> mostSpecific = null; for (ContextAccessor<?> accessor : accessors) { if (accessor.getContextType().isAssignableFrom(object.getClass())) { if (mostSpecific == null || mostSpecific.getContextType().isAssignableFrom(accessor.getContextType())) { mostSpecific = accessor; } } } synchronized (classAccessors) { classAccessors.put( object.getClass(), mostSpecific == null ? new JavaContextAccessor() : mostSpecific); } } return classAccessors.get(object.getClass()); }