FileDocCategorySizeDatePackage
JCRMIPermission.javaAPI DocphoneME MR2 API (J2ME)3880Wed May 02 18:00:38 BST 2007com.sun.satsa.acl

JCRMIPermission

public class JCRMIPermission extends Object
This class represents JCRMI permission.

Fields Summary
private String
hashModifier
Hash modifier value.
private String[]
classes
The list of class names.
private int[]
methods
The list of method identifiers.
Constructors Summary
public JCRMIPermission(String hashModifier, Vector classList, Vector methodList)
Constructor.

param
hashModifier hash modifier string.
param
classList the list of classes.
param
methodList the list of method names and signatures.


        this.hashModifier = hashModifier;

        classes = new String[classList.size()];
        classList.copyInto(classes);
        
        if (! methodList.isEmpty()) {
            methods = new int[methodList.size()];
            for (int i = 0; i < methodList.size(); i++) {
                if (methodList.elementAt(i) instanceof String) {
                    methods[i] = getMethodId(hashModifier,
                                             (String) methodList.elementAt(i));
                } else {
                    methods[i] = 
                        Utils.getInt((byte[])methodList.elementAt(i), 0);
                }
            }
        }
    
Methods Summary
public booleancheckAccess(java.lang.String className, java.lang.String method)
Verify if this permission allows to invoke this method.

param
className the name of class.
param
method method name and signature.
return
true if this permission allows to invoke this method.


        boolean found = false;
        
        for (int i = 0; i < classes.length; i++) {

            if (classes[i].equals(className)) {
                found = true;
                break;
            }
        }

        if (! found) {
            return false;
        }

        if (methods == null) {
            return true;
        }

        int id = getMethodId(hashModifier, method);

        for (int i = 0; i < methods.length; i++) {
            if (id == methods[i])
                return true;
        }
        return false;
    
private static intgetMethodId(java.lang.String hashModifier, java.lang.String method)
Calculates method ID for given hash modifier and method name.

param
hashModifier hash modifier value.
param
method method name and signature.
return
the identifier.


        if (hashModifier != null) {
            method = hashModifier + method;
        }
        byte data[] = Utils.stringToBytes(method);
        data = AccessControlManager.getHash(data, 0, data.length);
        return Utils.getInt(data, 0);