KickJava   Java API By Example, From Geeks To Geeks.

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


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.web.ServletFilterMapping;
28
29 /**
30  * Deployment object representing the servlet filter mapping spec
31  * @author Martin D. Flynn
32  */

33 public class ServletFilterMappingDescriptor
34     extends Descriptor
35     implements com.sun.enterprise.deployment.web.ServletFilterMapping
36 {
37
38     public static final String JavaDoc TARGET_TYPE_URLPATTERN =
39     ServletFilterMapping.TARGET_TYPE_URLPATTERN;
40     public static final String JavaDoc TARGET_TYPE_SERVLET =
41     ServletFilterMapping.TARGET_TYPE_SERVLET;
42
43     public static String JavaDoc INCLUDE = ServletFilterMapping.INCLUDE;
44     public static String JavaDoc REQUEST = ServletFilterMapping.REQUEST;
45     public static String JavaDoc FORWARD = ServletFilterMapping.FORWARD;
46
47     private static Set allowed_dispatchers;
48     
49     /** target type ("URLPattern", "Servlet") */
50     private String JavaDoc targetType = TARGET_TYPE_URLPATTERN;
51
52     /** the target URL or Servlet name */
53     private String JavaDoc target = "";
54
55     private Set dispatchers;
56     private List<String JavaDoc> servletNames;
57     private List<String JavaDoc> urlPatterns;
58
59     /** generic constructor */
60     public ServletFilterMappingDescriptor() {
61     super(""/*name*/, ""/*description*/);
62     }
63
64     /** copy constructor */
65     public ServletFilterMappingDescriptor(ServletFilterMappingDescriptor other) {
66         super(other);
67         targetType = other.targetType;
68         target = other.target;
69         dispatchers = (other.dispatchers != null)? new HashSet(other.dispatchers) : null;
70     }
71
72     /** constructor specifying the name & target */
73     public ServletFilterMappingDescriptor(String JavaDoc dispName,
74         String JavaDoc targetType, String JavaDoc target) {
75         super(dispName, ""/*description*/);
76         this.setTargetType(targetType);
77         this.setTarget(target);
78     }
79
80     /** set the target type */
81     public void setTargetType(String JavaDoc type) {
82         if (TARGET_TYPE_SERVLET.equals(type)) {
83             this.targetType = TARGET_TYPE_SERVLET;
84         } else {
85             this.targetType = TARGET_TYPE_URLPATTERN;
86         }
87     }
88
89     /** get the target type */
90     public String JavaDoc getTargetType() {
91         if (! getServletNames().isEmpty()) {
92             return TARGET_TYPE_SERVLET;
93         } else {
94             return TARGET_TYPE_URLPATTERN;
95         }
96     }
97
98     /** 'true' if URL-Pattern target type */
99     public boolean isURLPatternTarget() {
100         return TARGET_TYPE_URLPATTERN.equals(getTargetType());
101     }
102
103     /** 'true' if Servlet target type */
104     public boolean isServletNameTarget() {
105         return TARGET_TYPE_SERVLET.equals(getTargetType());
106     }
107
108     /** set the target name */
109     public void setTarget(String JavaDoc target) {
110         this.target = target;
111     }
112
113     /** get the target name */
114     public String JavaDoc getTarget() {
115         if (! getServletNames().isEmpty()) {
116             Iterator i = servletNames.iterator();
117             return (String JavaDoc) i.next();
118         } else {
119             Iterator i = urlPatterns.iterator();
120             return (String JavaDoc) i.next();
121         }
122     }
123     
124     public void addServletName(String JavaDoc servletName) {
125         getServletNames().add(servletName);
126     }
127
128     public List<String JavaDoc> getServletNames() {
129         if (servletNames == null) {
130             servletNames = new LinkedList<String JavaDoc>();
131         }
132         return servletNames;
133     }
134
135     public void addURLPattern(String JavaDoc urlPattern) {
136         getURLPatterns().add(urlPattern);
137     }
138
139     public List<String JavaDoc> getURLPatterns() {
140         if (urlPatterns == null) {
141             urlPatterns = new LinkedList<String JavaDoc>();
142         }
143         return urlPatterns;
144     }
145
146     public void addDispatcher(String JavaDoc dispatcher) {
147         if (dispatchers == null) {
148             dispatchers = new HashSet();
149         }
150         dispatchers.add(dispatcher);
151     }
152     
153     public void removeDispatcher(String JavaDoc dispatcher) {
154         if (dispatchers == null) {
155             return;
156         }
157         dispatchers.remove(dispatcher);
158     }
159
160     public Set getDispatchers() {
161         if (dispatchers == null) {
162             dispatchers = new HashSet();
163         }
164         return dispatchers;
165     }
166
167     public static Set getAllowedDispatchers() {
168         if (allowed_dispatchers == null) {
169             allowed_dispatchers = new HashSet();
170             allowed_dispatchers.add(INCLUDE);
171             allowed_dispatchers.add(REQUEST);
172             allowed_dispatchers.add(FORWARD);
173         }
174         return allowed_dispatchers;
175     }
176
177     /** compare equals */
178     public boolean equals(Object JavaDoc obj) {
179         if (obj instanceof ServletFilterMapping) {
180             ServletFilterMapping o = (ServletFilterMapping) obj;
181             if ( this.getName().equals(o.getName())
182                     && this.getServletNames().equals(o.getServletNames())
183                     && this.getURLPatterns().equals(o.getURLPatterns()) ) {
184                 return true;
185             }
186         }
187
188         return false;
189     }
190 }
191
Popular Tags