FileDocCategorySizeDatePackage
BCELClassFile.javaAPI DocGlassfish v2 API12202Fri May 04 22:33:24 BST 2007com.sun.enterprise.tools.verifier.apiscan.classfile

BCELClassFile

public class BCELClassFile extends Object implements ClassFile
This is an implementation of {@link ClassFile} interface. It uses Apache's BCEL library in its implementation. This is a thread safe implementation of ClassFile interface. This is NOT a public class. Access thru' {@link ClassFile} interface. Use {@link ClassFileLoaderFactory} to create new instances of this class.
author
Sanjeeb.Sahoo@Sun.COM

Fields Summary
private JavaClass
jc
private Set
classNames
private HashSet
methods
private static Logger
logger
private static final String
myClassName
Constructors Summary
public BCELClassFile(InputStream is, String file_name)

param
is is could be a Zip or Jar InputStream or a regular InputStream.
param
file_name is the name of the .class file. If is a Zip or Jar Input stream, then this name should just be the entry path, because it is used internally in the is.getEntry(file_name) to locate the .class file. If is is a regular stream, then file_name should not be really needed, I don't have a choice as BCEL ClassFile does not have a constructor that just takes an InputStream. Any way, if is is a regular stream, then it should either be the internal name of the class or the path to the actual .class file that the input stream represents. This constructor does not check if the ClassFile created here indeed represents the class that is being requested. That check should be done by ClassFileLoader.

 // NOI18N

                                                                                                                                                                                                                                                                                                                                                                                          
           
        logger.entering(myClassName, "<init>(InputStream, String)", file_name); // NOI18N
        jc = new ClassParser(is, file_name).parse();
    
public BCELClassFile(String file_path)

param
file_path Absolute path to the .class file.

        logger.entering(myClassName, "<init>(String)", file_path); // NOI18N
        jc = new ClassParser(file_path).parse();
    
Methods Summary
public synchronized java.util.CollectiongetAllReferencedClassNames()

        if (classNames == null) {
            getAllReferencedClassNamesInInternalForm();
        }
        HashSet<String> extClassNames = new HashSet<String>(classNames.size());
        for (Iterator i = classNames.iterator(); i.hasNext();) {
            extClassNames.add(Util.convertToExternalClassName((String) i.next()));
        }
        return extClassNames;
    
public synchronized java.util.CollectiongetAllReferencedClassNamesInInternalForm()

        if (classNames == null) {
            classNames = new HashSet<String>();//lazy instantiation
            logger.logp(Level.FINER, myClassName, "getAllReferencedClassNames", // NOI18N
                    "Starting to visit"); // NOI18N
            jc.accept(new DescendingVisitor(jc, new Visitor(this)));
            logger.logp(Level.FINER, myClassName, "getAllReferencedClassNames", // NOI18N
                    "Finished visting"); // NOI18N
            classNames = Collections.unmodifiableSet(classNames);
        }
        return classNames;
    
public java.lang.StringgetInternalName()

        return Util.convertToInternalClassName(getName());
    
public java.lang.StringgetInternalNameOfSuperClass()

        return Util.convertToInternalClassName(getNameOfSuperClass());
    
public java.lang.String[]getInternalNamesOfInterfaces()

        String[] result = getNamesOfInterfaces();
        for(int i = 0; i< result.length; ++i) {
            result[i] = Util.convertToInternalClassName(result[i]);
        }
        return result;
    
public com.sun.enterprise.tools.verifier.apiscan.classfile.MethodgetMethod(MethodRef methodRef)

        throw new UnsupportedOperationException();
    
public java.util.CollectiongetMethods()

        return Collections.unmodifiableSet(methods);
    
public java.lang.StringgetName()

        return jc.getClassName();
    
public java.lang.StringgetNameOfSuperClass()

        return jc.getSuperclassName();
    
public java.lang.String[]getNamesOfInterfaces()

        return jc.getInterfaceNames();
    
public java.lang.StringgetPackageName()

        //not necessary as we always use external name for package. .replace('.','/');
        return jc.getPackageName();
    
public booleanisInterface()

        return !jc.isClass();
    
private static java.util.ListsignatureToClassNames(java.lang.String signature)

        logger.entering(myClassName, "signatureToClassNames", signature); // NOI18N
        List<String> result = new ArrayList<String>();
        int i = 0;
        while ((i = signature.indexOf('L", i)) != -1) {
            int j = signature.indexOf(';", i);
            if (j > i) {
                // get name, minus leading 'L' and trailing ';'
                String className = signature.substring(i + 1, j);
                if (!Util.isPrimitive(className)) result.add(className);
                i = j + 1;
            } else
                break;
        }
        if (logger.isLoggable(Level.FINE)) {
            StringBuffer sb = new StringBuffer("Class Names are {"); // NOI18N
            int size = result.size();
            for (int k = 0; k < size; k++) {
                sb.append((String) result.get(k));
                if (k != size - 1) sb.append(", "); // NOI18N
            }
            sb.append("}"); // NOI18N
            logger.finer(sb.toString());
        }
        return result;
    
public java.lang.StringtoString()

        return
                "External Name: " + getName() + "\n" + // NOI18N
                "Internal Name: " + getInternalName() + "\n" + // NOI18N
                jc.toString()
                + "\n------------CONSTANT POOL BEGIN--------------\n" // NOI18N
                + jc.getConstantPool()
                + "\n------------CONSTANT POOL END--------------"; // NOI18N