1 23 24 33 34 package com.sun.enterprise.deployment.annotation.introspection; 35 36 import java.nio.channels.ReadableByteChannel ; 37 import java.nio.ByteBuffer ; 38 import java.nio.CharBuffer ; 39 import java.io.IOException ; 40 41 import com.sun.enterprise.deployment.util.DOLUtils; 42 46 public class ConstantPoolInfo { 47 48 byte[] bytes = new byte[Short.MAX_VALUE]; 49 private CustomAnnotationScanner customScanner = null; 50 51 52 public ConstantPoolInfo() { 53 } 54 55 public ConstantPoolInfo(CustomAnnotationScanner scanner) { 56 customScanner = scanner; 57 } 58 59 63 public boolean containsAnnotation(int constantPoolSize, final ByteBuffer buffer) throws IOException { 64 65 for (int i=1;i<constantPoolSize;i++) { 66 final byte type = buffer.get(); 67 switch(type) { 68 case ASCIZ: 69 case UNICODE: 70 final short length = buffer.getShort(); 71 if (length<0 || length>Short.MAX_VALUE) { 72 return true; 73 } 74 buffer.get(bytes, 0, length); 75 80 if (bytes[0]=='L' && bytes[1]=='j' && bytes[2]=='a') { 81 String stringValue; 82 if (type==ASCIZ) { 83 stringValue = new String (bytes, 0, length,"US-ASCII"); 84 } else { 85 stringValue = new String (bytes, 0, length); 86 } 87 if (customScanner != null) { 88 if (customScanner.isAnnotation(stringValue)) { 89 return true; 90 } 91 } else { 92 if (AnnotationScanner.isAnnotation(stringValue)) { 93 return true; 94 } 95 } 96 } 97 break; 98 case CLASS: 99 case STRING: 100 buffer.getShort(); 101 break; 102 case FIELDREF: 103 case METHODREF: 104 case INTERFACEMETHODREF: 105 case INTEGER: 106 case FLOAT: 107 buffer.position(buffer.position()+4); 108 break; 109 case LONG: 110 case DOUBLE: 111 buffer.position(buffer.position()+8); 112 i++; 114 break; 115 case NAMEANDTYPE: 116 buffer.getShort(); 117 buffer.getShort(); 118 break; 119 default: 120 DOLUtils.getDefaultLogger().severe("Unknow type constant pool " + type + " at position" + i); 121 break; 122 } 123 } 124 return false; 125 } 126 127 128 public static final byte CLASS = 7; 129 public static final int FIELDREF = 9; 130 public static final int METHODREF = 10; 131 public static final int STRING = 8; 132 public static final int INTEGER = 3; 133 public static final int FLOAT = 4; 134 public static final int LONG = 5; 135 public static final int DOUBLE = 6; 136 public static final int INTERFACEMETHODREF = 11; 137 public static final int NAMEANDTYPE = 12; 138 public static final int ASCIZ = 1; 139 public static final int UNICODE = 2; 140 } 141 | Popular Tags |