01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.services.persondir.support.legacy;
07:
08: import java.io.IOException;
09: import java.util.ArrayList;
10: import java.util.Iterator;
11: import java.util.List;
12: import java.util.Map;
13: import java.util.Set;
14:
15: import javax.xml.parsers.ParserConfigurationException;
16:
17: import org.jasig.portal.ResourceMissingException;
18: import org.jasig.portal.services.persondir.IPersonAttributeDao;
19: import org.jasig.portal.services.persondir.support.MergingPersonAttributeDaoImpl;
20: import org.jasig.portal.services.persondir.support.merger.ReplacingAttributeAdder;
21: import org.jasig.portal.utils.ResourceLoader;
22: import org.w3c.dom.Document;
23: import org.xml.sax.SAXException;
24:
25: /**
26: * This implementation attempts to recreate the uPortal 2.4.2
27: * {@link org.jasig.portal.services.PersonDirectory} behavior of
28: * configuration using PersonDirs.xml.
29: *
30: * @author andrew.petro@yale.edu, Eric Dalquist <a href="mailto:edalquist@unicon.net">edalquist@unicon.net</a>
31: * @version $Revision: 35515 $ $Date: 2005-04-06 08:31:40 -0700 (Wed, 06 Apr 2005) $
32: * @since uPortal 2.5
33: */
34: public class LegacyPersonAttributeDao implements IPersonAttributeDao {
35:
36: private IPersonAttributeDao delegate;
37:
38: public static final String PERSON_DIRS_FILE_PATH = "/properties/PersonDirs.xml";
39:
40: /**
41: * This constructor builds a legacy PersonDirectory implementation suitable
42: * for environments in which Spring configuration is not available.
43: * @throws SAXException when PersonDirs.xml is not well formed
44: * @throws ParserConfigurationException when ResourceLoader is misconfigured
45: * @throws IOException - when PersonDirs.xml cannot be read
46: * @throws ResourceMissingException - when /properties/PersonDirs.xml is missing
47: */
48: public LegacyPersonAttributeDao() throws ResourceMissingException,
49: IOException, ParserConfigurationException, SAXException {
50: // build up from the bottom
51:
52: // we need PersonAttributeDaos implementing each of the
53: // sources represented by the infos in the parsed PersonDirs.xml file.
54: final List personAttributeDaos = new ArrayList();
55:
56: // Build a DOM tree out of uPortal/properties/PersonDirs.xml
57: final Document doc = ResourceLoader.getResourceAsDocument(this
58: .getClass(), PERSON_DIRS_FILE_PATH);
59:
60: final List personDirectoryInfos = PersonDirXmlParser
61: .getPersonDirInfos(doc);
62:
63: for (final Iterator pdInfoItr = personDirectoryInfos.iterator(); pdInfoItr
64: .hasNext();) {
65: final PersonDirInfo info = (PersonDirInfo) pdInfoItr.next();
66:
67: final IPersonAttributeDao adapted = PersonDirInfoAdaptor
68: .adapt(info);
69:
70: personAttributeDaos.add(adapted);
71: }
72:
73: // build a merger over the list of sources
74: final MergingPersonAttributeDaoImpl merger = new MergingPersonAttributeDaoImpl();
75: //Enforce the requisite merger
76: merger.setMerger(new ReplacingAttributeAdder());
77: merger.setPersonAttributeDaos(personAttributeDaos);
78: merger
79: .setDefaultAttributeName(PersonDirInfoAdaptor.QUERY_ATTRIBUTE);
80:
81: // store the constructed PersonDirectory implementation.
82: this .delegate = merger;
83: }
84:
85: public Set getPossibleUserAttributeNames() {
86: return this .delegate.getPossibleUserAttributeNames();
87: }
88:
89: public Map getUserAttributes(Map seed) {
90: return this .delegate.getUserAttributes(seed);
91: }
92:
93: public Map getUserAttributes(String uid) {
94: return this.delegate.getUserAttributes(uid);
95: }
96: }
|