001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.server.config.beans; 021 022 023import org.apache.directory.api.ldap.model.name.Dn; 024import org.apache.directory.api.util.Strings; 025import org.apache.directory.server.config.ConfigurationElement; 026 027 028/** 029 * A class used to store the Base ADS configuration. It can't be instanciated 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 */ 033public abstract class AdsBaseBean 034{ 035 /** 036 * The enabled flag, by default we treat every config entry 037 * as enabled if ads-enabled attribute is not present or if its 038 * value is set to 'TRUE'. 039 * A config entry is treated as disabled only if the value of 040 * ads-enabled attribute is set to 'FALSE' 041 * 042 * Note: the value true/false is case <b>insensitive</b> 043 */ 044 @ConfigurationElement(attributeType = "ads-enabled", isOptional = true) 045 private boolean enabled = true; 046 047 /** The description */ 048 @ConfigurationElement(attributeType = "description", isOptional = true) 049 private String description; 050 051 /** the DN of the entry with which this bean is associated */ 052 private Dn dn; 053 054 055 /** 056 * Create a new BaseBean instance 057 */ 058 protected AdsBaseBean() 059 { 060 } 061 062 063 /** 064 * @return <code>true</code> if the component is enabled 065 */ 066 public boolean isEnabled() 067 { 068 return enabled; 069 } 070 071 072 /** 073 * Enable or disable the component 074 * @param enabled if <code>true</code>, the component is enabled. 075 */ 076 public void setEnabled( boolean enabled ) 077 { 078 this.enabled = enabled; 079 } 080 081 082 /** 083 * @return the description for this component 084 */ 085 public String getDescription() 086 { 087 return description; 088 } 089 090 091 /** 092 * Sets the component description 093 * 094 * @param description The description 095 */ 096 public void setDescription( String description ) 097 { 098 this.description = description; 099 } 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}