KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > balancer > rules > BaseRule


1 /*
2  * Copyright 2000,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.webapp.balancer.rules;
17
18 import org.apache.webapp.balancer.Rule;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21
22
23 /**
24  * The BaseRule is an empty rule
25  * implementation which can be
26  * subclassed for extension.
27  *
28  * @author Yoav Shapira
29  */

30 public abstract class BaseRule implements Rule {
31     /**
32      * The rule name.
33      */

34     private String JavaDoc name;
35
36     /**
37      * The URL where matching
38      * requested will be redirected.
39      */

40     private String JavaDoc redirectUrl;
41
42     /**
43      * Sets the rule name.
44      *
45      * @param theName The rule name.
46      */

47     public void setName(String JavaDoc theName) {
48         if (theName == null) {
49             throw new IllegalArgumentException JavaDoc("The name cannot be null.");
50         } else {
51             name = theName;
52         }
53     }
54
55     /**
56      * Returns the rule name.
57      *
58      * @return String
59      */

60     protected String JavaDoc getName() {
61         return name;
62     }
63
64     /**
65      * @see Rule#getRedirectUrl
66      */

67     public String JavaDoc getRedirectUrl() {
68         return redirectUrl;
69     }
70
71     /**
72      * Sets the redirect URL.
73      *
74      * @param theRedirectUrl Where matching requests will be redirected
75      */

76     public void setRedirectUrl(String JavaDoc theRedirectUrl) {
77         if (theRedirectUrl == null) {
78             throw new IllegalArgumentException JavaDoc("redirectUrl may not be null.");
79         } else {
80             redirectUrl = theRedirectUrl;
81         }
82     }
83
84     /**
85      * @see Rule#matches(HttpServletRequest)
86      */

87     public abstract boolean matches(HttpServletRequest JavaDoc request);
88
89     /**
90      * Returns a String representation of this object.
91      *
92      * @return String
93      */

94     public String JavaDoc toString() {
95         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
96
97         buffer.append("[");
98         buffer.append(getClass().getName());
99         buffer.append(": ");
100
101         buffer.append("Redirect URL: ");
102         buffer.append(getRedirectUrl());
103
104         buffer.append("]");
105
106         return buffer.toString();
107     }
108 }
109
110
111 // End of file: BaseRule.java
112
Popular Tags