001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/tool/tags/sakai_2-4-1/tool-util/util/src/java/org/sakaiproject/util/Tool.java $
003: * $Id: Tool.java 27663 2007-03-22 19:50:10Z bkirschn@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.util;
021:
022: import java.util.Collections;
023: import java.util.HashSet;
024: import java.util.Properties;
025: import java.util.Set;
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.sakaiproject.tool.api.ActiveToolManager;
029:
030: ;
031:
032: /**
033: * <p>
034: * Tool is a utility class that implements the Tool interface.
035: * </p>
036: */
037: public class Tool implements org.sakaiproject.tool.api.Tool, Comparable {
038: /** Our log (commons). */
039: private static Log M_log = LogFactory.getLog(Tool.class);
040:
041: /** The access security. */
042: protected Tool.AccessSecurity m_accessSecurity = Tool.AccessSecurity.PORTAL;
043:
044: /** The tool Manager that possesses the RessourceBundle. */
045: private ActiveToolManager m_activeToolManager = org.sakaiproject.tool.cover.ActiveToolManager
046: .getInstance();
047:
048: /** The set of categories. */
049: protected Set m_categories = new HashSet();
050:
051: /** The description string. */
052: protected String m_description = null;
053:
054: /** The configuration properties that are set by registration and may not be changed by confguration. */
055: protected Properties m_finalConfig = new Properties();
056:
057: /** Home destination. */
058: protected String m_home = null;
059:
060: /** The well known identifier string. */
061: protected String m_id = null;
062:
063: /** The set of keywords. */
064: protected Set m_keywords = new HashSet();
065:
066: /** The configuration properties that may be changed by configuration. */
067: protected Properties m_mutableConfig = new Properties();
068:
069: /** The title string. */
070: protected String m_title = null;
071:
072: /**
073: * Construct
074: */
075: public Tool() {
076: }
077:
078: /**
079: * @inheritDoc
080: */
081: public int compareTo(Object obj) {
082: // let it throw a class case exception if the obj is not some sort of Tool
083: org.sakaiproject.tool.api.Tool tool = (org.sakaiproject.tool.api.Tool) obj;
084:
085: // do an id based
086: return getId().compareTo(tool.getId());
087: }
088:
089: /**
090: * {@inheritDoc}
091: */
092: public boolean equals(Object obj) {
093: if (!(obj instanceof Tool)) {
094: return false;
095: }
096:
097: return ((Tool) obj).getId().equals(getId());
098: }
099:
100: /**
101: * @inheritDoc
102: */
103: public Tool.AccessSecurity getAccessSecurity() {
104: return m_accessSecurity;
105: }
106:
107: /**
108: * @inheritDoc
109: */
110: public Set getCategories() {
111: return Collections.unmodifiableSet(m_categories);
112: }
113:
114: /**
115: * @inheritDoc
116: */
117: public String getDescription() {
118: final String localizedToolDescription = m_activeToolManager
119: .getLocalizedToolProperty(this .getId(), "description");
120:
121: if (localizedToolDescription == null) {
122: return m_description;
123: } else {
124: return localizedToolDescription;
125: }
126: }
127:
128: /**
129: * @inheritDoc
130: */
131: public Properties getFinalConfig() {
132: // return a copy so that it is read only
133: Properties rv = new Properties();
134: rv.putAll(m_finalConfig);
135: return rv;
136: }
137:
138: /**
139: * {@inheritDoc}
140: */
141: public String getHome() {
142: return m_home;
143: }
144:
145: /**
146: * @inheritDoc
147: */
148: public String getId() {
149: return m_id;
150: }
151:
152: /**
153: * @inheritDoc
154: */
155: public Set getKeywords() {
156: return Collections.unmodifiableSet(m_keywords);
157: }
158:
159: /**
160: * @inheritDoc
161: */
162: public Properties getMutableConfig() {
163: // return a copy so that it is read only
164: Properties rv = new Properties();
165: rv.putAll(m_mutableConfig);
166: return rv;
167: }
168:
169: /**
170: * @inheritDoc
171: */
172: public Properties getRegisteredConfig() {
173: // combine the final and mutable, and return a copy so that it is read only
174: Properties rv = new Properties();
175: rv.putAll(m_finalConfig);
176: rv.putAll(m_mutableConfig);
177: return rv;
178: }
179:
180: /**
181: * @inheritDoc
182: */
183: public String getTitle() {
184: final String localizedToolTitle = m_activeToolManager
185: .getLocalizedToolProperty(this .getId(), "title");
186:
187: if (localizedToolTitle == null) {
188: return m_title;
189: } else {
190: return localizedToolTitle;
191: }
192: }
193:
194: /**
195: * {@inheritDoc}
196: */
197: public int hashCode() {
198: return getId().hashCode();
199: }
200:
201: /**
202: * Set the access security.
203: *
204: * @param access
205: * The new access security setting.
206: */
207: public void setAccessSecurity(Tool.AccessSecurity access) {
208: m_accessSecurity = access;
209: }
210:
211: /**
212: * Set the categories.
213: *
214: * @param categories
215: * The new categories set (Strings).
216: */
217: public void setCategories(Set categories) {
218: m_categories = categories;
219: }
220:
221: /**
222: * Set the description.
223: *
224: * @param description
225: * The description to set.
226: */
227: public void setDescription(String description) {
228: m_description = description;
229: }
230:
231: public void setHome(String home) {
232: m_home = home;
233: }
234:
235: /**
236: * Set the id.
237: *
238: * @param m_id
239: * The m_id to set.
240: */
241: public void setId(String id) {
242: m_id = id;
243: }
244:
245: /**
246: * Set the keywords.
247: *
248: * @param keywords
249: * The new keywords set (Strings).
250: */
251: public void setKeywords(Set keywords) {
252: m_keywords = keywords;
253: }
254:
255: /**
256: * Set the registered configuration.
257: *
258: * @param config
259: * The new registered configuration Properties.
260: */
261: public void setRegisteredConfig(Properties finalConfig,
262: Properties mutableConfig) {
263: m_finalConfig = finalConfig;
264: if (m_finalConfig == null) {
265: m_finalConfig = new Properties();
266: }
267:
268: m_mutableConfig = mutableConfig;
269: if (m_mutableConfig == null) {
270: m_mutableConfig = new Properties();
271: }
272: }
273:
274: /**
275: * Set the title.
276: *
277: * @param title
278: * The title to set.
279: */
280: public void setTitle(String title) {
281: m_title = title;
282: }
283: }
|