Ejemplo n.º 1
0
  /**
   * Find a Method using the methodKey provided.
   *
   * <p>Look in the methodMap for an entry. If found, it'll either be a CACHE_MISS, in which case we
   * simply give up, or it'll be a Method, in which case, we return it.
   *
   * <p>If nothing is found, then we must actually go and introspect the method from the MethodMap.
   */
  public Method findMethod(String name, Object[] params) throws MethodMap.AmbiguousException {
    String methodKey = makeMethodKey(name, params);
    Object cacheEntry = methodCache.get(methodKey);

    if (cacheEntry == CACHE_MISS) {
      return null;
    }

    if (cacheEntry == null) {
      try {
        cacheEntry = methodMap.find(name, params);
      } catch (MethodMap.AmbiguousException ae) {
        /*
         *  that's a miss :)
         */

        methodCache.put(methodKey, CACHE_MISS);

        throw ae;
      }

      if (cacheEntry == null) {
        methodCache.put(methodKey, CACHE_MISS);
      } else {
        methodCache.put(methodKey, cacheEntry);
      }
    }

    // Yes, this might just be null.

    return (Method) cacheEntry;
  }
Ejemplo n.º 2
0
  /**
   * Populate the Map of direct hits. These are taken from all the public methods that our class
   * provides.
   */
  private void populateMethodCache() {
    StringBuffer methodKey;

    /*
     *  get all publicly accessible methods
     */

    Method[] methods = getAccessibleMethods(clazz);

    /*
     * map and cache them
     */

    for (int i = 0; i < methods.length; i++) {
      Method method = methods[i];

      /*
       *  now get the 'public method', the method declared by a
       *  public interface or class. (because the actual implementing
       *  class may be a facade...
       */

      Method publicMethod = getPublicMethod(method);

      /*
       *  it is entirely possible that there is no public method for
       *  the methods of this class (i.e. in the facade, a method
       *  that isn't on any of the interfaces or superclass
       *  in which case, ignore it.  Otherwise, map and cache
       */

      if (publicMethod != null) {
        methodMap.add(publicMethod);
        methodCache.put(makeMethodKey(publicMethod), publicMethod);
      }
    }
  }