FileDocCategorySizeDatePackage
HttpMethodSpec.javaAPI DocGlassfish v2 API11079Fri May 04 22:36:00 BST 2007javax.security.jacc

HttpMethodSpec

public final class HttpMethodSpec extends Object
This class is used ...

author
Ron Monzillo
author
Gary Ellison

Fields Summary
private static final String
comma
private static final String
emptyString
private static final String
exclaimationPoint
private static final char
exclaimationPointChar
private static Object[]
methodKeys
private static int
mapSize
private static HashMap
methodHash
private static int
allSet
private static HttpMethodSpec[]
specArray
private static HttpMethodSpec[]
exceptionSpecArray
private static HttpMethodSpec
allSpec
private static ArrayList
extensionMethods
HttpMethodSpec
standardSpec
boolean
exceptionList
int
standardMap
BitSet
extensionSet
String
actions
Constructors Summary
private HttpMethodSpec(boolean isExceptionList, int map)

	standardSpec = null;
	exceptionList = isExceptionList;
	standardMap = map;
	extensionSet = null;
	actions = null;
    
private HttpMethodSpec(HttpMethodSpec spec, BitSet set)

	standardSpec = spec;
	exceptionList = spec.exceptionList;
	standardMap = spec.standardMap;
	extensionSet = set.isEmpty() ? null : set;
	actions = null;
    
Methods Summary
public booleanequals(java.lang.Object that)

	boolean rvalue = false;
	if (that != null && that instanceof HttpMethodSpec) {
	    if (that == this) {
		rvalue = true;
	    } else {
	        rvalue = this.hashCode() == ((HttpMethodSpec) that).hashCode();
	    }
	} 
	return rvalue;
    
java.lang.StringgetActions()

	
	if (standardMap == 0 && extensionSet == null) {
	    return null;
	}

	synchronized(this) {
	    if (actions != null) {
		return actions;
	    }

	    if (standardSpec != null) {
		actions = getExtensionActions(standardSpec.getActions(),standardMap,
					      extensionSet);
	    } else {
		actions = getStandardActions(exceptionList,standardMap);
	    }
	}

	return actions;
    
private java.lang.StringgetExtensionActions(java.lang.String standardActions, int map, java.util.BitSet set)

	ArrayList methods = null;
	for(int i=set.nextSetBit(0); i>=0; i=set.nextSetBit(i+1)) {
	    if (methods == null) {
		methods = new ArrayList();
	    }
	    methods.add(getExtensionMethod(i));
	}
	String rvalue;
	if (methods == null) {
	    rvalue = standardActions;
	} else {
	    Collections.sort(methods);
	    StringBuffer actBuf = new StringBuffer
		(standardActions == null ?
                    (exceptionList ? exclaimationPoint : emptyString) :
                    standardActions);
	    for (int i = 0; i < methods.size(); i++) {
		if (i > 0 || map > 0) {
		    actBuf.append(comma);
		}
		actBuf.append(methods.get(i));
	    }
	    rvalue = actBuf.toString();
	}
	return rvalue;
    
private static java.lang.StringgetExtensionMethod(int bitPos)

	synchronized (extensionMethods) {
	    if (bitPos >= 0 && bitPos < extensionMethods.size()) {
		return (String) extensionMethods.get(bitPos);
	    } else {
		throw new RuntimeException
		    ("invalid (extensionMethods) bit position: '" + bitPos + 
		     "' size: '" + extensionMethods.size() + " '");
	    }
	}
    
static javax.security.jacc.HttpMethodSpecgetSpec(java.lang.String actions)


        
    
	HttpMethodSpec rvalue;

	if (actions == null || actions.equals(emptyString)) {
	    rvalue = allSpec;
	} else {

	    BitSet set = new BitSet();
	    rvalue = getStandardSpec(actions,set);

	    if (!set.isEmpty()) {
		rvalue = new HttpMethodSpec(rvalue,set);
	    }
	}
	return rvalue;
    
static javax.security.jacc.HttpMethodSpecgetSpec(java.lang.String[] methods)

	HttpMethodSpec rvalue;

	if (methods == null || methods.length == 0) {
	    rvalue = allSpec;
	} else {

	    int map = 0;
	    BitSet set = new BitSet();

	    for (int i=0; i<methods.length; i++) {
		Integer bit = (Integer) methodHash.get(methods[i]);
		if (bit != null) {
		    map |= bit.intValue();
		} else {
		    setExtensionBit(methods[i],set);
		}
	    }

	    if (set.isEmpty()) {
		rvalue = specArray[map];
	    } else {
		rvalue = new HttpMethodSpec(specArray[map],set);
	    }
	}
	return rvalue;
    
