KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > web > cache > mapping > CacheMapping


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.appserv.web.cache.mapping;
25
26 import com.sun.appserv.web.cache.CacheHelper;
27
28 /** CacheMapping represents a cache target specified via servlet-name or a
29  * url-pattern, a timeout, allowed methods, a set of key fields to be used to
30  * construct the key into the cache, and a set of constraints on the field
31  * values.
32  */

33 public class CacheMapping {
34     private String JavaDoc helperNameRef;
35     private String JavaDoc servletName;
36     private String JavaDoc urlPattern;
37
38     // timeout specified value or via Field
39
private int timeout = CacheHelper.TIMEOUT_VALUE_NOT_SET;
40     private Field timeoutField = null;
41
42     // a field to force caching engine to refresh entry
43
private Field refreshField = null;
44
45     // set of standard HTTP methods eligible for caching
46
private String JavaDoc methods[] = new String JavaDoc[0];
47
48     // components of the key to be used to access the cache.
49
private Field keyFields[] = new Field[0];
50
51     // additional cache constraints
52
private ConstraintField constraintFields[] = new ConstraintField[0];
53
54     /** default cache mapping
55      */

56     public CacheMapping() {
57     }
58
59     // public config getters and setters
60

61     /**
62      * set the helper name ref associated with this cache mapping
63      * @param helperNameRef helper name ref for this cache mapping
64      */

65     public void setHelperNameRef(String JavaDoc helperNameRef) {
66         this.helperNameRef = helperNameRef;
67     }
68
69     /** set the servlet-name this mapping applies
70      * @param servletName name of the servlet
71      */

72     public void setServletName(String JavaDoc servletName) {
73         this.servletName = servletName;
74     }
75
76     /** set the url-pattern this mapping applies
77      * @param urlPattern url pattern this mapping applies
78      */

79     public void setURLPattern(String JavaDoc urlPattern) {
80         this.urlPattern = urlPattern;
81     }
82
83     /** set the timeout
84      * @param timeout specific timeout of the cacheable entries
85      */

86     public void setTimeout(int timeout) {
87         this.timeout = timeout;
88     }
89
90     /** set the timeout field
91      * @param field default timeout of the cacheable entries
92      */

93     public void setTimeoutField(Field field) {
94         this.timeoutField = field;
95     }
96
97     /** set the refresh field
98      * @param field Boolean field for controlling when a refresh is needed
99      */

100     public void setRefreshField(Field field) {
101         this.refreshField = field;
102     }
103
104     /** get the refresh field
105      * @return Configured refresh field
106      */

107     public Field getRefreshField() {
108         return refreshField;
109     }
110
111     /** set allowable HTTP methods
112      * @param methods allowable methods
113      */

114     public void setMethods(String JavaDoc[] methods) {
115         if (methods == null)
116             return;
117
118         this.methods = methods;
119     }
120
121     /** add an allowable HTTP method
122      * @param method allowable method
123      */

124     public void addMethod(String JavaDoc method) {
125         if (method == null)
126             return;
127
128         String JavaDoc results[] = new String JavaDoc[methods.length + 1];
129         for (int i = 0; i < methods.length; i++)
130             results[i] = methods[i];
131         results[methods.length] = method;
132
133         methods = results;
134     }
135     
136     /** add a key field
137      * @param field key Field to add
138      */

139     public void addKeyField(Field field) {
140         if (field == null)
141             return;
142
143         Field results[] = new Field[keyFields.length + 1];
144         for (int i = 0; i < keyFields.length; i++)
145             results[i] = keyFields[i];
146         results[keyFields.length] = field;
147
148         keyFields = results;
149     }
150
151     /** add a constraint key field
152      * @param field ConstraintField to add
153      */

154     public void addConstraintField(ConstraintField field) {
155         if (field == null)
156             return;
157
158         ConstraintField results[] =
159                 new ConstraintField[constraintFields.length + 1];
160
161         for (int i = 0; i < constraintFields.length; i++)
162             results[i] = constraintFields[i];
163         results[constraintFields.length] = field;
164
165         constraintFields = results;
166     }
167
168     /*** cache-mapping getter methods ***/
169
170     /**
171      * get helper-name-ref associated with this mapping
172      * @return helper name associated
173      */

174     public String JavaDoc getHelperNameRef() {
175         return helperNameRef;
176     }
177
178     /**
179      * get the underlying servlet-name
180      * @return servlet name
181      */

182     public String JavaDoc getServletName() {
183         return servletName;
184     }
185
186     /**
187      * get the underlying url-pattern this mapping applicable
188      * @return url-pattern string configured
189      */

190     public String JavaDoc getURLPattern() {
191         return urlPattern;
192     }
193
194     /**
195      * Return <code>true</code> if the specified HTTP request method is
196      * allowed for caching
197      *
198      * @param method Request method to check
199      */

200     public boolean findMethod(String JavaDoc method) {
201         if (methods.length == 0)
202             return (true);
203         for (int i = 0; i < methods.length; i++) {
204              if (methods[i].equals(method))
205              return (true);
206         }
207         return (false);
208     }
209
210     /**
211      * get the timeout
212      * @return timeout value configured
213      */

214     public int getTimeout() {
215         return timeout;
216     }
217
218     /**
219      * get the timeout field
220      * @return timeout field configured
221      */

222     public Field getTimeoutField() {
223         return timeoutField;
224     }
225
226     /**
227      * get the key fields
228      * @return key fields configured
229      */

230     public Field[] getKeyFields() {
231         return keyFields;
232     }
233
234     /**
235      * get the constraint fields
236      * @return constraint fields configured
237      */

238     public ConstraintField[] getConstraintFields() {
239         return constraintFields;
240     }
241 }
242
Popular Tags