001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: MethodDesc.java 4854 2004-06-01 11:24:01Z benoitf $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_web.deployment.api;
026:
027: import java.util.ArrayList;
028: import java.util.Iterator;
029: import java.util.List;
030:
031: /**
032: * Defines a Method object. It manages exclued, unchecked methods with
033: * the right transportGuarantee. It also manages the roles which were
034: * defined for this method
035: * @author Florent Benoit
036: */
037: public class MethodDesc {
038:
039: /**
040: * Name of the http-method
041: */
042: private String name = null;
043:
044: /**
045: * Method excluded ?
046: */
047: private boolean excluded = false;
048:
049: /**
050: * Method unchecked (by default = yes) ?
051: */
052: private boolean unchecked = true;
053:
054: /**
055: * Transport Guarantee value(s)
056: */
057: private TransportGuaranteeDesc transportGuarantee;
058:
059: /**
060: * List of roles and transportGuarantee
061: * key = role name
062: * value = transport guarantee value
063: */
064: private List roles = null;
065:
066: /**
067: * Constructor
068: * Build a Method with the right type
069: * @param name the name of the method
070: */
071: public MethodDesc(String name) {
072: this .name = name.toUpperCase();
073: this .roles = new ArrayList();
074: this .transportGuarantee = new TransportGuaranteeDesc();
075: }
076:
077: /**
078: * Is this method excluded ?
079: * @return true is this method is excluded, false otherwise
080: */
081: public boolean isExcluded() {
082: return excluded;
083: }
084:
085: /**
086: * Is this method unchecked ?
087: * @return true is this method is unchecked, false otherwise
088: */
089: public boolean isUnchecked() {
090: return unchecked;
091: }
092:
093: /**
094: * Set this method excluded
095: */
096: public void setExcluded() {
097: excluded = true;
098: unchecked = false;
099: }
100:
101: /**
102: * Set this method unchecked
103: */
104: public void setUnchecked() {
105: excluded = false;
106: unchecked = true;
107: }
108:
109: /**
110: * Defines the transport guarantee
111: * @param transportGuaranteeValue the value
112: */
113: public void addTransportGuarantee(String transportGuaranteeValue) {
114: transportGuarantee.addTransportValue(transportGuaranteeValue);
115: }
116:
117: /**
118: * Add role with its transportGuarantee to this method
119: * @param role role to add
120: * @param transportGuaranteeRoleValue transport guarantee for this role
121: */
122: public void addRole(String role, String transportGuaranteeRoleValue) {
123: if (!roles.contains(role)) {
124: roles.add(role);
125: }
126: addTransportGuarantee(transportGuaranteeRoleValue);
127: }
128:
129: /**
130: * Test if there are roles for this method
131: * @return true if there are roles defined for this method
132: */
133: public boolean hasRole() {
134: return (roles.size() > 0);
135: }
136:
137: /**
138: * Gets the name of the Method
139: * @return name of the Method
140: */
141: public String getName() {
142: return name;
143: }
144:
145: /**
146: * Gets iterator on roles
147: * @return iterator on roles
148: */
149: public Iterator getRolesIterator() {
150: return roles.iterator();
151: }
152:
153: /**
154: * Gets the transport guarantee
155: * @return transport guarantee
156: */
157: public TransportGuaranteeDesc getTransportGuarantee() {
158: return transportGuarantee;
159: }
160:
161: /**
162: * Defined the Equals method
163: * true if it is the same name
164: * @param other the object to test if it is equals or not
165: * @return true if it is the same object
166: */
167: public boolean equals(Object other) {
168: if (other instanceof String) {
169: return name.equals(other);
170: } else if (other instanceof MethodDesc) {
171: return name.equals(((MethodDesc) other).getName());
172: } else {
173: return false;
174: }
175: }
176:
177: /**
178: * Gets the hashcode for this object
179: * @return hashcode of this object
180: */
181: public int hashCode() {
182: return name.hashCode();
183: }
184:
185: /**
186: * String representation
187: * @return string representation of the pattern
188: */
189: public String toString() {
190: StringBuffer sb = new StringBuffer();
191: sb.append("Method[name=");
192: sb.append(name);
193: // excluded
194: if (excluded) {
195: sb.append(";excluded");
196: }
197: // unchecked
198: if (unchecked) {
199: sb.append(";unchecked");
200: }
201: // transportGuarantee
202: sb.append(transportGuarantee);
203:
204: // roles
205: sb.append(";roles=");
206: for (Iterator it = getRolesIterator(); it.hasNext();) {
207: String role = (String) it.next();
208: sb.append(role);
209: }
210: sb.append("]");
211: return sb.toString();
212:
213: }
214: }
|