KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.deployment.web.WebResourceCollection;
26 import java.util.*;
27
28 /**
29  * This descriptor represents a description of a portion of a web app
30  * in terms of a collection of url patterns and
31  * a collection of http methods on this patterns.
32  *
33  *@author Danny Coward
34  */

35
36
37 public class WebResourceCollectionImpl extends Descriptor
38                 implements WebResourceCollection
39 {
40     private Set urlPatterns;
41     private Set httpMethods;
42     
43     /**
44      * Return my urls patterns (String objects)
45      * @return the enumeration of the url patterns.
46      */

47     public Enumeration getUrlPatterns() {
48     return (new Vector(this.getUrlPatternsSet())).elements();
49     }
50     
51     /**
52      * Add a URL pattern to this collection.
53      * @param the url pattern to be added.
54      */

55     public void addUrlPattern(String JavaDoc urlPattern) {
56     this.getUrlPatternsSet().add(urlPattern);
57     }
58     
59     /**
60      * Remove the specified url pattern from the collection.
61      * @param the url pattern to be removed.
62      */

63     public void removeUrlPattern(String JavaDoc urlPattern) {
64     this.getUrlPatternsSet().remove(urlPattern);
65     }
66     
67     /**
68      * Clean out the collection of URL pattern and replace
69      * it with the given Set of (String) url patterns.
70      * @param the url patterns to replace the current set.
71      */

72     public void setUrlPatterns(Set urlPatterns) {
73     this.urlPatterns = urlPatterns;
74     }
75     
76     private Set getHttpMethodsSet() {
77     if (this.httpMethods == null) {
78         this.httpMethods = new HashSet();
79     }
80     return this.httpMethods;
81     }
82     
83     /**
84      * Return the enumeration of HTTP methods this collection has.
85      * @return the enumeration of HTTP methods.
86      */

87     public Enumeration getHttpMethods() {
88     return (new Vector(this.getHttpMethodsSet())).elements();
89     }
90     /**
91      * Returns the HttpMethods this collection has in an array of strings
92      * @return array of strings of HttpMethods
93      */

94     /*
95      * added to speed up processing while creating webresource permissions
96      */

97     public String JavaDoc[] getHttpMethodsAsArray(){
98     if(httpMethods == null){
99         return (String JavaDoc[]) null;
100     }
101     String JavaDoc[] array = (String JavaDoc[])httpMethods.toArray(new String JavaDoc[0]);
102     return array;
103     }
104     /**
105      * Sets the set of HTTP methods this collection has.
106      * @param the set of HTTP methods.
107      */

108     public void setHttpMethods(Set httpMethods) {
109     this.httpMethods = httpMethods;
110     }
111
112     /**
113      * Adds the given HTTP method to the collection of http methods this
114      * collection has.
115      * @param the HTTP method to be added.
116      */

117     public void addHttpMethod(String JavaDoc httpMethod) {
118     this.getHttpMethodsSet().add(httpMethod);
119     }
120     
121     /**
122      * Removes the given HTTP method from the collection of http methods.
123      * @param the HTTP method to be removed.
124      */

125     public void removeHttpMethod(String JavaDoc httpMethod) {
126     this.getHttpMethodsSet().remove(httpMethod);
127     }
128     
129     /**
130      * A formatted string of the state.
131      */

132     public void print(StringBuffer JavaDoc toStringBuffer) {
133     toStringBuffer.append("WebresourceCollection: ");
134     toStringBuffer.append(" urlPatterns: ").append(this.urlPatterns);
135     toStringBuffer.append(" httpMethods ").append(this.httpMethods);
136     }
137
138     private Set getUrlPatternsSet() {
139     if (this.urlPatterns == null) {
140         this.urlPatterns = new HashSet();
141     }
142     return this.urlPatterns;
143     }
144
145 }
146
147
Popular Tags