FileDocCategorySizeDatePackage
ConstantPoolInfo.javaAPI DocGlassfish v2 API6104Fri May 04 22:31:36 BST 2007com.sun.enterprise.deployment.annotation.introspection

ConstantPoolInfo

public class ConstantPoolInfo extends Object
author
dochez

Fields Summary
byte[]
bytes
private CustomAnnotationScanner
customScanner
public static final byte
CLASS
public static final int
FIELDREF
public static final int
METHODREF
public static final int
STRING
public static final int
INTEGER
public static final int
FLOAT
public static final int
LONG
public static final int
DOUBLE
public static final int
INTERFACEMETHODREF
public static final int
NAMEANDTYPE
public static final int
ASCIZ
public static final int
UNICODE
Constructors Summary
public ConstantPoolInfo()
Creates a new instance of ConstantPoolInfo

    
           
      
    
public ConstantPoolInfo(CustomAnnotationScanner scanner)

        customScanner = scanner;
    
Methods Summary
public booleancontainsAnnotation(int constantPoolSize, java.nio.ByteBuffer buffer)
Read the input channel and initialize instance data structure.

 
            
        for (int i=1;i<constantPoolSize;i++) {
            final byte type = buffer.get();
            switch(type) {
                case ASCIZ:
                case UNICODE:
                    final short length = buffer.getShort();
                    if (length<0 || length>Short.MAX_VALUE) {
                        return true;
                    }
                    buffer.get(bytes, 0, length);
                    /* to speed up the process, I am comparing the first few
                     * bytes to Ljava since all annotations are in the java
                     * package, the reduces dramatically the number or String
                     * construction
                     */
                    if (bytes[0]=='L" && bytes[1]=='j" && bytes[2]=='a") {
                        String stringValue;
                        if (type==ASCIZ) {
                            stringValue = new String(bytes, 0, length,"US-ASCII");
                        } else {
                            stringValue = new String(bytes, 0, length);
                        }
                        if (customScanner != null) {
                            if (customScanner.isAnnotation(stringValue)) {
                                return true;
                            }
                        } else {
                            if (AnnotationScanner.isAnnotation(stringValue)) {
                                return true;
                            }
                        }
                    }
                    break;
                case CLASS:
                case STRING:
                    buffer.getShort();
                    break;
                case FIELDREF:
                case METHODREF:
                case INTERFACEMETHODREF:
                case INTEGER:
                case FLOAT:
                    buffer.position(buffer.position()+4);
                    break;
                case LONG:
                case DOUBLE:
                    buffer.position(buffer.position()+8);
                    // for long, and double, they use 2 constantPool 
                    i++;
                    break;
                case NAMEANDTYPE:
                    buffer.getShort();
                    buffer.getShort();
                    break;
                default:
                    DOLUtils.getDefaultLogger().severe("Unknow type constant pool " + type + " at position" + i);
                    break;
            }
        }
        return false;