- Fixed bug where config files in src-conf did not have IDP_HOME/SP_HOME properly...
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / wayf / WayfOrigins.java
1 /*
2  * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package edu.internet2.middleware.shibboleth.wayf;
18
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Iterator;
22
23 import org.apache.log4j.Logger;
24
25 /**
26  * This class is a container for OriginSets, allowing lookup and searching of the same.
27  * 
28  * @author Walter Hoehn wassa@columbia.edu
29  */
30
31 public class WayfOrigins {
32
33         private HashMap origins = new HashMap();
34         private static Logger log = Logger.getLogger(WayfOrigins.class.getName());
35
36         public OriginSet[] getOriginSets() {
37
38                 return (OriginSet[]) origins.values().toArray(new OriginSet[0]);
39         }
40
41         public void addOriginSet(OriginSet originSet) {
42
43                 if (origins.containsKey(originSet.getName())) {
44                         OriginSet previousOrigins = (OriginSet) origins.get(originSet.getName());
45                         Origin[] newOrigins = originSet.getOrigins();
46                         for (int i = 0; (i < newOrigins.length); i++) {
47                                 previousOrigins.addOrigin(newOrigins[i]);
48                         }
49                 } else {
50                         origins.put(originSet.getName(), originSet);
51                 }
52                 log.debug("Adding origin set :" + originSet.getName() + ": to configuration");
53         }
54
55         public String lookupHSbyName(String originName) {
56
57                 if (originName != null) {
58                         Iterator originSetIt = origins.values().iterator();
59                         while (originSetIt.hasNext()) {
60
61                                 OriginSet originSet = (OriginSet) originSetIt.next();
62                                 Origin[] origins = originSet.getOrigins();
63                                 for (int i = 0; (i < origins.length); i++) {
64                                         if (originName.equals(origins[i].getName())) { return origins[i].getHandleService(); }
65                                 }
66                         }
67
68                 }
69                 return null;
70
71         }
72
73         public Origin[] seachForMatchingOrigins(String searchString, WayfConfig config) {
74
75                 Iterator originSetIt = origins.values().iterator();
76                 HashSet searchResults = new HashSet();
77                 while (originSetIt.hasNext()) {
78
79                         OriginSet originSet = (OriginSet) originSetIt.next();
80                         Origin[] origins = originSet.getOrigins();
81                         for (int i = 0; (i < origins.length); i++) {
82                                 if (origins[i].isMatch(searchString, config)) {
83                                         searchResults.add(origins[i]);
84                                 }
85                         }
86                 }
87                 return (Origin[]) searchResults.toArray(new Origin[0]);
88         }
89
90 }