/** Constructs with a class. * @param args the map of arguments. Ignored if null.<br/> * Notice that, once assigned, the map belongs to this object, and the caller * shall not access it again * @since 3.6.1 */ public FunctionMapperInfo(Class<? extends FunctionMapper> cls, Map<String, String> args) { super(args); checkClass(cls); _mapper = cls; }
/** Constructs with a class name. * * @param clsnm the class name; it could be an EL expression. */ public FunctionMapperInfo(String clsnm, Map<String, String> args) throws ClassNotFoundException { super(args); if (clsnm == null || clsnm.length() == 0) throw new IllegalArgumentException("empty"); if (clsnm.indexOf("${") < 0) { if (clsnm.indexOf('.') >= 0) { //resolve it now try { final Class<?> cls = Classes.forNameByThread(clsnm); checkClass(cls); _mapper = cls; } catch (ClassNotFoundException ex) { throw new ClassNotFoundException("Class not found: " + clsnm, ex); } } else { //it might depend on <?import?> _mapper = clsnm; } } else { _mapper = new ExValue(clsnm, String.class); } }
/** Creates and returns the function mapper for the specified evaluator and page. * @since 3.6.2 */ public FunctionMapper newFunctionMapper(Evaluator eval, Page page) throws Exception { if (_mapper instanceof FunctionMapper) return (FunctionMapper) _mapper; String clsnm = null; if (_mapper instanceof ExValue) { clsnm = (String) ((ExValue) _mapper).getValue(eval, page); if (clsnm == null || clsnm.length() == 0) { return null; //ignore it!! } } else if (_mapper instanceof String) { clsnm = (String) _mapper; } final Class<?> cls; if (clsnm != null) { try { cls = page != null ? page.resolveClass(clsnm) : Classes.forNameByThread(clsnm); checkClass(cls); } catch (ClassNotFoundException ex) { throw new ClassNotFoundException("Class not found: " + clsnm + " (" + _mapper + ")", ex); } if (clsnm.equals(_mapper)) _mapper = cls; //cache it for better performance } else { cls = (Class<?>) _mapper; } return (FunctionMapper) newInstance(cls, eval, page); }