001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.providers.containers;
014:
015: import java.util.List;
016: import java.util.Iterator;
017: import java.util.Map;
018: import java.util.logging.Level;
019: import java.util.logging.LogRecord;
020: import java.util.logging.Logger;
021:
022: import com.sun.portal.providers.ProfileProviderAdapter;
023: import com.sun.portal.providers.context.ProviderContext;
024: import com.sun.portal.providers.context.ContainerProviderContext;
025: import com.sun.portal.providers.context.ProviderContextException;
026: import com.sun.portal.providers.ProviderException;
027: import com.sun.portal.providers.Provider;
028:
029: import com.sun.portal.desktop.DesktopRequestThreadLocalizer;
030: import com.sun.portal.log.common.PortalLogger;
031:
032: // Code in this class is duplicated in JSPContainerProviderAdapter. Changes
033: // applied to this class should also be considered for
034: // JSPContainerProviderAdapter.
035:
036: /**
037: * This class provides default implementations of methods in the
038: * ContainerProvider
039: * interface implemented using a containerProviderContext object as the
040: * persistent store.
041: *
042: * For method details, see the descriptions in the <code>Provider</code>
043: * interface.
044: *
045: * @see com.sun.portal.providers.context.ContainerProviderContext
046: * @see com.sun.portal.providers.Provider
047: */
048: public class ContainerProviderAdapter extends ProfileProviderAdapter
049: implements ContainerProvider {
050:
051: private static Logger logger = PortalLogger
052: .getLogger(ContainerProviderAdapter.class);
053:
054: /**
055: * Gets the <code>ContainerProviderContext</code> for the container provider.
056: *
057: * @return <code>ContainerProviderContext</code>.
058: *
059: * @see com.sun.portal.providers.context.ContainerProviderContext
060: *
061: */
062: public ContainerProviderContext getContainerProviderContext()
063: throws ProviderException {
064: ProviderContext pc = getProviderContext();
065:
066: if (!(pc instanceof ContainerProviderContext)) {
067: throw new ProviderException(
068: "ContainerProviderAdapter.getContainerProviderContext(): "
069: + "not a container provider context");
070: }
071:
072: return (ContainerProviderContext) pc;
073: }
074:
075: public List getSelectedChannels() throws ProviderException {
076: try {
077: return getContainerProviderContext().getSelectedChannels(
078: getName());
079: } catch (ProviderContextException pce) {
080: throw new ProviderException(
081: "ContainerProviderAdapter.getSelectedChannels(): ",
082: pce);
083: }
084: }
085:
086: public List getAvailableChannels() throws ProviderException {
087: try {
088: return getContainerProviderContext().getAvailableChannels(
089: getName());
090: } catch (ProviderContextException pce) {
091: throw new ProviderException(
092: "ContainerProviderAdapter.getAvailableChannels(): ",
093: pce);
094: }
095: }
096:
097: /**
098: * Gets the list of available and user defined channel names.
099: *
100: * Available Channels are channels that are available to be added to the portal page.
101: * User Defined Channels are channels the user has created.
102: *
103: * @return The list of available and user defined channel names, a list of string names.
104: *
105: * @exception ProviderException If the list of channel names cannot be returned.
106: */
107: public List getAvailableAndUserDefinedChannels()
108: throws ProviderException {
109: try {
110: List availableChannels = getAvailableChannels();
111: Map userDefinedChannels = getProviderContext()
112: .getCollectionProperty(getName(),
113: "userDefinedChannels");
114:
115: // Remove all elements from availableChannels contained in userDefinedChannels collection.
116: availableChannels.removeAll(userDefinedChannels.values());
117:
118: // Add all elements from userDefinedChannels to availableChannels.
119: Iterator itr = userDefinedChannels.keySet().iterator();
120: while (itr.hasNext()) {
121: availableChannels.add((String) itr.next());
122: }
123: return availableChannels;
124: } catch (ProviderContextException pce) {
125: throw new ProviderException(
126: "ContainerProviderAdapter.getAvailableAndUserDefinedChannels()",
127: pce);
128: }
129: }
130:
131: public void setSelectedChannels(List sel) throws ProviderException {
132: try {
133: getContainerProviderContext().setSelectedChannels(
134: getName(), sel);
135: } catch (ProviderContextException pce) {
136: throw new ProviderException(
137: "ContainerProviderAdapter.setSelectedChannels(): ",
138: pce);
139: }
140: }
141:
142: public void setAvailableChannels(List avail)
143: throws ProviderException {
144: try {
145: getContainerProviderContext().setAvailableChannels(
146: getName(), avail);
147: } catch (ProviderContextException pce) {
148: throw new ProviderException(
149: "ContainerProviderAdapter.getAvailableChannels(): ",
150: pce);
151: }
152: }
153:
154: public long getRefreshTime() throws ProviderException {
155:
156: String refreshTime = getStringProperty("refreshTime");
157: long refreshTimelong = 0;
158: if (refreshTime != null && refreshTime.length() != 0) {
159: return Long.parseLong(refreshTime);
160: } else {
161: //calculate the refreshTime from selected channels
162: List selected = getSelectedChannels();
163: int size = selected.size();
164: for (int i = 0; i < size; i++) {
165: String channel = (String) selected.get(i);
166: Provider p = getContainerProviderContext().getProvider(
167: DesktopRequestThreadLocalizer.getRequest(),
168: getName(), channel);
169: if (p != null) {
170: try {
171: long rt = p.getRefreshTime();
172: if (i == 0) {
173: refreshTimelong = rt;
174: } else {
175: refreshTimelong = Math.min(refreshTimelong,
176: rt);
177: }
178: } catch (ProviderException pe) {
179: if (logger.isLoggable(Level.SEVERE)) {
180: LogRecord rec = new LogRecord(Level.SEVERE,
181: "PSDT_CSPPC0001");
182: rec.setLoggerName(logger.getName());
183: String[] param = { channel };
184: rec.setParameters(param);
185: rec.setThrown(pe);
186: logger.log(rec);
187: }
188: }
189: } else {
190: if (logger.isLoggable(Level.SEVERE))
191: logger.log(Level.SEVERE, "PSDT_CSPPC0002",
192: channel);
193: }
194: if (refreshTimelong == 0) {
195: break;
196: } else {
197: continue;
198: }
199: }
200:
201: String[] param = { new Long(refreshTimelong).toString(),
202: getName() };
203: if (logger.isLoggable(Level.FINEST)) {
204: logger.log(Level.FINEST, "PSDT_CSPPC0003", param);
205: }
206:
207: return refreshTimelong;
208: }
209: }
210:
211: /**
212: * Gets the window state of the channel.
213: *
214: * This method is a default implementation of the ContainerProvider.getWindowState()
215: * This method currently has no effect and just returns ProviderWindowStates.NOT_DEFINED.
216: *
217: * Subclasses that wish to allow getting a WindowState should
218: * override this method.
219: *
220: * @param channelName channel for which the window state is requested.
221: *
222: * @return window state
223: * @exception ProviderException
224: * @see com.sun.portal.providers.containers.ProviderWindowStates#NOT_DEFINED
225: */
226: public int getWindowState(String channelName)
227: throws ProviderException {
228: return ProviderWindowStates.NOT_DEFINED;
229: }
230:
231: /**
232: * Sets the window state of a channel.
233: *
234: * This method is a default implementation of the ContainerProvider.setWindowState()
235: * This method currently has no effect and just throws UnsupportedWindowStateException.
236: *
237: * Subclasses that wish to allow setting a WindowState should
238: * override this method.
239: * @param channelName channel for which the window state needs to be set
240: * @param windowState The new window state
241: *
242: * @exception UnsupportedWindowStateException.
243: */
244: public void setWindowState(String channelName, int windowState)
245: throws UnsupportedWindowStateException {
246: throw new UnsupportedWindowStateException(
247: "Setting a window state is not supported in the default impl of containerprovider");
248: }
249:
250: /**
251: * Gets the supported window states.
252: *
253: * This method is a default implementation of the ContainerProvider.getSupportedWindowStates()
254: * This method currently has no effect and just returns an integer array containing
255: * ProviderWindowStates.NOT_DEFINED.
256: *
257: * Subclasses that wish to allow getting supported WindowStates should
258: * override this method.
259: *
260: * @return Supported Window States as an integer array.
261: *
262: * @exception ProviderException If the window states cannot be returned.
263: *
264: * @see com.sun.portal.providers.containers.ContainerProviderAdapter#getWindowState()
265: * @see com.sun.portal.providers.containers.ContainerProviderAdapter#setWindowState()
266: */
267: public int[] getSupportedWindowStates() throws ProviderException {
268: int[] winstates = new int[1];
269: winstates[0] = ProviderWindowStates.NOT_DEFINED;
270: return winstates;
271: }
272:
273: }
|