01: /*
02: * Copyright 2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package com.pentaho.security.ldap.search;
14:
15: import java.util.ArrayList;
16: import java.util.HashSet;
17: import java.util.Iterator;
18: import java.util.List;
19: import java.util.Set;
20:
21: //import org.apache.commons.logging.Log;
22: //import org.apache.commons.logging.LogFactory;
23: import org.springframework.beans.factory.InitializingBean;
24: import org.springframework.util.Assert;
25:
26: /**
27: * Iterates over <code>LdapSearch</code> instances in <code>searches</code>
28: * and unions the results.
29: *
30: * @author mlowery
31: */
32: public class UnionizingLdapSearch implements LdapSearch,
33: InitializingBean {
34: // ~ Static fields/initializers ============================================
35:
36: // private static final Log logger = LogFactory.getLog(UnionizingLdapSearch.class);
37:
38: // ~ Instance fields =======================================================
39:
40: private Set searches;
41:
42: // ~ Constructors ==========================================================
43:
44: public UnionizingLdapSearch() {
45: super ();
46: }
47:
48: public UnionizingLdapSearch(final Set searches) {
49: this .searches = searches;
50: }
51:
52: // ~ Methods ===============================================================
53:
54: public List search(final Object[] filterArgs) {
55: Set results = new HashSet();
56: Iterator iter = searches.iterator();
57: while (iter.hasNext()) {
58: results.addAll(((LdapSearch) iter.next())
59: .search(filterArgs));
60: }
61: return new ArrayList(results);
62: }
63:
64: public void setSearches(final Set searches) {
65: this .searches = searches;
66: }
67:
68: public void afterPropertiesSet() throws Exception {
69: Assert.notEmpty(searches);
70: }
71:
72: }
|