KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > ServletFilterDescriptor


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 package com.sun.enterprise.deployment;
24
25 import java.io.*;
26 import java.util.*;
27 import com.sun.enterprise.deployment.EnvironmentProperty;
28 import com.sun.enterprise.deployment.web.InitializationParameter;
29 import com.sun.enterprise.deployment.web.ServletFilter;
30 import com.sun.enterprise.deployment.web.ServletFilterMapping;
31
32 /**
33  * Deployment object representing the servlet filter spec
34  * @author Martin D. Flynn
35  */

36 public class ServletFilterDescriptor
37     extends Descriptor
38     implements ServletFilter
39 {
40
41     /** class name */
42     private String JavaDoc className = "";
43
44     /** display name */
45     private String JavaDoc displayName = "";
46
47     /** filter name */
48     private String JavaDoc filterName = "";
49
50     /** initialization parameters */
51     private Vector initParms = new Vector();
52
53     /* ----
54     */

55
56     /** generic constructor */
57     public ServletFilterDescriptor() {
58     super("", ""/*description*/);
59     this.setClassName("");
60     }
61
62     /** constructor specifying descriptor name (Filter name) & displayName */
63     public ServletFilterDescriptor(String JavaDoc className, String JavaDoc name) {
64     super(name, ""/*description*/);
65     this.setClassName(className);
66     }
67
68     /* ----
69     */

70
71     /** set class name */
72     public void setClassName(String JavaDoc name) {
73     this.className = (name != null)? name : "";
74     }
75
76     /** get class name */
77     public String JavaDoc getClassName() {
78     if (this.className == null) {
79         this.className = "";
80     }
81     return this.className;
82     }
83
84     /** set display name */
85     public void setDisplayName(String JavaDoc name) {
86     this.displayName = (name != null)? name : "";
87     }
88
89     /** get display name */
90     public String JavaDoc getDisplayName() {
91     String JavaDoc n = this.displayName;
92     if ((n == null) || n.equals("")) {
93         n = this.getName();
94     }
95     return n;
96     }
97
98     /** set filter name */
99     public void setName(String JavaDoc filterName) {
100         this.filterName = filterName;
101     }
102
103     /** get filter name */
104     public String JavaDoc getName() {
105     if ((filterName == null) || filterName.equals("")) {
106         String JavaDoc c = this.getClassName();
107         int p = c.lastIndexOf('.');
108         filterName = (p < 0)? c : c.substring(p + 1);
109     }
110     return filterName;
111     }
112
113     /* ----
114     */

115
116     /* set initialization parameters */
117     public void setInitializationParameters(Collection c) {
118     this.initParms.clear();
119     this.initParms.addAll(c);
120     }
121
122     /* get initialization parameters */
123     public Vector getInitializationParameters() {
124     return (Vector)this.initParms.clone();
125     }
126
127     /* add a single initialization parameter */
128     public void addInitializationParameter(InitializationParameter ref) {
129     this.initParms.addElement(ref);
130     }
131     
132     /* add a single initialization parameter */
133     public void addInitializationParameter(EnvironmentProperty ref) {
134     addInitializationParameter((InitializationParameter) ref);
135     }
136
137     /* remove a single initialization parameter */
138     public void removeInitializationParameter(InitializationParameter ref) {
139     this.initParms.removeElement(ref);
140     }
141
142     /* ----
143     */

144
145     /** compare equals */
146     public boolean equals(Object JavaDoc obj) {
147         /*
148     return (obj instanceof ServletFilter)?
149         this.getClassName().equals(((ServletFilter)obj).getClassName()) :
150         super.equals(obj);
151         */

152
153         //Should allow a filter with different name mapping
154
//to the same class.
155
if (obj instanceof ServletFilter) {
156         if (this.getClassName().equals(
157                         ((ServletFilter)obj).getClassName())
158                     && this.getName().equals(
159                             ((ServletFilter)obj).getName())) {
160                 return true;
161             }
162         }
163
164         return false;
165     }
166 }
167
Popular Tags