Package javassist

Examples of javassist.ClassPool


     * @param classLoader the class loader to return the class pool for
     * @return
     */
    public static ClassPool getClassPool(ClassLoader classLoader) {
        synchronized (CLASS_POOL_PER_CLASS_LOADER) {
            ClassPool ret = CLASS_POOL_PER_CLASS_LOADER.get(classLoader);
            if (ret == null) {
                ret = classLoader == null ? new ClassPool() : new ClassLoaderBoundClassPool(classLoader);
                initClassPool(ret);
                CLASS_POOL_PER_CLASS_LOADER.put(classLoader, ret);
            }

            return ret;
View Full Code Here


        public Object invoke(Object[] args) throws Exception {
            if (!LazyLoadScenario.isShouldLoad())
                return null;

            ClassPool pool = ClassPoolFactory.getClassPoolForCurrentContextClassLoader();

            Configuration parameters = ConfigurationClassBuilder.translateParametersToConfig(pool,
                definition.getParametersConfigurationDefinition(), args);

            OperationManagerRemote operationManager = remoteClient.getProxy(OperationManagerRemote.class);
View Full Code Here

        return method.getAnnotation(SimplifiedMethod.class) != null;
    }

    public static Class<?> simplify(Class<?> intf) {
        try {
            ClassPool classPool = ClassPoolFactory.getClassPoolForCurrentContextClassLoader();

            String simplifiedName = getSimplifiedName(intf);
            LOG.debug("Simplifying " + intf + " (simplified interface name: " + simplifiedName + ")...");

            CtClass cached = null;
            try {
                cached = classPool.get(simplifiedName);
                return Class.forName(simplifiedName, false, classPool.getClassLoader());
            } catch (NotFoundException e) {
                // ok... load it
            } catch (ClassNotFoundException e) {
                LOG.debug("Class [" + simplifiedName + "] not found - cause: " + e, e);
                if (cached != null) {
                    // strange - we found the class definition in the class pool, which means we must have touched it
                    // before but Class.forName failed to find the class in the class pool's class loader.
                    return cached.toClass();
                }
            }

            CtClass originalClass = classPool.get(intf.getName());
            ClassFile originalClassFile = originalClass.getClassFile();

            CtClass newClass = classPool.makeInterface(simplifiedName);

            newClass.defrost();

            ClassFile newClassFile = newClass.getClassFile();
View Full Code Here

    }
   
    private Class<?> defineCustomInterface(ResourceClientProxy proxy) {
        try {
            // define the dynamic class - do not put it in any known rhq package in case our jars are signed (see BZ-794503)
            ClassPool pool = ClassPoolFactory.getClassPool(ResourceClientProxy.class.getClassLoader());
            CtClass customClass = pool.makeInterface("org.rhq.bindings.client.dynamic."
                + ResourceClientProxy.class.getSimpleName() + proxy.fingerprint);

            for (String key : proxy.allProperties.keySet()) {
                Object prop = proxy.allProperties.get(key);

                if (prop instanceof ResourceClientProxy.Measurement) {
                    String name = ResourceClientProxy.getterName(key);

                    try {
                        ResourceClientProxy.class.getMethod(name);
                    } catch (NoSuchMethodException nsme) {
                        CtMethod method = CtNewMethod.abstractMethod(pool.get(ResourceClientProxy.Measurement.class.getName()),
                                ResourceClientProxy.getterName(key), new CtClass[0], new CtClass[0], customClass);
                        customClass.addMethod(method);
                    }
                } else if (prop instanceof ResourceClientProxy.Operation) {
                    ResourceClientProxy.Operation o = (ResourceClientProxy.Operation) prop;
View Full Code Here

    @Before public void setUpMockSWTEnvironment() {
        display = context.mock(Display.class);
        shell = context.mock(Shell.class);

        ClassPool pool = ClassPool.getDefault();
        pool.appendClassPath(new ClassClassPath(MockedAnimatedCanvas.class));
        CtClass ctControl = pool.makeClass("MockedAnimatedCanvas");
        ctControl.addConstructor(new CtConstructor());

        context.checking(new Expectations() {{
            oneOf(display).isDisposed(); will(returnValue(false));
            oneOf(shell).isDisposed(); will(returnValue(false));
View Full Code Here

  /**
   * 建立代理模块, 配置基本的系统环境
   */
  public ProxyModule() {
    classPool = new ClassPool();
    classPool.appendClassPath(new LoaderClassPath(this.getClass()
        .getClassLoader()));
  }
View Full Code Here

      String deployADir = "/scopedA.ear/scopedA.jar";
      File libDir = new File(jbosstestDeployDir, deployADir);
      System.out.println("libDir = " + libDir.getAbsolutePath());
      // Create a SimpleResponseDTO class with a static serialVersionUID of 1L
      //ClassPool defaultPool = ClassPool.getDefault();
      ClassPool classes1Pool = ClassPool.getDefault();
      //ClassPool classes1Pool = new ClassPool(defaultPool);
      CtClass info = classes1Pool.makeClass("org.jboss.test.scoped.interfaces.dto.SimpleResponseDTO");
      info.addInterface(classes1Pool.get("java.io.Serializable"));
      CtClass s = classes1Pool.get("java.lang.String");
      CtField firstName = new CtField(s, "firstName", info);
      firstName.setModifiers(Modifier.PRIVATE);
      info.addField(firstName);
      CtMethod getFirstName = CtNewMethod.getter("getFirstName", firstName);
      getFirstName.setModifiers(Modifier.PUBLIC);
      info.addMethod(getFirstName);
      CtMethod setFirstName = CtNewMethod.setter("setFirstName", firstName);
      setFirstName.setModifiers(Modifier.PUBLIC);
      info.addMethod(setFirstName);
      CtClass s2 = classes1Pool.get("java.lang.String");
      CtField lastName = new CtField(s2, "lastName", info);
      lastName.setModifiers(Modifier.PRIVATE);
      info.addField(lastName);
      CtMethod getLastName = CtNewMethod.getter("getLastName", lastName);
      getLastName.setModifiers(Modifier.PUBLIC);
View Full Code Here

      String deployBDir = "/scopedB.ear/scopedB.jar";
      File libDir = new File(jbosstestDeployDir, deployBDir);
      System.out.println("libDir = " + libDir.getAbsolutePath());
      // Create a SimpleResponseDTO class with a static serialVersionUID of 1L
      //ClassPool defaultPool = ClassPool.getDefault();
      ClassPool classes1Pool = ClassPool.getDefault();
      //ClassPool classes1Pool = new ClassPool(defaultPool);
      CtClass info = classes1Pool.makeClass("org.jboss.test.scoped.interfaces.dto.SimpleResponseDTO");
      info.addInterface(classes1Pool.get("java.io.Serializable"));
      CtClass s = classes1Pool.get("java.lang.String");
      CtField firstName = new CtField(s, "firstName", info);
      firstName.setModifiers(Modifier.PRIVATE);
      info.addField(firstName);
      CtMethod getFirstName = CtNewMethod.getter("getFirstName", firstName);
      getFirstName.setModifiers(Modifier.PUBLIC);
      info.addMethod(getFirstName);
      CtMethod setFirstName = CtNewMethod.setter("setFirstName", firstName);
      setFirstName.setModifiers(Modifier.PUBLIC);
      info.addMethod(setFirstName);
      CtClass s2 = classes1Pool.get("java.lang.String");
      CtField lastName = new CtField(s2, "lastName", info);
      lastName.setModifiers(Modifier.PRIVATE);
      info.addField(lastName);
      CtMethod getLastName = CtNewMethod.getter("getLastName", lastName);
      getLastName.setModifiers(Modifier.PUBLIC);
View Full Code Here

   protected ClassPool createChildURLClassPoolParentLast(ClassPool parent, URL url)
   {
      ClassLoader parentLoader = parent != null ? parent.getClassLoader() : null;
      ClassLoader cl = createChildURLClassLoaderParentLast(parentLoader, url);
      registeredClassLoaders.add(cl);
      ClassPool pool = AspectManager.instance().registerClassLoader(cl);
      pool.childFirstLookup = true;
      return pool;
   }  
View Full Code Here

   }

   public void testChildInParent() throws Exception
   {
      ClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
      ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
      ClassPool childPool = createDelegatingClassPool(child, JAR_A);
     
      //The first time we access the pool it will create the classes, second time will use the cache
      accessChildInParent(parentPool, childPool);
      accessChildInParent(parentPool, childPool);
   }
View Full Code Here

TOP

Related Classes of javassist.ClassPool

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.