コード例 #1
0
  /**
   * Wraps given object using proxy created by {@link ProxyInstanceFactory}.
   *
   * @param obj
   * @return
   * @throws InstantiationException
   * @throws IllegalAccessException
   */
  @SuppressWarnings("unchecked")
  private <T> T proxyImpl(T obj) throws InstantiationException, IllegalAccessException {
    ChainStateHolder.setChain(new ArrayList<String>());
    retrievePossibleChains();

    Integer chainIndex = ChainStateHolder.getCurrentChainIndex();
    if (chainIndex == null) {
      chainIndex = 0;
    } else {
      ++chainIndex;
    }
    ChainStateHolder.setCurrentChainIndex(chainIndex);

    return (T) proxyInstanceFactory.proxy(obj, (Class<T>) obj.getClass());
  }
コード例 #2
0
  private void retrievePossibleChains() {
    StackTraceElement[] stackTrace = new Throwable().getStackTrace();
    String wrapperName = null;
    for (StackTraceElement elem : stackTrace) {
      if (!libraryClassesInChain.contains(elem)) {
        StackTraceElement libraryClassElement = getLibraryClassElement(elem);
        if (libraryClassElement == null) {
          ChainStateHolder.setPossibleChains(
              chainRetriever.getInvokationChains(
                  elem.getClassName(), elem.getMethodName(), elem.getLineNumber(), wrapperName));
          currentLine.set(elem.getLineNumber());
          return;
        }
        libraryClassesInChain.add(libraryClassElement);
      }

      wrapperName = elem.getMethodName();
    }

    throw new IllegalStateException("No caller found");
  }