Source Code Cross Referenced for RepositoryManager.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » component » osid » repository » registry » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.component.osid.repository.registry 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/trunk/sakai/osid/api-impl/src/java/org/sakaiproject/component/osid/id/IdManager.java $
003:         * $Id: IdManager.java 632 2005-07-14 21:22:50Z janderse@umich.edu $
004:         **********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005 The Regents of the University of Michigan, Trustees of Indiana University,
007:         *                  Board of Trustees of the Leland Stanford, 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 have read,
011:         * understand, and will comply with the terms and conditions of the Educational Community License.
012:         * 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 IMPLIED,
017:         * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
018:         * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
019:         * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
020:         * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
021:         *
022:         **********************************************************************************/package org.sakaiproject.component.osid.repository.registry;
023:
024:        /**
025:         * <p> This is an implementation of the RepositoryManager interface in the Repository OSID.
026:         * This implementation federates across other RepositoryManagers.  These managers are found
027:         * in a registry.  The details of the registry are hidden within the implementation of a
028:         * "straw-man" Registry OSID.  That OSID's RegistryManager provides access to the individual
029:         * RepositoryManagers' Repositories.  In this implementation of RepositoryManager, in many cases
030:         * we pass the call to the registered implementations and the result or results.  </p>
031:         * 
032:         * @author Massachusetts Institute of Techbology, Sakai Software Development Team
033:         * @version
034:         */
035:
036:        public class RepositoryManager implements 
037:                org.osid.repository.RepositoryManager {
038:            private org.osid.OsidContext context = null;
039:            private java.util.Properties configurationProperties = null;
040:            private java.util.Vector repositoryManagerVector = new java.util.Vector();
041:            private edu.mit.osid.registry.RegistryManager registryManager = null;
042:            private org.osid.id.IdManager idManager = null;
043:            private static final String ADUSTER_XML_FILENAME = "RepositoryOSIDAdjuster.xml";
044:            private static final String REGISTRY_OSID = "edu.mit.osid.registry.RegistryManager";
045:            private static final String REGISTRY_OSID_IMPLEMENTATION = "org.sakaiproject.component.osid.registry";
046:            private org.w3c.dom.Document adjusterDocument = null;
047:
048:            /**
049:            	Simply return OsidContext set by assignOsidContext
050:             */
051:            public org.osid.OsidContext getOsidContext()
052:                    throws org.osid.repository.RepositoryException {
053:                System.out.println(this  + " returning the context " + context);
054:                return context;
055:            }
056:
057:            /**
058:            	Simply stores the OsidContext
059:             */
060:            public void assignOsidContext(org.osid.OsidContext context)
061:                    throws org.osid.repository.RepositoryException {
062:                System.out
063:                        .println(this  + " assigning context to be " + context);
064:                this .context = context;
065:            }
066:
067:            /**
068:             * Simple getter for IdManager with error checking - Use Sakai Component Manager
069:             */
070:            private org.osid.id.IdManager getIdManager() {
071:                if (this .idManager != null)
072:                    return this .idManager;
073:                try {
074:                    this .idManager = (org.osid.id.IdManager) org.sakaiproject.component.cover.ComponentManager
075:                            .get(org.osid.id.IdManager.class);
076:
077:                } catch (Throwable t) {
078:                    log(t);
079:                }
080:                return this .idManager;
081:            }
082:
083:            /**
084:             * Simply stores the Configuration and then sets up to access implementations of the RegistryManager and an IdManager
085:             */
086:            public void assignConfiguration(
087:                    java.util.Properties configurationProperties)
088:                    throws org.osid.repository.RepositoryException {
089:                this .configurationProperties = configurationProperties;
090:
091:                try {
092:                    if (this .registryManager == null) {
093:                        this .registryManager = (edu.mit.osid.registry.RegistryManager) org.sakaiproject.component.osid.loader.OsidLoader
094:                                .getManager(REGISTRY_OSID,
095:                                        REGISTRY_OSID_IMPLEMENTATION,
096:                                        getOsidContext(),
097:                                        new java.util.Properties());
098:                    }
099:                } catch (Throwable t) {
100:                    t.printStackTrace();
101:                    log(t);
102:                    throw new org.osid.repository.RepositoryException(
103:                            org.osid.OsidException.CONFIGURATION_ERROR);
104:                }
105:
106:                try {
107:                    java.io.InputStream istream = org.sakaiproject.component.osid.loader.OsidLoader
108:                            .getConfigStream(ADUSTER_XML_FILENAME, getClass());
109:                    if (istream != null) {
110:                        javax.xml.parsers.DocumentBuilderFactory dbf = null;
111:                        javax.xml.parsers.DocumentBuilder db = null;
112:
113:                        dbf = javax.xml.parsers.DocumentBuilderFactory
114:                                .newInstance();
115:                        db = dbf.newDocumentBuilder();
116:                        adjusterDocument = db.parse(istream);
117:                    }
118:                } catch (Throwable t) {
119:                    // Missing or ill-formatted file is non-fatal
120:                }
121:            }
122:
123:            /**
124:             * Unimplemented method.  We don't know to which RepositoryManager to delegate this, so we do nothing.
125:             */
126:            public org.osid.repository.Repository createRepository(
127:                    String displayName, String description,
128:                    org.osid.shared.Type repositoryType)
129:                    throws org.osid.repository.RepositoryException {
130:                throw new org.osid.repository.RepositoryException(
131:                        org.osid.OsidException.UNIMPLEMENTED);
132:            }
133:
134:            /**
135:            	Unimplemented method.  We could do this by checking all managers, but this seems outside the purpose of this implementation.
136:             */
137:            public void deleteRepository(org.osid.shared.Id repositoryId)
138:                    throws org.osid.repository.RepositoryException {
139:                throw new org.osid.repository.RepositoryException(
140:                        org.osid.OsidException.UNIMPLEMENTED);
141:            }
142:
143:            /**
144:            	Working from the current Repository Manager Registry, this method returns the union of Repositories across registered RepositoryManagers.  Note that the contents of the Registry can change at run-time and the Repositories and their order returned by a registered RepositoryManager can change at any time.
145:            	<p>
146:            	If an exception is thrown by a call to a manager, the exception is logged and processing continues.
147:            	<p>
148:            	This method can throw org.osid.OsidException.OPERATION_FAILED
149:             */
150:            public org.osid.repository.RepositoryIterator getRepositories()
151:                    throws org.osid.repository.RepositoryException {
152:                try {
153:                    // set the current list of repository managers
154:                    refresh();
155:                    java.util.Vector result = new java.util.Vector();
156:                    java.util.Vector idStringVector = new java.util.Vector(); // to help check for duplicates
157:
158:                    // call getRepositories() for each registered manager and accumulate the results
159:                    for (int i = 0, size = this .repositoryManagerVector.size(); i < size; i++) {
160:                        org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) this .repositoryManagerVector
161:                                .elementAt(i);
162:                        try {
163:                            org.osid.repository.RepositoryIterator repositoryIterator = repositoryManager
164:                                    .getRepositories();
165:                            while (repositoryIterator.hasNextRepository()) {
166:                                // we should check for the unlikely case of a duplicate
167:                                org.osid.repository.Repository nextRepository = repositoryIterator
168:                                        .nextRepository();
169:                                String idString = nextRepository.getId()
170:                                        .getIdString();
171:                                if (!result.contains(idString)) {
172:                                    result.addElement(nextRepository);
173:                                    idStringVector.addElement(idString);
174:                                }
175:                            }
176:                        } catch (Throwable t) {
177:                            log(t);
178:                        }
179:                    }
180:                    return new RepositoryIterator(result);
181:                } catch (Throwable t) {
182:                    t.printStackTrace();
183:                    log(t);
184:                }
185:                throw new org.osid.repository.RepositoryException(
186:                        org.osid.OsidException.OPERATION_FAILED);
187:            }
188:
189:            /**
190:            	Working from the current Repository Manager Registry, this method returns the union of Repositories across registered RepositoryManagers.  Note that the contents of the Registry can change at run-time and the Repositories and their order returned by a registered RepositoryManager can change at any time. 
191:            	<p>
192:            	If an exception is thrown by a call to a manager, the exception is logged and processing continues.  Any repository that does not support the repositoryType, should throw the exception org.osid.shared.SharedException.UNKNOWN_TYPE.
193:            	<p>
194:            	This method throws org.osid.shared.SharedException.NULL_ARGUMENT if the repositoryType argument is null.
195:            	This method throws org.osid.shared.SharedException.UNKNOWN_TYPE if all managers throw this exception.
196:            	This method can throw org.osid.OsidException.OPERATION_FAILED.
197:             */
198:            public org.osid.repository.RepositoryIterator getRepositoriesByType(
199:                    org.osid.shared.Type repositoryType)
200:                    throws org.osid.repository.RepositoryException {
201:                if (repositoryType == null) {
202:                    throw new org.osid.repository.RepositoryException(
203:                            org.osid.OsidException.NULL_ARGUMENT);
204:                }
205:                boolean unknownTypeAlwaysThrown = true;
206:                try {
207:                    // set the current list of repository managers
208:                    refresh();
209:                    java.util.Vector result = new java.util.Vector();
210:
211:                    // call getRepositoriesByType() for each registered manager and accumulate the results
212:                    for (int i = 0, size = this .repositoryManagerVector.size(); i < size; i++) {
213:                        org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) this .repositoryManagerVector
214:                                .elementAt(i);
215:                        try {
216:                            org.osid.repository.RepositoryIterator repositoryIterator = repositoryManager
217:                                    .getRepositoriesByType(repositoryType);
218:                            while (repositoryIterator.hasNextRepository()) {
219:                                result.addElement(repositoryIterator
220:                                        .nextRepository());
221:                            }
222:                            unknownTypeAlwaysThrown = false;
223:                        } catch (Throwable t) {
224:                            unknownTypeAlwaysThrown = unknownTypeAlwaysThrown
225:                                    && (t.getMessage() == org.osid.shared.SharedException.UNKNOWN_TYPE);
226:                            log(t);
227:                        }
228:                    }
229:                    return new RepositoryIterator(result);
230:                } catch (Throwable t) {
231:                    log(t);
232:                    unknownTypeAlwaysThrown = false;
233:                }
234:                if (unknownTypeAlwaysThrown) {
235:                    throw new org.osid.repository.RepositoryException(
236:                            org.osid.shared.SharedException.UNKNOWN_TYPE);
237:                }
238:                throw new org.osid.repository.RepositoryException(
239:                        org.osid.OsidException.OPERATION_FAILED);
240:            }
241:
242:            /**
243:            	Working from the current Repository Manager Registry, this method checks the repository id provided against the known repositories ids for a match.
244:            	<p>
245:            	This implementation assumes repository ids are unique and returns the first repository whose id matches the criterion.
246:            	<p>
247:            	If an exception is thrown by a call to a manager, the exception is logged and processing continues.  Any repository that does not recognize the repository id, should throw the exception org.osid.shared.SharedException.UNKNOWN_ID.
248:            	This method throws org.osid.shared.SharedException.NULL_ARGUMENT if the repositoryId argument is null.
249:            	This method throws org.osid.shared.SharedException.UNKNOWN_ID if all managers throw this exception.
250:            	This method can throw org.osid.OsidException.OPERATION_FAILED.
251:             */
252:            public org.osid.repository.Repository getRepository(
253:                    org.osid.shared.Id repositoryId)
254:                    throws org.osid.repository.RepositoryException {
255:                if (repositoryId == null) {
256:                    throw new org.osid.repository.RepositoryException(
257:                            org.osid.OsidException.NULL_ARGUMENT);
258:                }
259:                boolean unknownIdAlwaysThrown = true;
260:                try {
261:                    // set the current list of repository managers
262:                    refresh();
263:
264:                    // call getRepository() for each registered manager and return the first match
265:                    for (int i = 0, size = this .repositoryManagerVector.size(); i < size; i++) {
266:                        org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) this .repositoryManagerVector
267:                                .elementAt(i);
268:                        try {
269:                            return repositoryManager
270:                                    .getRepository(repositoryId);
271:                        } catch (Throwable t) {
272:                            unknownIdAlwaysThrown = unknownIdAlwaysThrown
273:                                    && (t.getMessage() == org.osid.shared.SharedException.UNKNOWN_ID);
274:                        }
275:                    }
276:                } catch (Throwable t) {
277:                    log(t);
278:                    unknownIdAlwaysThrown = false;
279:                }
280:                if (unknownIdAlwaysThrown) {
281:                    throw new org.osid.repository.RepositoryException(
282:                            org.osid.shared.SharedException.UNKNOWN_ID);
283:                }
284:                throw new org.osid.repository.RepositoryException(
285:                        org.osid.OsidException.OPERATION_FAILED);
286:            }
287:
288:            /**
289:            	Working from the current Repository Manager Registry, this method asks each manager to get the asset.
290:            	<p>
291:            	If an exception is thrown by a call to a manager, the exception is logged and processing continues.  Any manager that does not recognize the asset id, should throw the exception org.osid.shared.SharedException.UNKNOWN_ID.
292:            	This method throws org.osid.shared.SharedException.NULL_ARGUMENT if the assetId argument is null.
293:            	This method throws org.osid.shared.SharedException.UNKNOWN_ID if all managers throw this exception.
294:            	This method can throw org.osid.OsidException.OPERATION_FAILED.
295:             */
296:            public org.osid.repository.Asset getAsset(org.osid.shared.Id assetId)
297:                    throws org.osid.repository.RepositoryException {
298:                if (assetId == null) {
299:                    throw new org.osid.repository.RepositoryException(
300:                            org.osid.OsidException.NULL_ARGUMENT);
301:                }
302:                boolean unknownIdAlwaysThrown = true;
303:                try {
304:                    // set the current list of repository managers
305:                    refresh();
306:
307:                    // call getAsset() for each registered manager and return the first match
308:                    for (int i = 0, size = this .repositoryManagerVector.size(); i < size; i++) {
309:                        org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) this .repositoryManagerVector
310:                                .elementAt(i);
311:                        try {
312:                            return repositoryManager.getAsset(assetId);
313:                        } catch (Throwable t) {
314:                            unknownIdAlwaysThrown = unknownIdAlwaysThrown
315:                                    && (t.getMessage() == org.osid.shared.SharedException.UNKNOWN_ID);
316:                        }
317:                    }
318:                } catch (Throwable t) {
319:                    log(t);
320:                    unknownIdAlwaysThrown = false;
321:                }
322:                if (unknownIdAlwaysThrown) {
323:                    throw new org.osid.repository.RepositoryException(
324:                            org.osid.shared.SharedException.UNKNOWN_ID);
325:                }
326:                throw new org.osid.repository.RepositoryException(
327:                        org.osid.OsidException.OPERATION_FAILED);
328:            }
329:
330:            /**
331:            	Working from the current Repository Manager Registry, this method asks each manager to get the asset.
332:            	<p>
333:            	If an exception is thrown by a call to a manager, the exception is logged and processing continues.  Any manager that does not recognize the asset id, should throw the exception org.osid.shared.SharedException.UNKNOWN_ID.
334:            	This method throws org.osid.shared.SharedException.NULL_ARGUMENT if the assetId argument is null.
335:            	This method throws org.osid.shared.SharedException.UNKNOWN_ID if all managers throw this exception.
336:            	This method can throw org.osid.OsidException.OPERATION_FAILED.
337:             */
338:            public org.osid.repository.Asset getAssetByDate(
339:                    org.osid.shared.Id assetId, long date)
340:                    throws org.osid.repository.RepositoryException {
341:                if (assetId == null) {
342:                    throw new org.osid.repository.RepositoryException(
343:                            org.osid.OsidException.NULL_ARGUMENT);
344:                }
345:                boolean unknownIdAlwaysThrown = true;
346:                try {
347:                    // set the current list of repository managers
348:                    refresh();
349:
350:                    // call getAssetByDate() for each registered manager and return the first match
351:                    for (int i = 0, size = this .repositoryManagerVector.size(); i < size; i++) {
352:                        org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) this .repositoryManagerVector
353:                                .elementAt(i);
354:                        try {
355:                            return repositoryManager.getAssetByDate(assetId,
356:                                    date);
357:                        } catch (Throwable t) {
358:                            unknownIdAlwaysThrown = unknownIdAlwaysThrown
359:                                    && (t.getMessage() == org.osid.shared.SharedException.UNKNOWN_ID);
360:                        }
361:                    }
362:                } catch (Throwable t) {
363:                    log(t);
364:                    unknownIdAlwaysThrown = false;
365:                }
366:                if (unknownIdAlwaysThrown) {
367:                    throw new org.osid.repository.RepositoryException(
368:                            org.osid.shared.SharedException.UNKNOWN_ID);
369:                }
370:                throw new org.osid.repository.RepositoryException(
371:                        org.osid.OsidException.OPERATION_FAILED);
372:            }
373:
374:            /**
375:            	Working from the current Repository Manager Registry, this method asks each manager to get the asset's dates.
376:            	<p>
377:            	If an exception is thrown by a call to a manager, the exception is logged and processing continues.  Any manager that does not recognize the asset id, should throw the exception org.osid.shared.SharedException.UNKNOWN_ID.
378:            	This method throws org.osid.shared.SharedException.NULL_ARGUMENT if the repositories argument is null.
379:            	This method throws org.osid.shared.SharedException.UNKNOWN_ID if all managers throw this exception.
380:            	This method can throw org.osid.OsidException.OPERATION_FAILED.
381:             */
382:            public org.osid.shared.LongValueIterator getAssetDates(
383:                    org.osid.shared.Id assetId)
384:                    throws org.osid.repository.RepositoryException {
385:                if (assetId == null) {
386:                    throw new org.osid.repository.RepositoryException(
387:                            org.osid.OsidException.NULL_ARGUMENT);
388:                }
389:                boolean unknownIdAlwaysThrown = true;
390:                try {
391:                    // set the current list of repository managers
392:                    refresh();
393:                    java.util.Vector result = new java.util.Vector();
394:
395:                    // call getAssetDates() for each registered manager and return the first match
396:                    for (int i = 0, size = this .repositoryManagerVector.size(); i < size; i++) {
397:                        org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) this .repositoryManagerVector
398:                                .elementAt(i);
399:                        try {
400:                            org.osid.shared.LongValueIterator longValueIterator = repositoryManager
401:                                    .getAssetDates(assetId);
402:                            while (longValueIterator.hasNextLongValue()) {
403:                                result.addElement(new Long(longValueIterator
404:                                        .nextLongValue()));
405:                            }
406:                            unknownIdAlwaysThrown = false;
407:                        } catch (Throwable t) {
408:                            log(t);
409:                            unknownIdAlwaysThrown = unknownIdAlwaysThrown
410:                                    && (t.getMessage() == org.osid.shared.SharedException.UNKNOWN_ID);
411:                        }
412:                    }
413:                    return new LongValueIterator(result);
414:                } catch (Throwable t) {
415:                    log(t);
416:                    unknownIdAlwaysThrown = false;
417:                }
418:                if (unknownIdAlwaysThrown) {
419:                    throw new org.osid.repository.RepositoryException(
420:                            org.osid.shared.SharedException.UNKNOWN_ID);
421:                }
422:                throw new org.osid.repository.RepositoryException(
423:                        org.osid.OsidException.OPERATION_FAILED);
424:            }
425:
426:            /**
427:            	Working from the current Repository Manager Registry, this method asks each manager to search for the assets.
428:            	<p>
429:            	If an exception is thrown by a call to a manager, the exception is logged and processing continues.
430:            	This method throws org.osid.shared.SharedException.NULL_ARGUMENT if the repositories argument is null.
431:            	This method can throw org.osid.OsidException.OPERATION_FAILED.
432:             */
433:            public org.osid.repository.AssetIterator getAssetsBySearch(
434:                    org.osid.repository.Repository[] repositories,
435:                    java.io.Serializable searchCriteria,
436:                    org.osid.shared.Type searchType,
437:                    org.osid.shared.Properties searchProperties)
438:                    throws org.osid.repository.RepositoryException {
439:                if (repositories == null) {
440:                    throw new org.osid.repository.RepositoryException(
441:                            org.osid.OsidException.NULL_ARGUMENT);
442:                }
443:
444:                try {
445:                    // set the current list of repository managers
446:                    refresh();
447:                    java.util.Vector result = new java.util.Vector();
448:
449:                    /*
450:                     Call getAssetsBySearch() for each repository.  Since the list of Repositories may span Managers, check all
451:                     Managers for the Repository.
452:                     */
453:
454:                    int numManagers = this .repositoryManagerVector.size();
455:                    // for each Repository
456:                    for (int i = 0; i < repositories.length; i++) {
457:                        // get its id
458:                        org.osid.shared.Id repositoryId = repositories[i]
459:                                .getId();
460:                        boolean found = false;
461:
462:                        // look in each Manager for the Repository
463:                        for (int j = 0; j < numManagers; j++) {
464:                            org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) this .repositoryManagerVector
465:                                    .elementAt(j);
466:
467:                            try {
468:                                org.osid.repository.Repository repository = repositoryManager
469:                                        .getRepository(repositoryId);
470:
471:                                // we have found the Repository, now call the search
472:                                found = true;
473:                                try {
474:
475:                                    java.io.Serializable adjustedSearchCriteria = null;
476:                                    org.osid.shared.Type adjustedSearchType = null;
477:                                    org.osid.shared.Properties adjustedSearchProperties = null;
478:
479:                                    // check there is no class that implements the type or criteria adjuster interface
480:                                    if (this .adjusterDocument != null) {
481:                                        try {
482:                                            // find the adjuster class for this reposiory id, if there is one
483:                                            org.w3c.dom.NodeList nodeList = this .adjusterDocument
484:                                                    .getElementsByTagName("repository");
485:                                            int numNodes = nodeList.getLength();
486:                                            for (int n = 0; n < numNodes; n++) {
487:                                                org.w3c.dom.Element node = (org.w3c.dom.Element) nodeList
488:                                                        .item(n);
489:                                                String idString = node
490:                                                        .getAttribute("id");
491:                                                org.osid.shared.Id id = getIdManager()
492:                                                        .getId(idString);
493:                                                if (id.isEqual(repositoryId)) {
494:                                                    String adjusterClassName = node
495:                                                            .getAttribute("adjusterclass");
496:                                                    if (adjusterClassName
497:                                                            .length() > 0) {
498:
499:                                                        try {
500:                                                            // instantiate the class and get the adjuster arguments
501:                                                            Class adjusterClass = Class
502:                                                                    .forName(adjusterClassName);
503:                                                            edu.mit.osid.repository.SearchArgumentAdjuster adjuster = (edu.mit.osid.repository.SearchArgumentAdjuster) (adjusterClass
504:                                                                    .newInstance());
505:                                                            adjuster
506:                                                                    .adjust(
507:                                                                            searchCriteria,
508:                                                                            searchType,
509:                                                                            searchProperties);
510:                                                            adjustedSearchCriteria = adjuster
511:                                                                    .getSearchCriteria();
512:                                                            adjustedSearchType = adjuster
513:                                                                    .getSearchType();
514:                                                            adjustedSearchProperties = adjuster
515:                                                                    .getSearchProperties();
516:                                                        } catch (Throwable t) {
517:                                                            // just log
518:                                                            log(t);
519:                                                        }
520:                                                    }
521:                                                }
522:                                            }
523:                                        } catch (Throwable t) {
524:                                            // just log
525:                                            log(t);
526:                                        }
527:                                    }
528:
529:                                    // perform the search
530:                                    System.out
531:                                            .println("Now searching "
532:                                                    + repository
533:                                                            .getDisplayName()
534:                                                    + " with criteria "
535:                                                    + ((adjustedSearchCriteria != null) ? adjustedSearchCriteria
536:                                                            : searchCriteria));
537:                                    org.osid.repository.AssetIterator assetIterator = repository
538:                                            .getAssetsBySearch(
539:                                                    (adjustedSearchCriteria != null) ? adjustedSearchCriteria
540:                                                            : searchCriteria,
541:                                                    (adjustedSearchType != null) ? adjustedSearchType
542:                                                            : searchType,
543:                                                    (adjustedSearchProperties != null) ? adjustedSearchProperties
544:                                                            : searchProperties);
545:                                    // accumulate in the result set
546:                                    while (assetIterator.hasNextAsset()) {
547:                                        result.addElement(assetIterator
548:                                                .nextAsset());
549:                                    }
550:                                } catch (Throwable t) {
551:                                    // this could be a Type mismatch or other non-fatal issue
552:                                }
553:                                break;
554:                            } catch (Throwable t) {
555:                                // this could be a repository not found
556:                            }
557:                        }
558:                        if (!found) {
559:                            throw new org.osid.repository.RepositoryException(
560:                                    org.osid.shared.SharedException.UNKNOWN_ID);
561:                        }
562:                    }
563:                    return new AssetIterator(result);
564:                } catch (Throwable t) {
565:                    log(t);
566:                    if (t.getMessage().equals(
567:                            org.osid.shared.SharedException.UNKNOWN_ID)) {
568:                        throw new org.osid.repository.RepositoryException(
569:                                org.osid.shared.SharedException.UNKNOWN_ID);
570:                    }
571:                }
572:                throw new org.osid.repository.RepositoryException(
573:                        org.osid.OsidException.OPERATION_FAILED);
574:            }
575:
576:            /**
577:            	Unimplemented method
578:             */
579:            public org.osid.shared.Id copyAsset(
580:                    org.osid.repository.Repository repository,
581:                    org.osid.shared.Id assetId)
582:                    throws org.osid.repository.RepositoryException {
583:                throw new org.osid.repository.RepositoryException(
584:                        org.osid.OsidException.UNIMPLEMENTED);
585:            }
586:
587:            /**
588:            	Working from the current Repository Manager Registry, this method asks each manager to get all its repository types.  The method returns distinct values -- no duplicates.
589:            	<p>
590:            	If an exception is thrown by a call to a manager, the exception is logged and processing continues.
591:            	This method can throw org.osid.OsidException.OPERATION_FAILED.
592:             */
593:            public org.osid.shared.TypeIterator getRepositoryTypes()
594:                    throws org.osid.repository.RepositoryException {
595:                try {
596:                    // set the current list of repository managers
597:                    refresh();
598:                    java.util.Vector result = new java.util.Vector();
599:
600:                    // call getRepositoryTypes() for each registered manager and accumulate the results
601:                    for (int i = 0, size = this .repositoryManagerVector.size(); i < size; i++) {
602:                        org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) this .repositoryManagerVector
603:                                .elementAt(i);
604:                        try {
605:                            org.osid.shared.TypeIterator typeIterator = repositoryManager
606:                                    .getRepositoryTypes();
607:                            while (typeIterator.hasNextType()) {
608:                                org.osid.shared.Type nextType = typeIterator
609:                                        .nextType();
610:                                // do not add in duplicates; note we do not simply check if the type is in the vector since
611:                                // equality is defined by the OSIDType class distributed by O.K.I.
612:                                boolean found = false;
613:                                for (int j = 0, numTypes = result.size(); j < numTypes; j++) {
614:                                    if (nextType
615:                                            .isEqual((org.osid.shared.Type) result
616:                                                    .elementAt(j))) {
617:                                        found = true;
618:                                        break;
619:                                    }
620:                                }
621:                                if (!found) {
622:                                    result.addElement(nextType);
623:                                }
624:                            }
625:                        } catch (Throwable t) {
626:                            log(t);
627:                        }
628:                    }
629:                    return new TypeIterator(result);
630:                } catch (Throwable t) {
631:                    log(t);
632:                }
633:                throw new org.osid.repository.RepositoryException(
634:                        org.osid.OsidException.OPERATION_FAILED);
635:            }
636:
637:            /*
638:             * A required empty implementation called by the default OsidLoader.
639:             */
640:            public void osidVersion_2_0()
641:                    throws org.osid.repository.RepositoryException {
642:            }
643:
644:            // private utility methods
645:
646:            private void refresh()
647:                    throws org.osid.repository.RepositoryException {
648:                try {
649:                    this .repositoryManagerVector.removeAllElements();
650:                    edu.mit.osid.registry.ProviderIterator providerIterator = this .registryManager
651:                            .getProviders();
652:                    while (providerIterator.hasNextProvider()) {
653:                        edu.mit.osid.registry.Provider provider = providerIterator
654:                                .nextProvider();
655:
656:                        String service = provider.getOsidService();
657:                        String version = provider.getOsidVersion();
658:                        String loadkey = provider.getOsidLoadKey();
659:
660:                        log("Loading OSID DR Implementation " + loadkey);
661:
662:                        if ((service.equals("org.osid.repository"))
663:                                && (version.equals("2.0"))) {
664:                            try {
665:                                this .repositoryManagerVector
666:                                        .addElement(org.sakaiproject.component.osid.loader.OsidLoader
667:                                                .getManager(
668:                                                        "org.osid.repository.RepositoryManager",
669:                                                        loadkey,
670:                                                        getOsidContext(),
671:                                                        new java.util.Properties()));
672:                            } catch (Throwable t) {
673:                                log(t);
674:                                log("OSID Service: " + service);
675:                                log("OSID Version: " + version);
676:                                log("OSID LoadKey: " + loadkey);
677:                                t.printStackTrace();
678:                                // continue trying other managers
679:                            }
680:                        }
681:                    }
682:                } catch (Throwable t) {
683:                    t.printStackTrace();
684:                    log(t);
685:                    throw new org.osid.repository.RepositoryException(
686:                            org.osid.OsidException.OPERATION_FAILED);
687:                }
688:            }
689:
690:            private void log(Throwable t) {
691:                System.out.println(t.getMessage());
692:            }
693:
694:            private void log(String entry) {
695:                System.out.println(entry);
696:            }
697:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.