FileDocCategorySizeDatePackage
ConstraintField.javaAPI DocGlassfish v2 API7604Fri May 04 22:35:28 BST 2007com.sun.appserv.web.cache.mapping

ConstraintField

public class ConstraintField extends Field
ConstraintField class represents a single Field and constraints on its values; Field name and its scope are inherited from the Field class.

Fields Summary
private static final String[]
SCOPE_NAMES
private static Logger
_logger
private static boolean
_isTraceEnabled
boolean
cacheOnMatch
boolean
cacheOnMatchFailure
ValueConstraint[]
constraints
Constructors Summary
public ConstraintField(String name, String scope)
create a new cache field, given a string representation of the scope

param
name name of this field
param
scope scope of this field


                                 
          
                                  
        super(name, scope);
        if (_logger == null) {
            _logger = LogDomains.getLogger(LogDomains.PWC_LOGGER);
            _isTraceEnabled = _logger.isLoggable(Level.FINE);
        }
    
Methods Summary
public voidaddConstraint(ValueConstraint constraint)
add a constraint for this field

param
constraint one constraint associated with 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 booleanapplyConstraints(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 booleangetCacheOnMatch()

return
cache-on-match setting

        return cacheOnMatch;
    
public booleangetCacheOnMatchFailure()

return
cache-on-match-failure setting

        return cacheOnMatchFailure;
    
public voidsetCacheOnMatch(boolean cacheOnMatch)
set whether to cache should the constraints check pass

param
cacheOnMatch should the constraint check pass, should we cache?

        this.cacheOnMatch = cacheOnMatch;
    
public voidsetCacheOnMatchFailure(boolean cacheOnMatchFailure)
set whether to cache should there be a failure forcing the constraint

param
cacheOnMatchFailure should there be a constraint check failure, enable cache?

        this.cacheOnMatchFailure = cacheOnMatchFailure;
    
public voidsetValueConstraints(ValueConstraint[] vcs)
add an array of constraints for this field

param
vcs constraints associated with this field

        if (vcs == null)
            return;

        constraints = vcs;