Package javassist

Examples of javassist.CtClass.toClass()


      Thread.currentThread().setContextClassLoader(cherryPickCl);
      ClassPool pool = ClassPool.getDefault();
      CtClass ct = pool.get(PERSON);
      try {
         ct.addField(CtField.make("public String name;", ct));
         Class clazz = ct.toClass();
         if (isNewExternalizer) {
            CtClass extCt = pool.get(PERSON_EXT);
            CtMethod writeObjMeth = extCt.getMethod("writeObject", "(Ljava/io/ObjectOutput;Ljava/lang/Object;)V");
            writeObjMeth.setBody("{\n" +
               "$1.writeInt(((" + PERSON + ") $2).age);\n" +
View Full Code Here


               "   o.name = (String) $1.readObject();\n" +
               "} catch(java.io.OptionalDataException e) {}\n" +
               "return o;\n" +
            "}\n"
            );
            extCt.toClass(); // Convert to class so that it gets loaded!!!
         }

         Object oldFromWire = unmarshall(bytes, method);

         Field age = clazz.getDeclaredField("age");
View Full Code Here

      Thread.currentThread().setContextClassLoader(cherryPickCl);
      ClassPool pool = ClassPool.getDefault();
      CtClass ct = pool.get(HOUSE);
      try {
         ct.removeField(ct.getField("number"));
         Class clazz = ct.toClass();
         if (isNewExternalizer) {
            CtClass extCt = pool.get(HOUSE_EXT);
            CtMethod writeObjMeth = extCt.getMethod("writeObject", "(Ljava/io/ObjectOutput;Ljava/lang/Object;)V");
            writeObjMeth.setBody("{\n" +
               "$1.writeInt(0);\n" + // Safe the spot to avoid incompatibility
View Full Code Here

               "} catch(java.io.OptionalDataException e) {}\n" +
               "o.street = (String) $1.readObject();\n" +
               "return o;\n" +
            "}\n"
            );
            extCt.toClass(); // Convert to class so that it gets loaded!!!
         }

         Object oldFromWire = unmarshall(bytes, method);

         Field street = clazz.getDeclaredField("street");
View Full Code Here

            attr = filterExistingAnnotations(add, method);
            addNewAnnotations(add, method, constpool, pool, attr);
        }
        cc.setName(cc.getName() + "$ClassModifier$" + COUNTER.increment());
        cc.setSuperclass(pool.get(clazz.getCanonicalName()));
        return cc.toClass();
    }

    private static CtClass getType(Object value, Class<?> valueType, ClassPool classPool) throws NotFoundException
    {
        if (value instanceof Boolean) {
View Full Code Here

                pcClass.addMethod(setContainerInstance);
               
                CtMethod createContainerInstance = CtMethod.make("public static org.rhq.core.pc.PluginContainer getContainerInstance(java.lang.String name) { org.rhq.core.pc.PluginContainer inst = (org.rhq.core.pc.PluginContainer) INSTANCES.get(name); if (inst == null) { inst = new org.rhq.core.pc.PluginContainer(); INSTANCES.put(name, inst);} return inst;}", pcClass);
                pcClass.addMethod(createContainerInstance);
               
                pcClass.toClass(cl, null);
            } catch (Exception e) {
                throw new IllegalStateException("Could not enhance the PluginContainer class", e);
            } finally {
                initialized = true;
            }
View Full Code Here

            } 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();
View Full Code Here

                //it is important to add the method directly to the classfile, not the class
                //because otherwise the generics info wouldn't survive
                newClassFile.addMethod(newMethod.getMethodInfo());
            }

            return newClass.toClass();

        } catch (Exception e) {
            String msg = "Failed to simplify " + intf + ".";
            LOG.error(msg, e);
            throw new IllegalStateException(msg, e);
View Full Code Here

                    customClass.addMethod(method);
                }
            }

            return customClass.toClass();
        } catch (NotFoundException e) {
            LOG.error("Could not create custom interface for resource with id " + proxy.getId(), e);
            throw new IllegalStateException("Could not create custom interface for resource with id " + proxy.getId(), e);
        } catch (CannotCompileException e) {
            LOG.error("Could not create custom interface for resource with id " + proxy.getId(), e);
View Full Code Here

      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
      ClassPool childPool = createDelegatingClassPool(child, JAR_A);
      CtClass parentClazz = TransformerCommon.makeClass(parentPool, "test.Test");
      assertSame(parentClazz, parentPool.get("test.Test"));
      assertSame(parentPool, parentClazz.getClassPool());
      Class<?> parentClass = parentClazz.toClass();
      assertSame(parentPool.getClassLoader(), parentClass.getClassLoader());
     
      CtClass childClazz = TransformerCommon.makeClass(childPool, "test.Test");
      assertSame(childClazz, childPool.get("test.Test"));
      assertSame(childPool, childClazz.getClassPool());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.