001: package edu.indiana.lib.osid.base.repository.http;
002:
003: /**********************************************************************************
004: * $URL: https://source.sakaiproject.org/svn/citations/tags/sakai_2-4-1/citations-osid/web2bridge/src/java/edu/indiana/lib/osid/base/repository/http/Asset.java $
005: * $Id: Asset.java 22624 2007-03-14 20:17:21Z jimeng@umich.edu $
006: **********************************************************************************
007: *
008: * Copyright (c) 2003, 2004, 2005 The Regents of the University of Michigan, Trustees of Indiana University,
009: * Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
010: *
011: * Licensed under the Educational Community License Version 1.0 (the "License");
012: * By obtaining, using and/or copying this Original Work, you agree that you have read,
013: * understand, and will comply with the terms and conditions of the Educational Community License.
014: * You may obtain a copy of the License at:
015: *
016: * http://cvs.sakaiproject.org/licenses/license_1_0.html
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
019: * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
020: * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
021: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
022: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: **********************************************************************************/
025: /**
026: * @author Massachusetts Institute of Techbology, Sakai Software Development Team
027: * @version
028: */
029: public class Asset extends edu.indiana.lib.osid.base.repository.Asset {
030: private static org.apache.commons.logging.Log _log = edu.indiana.lib.twinpeaks.util.LogUtils
031: .getLog(Asset.class);
032:
033: private org.osid.shared.Type assetType = new Type("mit.edu",
034: "asset", "library_content");
035: private org.osid.shared.Type recordStructureType = new Type(
036: "mit.edu", "recordStructure", "library_content");
037: private org.osid.shared.Type dcRecordStructureType = new Type(
038: "mit.edu", "recordStructure", "dublinCore");
039: private org.osid.shared.Type vueRecordStructureType = new Type(
040: "tufts.edu", "recordStructure", "vue");
041:
042: private org.osid.id.IdManager idManager = Managers.getIdManager();
043: private org.osid.shared.Id id = null;
044: private org.osid.shared.Id repositoryId = null;
045: private String idString = null;
046: private String displayName = null;
047: private String description = null;
048: private org.osid.shared.Type type = null;
049: private java.util.Vector recordVector = new java.util.Vector();
050: private String content = null;
051:
052: protected Asset(String displayName, String description,
053: String idString, org.osid.shared.Id repositoryId)
054: throws org.osid.repository.RepositoryException {
055: this .displayName = displayName;
056: this .description = description;
057: this .repositoryId = repositoryId;
058: this .type = new Type("mit.edu", "asset", "library_content");
059:
060: try {
061: this .id = idManager.getId(idString);
062: } catch (Throwable t) {
063: _log.error(t.getMessage());
064: }
065:
066: }
067:
068: public String getDisplayName()
069: throws org.osid.repository.RepositoryException {
070: return this .displayName;
071: }
072:
073: public String getDescription()
074: throws org.osid.repository.RepositoryException {
075: return this .description;
076: }
077:
078: public org.osid.shared.Id getId()
079: throws org.osid.repository.RepositoryException {
080: return this .id;
081: }
082:
083: public org.osid.shared.Id getRepository()
084: throws org.osid.repository.RepositoryException {
085: return this .repositoryId;
086: }
087:
088: public java.io.Serializable getContent()
089: throws org.osid.repository.RepositoryException {
090: return this .content;
091: }
092:
093: public void updateContent(java.io.Serializable content)
094: throws org.osid.repository.RepositoryException {
095: this .content = (String) content;
096: }
097:
098: public org.osid.repository.AssetIterator getAssets()
099: throws org.osid.repository.RepositoryException {
100: return new AssetIterator(new java.util.Vector());
101: }
102:
103: public org.osid.repository.AssetIterator getAssetsByType(
104: org.osid.shared.Type assetType)
105: throws org.osid.repository.RepositoryException {
106: if (assetType == null) {
107: throw new org.osid.repository.RepositoryException(
108: org.osid.shared.SharedException.NULL_ARGUMENT);
109: }
110: return new AssetIterator(new java.util.Vector());
111: }
112:
113: public org.osid.repository.Record createRecord(
114: org.osid.shared.Id recordStructureId)
115: throws org.osid.repository.RepositoryException {
116: if (recordStructureId == null) {
117: throw new org.osid.repository.RepositoryException(
118: org.osid.shared.SharedException.NULL_ARGUMENT);
119: }
120: try {
121: org.osid.repository.Record record = new Record(
122: recordStructureId, this .idManager);
123: this .recordVector.addElement(record);
124: return record;
125: } catch (Throwable t) {
126: _log.error(t.getMessage());
127: throw new org.osid.repository.RepositoryException(
128: org.osid.OsidException.OPERATION_FAILED);
129: }
130: }
131:
132: public void deleteRecord(org.osid.shared.Id recordId)
133: throws org.osid.repository.RepositoryException {
134: if (recordId == null) {
135: throw new org.osid.repository.RepositoryException(
136: org.osid.shared.SharedException.NULL_ARGUMENT);
137: }
138: try {
139: for (int i = 0, size = this .recordVector.size(); i < size; i++) {
140: org.osid.repository.Record record = (org.osid.repository.Record) this .recordVector
141: .elementAt(i);
142: if (record.getId().isEqual(recordId)) {
143: this .recordVector.removeElementAt(i);
144: return;
145: }
146: }
147: throw new org.osid.repository.RepositoryException(
148: org.osid.shared.SharedException.UNKNOWN_ID);
149: } catch (Throwable t) {
150: _log.error(t.getMessage());
151: throw new org.osid.repository.RepositoryException(
152: org.osid.OsidException.OPERATION_FAILED);
153: }
154: }
155:
156: public org.osid.repository.RecordIterator getRecords()
157: throws org.osid.repository.RepositoryException {
158: return new RecordIterator(this .recordVector);
159: }
160:
161: public org.osid.repository.RecordIterator getRecordsByRecordStructure(
162: org.osid.shared.Id recordStructureId)
163: throws org.osid.repository.RepositoryException {
164: if (recordStructureId == null) {
165: throw new org.osid.repository.RepositoryException(
166: org.osid.shared.SharedException.NULL_ARGUMENT);
167: }
168: try {
169: return new RecordIterator(this .recordVector);
170: } catch (Throwable t) {
171: _log.error(t.getMessage());
172: throw new org.osid.repository.RepositoryException(
173: org.osid.OsidException.OPERATION_FAILED);
174: }
175: }
176:
177: public org.osid.shared.Type getAssetType()
178: throws org.osid.repository.RepositoryException {
179: return this .type;
180: }
181:
182: public org.osid.repository.RecordStructureIterator getRecordStructures()
183: throws org.osid.repository.RepositoryException {
184: java.util.Vector results = new java.util.Vector();
185: results.addElement(new RecordStructure());
186: return new RecordStructureIterator(results);
187: }
188:
189: public org.osid.repository.RecordStructure getContentRecordStructure()
190: throws org.osid.repository.RepositoryException {
191: return new RecordStructure();
192: }
193:
194: public org.osid.repository.Record getRecord(
195: org.osid.shared.Id recordId)
196: throws org.osid.repository.RepositoryException {
197: if (recordId == null) {
198: throw new org.osid.repository.RepositoryException(
199: org.osid.shared.SharedException.NULL_ARGUMENT);
200: }
201: try {
202: for (int i = 0, size = this .recordVector.size(); i < size; i++) {
203: org.osid.repository.Record record = (org.osid.repository.Record) this .recordVector
204: .elementAt(i);
205: if (record.getId().isEqual(recordId)) {
206: return record;
207: }
208: }
209: throw new org.osid.repository.RepositoryException(
210: org.osid.shared.SharedException.UNKNOWN_ID);
211: } catch (Throwable t) {
212: _log.error(t.getMessage());
213: throw new org.osid.repository.RepositoryException(
214: org.osid.OsidException.OPERATION_FAILED);
215: }
216: }
217:
218: public org.osid.repository.Part getPart(org.osid.shared.Id partId)
219: throws org.osid.repository.RepositoryException {
220: if (partId == null) {
221: throw new org.osid.repository.RepositoryException(
222: org.osid.shared.SharedException.NULL_ARGUMENT);
223: }
224: try {
225: for (int i = 0, size = this .recordVector.size(); i < size; i++) {
226: org.osid.repository.Record record = (org.osid.repository.Record) this .recordVector
227: .elementAt(i);
228: org.osid.repository.PartIterator partIterator = record
229: .getParts();
230: while (partIterator.hasNextPart()) {
231: org.osid.repository.Part part = partIterator
232: .nextPart();
233: if (part.getId().isEqual(partId)) {
234: return part;
235: }
236: }
237: }
238: throw new org.osid.repository.RepositoryException(
239: org.osid.shared.SharedException.UNKNOWN_ID);
240: } catch (Throwable t) {
241: _log.error(t.getMessage());
242: throw new org.osid.repository.RepositoryException(
243: org.osid.OsidException.OPERATION_FAILED);
244: }
245: }
246:
247: public java.io.Serializable getPartValue(org.osid.shared.Id partId)
248: throws org.osid.repository.RepositoryException {
249: org.osid.repository.Part part = getPart(partId);
250: return part.getValue();
251: }
252:
253: public org.osid.repository.PartIterator getPartByPart(
254: org.osid.shared.Id partStructureId)
255: throws org.osid.repository.RepositoryException {
256: if (partStructureId == null) {
257: throw new org.osid.repository.RepositoryException(
258: org.osid.shared.SharedException.NULL_ARGUMENT);
259: }
260: try {
261: java.util.Vector results = new java.util.Vector();
262: for (int i = 0, size = this .recordVector.size(); i < size; i++) {
263: org.osid.repository.Record record = (org.osid.repository.Record) this .recordVector
264: .elementAt(i);
265: org.osid.repository.PartIterator partIterator = record
266: .getParts();
267: while (partIterator.hasNextPart()) {
268: org.osid.repository.Part part = partIterator
269: .nextPart();
270: if (part.getPartStructure().getId().isEqual(
271: partStructureId)) {
272: results.addElement(part);
273: }
274: }
275: }
276: return new PartIterator(results);
277: } catch (Throwable t) {
278: _log.error(t.getMessage());
279: throw new org.osid.repository.RepositoryException(
280: org.osid.OsidException.OPERATION_FAILED);
281: }
282: }
283:
284: public org.osid.shared.ObjectIterator getPartValueByPart(
285: org.osid.shared.Id partStructureId)
286: throws org.osid.repository.RepositoryException {
287: java.util.Vector results = new java.util.Vector();
288: org.osid.repository.PartIterator partIterator = getPartByPart(partStructureId);
289: while (partIterator.hasNextPart()) {
290: results.addElement(partIterator.nextPart().getValue());
291: }
292: try {
293: return new ObjectIterator(results);
294: } catch (Throwable t) {
295: _log.error(t.getMessage());
296: throw new org.osid.repository.RepositoryException(
297: org.osid.OsidException.OPERATION_FAILED);
298: }
299: }
300:
301: public org.osid.shared.ObjectIterator getPartValuesByPartStructure(
302: org.osid.shared.Id partStructureId)
303: throws org.osid.repository.RepositoryException {
304: if (partStructureId == null) {
305: throw new org.osid.repository.RepositoryException(
306: org.osid.shared.SharedException.NULL_ARGUMENT);
307: }
308: try {
309: java.util.Vector results = new java.util.Vector();
310: org.osid.repository.PartIterator partIterator = getPartsByPartStructure(partStructureId);
311: while (partIterator.hasNextPart()) {
312: org.osid.repository.Part part = partIterator.nextPart();
313: results.addElement(part.getValue());
314: }
315: return new ObjectIterator(results);
316: } catch (Throwable t) {
317: _log.error(t.getMessage());
318: throw new org.osid.repository.RepositoryException(
319: org.osid.OsidException.OPERATION_FAILED);
320: }
321: }
322:
323: public org.osid.repository.PartIterator getPartsByPartStructure(
324: org.osid.shared.Id partStructureId)
325: throws org.osid.repository.RepositoryException {
326: if (partStructureId == null) {
327: throw new org.osid.repository.RepositoryException(
328: org.osid.shared.SharedException.NULL_ARGUMENT);
329: }
330: try {
331: java.util.Vector results = new java.util.Vector();
332: org.osid.repository.RecordIterator recordIterator = getRecords();
333: while (recordIterator.hasNextRecord()) {
334: org.osid.repository.Record record = recordIterator
335: .nextRecord();
336: org.osid.repository.PartIterator partIterator = record
337: .getParts();
338: while (partIterator.hasNextPart()) {
339: org.osid.repository.Part part = partIterator
340: .nextPart();
341: if (part.getPartStructure().getId().isEqual(
342: partStructureId)) {
343: results.addElement(part);
344: }
345: }
346: }
347: return new PartIterator(results);
348: } catch (Throwable t) {
349: _log.error(t.getMessage());
350: throw new org.osid.repository.RepositoryException(
351: org.osid.OsidException.OPERATION_FAILED);
352: }
353: }
354:
355: public org.osid.repository.RecordIterator getRecordsByRecordStructureType(
356: org.osid.shared.Type recordStructureType)
357: throws org.osid.repository.RepositoryException {
358: if (recordStructureType == null) {
359: throw new org.osid.repository.RepositoryException(
360: org.osid.shared.SharedException.NULL_ARGUMENT);
361: }
362:
363: if ((!recordStructureType.isEqual(this .recordStructureType))
364: && (!recordStructureType
365: .isEqual(this .dcRecordStructureType))
366: && (!recordStructureType
367: .isEqual(this .vueRecordStructureType))) {
368: throw new org.osid.repository.RepositoryException(
369: org.osid.shared.SharedException.UNKNOWN_TYPE);
370: }
371:
372: java.util.Vector results = new java.util.Vector();
373: for (int i = 0, size = this .recordVector.size(); i < size; i++) {
374: org.osid.repository.Record r = (org.osid.repository.Record) this .recordVector
375: .elementAt(i);
376: if (r.getRecordStructure().getType().isEqual(
377: recordStructureType)) {
378: results.addElement(r);
379: }
380: }
381: return new RecordIterator(results);
382: }
383: }
|