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