1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.tomcat.util.descriptor.web;
18
19
20
21 /**
22 * Representation of a resource reference for a web application, as
23 * represented in a <code><resource-ref></code> element in the
24 * deployment descriptor.
25 *
26 * @author Craig R. McClanahan
27 * @author Peter Rossbach (pero@apache.org)
28 */
29 public class ContextResource extends ResourceBase {
30
31 private static final long serialVersionUID = 1L;
32
33 // ------------------------------------------------------------- Properties
34
35
36 /**
37 * The authorization requirement for this resource
38 * (<code>Application</code> or <code>Container</code>).
39 */
40 private String auth = null;
41
42 public String getAuth() {
43 return this.auth;
44 }
45
46 public void setAuth(String auth) {
47 this.auth = auth;
48 }
49
50 /**
51 * The sharing scope of this resource factory (<code>Shareable</code>
52 * or <code>Unshareable</code>).
53 */
54 private String scope = "Shareable";
55
56 public String getScope() {
57 return this.scope;
58 }
59
60 public void setScope(String scope) {
61 this.scope = scope;
62 }
63
64
65 /**
66 * Is this resource known to be a singleton resource. The default value is
67 * true since this is what users expect although the JavaEE spec implies
68 * that the default should be false.
69 */
70 private boolean singleton = true;
71
72 public boolean getSingleton() {
73 return singleton;
74 }
75
76 public void setSingleton(boolean singleton) {
77 this.singleton = singleton;
78 }
79
80
81 /**
82 * The name of the zero argument method to be called when the resource is
83 * no longer required to clean-up resources. This method must only speed up
84 * the clean-up of resources that would otherwise happen via garbage
85 * collection.
86 */
87 private String closeMethod = null;
88 private boolean closeMethodConfigured = false;
89
90 public String getCloseMethod() {
91 return closeMethod;
92 }
93
94 public void setCloseMethod(String closeMethod) {
95 closeMethodConfigured = true;
96 this.closeMethod = closeMethod;
97 }
98
99 public boolean getCloseMethodConfigured() {
100 return closeMethodConfigured;
101 }
102
103
104 // --------------------------------------------------------- Public Methods
105
106
107 /**
108 * Return a String representation of this object.
109 */
110 @Override
111 public String toString() {
112
113 StringBuilder sb = new StringBuilder("ContextResource[");
114 sb.append("name=");
115 sb.append(getName());
116 if (getDescription() != null) {
117 sb.append(", description=");
118 sb.append(getDescription());
119 }
120 if (getType() != null) {
121 sb.append(", type=");
122 sb.append(getType());
123 }
124 if (auth != null) {
125 sb.append(", auth=");
126 sb.append(auth);
127 }
128 if (scope != null) {
129 sb.append(", scope=");
130 sb.append(scope);
131 }
132 sb.append("]");
133 return sb.toString();
134 }
135
136
137 @Override
138 public int hashCode() {
139 final int prime = 31;
140 int result = super.hashCode();
141 result = prime * result + ((auth == null) ? 0 : auth.hashCode());
142 result = prime * result +
143 ((closeMethod == null) ? 0 : closeMethod.hashCode());
144 result = prime * result + ((scope == null) ? 0 : scope.hashCode());
145 result = prime * result + (singleton ? 1231 : 1237);
146 return result;
147 }
148
149
150 @Override
151 public boolean equals(Object obj) {
152 if (this == obj) {
153 return true;
154 }
155 if (!super.equals(obj)) {
156 return false;
157 }
158 if (getClass() != obj.getClass()) {
159 return false;
160 }
161 ContextResource other = (ContextResource) obj;
162 if (auth == null) {
163 if (other.auth != null) {
164 return false;
165 }
166 } else if (!auth.equals(other.auth)) {
167 return false;
168 }
169 if (closeMethod == null) {
170 if (other.closeMethod != null) {
171 return false;
172 }
173 } else if (!closeMethod.equals(other.closeMethod)) {
174 return false;
175 }
176 if (scope == null) {
177 if (other.scope != null) {
178 return false;
179 }
180 } else if (!scope.equals(other.scope)) {
181 return false;
182 }
183 if (singleton != other.singleton) {
184 return false;
185 }
186 return true;
187 }
188 }
189