@Override public Result<Object> execute(final String name, Object... args) throws ExtractException { String[] prefixes = new String[]{ "get", "is", "has" }; Set<Method> methods = getAllMethods(context.getClass(), methodMatcher(equalToIgnoringCase(name), args.length)); int i = 0; while (methods.isEmpty() && i < prefixes.length) { methods = getAllMethods(context.getClass(), methodMatcher(equalToIgnoringCase(prefixes[i++] + name), args.length)); } if (methods.isEmpty()) return new Result<Object>(); else { Iterator<Method> iterator = methods.iterator(); while (iterator.hasNext()) { try { return new Result<Object>(iterator.next().invoke(context, args)); } catch (InvocationTargetException e) { throw new ExtractException(e); } catch (IllegalAccessException e) { // do nothing } } } return new Result<Object>(); } };
return new Result<Object>(iterator.next().invoke(context, args)); } catch (InvocationTargetException e) { throw new ExtractException(e); } catch (IllegalAccessException e) {
return new Result<Object>(iterator.next().invoke(context, args)); } catch (InvocationTargetException e) { throw new ExtractException(e); } catch (IllegalAccessException e) {
@Override public Result<Object> execute(final String name, Object... args) throws ExtractException { String[] prefixes = new String[]{ "get", "is", "has" }; Set<Method> methods = getAllMethods(context.getClass(), methodMatcher(equalToIgnoringCase(name), args.length)); int i = 0; while (methods.isEmpty() && i < prefixes.length) { methods = getAllMethods(context.getClass(), methodMatcher(equalToIgnoringCase(prefixes[i++] + name), args.length)); } if (methods.isEmpty()) return new Result<Object>(); else { Iterator<Method> iterator = methods.iterator(); while (iterator.hasNext()) { try { return new Result<Object>(iterator.next().invoke(context, args)); } catch (InvocationTargetException e) { throw new ExtractException(e); } catch (IllegalAccessException e) { // do nothing } } } return new Result<Object>(); } };
public Object extract (final String name, Object... parameters) throws ExtractException { List<Callable> callables = new ArrayList<Callable>(); if (parameters.length == 0) { callables.add(tryField()); } callables.add(tryMethod()); if (knownType(context)) callables.add(tryKnownType()); for (Callable callable : callables) { Result<Object> result = callable.execute(name, parameters); if (result.hasResult()) return result.getResult(); } throw new ExtractException("Unable to find field or method "+name+" in "+context); }
public Object extract (final String name, Object... parameters) throws ExtractException { List<Callable> callables = new ArrayList<Callable>(); if (parameters.length == 0) { callables.add(tryField()); } callables.add(tryMethod()); if (knownType(context)) callables.add(tryKnownType()); for (Callable callable : callables) { Result<Object> result = callable.execute(name, parameters); if (result.hasResult()) return result.getResult(); } throw new ExtractException("Unable to find field or method "+name+" in "+context); }