001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/calendar/tags/sakai_2-4-1/mergedlist-util/util/src/java/org/sakaiproject/util/MergedListEntryProviderFixedListWrapper.java $
003: * $Id: MergedListEntryProviderFixedListWrapper.java 8050 2006-04-20 17:39:55Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 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.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import org.sakaiproject.entity.api.ResourceProperties;
027: import org.sakaiproject.site.api.Site;
028:
029: /*
030: * Used to provide a interface to the MergedList class. This wrapper
031: * is created with a fixed set of channel references. It then
032: * defers most function calls to a wrapped EntryProvider that can
033: * be of any type. This is used when we know ahead of time which
034: * channel references that we'll want to use. This is to avoid
035: * trying to process all sites.
036: */
037: public class MergedListEntryProviderFixedListWrapper implements
038: MergedList.EntryProvider {
039: /**
040: * Defines a callback interface to convert a reference into a channel.
041: */
042: public interface ReferenceToChannelConverter {
043:
044: Object getChannel(String channelReference);
045:
046: }
047:
048: private MergedList.EntryProvider entryProvider;
049: private List channelReferenceList = new ArrayList();
050:
051: public MergedListEntryProviderFixedListWrapper(
052: MergedList.EntryProvider entryProvider,
053: String primaryChannelReference,
054: String[] mergedChannelsReferences,
055: ReferenceToChannelConverter refToChan) {
056: this .entryProvider = entryProvider;
057:
058: channelReferenceList.add(refToChan
059: .getChannel(primaryChannelReference));
060:
061: // Add the merged channels.
062: for (int i = 0; i < mergedChannelsReferences.length; i++) {
063: // Don't add the primary channel if it is already in the list.
064: if (!primaryChannelReference
065: .equals(mergedChannelsReferences[i])) {
066: channelReferenceList.add(refToChan
067: .getChannel(mergedChannelsReferences[i]));
068: }
069: }
070: }
071:
072: /* (non-Javadoc)
073: * @see org.sakaiproject.util.MergedList.EntryProvider#getIterator()
074: */
075: public Iterator getIterator() {
076: return channelReferenceList.iterator();
077: }
078:
079: /* (non-Javadoc)
080: * @see org.sakaiproject.util.MergedList.EntryProvider#allowGet(java.lang.String)
081: */
082: public boolean allowGet(String ref) {
083: return entryProvider.allowGet(ref);
084: }
085:
086: /* (non-Javadoc)
087: * @see org.sakaiproject.util.MergedList.EntryProvider#getContext(java.lang.Object)
088: */
089: public String getContext(Object obj) {
090: return entryProvider.getContext(obj);
091: }
092:
093: /* (non-Javadoc)
094: * @see org.sakaiproject.util.MergedList.EntryProvider#getReference(java.lang.Object)
095: */
096: public String getReference(Object obj) {
097: if (obj == null) {
098: return null;
099: }
100:
101: return entryProvider.getReference(obj);
102: }
103:
104: /* (non-Javadoc)
105: * @see org.sakaiproject.util.MergedList.EntryProvider#getProperties(java.lang.Object)
106: */
107: public ResourceProperties getProperties(Object obj) {
108: if (obj == null) {
109: return null;
110: }
111:
112: return entryProvider.getProperties(obj);
113: }
114:
115: /* (non-Javadoc)
116: * @see org.sakaiproject.util.MergedList.EntryProvider#isUserChannel(java.lang.Object)
117: */
118: public boolean isUserChannel(Object channel) {
119: if (channel == null) {
120: return false;
121: }
122:
123: return entryProvider.isUserChannel(channel);
124: }
125:
126: /* (non-Javadoc)
127: * @see org.sakaiproject.util.MergedList.EntryProvider#isSpecialSite(java.lang.Object)
128: */
129: public boolean isSpecialSite(Object channel) {
130: if (channel == null) {
131: return true;
132: }
133: return entryProvider.isSpecialSite(channel);
134: }
135:
136: /* (non-Javadoc)
137: * @see org.sakaiproject.util.MergedList.EntryProvider#getSiteUserId(java.lang.Object)
138: */
139: public String getSiteUserId(Object channel) {
140: if (channel == null) {
141: return "";
142: }
143: return entryProvider.getSiteUserId(channel);
144: }
145:
146: /* (non-Javadoc)
147: * @see org.sakaiproject.util.MergedList.EntryProvider#getSite(java.lang.Object)
148: */
149: public Site getSite(Object channel) {
150: if (channel == null) {
151: return null;
152: }
153:
154: return entryProvider.getSite(channel);
155: }
156:
157: }
|