summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java
diff options
context:
space:
mode:
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.java73
1 files changed, 41 insertions, 32 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 e94f4dc52..5e6458be2 100644
--- a/pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java
+++ b/pki/base/common/src/com/netscape/cmscore/policy/SimpleExpression.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.policy;
+
import java.util.Enumeration;
import java.util.Vector;
@@ -27,12 +28,13 @@ 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$
*/
@@ -45,11 +47,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;
@@ -70,8 +72,7 @@ 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('.');
@@ -116,18 +117,20 @@ 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();
@@ -139,7 +142,8 @@ 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++) {
@@ -150,32 +154,33 @@ 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) {
@@ -215,7 +220,8 @@ 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();
@@ -223,8 +229,7 @@ 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) {
@@ -258,13 +263,15 @@ 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:
@@ -313,9 +320,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;
}
@@ -404,6 +411,7 @@ public class SimpleExpression implements IExpression {
}
}
+
class ExpressionComps {
String attr;
int op;
@@ -427,3 +435,4 @@ class ExpressionComps {
return val;
}
}
+