001: package org.sakaibrary.osid.repository.xserver;
002:
003: /*******************************************************************************
004: * Copyright (c) 2003, 2004, 2005 The Regents of the University of Michigan,
005: * Trustees of Indiana University, Board of Trustees of the Leland Stanford,
006: * Jr., University, and The MIT Corporation
007: *
008: * Licensed under the Educational Community License Version 1.0 (the "License");
009: * By obtaining, using and/or copying this Original Work, you agree that you
010: * have read, understand, and will comply with the terms and conditions of the
011: * Educational Community License. You may obtain a copy of the License at:
012: *
013: * http://cvs.sakaiproject.org/licenses/license_1_0.html
014: *
015: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
021: * SOFTWARE.
022: *
023: *******************************************************************************/
024:
025: /**
026: * RepositoryManager manages Repositories.
027: *
028: * @author Gaurav Bhatnagar (gbhatnag@umich.edu)
029: * @version
030: */
031: public class RepositoryManager implements
032: org.osid.repository.RepositoryManager {
033: // constants
034: private static final long serialVersionUID = 1L;
035: public static final String REPOSITORY_DISPLAY_NAME = "MetaLib X-Server";
036: public static final String REPOSITORY_DESCRIPTION = "UM metasearch engine for searching library licensed digital content";
037: public static final String REPOSITORY_ID = "XSERVER01";
038:
039: private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
040: .getLog("org.sakaibrary.osid.repository.xserver.RepositoryManager");
041:
042: private org.osid.id.IdManager idManager = null;
043: private org.osid.OsidContext context = null;
044: private java.util.Vector<Repository> repositoryVector = new java.util.Vector<Repository>();
045:
046: public org.osid.OsidContext getOsidContext()
047: throws org.osid.repository.RepositoryException {
048: return context;
049: }
050:
051: public void assignOsidContext(org.osid.OsidContext context)
052: throws org.osid.repository.RepositoryException {
053: this .context = context;
054: }
055:
056: public void assignConfiguration(java.util.Properties configuration)
057: throws org.osid.repository.RepositoryException {
058: try {
059: // get idManager TODO get from config
060: this .idManager = (org.osid.id.IdManager) org.sakaibrary.osid.loader.OsidLoader
061: .getManager("org.osid.id.IdManager",
062: "org.sakaiproject.component.osid.id",
063: this .context, new java.util.Properties());
064:
065: Managers.setIdManager(this .idManager);
066:
067: // supported search types TODO get from config
068: java.util.Vector<Type> searchTypes = new java.util.Vector<Type>();
069: searchTypes.add(new Type("sakaibrary", "search",
070: "asynchMetasearch"));
071:
072: repositoryVector.add(new Repository(
073: REPOSITORY_DISPLAY_NAME, REPOSITORY_DESCRIPTION,
074: REPOSITORY_ID, searchTypes, this .idManager));
075: } catch (Throwable t) {
076: LOG
077: .warn(
078: "RepositoryManager.assignConfiguration() failed in reading "
079: + "configuration properties or creating a new Repository: "
080: + t.getMessage(), t);
081:
082: if (t instanceof org.osid.repository.RepositoryException) {
083: throw new org.osid.repository.RepositoryException(t
084: .getMessage());
085: } else {
086: throw new org.osid.repository.RepositoryException(
087: org.osid.OsidException.OPERATION_FAILED);
088: }
089: }
090: }
091:
092: public org.osid.repository.Repository createRepository(
093: String displayName, String description,
094: org.osid.shared.Type repositoryType)
095: throws org.osid.repository.RepositoryException {
096: throw new org.osid.repository.RepositoryException(
097: org.osid.OsidException.UNIMPLEMENTED);
098: }
099:
100: public void deleteRepository(org.osid.shared.Id repositoryId)
101: throws org.osid.repository.RepositoryException {
102: if (repositoryId == null) {
103: throw new org.osid.repository.RepositoryException(
104: org.osid.shared.SharedException.NULL_ARGUMENT);
105: }
106: throw new org.osid.repository.RepositoryException(
107: org.osid.OsidException.UNIMPLEMENTED);
108: }
109:
110: public org.osid.repository.RepositoryIterator getRepositories()
111: throws org.osid.repository.RepositoryException {
112: return new RepositoryIterator(this .repositoryVector);
113: }
114:
115: public org.osid.repository.RepositoryIterator getRepositoriesByType(
116: org.osid.shared.Type repositoryType)
117: throws org.osid.repository.RepositoryException {
118: if (repositoryType == null) {
119: throw new org.osid.repository.RepositoryException(
120: org.osid.shared.SharedException.NULL_ARGUMENT);
121: }
122: java.util.Vector result = new java.util.Vector();
123: org.osid.repository.RepositoryIterator repositoryIterator = getRepositories();
124: while (repositoryIterator.hasNextRepository()) {
125: org.osid.repository.Repository nextRepository = repositoryIterator
126: .nextRepository();
127: if (nextRepository.getType().isEqual(repositoryType)) {
128: result.addElement(nextRepository);
129: }
130: }
131: return new RepositoryIterator(result);
132: }
133:
134: public org.osid.repository.Repository getRepository(
135: org.osid.shared.Id repositoryId)
136: throws org.osid.repository.RepositoryException {
137: if (repositoryId == null) {
138: throw new org.osid.repository.RepositoryException(
139: org.osid.shared.SharedException.NULL_ARGUMENT);
140: }
141: try {
142: org.osid.repository.RepositoryIterator repositoryIterator = getRepositories();
143: while (repositoryIterator.hasNextRepository()) {
144: org.osid.repository.Repository nextRepository = repositoryIterator
145: .nextRepository();
146: if (nextRepository.getId().isEqual(repositoryId)) {
147: return nextRepository;
148: }
149: }
150: throw new org.osid.repository.RepositoryException(
151: org.osid.shared.SharedException.UNKNOWN_ID);
152: } catch (Throwable t) {
153: LOG.warn(t.getMessage());
154: throw new org.osid.repository.RepositoryException(
155: org.osid.OsidException.OPERATION_FAILED);
156: }
157: }
158:
159: public org.osid.repository.Asset getAsset(org.osid.shared.Id assetId)
160: throws org.osid.repository.RepositoryException {
161: if (assetId == null) {
162: throw new org.osid.repository.RepositoryException(
163: org.osid.shared.SharedException.NULL_ARGUMENT);
164: }
165: try {
166: org.osid.repository.RepositoryIterator repositoryIterator = getRepositories();
167: while (repositoryIterator.hasNextRepository()) {
168: org.osid.repository.Repository nextRepository = repositoryIterator
169: .nextRepository();
170: try {
171: org.osid.repository.Asset asset = nextRepository
172: .getAsset(assetId);
173: return asset;
174: } catch (Throwable t) {
175: }
176: }
177: } catch (Throwable t) {
178: LOG.warn(t.getMessage());
179: throw new org.osid.repository.RepositoryException(
180: org.osid.OsidException.OPERATION_FAILED);
181: }
182: throw new org.osid.repository.RepositoryException(
183: org.osid.shared.SharedException.UNKNOWN_ID);
184: }
185:
186: public org.osid.repository.Asset getAssetByDate(
187: org.osid.shared.Id assetId, long date)
188: throws org.osid.repository.RepositoryException {
189: if (assetId == null) {
190: throw new org.osid.repository.RepositoryException(
191: org.osid.shared.SharedException.NULL_ARGUMENT);
192: }
193: try {
194: org.osid.repository.RepositoryIterator repositoryIterator = getRepositories();
195: while (repositoryIterator.hasNextRepository()) {
196: org.osid.repository.Repository nextRepository = repositoryIterator
197: .nextRepository();
198: try {
199: org.osid.repository.Asset asset = nextRepository
200: .getAssetByDate(assetId, date);
201: return asset;
202: } catch (Throwable t) {
203: }
204: }
205: } catch (Throwable t) {
206: LOG.warn(t.getMessage());
207: throw new org.osid.repository.RepositoryException(
208: org.osid.OsidException.OPERATION_FAILED);
209: }
210: throw new org.osid.repository.RepositoryException(
211: org.osid.shared.SharedException.UNKNOWN_ID);
212: }
213:
214: public org.osid.shared.LongValueIterator getAssetDates(
215: org.osid.shared.Id assetId)
216: throws org.osid.repository.RepositoryException {
217: if (assetId == null) {
218: throw new org.osid.repository.RepositoryException(
219: org.osid.shared.SharedException.NULL_ARGUMENT);
220: }
221: java.util.Vector result = new java.util.Vector();
222: try {
223: org.osid.repository.RepositoryIterator repositoryIterator = getRepositories();
224: while (repositoryIterator.hasNextRepository()) {
225: org.osid.repository.Repository nextRepository = repositoryIterator
226: .nextRepository();
227: org.osid.shared.LongValueIterator longValueIterator = nextRepository
228: .getAssetDates(assetId);
229: while (longValueIterator.hasNextLongValue()) {
230: result.addElement(new Long(longValueIterator
231: .nextLongValue()));
232: }
233: }
234: return new LongValueIterator(result);
235: } catch (Throwable t) {
236: LOG.warn(t.getMessage());
237: throw new org.osid.repository.RepositoryException(
238: org.osid.OsidException.OPERATION_FAILED);
239: }
240: }
241:
242: public org.osid.repository.AssetIterator getAssetsBySearch(
243: org.osid.repository.Repository[] repositories,
244: java.io.Serializable searchCriteria,
245: org.osid.shared.Type searchType,
246: org.osid.shared.Properties searchProperties)
247: throws org.osid.repository.RepositoryException {
248: if (repositories == null) {
249: throw new org.osid.repository.RepositoryException(
250: org.osid.shared.SharedException.NULL_ARGUMENT);
251: }
252:
253: throw new org.osid.repository.RepositoryException(
254: org.osid.OsidException.UNIMPLEMENTED);
255: }
256:
257: public org.osid.shared.Id copyAsset(
258: org.osid.repository.Repository repository,
259: org.osid.shared.Id assetId)
260: throws org.osid.repository.RepositoryException {
261: if ((repository == null) || (assetId == null)) {
262: throw new org.osid.repository.RepositoryException(
263: org.osid.shared.SharedException.NULL_ARGUMENT);
264: }
265: throw new org.osid.repository.RepositoryException(
266: org.osid.OsidException.UNIMPLEMENTED);
267: }
268:
269: public org.osid.shared.TypeIterator getRepositoryTypes()
270: throws org.osid.repository.RepositoryException {
271: java.util.Vector results = new java.util.Vector();
272: try {
273: results.addElement(new Type("sakaibrary", "repository",
274: "metasearch"));
275: return new TypeIterator(results);
276: } catch (Throwable t) {
277: LOG.warn(t.getMessage());
278: throw new org.osid.repository.RepositoryException(
279: org.osid.OsidException.OPERATION_FAILED);
280: }
281: }
282:
283: public void osidVersion_2_0()
284: throws org.osid.repository.RepositoryException {
285: LOG.debug("osidVersion_2_0() called");
286: }
287: }
|