diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java | 73 |
1 files changed, 32 insertions, 41 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java b/pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java index 5e6458be..e94f4dc5 100644 --- a/pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java +++ b/pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.policy; - import java.util.Enumeration; import java.util.Vector; @@ -28,13 +27,12 @@ import com.netscape.certsrv.request.IRequest; import com.netscape.cmscore.util.AssertionException; import com.netscape.cmscore.util.Debug; - /** - * This class represents an expression of the form var = val, - * var != val, var < val, var > val, var <= val, var >= val. - * + * This class represents an expression of the form var = val, var != val, var < + * val, var > val, var <= val, var >= val. + * * Expressions are used as predicates for policy selection. - * + * * @author kanda * @version $Revision$, $Date$ */ @@ -47,11 +45,11 @@ public class SimpleExpression implements IExpression { private boolean hasWildCard; public static final char WILDCARD_CHAR = '*'; - // This is just for indicating a null expression. - public static SimpleExpression NULL_EXPRESSION = new SimpleExpression("null", OP_EQUAL, "null"); + // This is just for indicating a null expression. + public static SimpleExpression NULL_EXPRESSION = new SimpleExpression( + "null", OP_EQUAL, "null"); - public static IExpression parse(String input) - throws EPolicyException { + public static IExpression parse(String input) throws EPolicyException { // Get the index of operator // Debug.trace("SimpleExpression::input: " + input); String var = null; @@ -72,7 +70,8 @@ public class SimpleExpression implements IExpression { if (comps == null) comps = parseForLT(input); if (comps == null) - throw new EPolicyException(CMS.getUserMessage("CMS_POLICY_BAD_POLICY_EXPRESSION", input)); + throw new EPolicyException(CMS.getUserMessage( + "CMS_POLICY_BAD_POLICY_EXPRESSION", input)); String pfx = null; String rawVar = comps.getAttr(); int dotIdx = rawVar.indexOf('.'); @@ -117,20 +116,18 @@ public class SimpleExpression implements IExpression { hasWildCard = false; } - public boolean evaluate(IRequest req) - throws EPolicyException { + public boolean evaluate(IRequest req) throws EPolicyException { // mPfx and mVar are looked up case-indendently String givenVal = req.getExtDataInString(mPfx, mVar); if (Debug.ON) - Debug.trace("mPfx: " + mPfx + " mVar: " + mVar + - ",Given Value: " + givenVal + ", Value to compare with: " + mVal); + Debug.trace("mPfx: " + mPfx + " mVar: " + mVar + ",Given Value: " + + givenVal + ", Value to compare with: " + mVal); return matchValue(givenVal); } - private boolean matchVector(Vector value) - throws EPolicyException { + private boolean matchVector(Vector value) throws EPolicyException { boolean result = false; Enumeration e = (Enumeration) value.elements(); @@ -142,8 +139,7 @@ public class SimpleExpression implements IExpression { return result; } - private boolean matchStringArray(String[] value) - throws EPolicyException { + private boolean matchStringArray(String[] value) throws EPolicyException { boolean result = false; for (int i = 0; i < value.length; i++) { @@ -154,33 +150,32 @@ public class SimpleExpression implements IExpression { return result; } - private boolean matchValue(Object value) - throws EPolicyException { + private boolean matchValue(Object value) throws EPolicyException { boolean result; // There is nothing to compare with! if (value == null) return false; - // XXX - Kanda: We need a better way of handling this!. + // XXX - Kanda: We need a better way of handling this!. if (value instanceof String) result = matchStringValue((String) value); else if (value instanceof Integer) result = matchIntegerValue((Integer) value); else if (value instanceof Boolean) result = matchBooleanValue((Boolean) value); - else if (value instanceof Vector) + else if (value instanceof Vector) result = matchVector((Vector) value); - else if (value instanceof String[]) + else if (value instanceof String[]) result = matchStringArray((String[]) value); else - throw new EPolicyException(CMS.getUserMessage("CMS_POLICY_INVALID_ATTR_VALUE", - value.getClass().getName())); + throw new EPolicyException( + CMS.getUserMessage("CMS_POLICY_INVALID_ATTR_VALUE", value + .getClass().getName())); return result; } - private boolean matchStringValue(String givenVal) - throws EPolicyException { + private boolean matchStringValue(String givenVal) throws EPolicyException { boolean result; switch (mOp) { @@ -220,8 +215,7 @@ public class SimpleExpression implements IExpression { return result; } - private boolean matchIntegerValue(Integer intVal) - throws EPolicyException { + private boolean matchIntegerValue(Integer intVal) throws EPolicyException { boolean result; int storedVal; int givenVal = intVal.intValue(); @@ -229,7 +223,8 @@ public class SimpleExpression implements IExpression { try { storedVal = new Integer(mVal).intValue(); } catch (Exception e) { - throw new EPolicyException(CMS.getUserMessage("CMS_POLICY_INVALID_ATTR_VALUE", mVal)); + throw new EPolicyException(CMS.getUserMessage( + "CMS_POLICY_INVALID_ATTR_VALUE", mVal)); } switch (mOp) { @@ -263,15 +258,13 @@ public class SimpleExpression implements IExpression { return result; } - private boolean matchBooleanValue(Boolean givenVal) - throws EPolicyException { + private boolean matchBooleanValue(Boolean givenVal) throws EPolicyException { boolean result; Boolean storedVal; - if (!(mVal.equalsIgnoreCase("true") || - mVal.equalsIgnoreCase("false"))) - throw new EPolicyException(CMS.getUserMessage("CMS_POLICY_INVALID_ATTR_VALUE", - mVal)); + if (!(mVal.equalsIgnoreCase("true") || mVal.equalsIgnoreCase("false"))) + throw new EPolicyException(CMS.getUserMessage( + "CMS_POLICY_INVALID_ATTR_VALUE", mVal)); storedVal = new Boolean(mVal); switch (mOp) { case OP_EQUAL: @@ -320,9 +313,9 @@ public class SimpleExpression implements IExpression { op = IExpression.LE_STR; break; } - if (mPfx != null && mPfx.length() > 0) + if (mPfx != null && mPfx.length() > 0) return mPfx + "." + mVar + " " + op + " " + mVal; - else + else return mVar + " " + op + " " + mVal; } @@ -411,7 +404,6 @@ public class SimpleExpression implements IExpression { } } - class ExpressionComps { String attr; int op; @@ -435,4 +427,3 @@ class ExpressionComps { return val; } } - |