/** * 处理属性 * * @param propertyName 属性或类名 * @return 类元或类静态属性值 * @throws Exception 类或属性不存在时抛出 */ public Object doEvaluateProperties(String propertyName) throws Exception { String className = propertyName; Class clazz = ClassUtils.safeForName(className); Stack properties = new LinkedStack(); int index; while (clazz == null && (index = className.lastIndexOf('.')) != -1) { properties.push(className.substring(index + 1)); className = className.substring(0, index); clazz = ClassUtils.safeForName(className); } Assert.assertNotNull(clazz, "不存在类:{0}", new Object[] {propertyName}); Object result = convertResult(clazz); while (!properties.isEmpty()) { result = dotBinaryOperatorHandler.doEvaluate(result, properties.pop()); } return result; }
public FunctionMatcher(String beanAndFunction) { int i = beanAndFunction.lastIndexOf('.'); Assert.assertTrue(i > -1 && i < beanAndFunction.length(), "FunctionMatcher.format.error"); function = beanAndFunction.substring(i + 1); String beanName = beanAndFunction.substring(0, i); try { bean = ClassUtils.forName(beanName); } catch (ClassNotFoundException e) { Assert.fail("FunctionMatcher.type.error", new Object[] {beanName, e.getMessage()}); } }
/** * 处理函数 * * @param function 函数 * @return 函数值 * @throws Exception 类或属性不存在时抛出 */ public Object doEvaluateFunction(Function function) throws Exception { String name = function.getName(); int index = name.lastIndexOf('.'); Assert.assertTrue(index != -1, "不存在类:{0}", new Object[] {name}); String propertyName = name.substring(0, index); // 最点号前的作为类名或静态属性名 String className = propertyName; Function callFunction = new Function(name.substring(index + 1), function.getArgument()); // 将点号最后一截作为静态函数名 Class clazz = ClassUtils.safeForName(className); Stack properties = new LinkedStack(); while (clazz == null && (index = className.lastIndexOf('.')) != -1) { properties.push(className.substring(index + 1)); className = className.substring(0, index); clazz = ClassUtils.safeForName(className); } Assert.assertNotNull(clazz, "不存在类:{0}", new Object[] {propertyName}); Object result = convertResult(clazz); while (!properties.isEmpty()) { result = dotBinaryOperatorHandler.doEvaluate(result, properties.pop()); } return dotBinaryOperatorHandler.doEvaluate(result, callFunction); }