View Javadoc
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 org.apache.directory.api.ldap.model.name.Dn;
24  import org.apache.directory.api.util.Strings;
25  import org.apache.directory.server.config.ConfigurationElement;
26  
27  
28  /**
29   * A class used to store the Base ADS configuration. It can't be instanciated
30   *
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public abstract class AdsBaseBean
34  {
35      /**
36       * The enabled flag, by default we treat every config entry
37       * as enabled if ads-enabled attribute is not present or if its
38       * value is set to 'TRUE'.
39       * A config entry is treated as disabled only if the value of 
40       * ads-enabled attribute is set to 'FALSE'
41       * 
42       * Note: the value true/false is case <b>insensitive</b>
43       */
44      @ConfigurationElement(attributeType = "ads-enabled", isOptional = true)
45      private boolean enabled = true;
46  
47      /** The description */
48      @ConfigurationElement(attributeType = "description", isOptional = true)
49      private String description;
50  
51      /** the DN of the entry with which this bean is associated */
52      private Dn dn;
53  
54  
55      /**
56       * Create a new BaseBean instance
57       */
58      protected AdsBaseBean()
59      {
60      }
61  
62  
63      /**
64       * @return <code>true</code> if the component is enabled
65       */
66      public boolean isEnabled()
67      {
68          return enabled;
69      }
70  
71  
72      /**
73       * Enable or disable the component
74       * @param enabled if <code>true</code>, the component is enabled.
75       */
76      public void setEnabled( boolean enabled )
77      {
78          this.enabled = enabled;
79      }
80  
81  
82      /**
83       * @return the description for this component
84       */
85      public String getDescription()
86      {
87          return description;
88      }
89  
90  
91      /**
92       * Sets the component description
93       * 
94       * @param description The description
95       */
96      public void setDescription( String description )
97      {
98          this.description = description;
99      }
100 
101 
102     /**
103      * Formated print of a boolean
104      * 
105      * @param tabs The starting spaces
106      * @param name The bean name
107      * @param value the boolean value
108      * @return A string for this boolean
109      */
110     protected String toString( String tabs, String name, boolean value )
111     {
112         StringBuilder sb = new StringBuilder();
113 
114         sb.append( tabs ).append( name ).append( " : " );
115 
116         if ( value )
117         {
118             sb.append( "TRUE" );
119         }
120         else
121         {
122             sb.append( "FALSE" );
123         }
124 
125         sb.append( '\n' );
126 
127         return sb.toString();
128     }
129 
130 
131     /**
132      * Formated print of a String that can be null
133      * 
134      * @param tabs The starting spaces
135      * @param name The bean name
136      * @param value the string value
137      * @return A string for this String
138      */
139     protected String toString( String tabs, String name, String value )
140     {
141         if ( value != null )
142         {
143             return tabs + name + " : " + value + "\n";
144         }
145         else
146         {
147             return "";
148         }
149     }
150 
151 
152     /**
153      * Formated print of a Dn that can be null
154      * 
155      * @param tabs The starting spaces
156      * @param name The bean name
157      * @param value the Dn value
158      * @return A string for this Dn
159      */
160     protected String toString( String tabs, String name, Dn value )
161     {
162         if ( value != null )
163         {
164             return tabs + name + " : " + value.getName() + "\n";
165         }
166         else
167         {
168             return "";
169         }
170     }
171 
172 
173     /**
174      * a convenient method to finding if this bean was disabled in the config
175      * 
176      * @return true if the bean was disabled, false otherwise
177      */
178     public final boolean isDisabled()
179     {
180         return !enabled;
181     }
182 
183 
184     /**
185      * Formated print of a long
186      * 
187      * @param tabs The starting spaces
188      * @param name The bean name
189      * @param value the long value
190      * @return A string for this long
191      */
192     protected String toString( String tabs, String name, long value )
193     {
194         return tabs + name + " : " + value + "\n";
195     }
196 
197 
198     /**
199      * {@inheritDoc}
200      */
201     public String toString( String tabs )
202     {
203         StringBuilder sb = new StringBuilder();
204 
205         sb.append( toString( tabs, "enabled", enabled ) );
206 
207         if ( !Strings.isEmpty( description ) )
208         {
209             sb.append( tabs ).append( "description : '" ).append( description ).append( "'\n" );
210         }
211 
212         if ( dn != null )
213         {
214             sb.append( tabs ).append( "DN: " ).append( dn ).append( "'\n" );
215         }
216 
217         return sb.toString();
218     }
219 
220 
221     /**
222      * {@inheritDoc}
223      */
224     public void setDn( Dn dn )
225     {
226         this.dn = dn;
227     }
228 
229 
230     /**
231      * {@inheritDoc}
232      */
233     public Dn getDn()
234     {
235         return dn;
236     }
237 
238 
239     /**
240      * {@inheritDoc}
241      */
242     public String toString()
243     {
244         return toString( "" );
245     }
246 }