Methods Summary |
---|
public void | addConstraint(ValueConstraint constraint)add a constraint for this field
if (constraint == null)
return;
ValueConstraint results[] =
new ValueConstraint[constraints.length + 1];
for (int i = 0; i < constraints.length; i++)
results[i] = constraints[i];
results[constraints.length] = constraint;
constraints = results;
|
public boolean | applyConstraints(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request)apply the constraints on the value of the field in the given request.
return a true if all the constraints pass; false when the
field is not found or the field value doesn't pass the caching
constraints.
Object value = getValue(context, request);
if (value == null) {
// the field is not present in the request
if (_isTraceEnabled) {
_logger.fine(
"The constraint field " + name
+ " is not found in the scope " + SCOPE_NAMES[scope]
+ "; returning cache-on-match-failure: "
+ cacheOnMatchFailure);
}
return cacheOnMatchFailure;
} else if (constraints.length == 0) {
// the field is present but has no value constraints
if (_isTraceEnabled) {
_logger.fine(
"The constraint field " + name + " value = "
+ value.toString() + " is found in scope "
+ SCOPE_NAMES[scope] + "; returning cache-on-match: "
+ cacheOnMatch);
}
return cacheOnMatch;
}
// apply all the value constraints
for (int i = 0; i < constraints.length; i++) {
ValueConstraint c = constraints[i];
// one of the values matched
if (c.matches(value)) {
if (_isTraceEnabled) {
_logger.fine(
"The constraint field " + name + " value = "
+ value.toString() + " is found in scope "
+ SCOPE_NAMES[scope] + "; and matches with a value "
+ c.toString() + "; returning cache-on-match: "
+ cacheOnMatch);
}
return cacheOnMatch;
}
}
// none of the values matched; should we cache?
if (_isTraceEnabled) {
_logger.fine(
"The constraint field " + name + " value = "
+ value.toString() + " is found in scope " + SCOPE_NAMES[scope]
+ "; but didn't match any of the value constraints; "
+ "returning cache-on-match-failure = "
+ cacheOnMatchFailure);
}
return cacheOnMatchFailure;
|
public boolean | getCacheOnMatch()
return cacheOnMatch;
|
public boolean | getCacheOnMatchFailure()
return cacheOnMatchFailure;
|
public void | setCacheOnMatch(boolean cacheOnMatch)set whether to cache should the constraints check pass
this.cacheOnMatch = cacheOnMatch;
|
public void | setCacheOnMatchFailure(boolean cacheOnMatchFailure)set whether to cache should there be a failure forcing the constraint
this.cacheOnMatchFailure = cacheOnMatchFailure;
|
public void | setValueConstraints(ValueConstraint[] vcs)add an array of constraints for this field
if (vcs == null)
return;
constraints = vcs;
|