View Javadoc
1 package org.apache.fulcrum.configuration; 2 /* 3 * ==================================================================== The 4 * Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 1. 10 * Redistributions of source code must retain the above copyright notice, this 11 * list of conditions and the following disclaimer. 2. Redistributions in 12 * binary form must reproduce the above copyright notice, this list of 13 * conditions and the following disclaimer in the documentation and/or other 14 * materials provided with the distribution. 3. The end-user documentation 15 * included with the redistribution, if any, must include the following 16 * acknowledgment: "This product includes software developed by the Apache 17 * Software Foundation (http://www.apache.org/)." Alternately, this 18 * acknowledgment may appear in the software itself, if and wherever such 19 * third-party acknowledgments normally appear. 4. The names "Apache" and 20 * "Apache Software Foundation" and "Apache Turbine" must not be used to 21 * endorse or promote products derived from this software without prior written 22 * permission. For written permission, please contact apache@apache.org. 5. 23 * Products derived from this software may not be called "Apache", "Apache 24 * Turbine", nor may "Apache" appear in their name, without prior written 25 * permission of the Apache Software Foundation. 26 * 27 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 28 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 29 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 30 * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 31 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 36 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 * ==================================================================== 38 * 39 * This software consists of voluntary contributions made by many individuals 40 * on behalf of the Apache Software Foundation. For more information on the 41 * Apache Software Foundation, please see <http://www.apache.org/> . 42 */ 43 import java.io.File; 44 import java.util.Iterator; 45 import java.util.Properties; 46 import java.util.Vector; 47 48 import org.apache.avalon.framework.component.Component; 49 import org.apache.avalon.framework.configuration.Configurable; 50 import org.apache.avalon.framework.configuration.Configuration; 51 import org.apache.avalon.framework.configuration.ConfigurationException; 52 import org.apache.avalon.framework.context.Context; 53 import org.apache.avalon.framework.context.ContextException; 54 import org.apache.avalon.framework.context.Contextualizable; 55 import org.apache.avalon.framework.logger.AbstractLogEnabled; 56 import org.apache.commons.configuration.ConfigurationFactory; 57 58 /*** 59 * Starts up a commons configuration Configuration object via the 60 * 61 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a> 62 * @version $Id: DefaultConfigurationService.java,v 1.1 2003/10/27 16:53:06 epugh Exp $ 63 * 64 */ 65 public class DefaultConfigurationService 66 extends AbstractLogEnabled 67 implements Config, Component, Configurable, Contextualizable 68 { 69 /*** 70 * The property specifying the location where to read in the configuration 71 * path from. 72 */ 73 String CONFIGURATION_PATH = "configurationPath"; 74 75 /*** The Avalon Context */ 76 private Context context = null; 77 78 private String applicationRoot; 79 80 private org.apache.commons.configuration.Configuration configuration; 81 82 /*** 83 * @param arg0 84 * @param arg1 85 */ 86 public void addProperty(String arg0, Object arg1) 87 { 88 configuration.addProperty(arg0, arg1); 89 } 90 91 /*** 92 * @param arg0 93 */ 94 public void clearProperty(String arg0) 95 { 96 configuration.clearProperty(arg0); 97 } 98 99 /*** 100 * @param arg0 101 * @return 102 */ 103 public boolean containsKey(String arg0) 104 { 105 return configuration.containsKey(arg0); 106 } 107 108 /* 109 * (non-Javadoc) 110 * 111 * @see java.lang.Object#equals(java.lang.Object) 112 */ 113 public boolean equals(Object obj) 114 { 115 return configuration.equals(obj); 116 } 117 118 /*** 119 * @param arg0 120 * @return 121 */ 122 public boolean getBoolean(String arg0) 123 { 124 return configuration.getBoolean(arg0); 125 } 126 127 /*** 128 * @param arg0 129 * @param arg1 130 * @return 131 */ 132 public boolean getBoolean(String arg0, boolean arg1) 133 { 134 return configuration.getBoolean(arg0, arg1); 135 } 136 137 /*** 138 * @param arg0 139 * @param arg1 140 * @return 141 */ 142 public Boolean getBoolean(String arg0, Boolean arg1) 143 { 144 return configuration.getBoolean(arg0, arg1); 145 } 146 147 /*** 148 * @param arg0 149 * @return 150 */ 151 public byte getByte(String arg0) 152 { 153 return configuration.getByte(arg0); 154 } 155 156 /*** 157 * @param arg0 158 * @param arg1 159 * @return 160 */ 161 public byte getByte(String arg0, byte arg1) 162 { 163 return configuration.getByte(arg0, arg1); 164 } 165 166 /*** 167 * @param arg0 168 * @param arg1 169 * @return 170 */ 171 public Byte getByte(String arg0, Byte arg1) 172 { 173 return configuration.getByte(arg0, arg1); 174 } 175 176 /*** 177 * @param arg0 178 * @return 179 */ 180 public double getDouble(String arg0) 181 { 182 return configuration.getDouble(arg0); 183 } 184 185 /*** 186 * @param arg0 187 * @param arg1 188 * @return 189 */ 190 public double getDouble(String arg0, double arg1) 191 { 192 return configuration.getDouble(arg0, arg1); 193 } 194 195 /*** 196 * @param arg0 197 * @param arg1 198 * @return 199 */ 200 public Double getDouble(String arg0, Double arg1) 201 { 202 return configuration.getDouble(arg0, arg1); 203 } 204 205 /*** 206 * @param arg0 207 * @return 208 */ 209 public float getFloat(String arg0) 210 { 211 return configuration.getFloat(arg0); 212 } 213 214 /*** 215 * @param arg0 216 * @param arg1 217 * @return 218 */ 219 public float getFloat(String arg0, float arg1) 220 { 221 return configuration.getFloat(arg0, arg1); 222 } 223 224 /*** 225 * @param arg0 226 * @param arg1 227 * @return 228 */ 229 public Float getFloat(String arg0, Float arg1) 230 { 231 return configuration.getFloat(arg0, arg1); 232 } 233 234 /*** 235 * @param arg0 236 * @return 237 */ 238 public int getInt(String arg0) 239 { 240 return configuration.getInt(arg0); 241 } 242 243 /*** 244 * @param arg0 245 * @param arg1 246 * @return 247 */ 248 public int getInt(String arg0, int arg1) 249 { 250 return configuration.getInt(arg0, arg1); 251 } 252 253 /*** 254 * @param arg0 255 * @param arg1 256 * @return 257 */ 258 public Integer getInteger(String arg0, Integer arg1) 259 { 260 return configuration.getInteger(arg0, arg1); 261 } 262 263 /*** 264 * @return 265 */ 266 public Iterator getKeys() 267 { 268 return configuration.getKeys(); 269 } 270 271 /*** 272 * @param arg0 273 * @return 274 */ 275 public Iterator getKeys(String arg0) 276 { 277 return configuration.getKeys(arg0); 278 } 279 280 /*** 281 * @param arg0 282 * @return 283 */ 284 public long getLong(String arg0) 285 { 286 return configuration.getLong(arg0); 287 } 288 289 /*** 290 * @param arg0 291 * @param arg1 292 * @return 293 */ 294 public Long getLong(String arg0, Long arg1) 295 { 296 return configuration.getLong(arg0, arg1); 297 } 298 299 /*** 300 * @param arg0 301 * @param arg1 302 * @return 303 */ 304 public long getLong(String arg0, long arg1) 305 { 306 return configuration.getLong(arg0, arg1); 307 } 308 309 /*** 310 * @param arg0 311 * @return 312 */ 313 public Properties getProperties(String arg0) 314 { 315 return configuration.getProperties(arg0); 316 } 317 318 /*** 319 * @param arg0 320 * @return 321 */ 322 public Object getProperty(String arg0) 323 { 324 return configuration.getProperty(arg0); 325 } 326 327 /*** 328 * @param arg0 329 * @return 330 */ 331 public short getShort(String arg0) 332 { 333 return configuration.getShort(arg0); 334 } 335 336 /*** 337 * @param arg0 338 * @param arg1 339 * @return 340 */ 341 public Short getShort(String arg0, Short arg1) 342 { 343 return configuration.getShort(arg0, arg1); 344 } 345 346 /*** 347 * @param arg0 348 * @param arg1 349 * @return 350 */ 351 public short getShort(String arg0, short arg1) 352 { 353 return configuration.getShort(arg0, arg1); 354 } 355 356 /*** 357 * @param arg0 358 * @return 359 */ 360 public String getString(String arg0) 361 { 362 return configuration.getString(arg0); 363 } 364 365 /*** 366 * @param arg0 367 * @param arg1 368 * @return 369 */ 370 public String getString(String arg0, String arg1) 371 { 372 return configuration.getString(arg0, arg1); 373 } 374 375 /*** 376 * @param arg0 377 * @return 378 */ 379 public String[] getStringArray(String arg0) 380 { 381 return configuration.getStringArray(arg0); 382 } 383 384 /*** 385 * @param arg0 386 * @return 387 */ 388 public Vector getVector(String arg0) 389 { 390 return configuration.getVector(arg0); 391 } 392 393 /*** 394 * @param arg0 395 * @param arg1 396 * @return 397 */ 398 public Vector getVector(String arg0, Vector arg1) 399 { 400 return configuration.getVector(arg0, arg1); 401 } 402 403 /* 404 * (non-Javadoc) 405 * 406 * @see java.lang.Object#hashCode() 407 */ 408 public int hashCode() 409 { 410 return configuration.hashCode(); 411 } 412 413 /*** 414 * @return 415 */ 416 public boolean isEmpty() 417 { 418 return configuration.isEmpty(); 419 } 420 421 /*** 422 * @param arg0 423 * @param arg1 424 */ 425 public void setProperty(String arg0, Object arg1) 426 { 427 configuration.setProperty(arg0, arg1); 428 } 429 430 /*** 431 * @param arg0 432 * @return 433 */ 434 public org.apache.commons.configuration.Configuration subset(String arg0) 435 { 436 return configuration.subset(arg0); 437 } 438 439 /* 440 * (non-Javadoc) 441 * 442 * @see java.lang.Object#toString() 443 */ 444 public String toString() 445 { 446 return configuration.toString(); 447 } 448 449 /*** 450 * Avalon component lifecycle method 451 */ 452 public void configure(Configuration conf) throws ConfigurationException 453 { 454 try 455 { 456 applicationRoot = 457 (context == null) 458 ? null 459 : (String) context.get("componentAppRoot"); 460 } 461 catch (ContextException ce) 462 { 463 getLogger().error("Could not load Application Root from Context"); 464 } 465 466 String confPath = conf.getAttribute(CONFIGURATION_PATH); 467 File confFile = new File(confPath); 468 if(!confFile.exists()){ 469 confFile = new File(applicationRoot,confPath); 470 } 471 if(!confFile.exists()){ 472 throw new ConfigurationException("XML file for ConfigurationFactory can not be found:" +confFile); 473 } 474 475 ConfigurationFactory configurationFactory = 476 new ConfigurationFactory(confFile.getAbsolutePath()); 477 configurationFactory.setBasePath(applicationRoot); 478 try 479 { 480 configuration = configurationFactory.getConfiguration(); 481 } 482 catch (Exception e) 483 { 484 throw new ConfigurationException( 485 "Problem loading Configuration with Factory.", 486 e); 487 } 488 489 } 490 491 /*** 492 * @see org.apache.avalon.framework.context.Contextualizable 493 */ 494 public void contextualize(Context context) throws ContextException 495 { 496 this.context = context; 497 } 498 499 }

This page was automatically generated by Maven