FileDocCategorySizeDatePackage
JClass.javaAPI DocphoneME MR2 API (J2ME)7901Wed May 02 18:00:40 BST 2007com.sun.satsa.jcrmic.classfile

JClass

public class JClass extends Object
This class represents a Java Class.

Fields Summary
public static final int
ACC_INTERFACE
Constant for interface flag.
private int
access_flags
Access flags.
private String
class_name
Class name.
private String
super_class_name
Super class name.
private JMethod[]
methods
Array of declared methods.
private String[]
interface_names
Names of implemented interfaces.
private boolean
remote
'Remote' flag.
private boolean
verified
'Verified' flag.
private JClass
superClass
Super class.
private JClass[]
interfaces
Implemented interfaces.
private Loader
classes
Class loader.
Constructors Summary
public JClass(Loader classes)
Constructor.

param
classes class loader


              
       
        this.classes = classes;
    
Methods Summary
public java.lang.StringgetClassName()
Returns class name.

return
class name

        return class_name;
    
public com.sun.satsa.jcrmic.classfile.JClass[]getInterfaces()
Returns implemented interfaces.

return
implemented interfaces


        return interfaces;
    
public JMethod[]getMethods()
Returns methods declared by class.

return
methods declared by class

        return methods;
    
public com.sun.satsa.jcrmic.classfile.JClassgetSuperClass()
Returns super class.

return
super class


        return superClass;
    
public booleanisInterface()
Check if the class is interface.

return
true if the class is interface

        return (access_flags & ACC_INTERFACE) != 0;
    
public booleanisRemote()
Returns 'remote' flag value.

return
'remote' flag value

        return remote;
    
public booleanisSubclass(com.sun.satsa.jcrmic.classfile.JClass c2)
Verifies if the class is equal to or a sublass of specified class.

param
c2 class
return
true if the class is equal to or a sublass of specified class


        String name = c2.getClassName();

        JClass c1 = this;

        while (true) {

            if (c1.getClassName().equals(name)) {
                return true;
            }

            c1 = c1.getSuperClass();

            if (c1 == null) {
                return false;
            }
        }
    
public booleanisVerified()
Returns 'verifed' flag value.

return
'verifed' flag value

        return verified;
    
public voidparse(java.io.DataInputStream dis)
Parse and resolve Java class.

param
dis input stream
throws
IOException if I/O error occurs


        dis.readInt();   // magic

        dis.readUnsignedShort();    // minor_version
        dis.readUnsignedShort();    // major_version

        JConstantPool constant_pool =
                new JConstantPool(dis.readUnsignedShort());
        constant_pool.parse(dis);

        access_flags = dis.readUnsignedShort();
        int this_class_index = dis.readUnsignedShort();
        int super_class_index = dis.readUnsignedShort();

        int[] interface_indexes = new int[dis.readUnsignedShort()];

        for (int i = 0; i < interface_indexes.length; i++) {
            interface_indexes[i] = dis.readUnsignedShort();
        }

        int field_count = dis.readUnsignedShort();
        for (int i = 0; i < field_count; i++) {
            dis.readUnsignedShort();    // access_flags
            dis.readUnsignedShort();    // name_index
            dis.readUnsignedShort();    // descriptor_index
            int attrib_count = dis.readUnsignedShort();
            for (int k = 0; k < attrib_count; k++) {
                int index = dis.readUnsignedShort();
                JAttribute.create(constant_pool, index).parse(dis);
            }
        }

        methods = new JMethod[dis.readUnsignedShort()];
        for (int i = 0; i < methods.length; i++) {
            methods[i] = new JMethod(constant_pool);
            methods[i].parse(dis);
        }

        int attribute_count = dis.readUnsignedShort();
        for (int i = 0; i < attribute_count; i++) {
            int index = dis.readUnsignedShort();
            JAttribute.create(constant_pool, index).parse(dis);
        }

        // resolve

        class_name = constant_pool.getConstantClass(
                        this_class_index).getClassName();

        if (super_class_index != 0) {
            super_class_name = constant_pool.getConstantClass(
                                    super_class_index).getClassName();
        } else {
            super_class_name = null;
        }

        interface_names = new String[interface_indexes.length];
        for (int i = 0; i < interface_names.length; i++) {
            interface_names[i] = constant_pool.getConstantClass(
                                    interface_indexes[i]).getClassName();
        }
    
public voidsetRemote()
Set 'remote' flag.

        remote = true;
    
public voidsetVerified()
Set 'verified' flag.

        verified = true;
    
public booleanupdate()
Load all related classes.

return
true if successfull


        if (class_name.equals("java/rmi/Remote")) {
            setRemote();
        }

        String name = super_class_name;

        if (name != null) {

            if (! classes.loadClass(name))
                return false;

            superClass = classes.getClass(name);

            if (superClass.isRemote())
                setRemote();
        }

        interfaces = new JClass[interface_names.length];

        for (int i = 0; i < interface_names.length; i++) {

            if (!classes.loadClass(interface_names[i]))
                return false;

            interfaces[i] = classes.getClass(interface_names[i]);

            if (interfaces[i].isRemote())
                setRemote();
        }

        JMethod[] methods = getMethods();

        for (int i = 0; i < methods.length; i++) {

            String[] exceptions = methods[i].getExceptionsThrown();
            if (exceptions != null) {
                for (int j = 0; j < exceptions.length; j++) {
                    if (!classes.loadClass(exceptions[j])) {
                        return false;
                    }
                }
            }
        }

        return true;