001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/tool/tags/sakai_2-4-1/tool-util/util/src/java/org/sakaiproject/util/Placement.java $
003: * $Id: Placement.java 9588 2006-05-17 17:18:19Z ggolden@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.Properties;
023:
024: import org.sakaiproject.tool.api.Tool;
025: import org.sakaiproject.tool.cover.ToolManager;
026:
027: /**
028: * <p>
029: * Placement is a utility class that implements the Placement interface.
030: * </p>
031: */
032: public class Placement implements org.sakaiproject.tool.api.Placement {
033:
034: /** Placement configuration Properties (mutable). */
035: protected Properties m_config = new Properties();
036:
037: /** The placement context. */
038: protected String m_context = null;
039:
040: /** The well known identifier string. */
041: protected String m_id = null;
042:
043: /** The title string. */
044: protected String m_title = null;
045:
046: /** Tool placed. */
047: protected Tool m_tool = null;
048:
049: /** The placed tool's id - use if the tool is null. */
050: protected String m_toolId = null;
051:
052: /**
053: * Construct
054: */
055: public Placement() {
056: }
057:
058: /**
059: * Construct.
060: *
061: * @param id
062: * The placement id.
063: * @param toolId
064: * The well-known tool id associated with this placement.
065: * @param tool
066: * The tool to place.
067: * @param config
068: * The particular placement config Properties to use.
069: * @param context
070: * The particular placement context to use.
071: * @param title
072: * The tool placement title.
073: */
074: public Placement(String id, String toolId, Tool tool,
075: Properties config, String context, String title) {
076: m_id = id;
077: m_toolId = toolId;
078: m_tool = tool;
079: if (config != null) {
080: m_config = config;
081: }
082: m_context = context;
083: m_title = title;
084: }
085:
086: /**
087: * {@inheritDoc}
088: */
089: public boolean equals(Object obj) {
090: if (!(obj instanceof Placement)) {
091: return false;
092: }
093:
094: return ((Placement) obj).getId().equals(getId());
095: }
096:
097: /**
098: * {@inheritDoc}
099: */
100: public Properties getConfig() {
101: // the placement config overrides registered config
102: Properties p = new Properties();
103:
104: // put the registered ones in, and do it first so that the placement can override
105: if (m_tool != null) {
106: p.putAll(m_tool.getRegisteredConfig());
107: }
108:
109: // put the placement in
110: p.putAll(getPlacementConfig());
111:
112: return p;
113: }
114:
115: /**
116: * {@inheritDoc}
117: */
118: public String getContext() {
119: return m_context;
120: }
121:
122: /**
123: * @inheritDoc
124: */
125: public String getId() {
126: return m_id;
127: }
128:
129: /**
130: * {@inheritDoc}
131: */
132: public Properties getPlacementConfig() {
133: return m_config;
134: }
135:
136: /**
137: * @inheritDoc
138: */
139: public String getTitle() {
140: String rv = null;
141: if (m_title != null) {
142: rv = m_title;
143: } else if (m_tool != null) {
144: rv = m_tool.getTitle();
145: }
146:
147: return rv;
148: }
149:
150: /**
151: * @inheritDoc
152: */
153: public Tool getTool() {
154: // we might have a case where a placement was made before a tool was registered, leaving us with a toolId but no tool.
155: if ((m_tool == null) && (m_toolId != null)) {
156: // if so, we can try again
157: m_tool = ToolManager.getTool(m_toolId);
158: }
159:
160: return m_tool;
161: }
162:
163: /**
164: * @inheritDoc
165: */
166: public String getToolId() {
167: // if we really have a tool, use this id
168: if (m_tool != null)
169: return m_tool.getId();
170:
171: // otherwise use the id we are holding
172: return m_toolId;
173: }
174:
175: /**
176: * {@inheritDoc}
177: */
178: public int hashCode() {
179: return getId().hashCode();
180: }
181:
182: /**
183: * Set the context.
184: *
185: * @param context
186: * The context to set.
187: */
188: public void setContext(String context) {
189: m_context = context;
190: }
191:
192: /**
193: * Set the id.
194: *
195: * @param id
196: * The id to set.
197: */
198: public void setId(String id) {
199: m_id = id;
200: }
201:
202: /**
203: * {@inheritDoc}
204: */
205: public void setTitle(String title) {
206: m_title = title;
207: }
208:
209: /**
210: * {@inheritDoc}
211: */
212: public void setTool(String toolId, Tool tool) {
213: m_toolId = toolId;
214: m_tool = tool;
215: }
216:
217: /**
218: * {@inheritDoc}
219: */
220: public void save() {
221: }
222: }
|