예제 #1
0
  private void findModifierMap(ClassPool pool, String classname)
      throws NotFoundException, CannotCompileException {
    AbstractModifier modifier = modifierMap.get(classname);
    if (modifier == null) {
      return;
    }
    logger.info("Modify loader:{}, name:{},  modifier{}", loader, classname, modifier);

    final Thread thread = Thread.currentThread();
    final ClassLoader beforeClassLoader = thread.getContextClassLoader();
    thread.setContextClassLoader(loader);
    try {
      byte[] modify = modifier.modify(this.loader, classname, null, null);
      pool.makeClass(new ByteArrayInputStream(modify));
    } catch (IOException ex) {
      throw new NotFoundException(classname + " not found. Caused:" + ex.getMessage(), ex);
    } finally {
      thread.setContextClassLoader(beforeClassLoader);
    }
  }
예제 #2
0
 public AbstractModifier addModifier(AbstractModifier modifier) {
   return modifierMap.put(modifier.getTargetClass().replace('/', '.'), modifier);
 }