1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.server.config.beans;
21
22
23 import java.util.List;
24
25
26 /**
27 * The base class containing all the configuration hierarchy. This hierarchy
28 * starts with the DirectoryService elements.
29 *
30 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31 */
32 public class ConfigBean
33 {
34 /** The DirectoryService beans */
35 private List<AdsBaseBean> directoryServiceBeans;
36
37
38 /**
39 * Create a new ConfigBean instance
40 */
41 public ConfigBean()
42 {
43 }
44
45
46 /**
47 * Add underlying DirectoryServiceBean
48 * @param directoryServiceBeans The DirectoryServiceBeans
49 */
50 public void addDirectoryService( DirectoryServiceBean... directoryServiceBeans )
51 {
52 for ( DirectoryServiceBean directoryServiceBean : directoryServiceBeans )
53 {
54 this.directoryServiceBeans.add( directoryServiceBean );
55 }
56 }
57
58
59 /**
60 * @return the directoryServiceBeans
61 */
62 public List<AdsBaseBean> getDirectoryServiceBeans()
63 {
64 return directoryServiceBeans;
65 }
66
67
68 /**
69 * @return the first directoryServiceBean found into the configuration
70 */
71 public DirectoryServiceBean getDirectoryServiceBean()
72 {
73 if ( ( directoryServiceBeans == null ) || ( directoryServiceBeans.size() == 0 ) )
74 {
75 return null;
76 }
77
78 for ( AdsBaseBean bean : directoryServiceBeans )
79 {
80 if ( bean instanceof DirectoryServiceBean )
81 {
82 return ( DirectoryServiceBean ) bean;
83 }
84 }
85
86 return null;
87 }
88
89
90 /**
91 * @param The DirectoryService ID we want to get
92 * @return the found directoryServiceBean
93 */
94 public DirectoryServiceBean getDirectoryServiceBean( String directoryServiceId )
95 {
96 if ( ( directoryServiceBeans == null ) || ( directoryServiceBeans.size() == 0 ) )
97 {
98 return null;
99 }
100
101 for ( AdsBaseBean bean : directoryServiceBeans )
102 {
103 if ( bean instanceof DirectoryServiceBean )
104 {
105 if ( ( ( DirectoryServiceBean ) bean ).getDirectoryServiceId().equals( directoryServiceId ) )
106 {
107 return ( DirectoryServiceBean ) bean;
108 }
109 }
110 }
111
112 return null;
113 }
114
115
116 /**
117 * @param directoryServiceBeans the directoryServiceBeans to set
118 */
119 public void setDirectoryServiceBeans( List<AdsBaseBean> directoryServiceBeans )
120 {
121 this.directoryServiceBeans = directoryServiceBeans;
122 }
123
124
125 /**
126 * {@inheritDoc}
127 */
128 public String toString()
129 {
130 StringBuilder sb = new StringBuilder();
131
132 if ( directoryServiceBeans != null )
133 {
134 for ( AdsBaseBean directoryService : directoryServiceBeans )
135 {
136 sb.append( directoryService ).append( "\n\n" );
137 }
138 }
139
140 return sb.toString();
141 }
142 }