d3cca45865cfb3340f3a28dacfdccd72ae49e34b
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / search / registry / SearchProviderRegistry.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.search.registry;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.onap.aai.sparky.search.api.SearchProvider;
29
30 /**
31  * Make this a java-scoped singleton to resolve the contextual issue spanning a Spring Context and
32  * accessing the SPR in other parts of the code that are not directly instantiated by a Spring Bean.
33  * Eventually the SPR doesn’t have to be a real singleton, it could simply be a Spring bean scoped
34  * as a singleton and then wired in via dependency injection to the classes that need it. But I’m
35  * not there yet. This will get a demonstrable extension mechanism in place quickly at practically
36  * no cost, beyond what’s already in the email plus some testing.
37  */
38
39 public class SearchProviderRegistry {
40
41   private List<SearchProvider> searchProviders;
42
43   public SearchProviderRegistry() {
44     searchProviders = new ArrayList<SearchProvider>();
45   }
46
47   public List<SearchProvider> getSearchProviders() {
48     return searchProviders;
49   }
50
51   public final void addSearchProvider(SearchProvider searchProvider) {
52
53     if (searchProvider == null) {
54       return;
55     }
56
57     if (!searchProviders.contains(searchProvider)) {
58       searchProviders.add(searchProvider);
59     }
60   }
61
62   public final void addSearchProviders(List<SearchProvider> searchProviders) {
63
64     if (searchProviders == null) {
65       return;
66     }
67
68     for (SearchProvider searchProvider : searchProviders) {
69       addSearchProvider(searchProvider);
70     }
71
72   }
73
74 }