1 23 24 package com.sun.appserv.web.cache.mapping; 25 26 import java.util.logging.Logger ; 27 import java.util.logging.Level ; 28 29 import javax.servlet.ServletContext ; 30 import javax.servlet.http.HttpServletRequest ; 31 32 import com.sun.enterprise.web.logging.pwc.LogDomains; 33 34 37 public class ConstraintField extends Field { 38 39 private static Logger _logger = null; 40 private static boolean _isTraceEnabled = false; 41 42 boolean cacheOnMatch = true; 44 boolean cacheOnMatchFailure = false; 46 47 ValueConstraint constraints[] = new ValueConstraint[0]; 49 50 55 public ConstraintField (String name, String scope) 56 throws IllegalArgumentException { 57 super(name, scope); 58 if (_logger == null) { 59 _logger = LogDomains.getLogger(LogDomains.PWC_LOGGER); 60 _isTraceEnabled = _logger.isLoggable(Level.FINE); 61 } 62 } 63 64 67 public void setCacheOnMatch(boolean cacheOnMatch) { 68 this.cacheOnMatch = cacheOnMatch; 69 } 70 71 74 public boolean getCacheOnMatch() { 75 return cacheOnMatch; 76 } 77 78 82 public void setCacheOnMatchFailure(boolean cacheOnMatchFailure) { 83 this.cacheOnMatchFailure = cacheOnMatchFailure; 84 } 85 86 89 public boolean getCacheOnMatchFailure() { 90 return cacheOnMatchFailure; 91 } 92 93 97 public void addConstraint(ValueConstraint constraint) { 98 if (constraint == null) 99 return; 100 101 ValueConstraint results[] = 102 new ValueConstraint[constraints.length + 1]; 103 for (int i = 0; i < constraints.length; i++) 104 results[i] = constraints[i]; 105 106 results[constraints.length] = constraint; 107 constraints = results; 108 } 109 110 114 public void setValueConstraints(ValueConstraint[] vcs) { 115 if (vcs == null) 116 return; 117 118 constraints = vcs; 119 } 120 121 126 public boolean applyConstraints(ServletContext context, 127 HttpServletRequest request) { 128 129 Object value = getValue(context, request); 130 if (value == null) { 131 if (_isTraceEnabled) { 133 _logger.fine("The constraint field " + name + " is not found in the scope " + Constants.SCOPE_NAMES[scope] + "; returning cache-on-match-failure: " + cacheOnMatchFailure); 134 } 135 return cacheOnMatchFailure; 136 } else if (constraints.length == 0) { 137 if (_isTraceEnabled) { 139 _logger.fine("The constraint field " + name + " value = " + value.toString() + " is found in the scope " + Constants.SCOPE_NAMES[scope] + "; returning cache-on-match: " + cacheOnMatch); 140 } 141 return cacheOnMatch; 142 } 143 144 for (int i = 0; i < constraints.length; i++) { 146 ValueConstraint c = constraints[i]; 147 148 if (c.matches(value)) { 150 if (_isTraceEnabled) { 151 _logger.fine("The constraint field " + name + " value = " + value.toString() + " is found in the scope " + Constants.SCOPE_NAMES[scope] + "; and matches with a value " + c.toString() +"; returning cache-on-match: " + cacheOnMatch); 152 } 153 return cacheOnMatch; 154 } 155 } 156 157 if (_isTraceEnabled) { 159 _logger.fine("The constraint field " + name + " value = " + value.toString() + " is found in the scope " + Constants.SCOPE_NAMES[scope] + "; but didn't match with any of the value constraints; returning cache-on-match-failure = " + cacheOnMatchFailure); 160 } 161 return cacheOnMatchFailure; 162 } 163 } 164 | Popular Tags |