1 50 51 package org.apache.excalibur.configuration; 52 53 import org.apache.avalon.framework.configuration.Configuration; 54 import org.apache.avalon.framework.configuration.ConfigurationException; 55 import org.apache.avalon.framework.configuration.DefaultConfiguration; 56 57 67 public class CascadingConfiguration implements Configuration 68 { 69 73 76 private final Configuration m_base; 77 78 81 private final Configuration m_parent; 82 83 87 99 public CascadingConfiguration( final Configuration base, final Configuration parent ) 100 { 101 if( base == null ) 102 { 103 m_base = new DefaultConfiguration( "-", null ); 104 } 105 else 106 { 107 m_base = base; 108 } 109 if( parent == null ) 110 { 111 m_parent = new DefaultConfiguration( "-", null ); 112 } 113 else 114 { 115 m_parent = parent; 116 } 117 } 118 119 123 127 public String getName() 128 { 129 return m_base.getName(); 130 } 131 132 139 public String getLocation() 140 { 141 return m_base.getLocation(); 142 } 143 144 151 public String getNamespace() throws ConfigurationException 152 { 153 return m_base.getNamespace(); 154 } 155 156 163 public Configuration getChild( String child ) 164 { 165 return new CascadingConfiguration( m_base.getChild( child ), m_parent.getChild( child ) ); 166 } 167 168 180 public Configuration getChild( String child, boolean createNew ) 181 { 182 if( createNew ) 183 { 184 return getChild( child ); 185 } 186 Configuration c = m_base.getChild( child, false ); 187 if( c != null ) 188 { 189 return c; 190 } 191 return m_parent.getChild( child, false ); 192 } 193 194 202 public Configuration[] getChildren() 203 { 204 Configuration[] b = m_base.getChildren(); 205 Configuration[] p = m_parent.getChildren(); 206 Configuration[] result = new Configuration[ b.length + p.length ]; 207 System.arraycopy( b, 0, result, 0, b.length ); 208 System.arraycopy( p, 0, result, b.length, p.length ); 209 return result; 210 } 211 212 222 public Configuration[] getChildren( String name ) 223 { 224 Configuration[] b = m_base.getChildren( name ); 225 Configuration[] p = m_parent.getChildren( name ); 226 Configuration[] result = new Configuration[ b.length + p.length ]; 227 System.arraycopy( b, 0, result, 0, b.length ); 228 System.arraycopy( p, 0, result, b.length, p.length ); 229 return result; 230 } 231 232 243 public String [] getAttributeNames() 244 { 245 java.util.Vector vector = new java.util.Vector (); 246 String [] names = m_base.getAttributeNames(); 247 String [] names2 = m_parent.getAttributeNames(); 248 for( int i = 0; i < names.length; i++ ) 249 { 250 vector.add( names[ i ] ); 251 } 252 for( int i = 0; i < names2.length; i++ ) 253 { 254 if( vector.indexOf( names2[ i ] ) < 0 ) 255 { 256 vector.add( names2[ i ] ); 257 } 258 } 259 return (String [])vector.toArray( new String [ 0 ] ); 260 } 261 262 271 public String getAttribute( String paramName ) throws ConfigurationException 272 { 273 try 274 { 275 return m_base.getAttribute( paramName ); 276 } 277 catch( ConfigurationException e ) 278 { 279 return m_parent.getAttribute( paramName ); 280 } 281 } 282 283 291 public int getAttributeAsInteger( String paramName ) throws ConfigurationException 292 { 293 try 294 { 295 return m_base.getAttributeAsInteger( paramName ); 296 } 297 catch( ConfigurationException e ) 298 { 299 return m_parent.getAttributeAsInteger( paramName ); 300 } 301 } 302 303 312 public long getAttributeAsLong( String name ) throws ConfigurationException 313 { 314 try 315 { 316 return m_base.getAttributeAsLong( name ); 317 } 318 catch( ConfigurationException e ) 319 { 320 return m_parent.getAttributeAsLong( name ); 321 } 322 } 323 324 332 public float getAttributeAsFloat( String paramName ) throws ConfigurationException 333 { 334 try 335 { 336 return m_base.getAttributeAsFloat( paramName ); 337 } 338 catch( ConfigurationException e ) 339 { 340 return m_parent.getAttributeAsFloat( paramName ); 341 } 342 } 343 344 353 public boolean getAttributeAsBoolean( String paramName ) throws ConfigurationException 354 { 355 try 356 { 357 return m_base.getAttributeAsBoolean( paramName ); 358 } 359 catch( ConfigurationException e ) 360 { 361 return m_parent.getAttributeAsBoolean( paramName ); 362 } 363 } 364 365 372 public String getValue() throws ConfigurationException 373 { 374 try 375 { 376 return m_base.getValue(); 377 } 378 catch( ConfigurationException e ) 379 { 380 return m_parent.getValue(); 381 } 382 } 383 384 389 public int getValueAsInteger() throws ConfigurationException 390 { 391 try 392 { 393 return m_base.getValueAsInteger(); 394 } 395 catch( ConfigurationException e ) 396 { 397 return m_parent.getValueAsInteger(); 398 } 399 } 400 401 407 public float getValueAsFloat() throws ConfigurationException 408 { 409 try 410 { 411 return m_base.getValueAsFloat(); 412 } 413 catch( ConfigurationException e ) 414 { 415 return m_parent.getValueAsFloat(); 416 } 417 } 418 419 425 public boolean getValueAsBoolean() throws ConfigurationException 426 { 427 try 428 { 429 return m_base.getValueAsBoolean(); 430 } 431 catch( ConfigurationException e ) 432 { 433 return m_parent.getValueAsBoolean(); 434 } 435 } 436 437 443 public long getValueAsLong() throws ConfigurationException 444 { 445 try 446 { 447 return m_base.getValueAsLong(); 448 } 449 catch( ConfigurationException e ) 450 { 451 return m_parent.getValueAsLong(); 452 } 453 } 454 455 464 public String getValue( String defaultValue ) 465 { 466 try 467 { 468 return m_base.getValue(); 469 } 470 catch( ConfigurationException e ) 471 { 472 return m_parent.getValue( defaultValue ); 473 } 474 } 475 476 485 public int getValueAsInteger( int defaultValue ) 486 { 487 try 488 { 489 return m_base.getValueAsInteger(); 490 } 491 catch( ConfigurationException e ) 492 { 493 return m_parent.getValueAsInteger( defaultValue ); 494 } 495 } 496 497 506 public long getValueAsLong( long defaultValue ) 507 { 508 try 509 { 510 return m_base.getValueAsLong(); 511 } 512 catch( ConfigurationException e ) 513 { 514 return m_parent.getValueAsLong( defaultValue ); 515 } 516 } 517 518 527 public float getValueAsFloat( float defaultValue ) 528 { 529 try 530 { 531 return m_base.getValueAsFloat(); 532 } 533 catch( ConfigurationException e ) 534 { 535 return m_parent.getValueAsFloat( defaultValue ); 536 } 537 } 538 539 548 public boolean getValueAsBoolean( boolean defaultValue ) 549 { 550 try 551 { 552 return m_base.getValueAsBoolean(); 553 } 554 catch( ConfigurationException e ) 555 { 556 return m_parent.getValueAsBoolean( defaultValue ); 557 } 558 } 559 560 571 public String getAttribute( String name, String defaultValue ) 572 { 573 try 574 { 575 return m_base.getAttribute( name ); 576 } 577 catch( ConfigurationException e ) 578 { 579 return m_parent.getAttribute( name, defaultValue ); 580 } 581 } 582 583 594 public int getAttributeAsInteger( String name, int defaultValue ) 595 { 596 try 597 { 598 return m_base.getAttributeAsInteger( name ); 599 } 600 catch( ConfigurationException e ) 601 { 602 return m_parent.getAttributeAsInteger( name, defaultValue ); 603 } 604 } 605 606 617 public long getAttributeAsLong( String name, long defaultValue ) 618 { 619 try 620 { 621 return m_base.getAttributeAsLong( name ); 622 } 623 catch( ConfigurationException e ) 624 { 625 return m_parent.getAttributeAsLong( name, defaultValue ); 626 } 627 } 628 629 640 public float getAttributeAsFloat( String name, float defaultValue ) 641 { 642 try 643 { 644 return m_base.getAttributeAsFloat( name ); 645 } 646 catch( ConfigurationException e ) 647 { 648 return m_parent.getAttributeAsFloat( name, defaultValue ); 649 } 650 } 651 652 663 public boolean getAttributeAsBoolean( String name, boolean defaultValue ) 664 { 665 try 666 { 667 return m_base.getAttributeAsBoolean( name ); 668 } 669 catch( ConfigurationException e ) 670 { 671 return m_parent.getAttributeAsBoolean( name, defaultValue ); 672 } 673 } 674 } 675 676 677 678 | Popular Tags |