Package javassist.bytecode

Examples of javassist.bytecode.ClassFile


      List<VirtualFile> files = getClasses(unit);
      for(VirtualFile file : files)
      {
         try
         {
            ClassFile cf = loadClassFile(file);
            log.debug("Deploying possibly annotated class " + cf.getName());
            loader.deployClassFile(cf);
         }
         catch (Exception e)
         {
            throw new DeploymentException("Error reading annotations for " + file, e);
View Full Code Here


   }

   private ClassFile loadClassFile(VirtualFile file)
   {
      DataInputStream din = null;
      ClassFile cf = null;
      try
      {
         InputStream in = file.openStream();
         din = new DataInputStream(new BufferedInputStream(in));
         cf = new ClassFile(din);
      }
      catch (IOException e)
      {
         throw new RuntimeException("Error reading " + file, e);
      }
View Full Code Here

    private final byte[] bytes;
    private final ClassFile classFile;

    public CustomClassDescriptor(byte[] bytes) throws IOException {
      this.bytes = bytes;
      this.classFile = new ClassFile( new DataInputStream( new ByteArrayInputStream( bytes ) ) );
    }
View Full Code Here

    private final byte[] bytes;
    private final ClassFile classFile;

    public CustomClassDescriptor(byte[] bytes) throws IOException {
      this.bytes = bytes;
      this.classFile = new ClassFile( new DataInputStream( new ByteArrayInputStream( bytes ) ) );
    }
View Full Code Here

    // need to look into every entry in the archive to see if anybody has tags
    // defined.
    while ( it.hasNext() ) {
      InputStream stream = (InputStream) it.next();
      DataInputStream dstream = new DataInputStream( stream );
      ClassFile cf = null;
      try {
        try {
          cf = new ClassFile( dstream );
        }
        finally {
          dstream.close();
          stream.close();
        }
      }
      catch (IOException e) {
        throw new RuntimeException( e );
      }
      if ( cf.getName().endsWith( ".package-info" ) ) {
        int idx = cf.getName().indexOf( ".package-info" );
        String pkgName = cf.getName().substring( 0, idx );
        log.info( "found package: " + pkgName );
        packages.add( pkgName );
        continue;
      }

      AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute( AnnotationsAttribute.visibleTag );
      if ( visible != null ) {
        boolean isEntity = visible.getAnnotation( Entity.class.getName() ) != null;
        if ( isEntity ) {
          log.info( "found EJB3 Entity bean: " + cf.getName() );
          entities.add( cf.getName() );
        }
        boolean isEmbeddable = visible.getAnnotation( Embeddable.class.getName() ) != null;
        if ( isEmbeddable ) {
          log.info( "found EJB3 @Embeddable: " + cf.getName() );
          entities.add( cf.getName() );
        }
        boolean isEmbeddableSuperclass = visible.getAnnotation( MappedSuperclass.class.getName() ) != null;
        if ( isEmbeddableSuperclass ) {
          log.info( "found EJB3 @MappedSuperclass: " + cf.getName() );
          entities.add( cf.getName() );
        }
      }
    }
  }
View Full Code Here

    if ( filter.getAnnotations().length == 0 ) {
      is.close();
      return true;
    }
    DataInputStream dstream = new DataInputStream( is );
    ClassFile cf = null;

    try {
      cf = new ClassFile( dstream );
    }
    finally {
      dstream.close();
      is.close();
    }
    boolean match = false;
    AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute( AnnotationsAttribute.visibleTag );
    if ( visible != null ) {
      for ( Class annotation : filter.getAnnotations() ) {
        match = visible.getAnnotation( annotation.getName() ) != null;
        if ( match ) break;
      }
View Full Code Here

    this.callback = callback;
  }

  @Override
  public void handleEntry(ArchiveEntry entry, ArchiveContext context) {
    final ClassFile classFile = toClassFile( entry );
    final ClassDescriptor classDescriptor = toClassDescriptor( classFile, entry );

    if ( ! isListedOrDetectable( context, classDescriptor.getName() ) ) {
      return;
    }
View Full Code Here

  private ClassFile toClassFile(ArchiveEntry entry) {
    final InputStream inputStream = entry.getStreamAccess().accessInputStream();
    final DataInputStream dataInputStream = new DataInputStream( inputStream );
    try {
      return new ClassFile( dataInputStream );
    }
    catch (IOException e) {
      throw new ArchiveException( "Could not build ClassFile" );
    }
    finally {
View Full Code Here

   *
   * @throws Exception Indicates a problem performing the transformation
   */
  public void transform(File file) throws Exception {
    final DataInputStream in = new DataInputStream( new FileInputStream( file ) );
    final ClassFile classfile = new ClassFile( in );
    transform( classfile );

    final DataOutputStream out = new DataOutputStream( new FileOutputStream( file ) );
    try {
      classfile.write( out );
    }
    finally {
      out.close();
    }
  }
View Full Code Here

      ClassLoader loader,
      String className,
      Class classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer) {
    ClassFile classfile;
    try {
      // WARNING: classfile only
      classfile = new ClassFile( new DataInputStream( new ByteArrayInputStream( classfileBuffer ) ) );
    }
    catch (IOException e) {
      LOG.unableToBuildEnhancementMetamodel( className );
      return classfileBuffer;
    }

    final ClassPool cp = new ClassPool();
    cp.appendSystemPath();
    cp.appendClassPath( new ClassClassPath( this.getClass() ) );
    cp.appendClassPath( new ClassClassPath( classfile.getClass() ) );

    try {
      cp.makeClassIfNew( new ByteArrayInputStream( classfileBuffer ) );
    }
    catch (IOException e) {
      throw new RuntimeException( e.getMessage(), e );
    }

    final FieldTransformer transformer = getFieldTransformer( classfile, cp );
    if ( transformer != null ) {
      LOG.debugf( "Enhancing %s", className );

      DataOutputStream out = null;
      try {
        transformer.transform( classfile );
        final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        out = new DataOutputStream( byteStream );
        classfile.write( out );
        return byteStream.toByteArray();
      }
      catch (Exception e) {
        LOG.unableToTransformClass( e.getMessage() );
        throw new HibernateException( "Unable to transform class: " + e.getMessage() );
View Full Code Here

TOP

Related Classes of javassist.bytecode.ClassFile

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.