public ElInstanceMethods add(ReflectMethod m) { if(!m.getName().equals(name)){ throw new IllegalArgumentException("Method name '" + m.getName() + "' must be '" + name + "'"); } if(m.getReflectedMethod().isVarArgs()){ defaultMethod = m; }else{ Integer i = m.getParameters().length; if(!methods().containsKey(i)){ methods().put(i, m); } } return this; }
@Override public void setValue(Object bean, Object value) { m.invoke(o, value); } }
public ElInstanceMethod(ReflectMethod m,Object instance) { this.m = m; this.size = m.getReflectedMethod().isVarArgs() ? VAR_ARGS : m.getParameters().length; this.instance = instance; }
protected Doc searchUp(ReflectMethod m) { Class<?> c = m.getReflectedMethod().getDeclaringClass(); for(Class<?> ic : c.getInterfaces()) { try { Method im = ic.getMethod(m.getName(), m.getReflectedMethod().getParameterTypes()); return im.getAnnotation(Doc.class); } catch (NoSuchMethodException e) { //do nothing. } } return null; }
if(rm.isGetterMethod() || rm.isSetterMethod() || rm.isSynthetic()) { continue; if(!rm.isPublic()) { continue; a = rm.getAnnotation(Managed.class); if(null != a) { String name = Strings.firstNotEmpty(a.name(), rm.getName()); String desc = Strings.firstNotEmpty(a.desc(), rm.getName()); OpenType returnType = MBeanTypes.of(rm.getReturnType(), null); operations.put(new MSignature(name, rm.getReflectedMethod()), new MOperation(oi, rm));
if(m.isPublic() && m.isStatic()) { if(annotatedOnly && !isElFriendly(m.getReflectedMethod())){ continue; String fullName = fullName(prefix, m.getName()); f = new ElStaticMethods(cls, m.getName()); funcs.put(fullName, f);
if(m.getParameters().length == 1) { this.transactional = m.isAnnotationPresent(Transactional.class); ReflectParameter p = m.getParameters()[0]; func = (e) -> m.invoke(inst, e); return; func = (e) -> m.invoke(inst, ((EntityEventWithWrapper)e).getEntity()); return; func = (e) -> invoke((EntityEventWithWrapper)e, bt, (bean) -> m.invoke(inst, bean)); return; } else if(m.getParameters().length == 2) { this.transactional = true; ReflectParameter p0 = m.getParameters()[0]; ReflectParameter p1 = m.getParameters()[1]; func = (e) -> m.invoke(inst, ((EntityEventWithWrapper)e).getEntity(), e.getTransactionStatus()); return; func = (e) -> m.invoke(inst, e, e.getTransactionStatus()); return; func = (e) -> invoke((EntityEventWithWrapper)e, bt, (bean) -> m.invoke(inst, bean, e.getTransactionStatus())); return;
if(m.getParameters().length == 0 && m.isAnnotationPresent(Destroy.class)) { try { m.invoke(bean, Arrays2.EMPTY_OBJECT_ARRAY); } catch (Throwable e) { log.warn("Error destroy bean '{}' : {}", null == bd ? bean : bd, e.getMessage(), e);
return method.invoke(object, args); ReflectParameter p = method.getParameters()[i]; cargs[i] = JsConvert.convert(args[i], p.getType(), p.getGenericType()); return method.invoke(object, cargs);
public ReflectDeleteEntityListener(Object inst, ReflectMethod m) { this.inst = inst; this.method = m; if(m.getParameters().length == 1) { this.transactional = false; ReflectParameter p = m.getParameters()[0]; if(p.getType().equals(Object.class)) { func = (e) -> m.invoke(inst, e.getId()); return; }else if(p.getType().equals(DeleteEntityEvent.class)) { func = (e) -> m.invoke(inst, e); return; } } else if(m.getParameters().length == 2) { this.transactional = true; ReflectParameter p0 = m.getParameters()[0]; ReflectParameter p1 = m.getParameters()[1]; if(p0.getType().equals(Object.class) && p1.getType().equals(TransactionStatus.class)) { func = (e) -> m.invoke(inst, e.getId(), e.getTransactionStatus()); return; } if(p0.getType().equals(DeleteEntityEvent.class) && p1.getType().equals(TransactionStatus.class)) { func = (e) -> m.invoke(inst, e, e.getTransactionStatus()); return; } } throw new IllegalArgumentException("Incorrect parameters in method '" + Reflection.fullQualifyName(m.getReflectedMethod()) + "' for 'DeleteEntity' event"); }
@Override public ElMethod resolveMethod(Class<?> cls, String name, Object[] args) { ReflectClass rc = ReflectClass.of(cls); int len = args.length; for(ReflectMethod rm : rc.getMethods()){ if(rm.getName().equals(name) && rm.getParameters().length == len){ boolean ok = true; for(int i=0;i<len;i++){ Object v = args[i]; if(null != v && !rm.getParameters()[i].getType().isAssignableFrom(v.getClass())){ ok = false; break; } } if(ok){ return rm.isStatic() ? new ElStaticMethod(rm) : new ElInstanceMethod(rm); } } } return null; }
if(m.isSetterMethod() || m.isGetterMethod()) { continue; if(m.getParameters().length == 1) { Configurable.Nested nested = m.getAnnotation(Configurable.Nested.class); if(null != nested) { configureNested(bean, keyPrefix, new MethodReflectValued(bean, m), nested); ConfigProperty a = m.getAnnotation(ConfigProperty.class); if(null != a) { doBeanConfigure(bean, new MethodReflectValued(bean, m), keyPrefix, a);
void add(ReflectMethod method) { Integer size = method.getParameters().length; if(methods.containsKey(size)) { throw new IllegalStateException("Found duplicated method '" + method.getName() + "' with " + size + " args at '" + cls.getName() + "'"); } if(size > maxArgs) { maxArgs = size; } methods.put(size, method); }
if(!m.isPublic() || m.isStatic()) { continue; if(m.isAnnotationPresent(PreCreate.class)) { ReflectCreateEntityListener listener = new ReflectCreateEntityListener(inst, m); listeners.addPreCreateListener(listener, listener.isTransactional()); if(m.isAnnotationPresent(PostCreate.class)) { ReflectCreateEntityListener listener = new ReflectCreateEntityListener(inst, m); listeners.addPostCreateListener(listener, listener.isTransactional()); if(m.isAnnotationPresent(PreUpdate.class)) { ReflectUpdateEntityListener listener = new ReflectUpdateEntityListener(inst, m); listeners.addPreUpdateListener(listener, listener.isTransactional()); if(m.isAnnotationPresent(PostUpdate.class)) { ReflectUpdateEntityListener listener = new ReflectUpdateEntityListener(inst, m); listeners.addPostUpdateListener(listener, listener.isTransactional()); if(m.isAnnotationPresent(PreDelete.class)) { ReflectDeleteEntityListener listener = new ReflectDeleteEntityListener(inst, m); listeners.addPreDeleteListener(listener, listener.isTransactional()); if(m.isAnnotationPresent(PostDelete.class)) { ReflectDeleteEntityListener listener = new ReflectDeleteEntityListener(inst, m); listeners.addPostDeleteListener(listener, listener.isTransactional()); if(m.isAnnotationPresent(PostLoad.class)) { ReflectLoadEntityListener listener = new ReflectLoadEntityListener(inst, m);
public Method getGetter() { return null != getter ? getter.getReflectedMethod() : null; }
public MethodReflectValued(Object o, ReflectMethod m) { this.o = o; this.m = m; this.p = m.getParameters()[0]; }
public boolean test(ReflectMethod object) { return object.getName().equals(name); } }).toArray(new ReflectMethod[]{});