Package net.sourceforge.javautil.common.reflection.cache

Examples of net.sourceforge.javautil.common.reflection.cache.ClassMethod


    super(name);
    this.pojoContainer = pojoContainer;
  }

  @Override protected ILifecycle createLifecycle() {
    ClassMethod method = ClassCache.getFor(pojoContainer.getClass()).getMethod(Lifecycle.class);
    if (method != null) {
      return (ILifecycle) method.invoke(pojoContainer);
    } else {
      return new LifecyclePojo(pojoContainer);
    }
  }
View Full Code Here


    return null;
  }

  public void fire(Object source, String name, Object... arguments) {
    if (this.handlers.containsKey(name)) {
      ClassMethod handler = this.handlers.get(name);
      Event event = (Event) ClassCache.getFor(handler.getParameterTypes()[0]).newInstance(CollectionUtil.insert(arguments, 0, source, name));
      for (java.util.EventListener listener : listeners) {
        if (this.condition != null && (Boolean) this.condition.invoke(listener, event)) continue;

        handler.invoke(listener, event);
      }
    } else {
      EventObject event = eventType.newInstance(CollectionUtil.insert(arguments, 0, source, name));
      for (java.util.EventListener listener : listeners) {
        if (this.condition != null && !(Boolean) this.condition.invoke(listener, event)) continue;
View Full Code Here

   * @param defaultValue The default value to return if the method is not found
   * @param optionalArguments The optional arguments to pass to the method
   * @return The value from the invocation of the method if found, otherwise the defaultValue
   */
  public <V> V invokeAnnotated (Class<? extends Annotation> annotationType, V defaultValue, Object... optionalArguments) {
    ClassMethod method = this.descriptor.getMethod(annotationType);
    if (method != null) {
      switch (method.compareArguments(optionalArguments)) {
        case EXACT: case FUNCTIONAL:
          return (V) method.invoke(instance, optionalArguments);
         
        default:
          if (method.getParameterTypes().length == 0) {
            return (V) method.invoke(instance);
          } else {
            throw new ReflectionException("Parameters required for method: " + method.getJavaMember());
          }
      }
    } else {
      return defaultValue;
    }
View Full Code Here

  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Method target = this.adapters.size() > 0 ? this.adapter.translatedMethod(this, method, args) : method;
   
    Pojo pojo = target.getAnnotation(Pojo.class);
    if (pojo != null) {
      ClassMethod cm = pojoDescriptor.getMethod(pojo.value());
      if (cm != null) target = cm.getJavaMember(); else target = null;
    } else {
      ClassMethod cm = pojoDescriptor.findMethod(target.getName(), args);
      if (cm != null) target = cm.getJavaMember(); else target = null;
    }
   
    Object returnValue = null;
    if (target == null) {
      DefaultReturnValue drv = method.getAnnotation(DefaultReturnValue.class);
View Full Code Here

  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (method.getDeclaringClass() == Object.class) return method.invoke(target, args);
   
    Pojo pojo = method.getAnnotation(Pojo.class);
    ClassMethod cm = null;
    Object returnValue = null;
    if (pojo != null) {
      cm = targetType.getMethod(pojo.value());
    } else {
      cm = targetType.findMethod(method.getName(), args);
    }
    if (cm != null) returnValue = cm.invoke(target, args);
    else if (this.allEventHandler != null && method.getAnnotation(CollectionProxyCondition.class) == null) {
      returnValue = this.allEventHandler.invoke(target, args);
    }
   
    if (method.getReturnType() == void.class) return null;
View Full Code Here

           
            if (forType.isPrimitive() || ReflectionUtil.isBoxedType(forType))
              this.addCategory(classes, forType.isPrimitive() ? ReflectionUtil.getBoxedType(forType) : ReflectionUtil.getPrimitiveType(forType), cd);
           
            if (property && method.getParameterTypes().length == 1) {
              ClassMethod setter = null;
              for (ClassMethod setterp : cd.getMethods(setterName)) {
                if (setterp.getParameterTypes().length == 2 && setterp.getParameterTypes()[0] == forType && setterp.getParameterTypes()[1] == method.getReturnType()) {
                  setter = setterp; break;
                }
              }
View Full Code Here

  public Class<?>[] getForClasses() { return this.classes; }

  public GroovyDSLMethod getMethod(MetaClass clazz, Object instance, String name, Object... arguments) {
    List<ClassDescriptor> categories = this.lookup.get(instance instanceof Class ? "java.lang.Class" : clazz.getTheClass().getName());
    for (int i=0; i<categories.size(); i++) {
      ClassMethod method = categories.get(i).findMethod(name, CollectionUtil.insert(arguments, 0, instance));
      if (method != null) return new GroovyDSLCategoryMethod(method);
    }
    return null;
  }
View Full Code Here

   
    if (cnode != null) {
      type = cnode.value();
      parentRequired = cnode.parentRequired();
    } else {
      ClassMethod method = this.getTypeIndicator(child.getClass());
      if (method != null) {
        cnode = method.getAnnotation(Node.class);
        parentRequired = cnode.parentRequired();
        type = (Node.Type) method.invoke(child);
      } else {
        type = Node.Type.Branch;
        parentRequired = false;
      }
    }
View Full Code Here

   
    if (parent != null) this.setParent(child, parent);
  }
 
  protected void setParent (Object child, Object parent) {
    ClassMethod property = this.getParentSetter(child.getClass());
    if (property == null) return;

    property.invoke(child, parent);
  }
View Full Code Here

    property.invoke(child, parent);
  }

  protected void addChild (Object parent, Object child) {
    ClassMethod method = this.getChildAggregator(parent.getClass());
    if (method == null) return;
   
    method.invoke(parent, child);
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.javautil.common.reflection.cache.ClassMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.