KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_web > deployment > api > MethodDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: MethodDesc.java,v 1.2 2004/06/01 11:24:01 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_web.deployment.api;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32
33 /**
34  * Defines a Method object. It manages exclued, unchecked methods with
35  * the right transportGuarantee. It also manages the roles which were
36  * defined for this method
37  * @author Florent Benoit
38  */

39 public class MethodDesc {
40
41     /**
42      * Name of the http-method
43      */

44     private String JavaDoc name = null;
45
46
47     /**
48      * Method excluded ?
49      */

50     private boolean excluded = false;
51
52
53     /**
54      * Method unchecked (by default = yes) ?
55      */

56     private boolean unchecked = true;
57
58     /**
59      * Transport Guarantee value(s)
60      */

61     private TransportGuaranteeDesc transportGuarantee;
62
63
64     /**
65      * List of roles and transportGuarantee
66      * key = role name
67      * value = transport guarantee value
68      */

69     private List JavaDoc roles = null;
70
71
72     /**
73      * Constructor
74      * Build a Method with the right type
75      * @param name the name of the method
76      */

77     public MethodDesc(String JavaDoc name) {
78         this.name = name.toUpperCase();
79         this.roles = new ArrayList JavaDoc();
80         this.transportGuarantee = new TransportGuaranteeDesc();
81     }
82
83
84     /**
85      * Is this method excluded ?
86      * @return true is this method is excluded, false otherwise
87      */

88     public boolean isExcluded() {
89         return excluded;
90     }
91
92     /**
93      * Is this method unchecked ?
94      * @return true is this method is unchecked, false otherwise
95      */

96     public boolean isUnchecked() {
97         return unchecked;
98     }
99
100     /**
101      * Set this method excluded
102      */

103     public void setExcluded() {
104         excluded = true;
105         unchecked = false;
106     }
107
108     /**
109      * Set this method unchecked
110      */

111     public void setUnchecked() {
112         excluded = false;
113         unchecked = true;
114     }
115
116
117     /**
118      * Defines the transport guarantee
119      * @param transportGuaranteeValue the value
120      */

121     public void addTransportGuarantee(String JavaDoc transportGuaranteeValue) {
122         transportGuarantee.addTransportValue(transportGuaranteeValue);
123     }
124
125
126     /**
127      * Add role with its transportGuarantee to this method
128      * @param role role to add
129      * @param transportGuaranteeRoleValue transport guarantee for this role
130      */

131     public void addRole(String JavaDoc role, String JavaDoc transportGuaranteeRoleValue) {
132         if (!roles.contains(role)) {
133             roles.add(role);
134         }
135         addTransportGuarantee(transportGuaranteeRoleValue);
136     }
137
138
139     /**
140      * Test if there are roles for this method
141      * @return true if there are roles defined for this method
142      */

143     public boolean hasRole() {
144         return (roles.size() > 0);
145     }
146
147
148     /**
149      * Gets the name of the Method
150      * @return name of the Method
151      */

152     public String JavaDoc getName() {
153         return name;
154     }
155
156
157     /**
158      * Gets iterator on roles
159      * @return iterator on roles
160      */

161     public Iterator JavaDoc getRolesIterator() {
162         return roles.iterator();
163     }
164
165
166     /**
167      * Gets the transport guarantee
168      * @return transport guarantee
169      */

170     public TransportGuaranteeDesc getTransportGuarantee() {
171         return transportGuarantee;
172     }
173
174
175
176     /**
177      * Defined the Equals method
178      * true if it is the same name
179      * @param other the object to test if it is equals or not
180      * @return true if it is the same object
181      */

182     public boolean equals(Object JavaDoc other) {
183         if (other instanceof String JavaDoc) {
184             return name.equals(other);
185         } else if (other instanceof MethodDesc) {
186             return name.equals(((MethodDesc) other).getName());
187         } else {
188             return false;
189         }
190     }
191
192     /**
193      * Gets the hashcode for this object
194      * @return hashcode of this object
195      */

196     public int hashCode() {
197         return name.hashCode();
198     }
199
200
201     /**
202      * String representation
203      * @return string representation of the pattern
204      */

205     public String JavaDoc toString() {
206         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
207         sb.append("Method[name=");
208         sb.append(name);
209         // excluded
210
if (excluded) {
211             sb.append(";excluded");
212         }
213         // unchecked
214
if (unchecked) {
215             sb.append(";unchecked");
216         }
217         // transportGuarantee
218
sb.append(transportGuarantee);
219
220
221         // roles
222
sb.append(";roles=");
223         for (Iterator JavaDoc it = getRolesIterator(); it.hasNext();) {
224             String JavaDoc role = (String JavaDoc) it.next();
225             sb.append(role);
226         }
227         sb.append("]");
228         return sb.toString();
229
230     }
231 }
232
Popular Tags