示例#1
0
 private static byte[] findTypeAndTransform(CtClass javaClass)
     throws CannotCompileException, IOException, NotFoundException {
   int componentType = findComponentType(javaClass);
   ClassFile cf = javaClass.getClassFile();
   if (componentType != Info.COMPONENT_UNKNOWN && !cf.isInterface() && !cf.isAbstract()) {
     Log.info(
         javaClass.getName()
             + " is of type "
             + Info.TYPES[componentType]
             + " and will be instrumented");
     switch (componentType) {
       case Info.COMPONENT_SESSIONBEAN:
         return ComponentTransformer.transformSessionBean(javaClass);
       case Info.COMPONENT_ENTITYBEAN:
         return ComponentTransformer.transformEntityBean(javaClass);
       case Info.COMPONENT_MESSAGEDRIVENBEAN:
         return ComponentTransformer.transformMessageDrivenBean(javaClass);
       case Info.COMPONENT_CUSTOM:
         return ComponentTransformer.transformCustom(javaClass);
       case Info.COMPONENT_QUEUESENDER:
         return ComponentTransformer.transformQueueSender(javaClass);
       case Info.COMPONENT_SERVLET:
         return ComponentTransformer.transformServlet(javaClass);
       case Info.COMPONENT_SINGLETON:
         return ComponentTransformer.transformSingleton(javaClass);
       case Info.COMPONENT_TOPICPUBLISHER:
         return ComponentTransformer.transformTopicPublisher(javaClass);
       case Info.COMPONENT_SQLSTATEMENT:
         return ComponentTransformer.transformSQLStatement(javaClass);
       case Info.COMPONENT_SQLCONNECTION:
         return ComponentTransformer.transformSQLConnection(javaClass);
       default:
         return null;
     }
   }
   return null;
 }
示例#2
0
  private Method lookupMethod(
      CtClass clazz,
      String methodName,
      int[] argTypes,
      int[] argDims,
      String[] argClassNames,
      boolean onlyExact)
      throws CompileError {
    Method maybe = null;
    ClassFile cf = clazz.getClassFile2();
    // If the class is an array type, the class file is null.
    // If so, search the super class java.lang.Object for clone() etc.
    if (cf != null) {
      List list = cf.getMethods();
      int n = list.size();
      for (int i = 0; i < n; ++i) {
        MethodInfo minfo = (MethodInfo) list.get(i);
        if (minfo.getName().equals(methodName)) {
          int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames);
          if (res != NO) {
            Method r = new Method(clazz, minfo, res);
            if (res == YES) return r;
            else if (maybe == null || maybe.notmatch > res) maybe = r;
          }
        }
      }
    }

    if (onlyExact) maybe = null;
    else onlyExact = maybe != null;

    int mod = clazz.getModifiers();
    boolean isIntf = Modifier.isInterface(mod);
    try {
      // skip searching java.lang.Object if clazz is an interface type.
      if (!isIntf) {
        CtClass pclazz = clazz.getSuperclass();
        if (pclazz != null) {
          Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact);
          if (r != null) return r;
        }
      }
    } catch (NotFoundException e) {
    }

    if (isIntf || Modifier.isAbstract(mod))
      try {
        CtClass[] ifs = clazz.getInterfaces();
        int size = ifs.length;
        for (int i = 0; i < size; ++i) {
          Method r = lookupMethod(ifs[i], methodName, argTypes, argDims, argClassNames, onlyExact);
          if (r != null) return r;
        }

        if (isIntf) {
          // finally search java.lang.Object.
          CtClass pclazz = clazz.getSuperclass();
          if (pclazz != null) {
            Method r =
                lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact);
            if (r != null) return r;
          }
        }
      } catch (NotFoundException e) {
      }

    return maybe;
  }