private java.lang.StringgetStandardActions(boolean isExceptionList, int map)

	int bitValue = 1;

	StringBuffer actBuf = null;

	for (int i=0; i<mapSize; i++) {

	    if ((map & bitValue) == bitValue) {
		if (actBuf == null) {
		    actBuf = new StringBuffer
			(isExceptionList ? exclaimationPoint : emptyString);
		} else {
		    actBuf.append(comma);
		}
		actBuf.append((String) methodKeys[i]);
	    }
	    bitValue = bitValue * 2;
	}

	if (actBuf == null) {
	    return isExceptionList ? exclaimationPoint : emptyString;
	} else {
	    return actBuf.toString();
	}
    
private static javax.security.jacc.HttpMethodSpecgetStandardSpec(java.lang.String actions, java.util.BitSet set)

	boolean isExceptionList = false;
	if (actions.charAt(0) == exclaimationPointChar) {
	    isExceptionList = true;
	    if (actions.length() < 2) {
		throw new IllegalArgumentException
		    ("illegal HTTP method Spec actions: '" + actions + "'");
	    }
	    actions = actions.substring(1);
	}

	int map = makeMethodSet(actions, set);

	HttpMethodSpec rvalue;
	if (isExceptionList) {
	    rvalue = exceptionSpecArray[map];
	} else {
	    rvalue = specArray[map];
	}

	return rvalue;
    
public inthashCode()

	return (this.exceptionList ? 1 : 0) + (this.standardMap << 1) + 
	    ((this.extensionSet == null ? 0 : this.extensionSet.hashCode()) << mapSize +1);
    
booleanimplies(javax.security.jacc.HttpMethodSpec that)

	boolean rvalue;
	// null actions implies everything
	if (this.standardMap == 0 && this.extensionSet == null) {
	    rvalue = true;
	}
	// only the null actions can implie the null actions
	else if (that.standardMap == 0 && that.extensionSet == null) {
	    rvalue = false;
	}
	// both are an HttpMethodExceptionList
	else if (this.exceptionList && that.exceptionList) {
	    rvalue = (this.standardMap & that.standardMap) == this.standardMap;
	    if (rvalue) {
		if (this.extensionSet != null) {
		    if (that.extensionSet == null) {
			rvalue = false;
		    } else {
			BitSet clone = (BitSet) that.extensionSet.clone();
			clone.and(this.extensionSet);
			rvalue = clone.equals(this.extensionSet) ? true : false;
		    }
		}
	    }
	}
	// neither is an HttpMethodExceptionList
	else if (this.exceptionList == that.exceptionList) {
	    rvalue = (this.standardMap & that.standardMap) == that.standardMap;
	    if (rvalue) {
		if (that.extensionSet != null) {
		    if (this.extensionSet == null) {
			rvalue = false;
		    } else {
			BitSet clone = (BitSet) that.extensionSet.clone();
			clone.and(this.extensionSet);
			rvalue = clone.equals(that.extensionSet);
		    }
		}
	    }
	}
	// one or the other is an HttpMethodExceptionList
	else if (this.exceptionList) {
	    rvalue = (this.standardMap & that.standardMap) == 0;
	    if (rvalue) {
		if (that.extensionSet != null) {
		    if (this.extensionSet == null) {
			rvalue = true;
		    } else {
			rvalue = this.extensionSet.intersects
			    (that.extensionSet) ? false : true; 
		    }
		}
	    }
	}
	// an explicit list can never imply an exception list
	else {
	    rvalue = false;
	}

	return rvalue;
    
private static intmakeMethodSet(java.lang.String actions, java.util.BitSet set)

	int i = 0;
	int mSet = 0;
	int commaPos = 0;
	    
	while (commaPos >= 0 && i < actions.length()) {
 
	    commaPos = actions.indexOf(comma,i);

	    if (commaPos != 0) {

		String method;
		if (commaPos < 0) {
		    method = actions.substring(i);
		} else {
		    method = actions.substring(i,commaPos);
		}
		Integer bit = (Integer) methodHash.get(method);
		if (bit != null) {
		    mSet |= bit.intValue();
		} else {
		    setExtensionBit(method,set);
		}

		i = commaPos + 1;
	    }

	    else {
		throw new IllegalArgumentException
		    ("illegal HTTP method Spec actions: '" + actions + "'");
	    }
	}

	return mSet;
    
private static voidsetExtensionBit(java.lang.String method, java.util.BitSet set)

	int bitPos;
	synchronized (extensionMethods) {
	    bitPos = extensionMethods.indexOf(method);
	    if (bitPos < 0) {
		bitPos = extensionMethods.size();
		// *** should ensure method is syntactically legal
		extensionMethods.add(method);
	    }
	}
	set.set(bitPos);
    
public java.lang.StringtoString()

	return getActions();