KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > apacheds > configuration > model > ServerConfigurationParser


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.ldapstudio.apacheds.configuration.model;
21
22
23 import java.io.BufferedReader JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.StringReader JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import javax.naming.NamingException JavaDoc;
32 import javax.naming.directory.Attributes JavaDoc;
33 import javax.naming.directory.BasicAttributes JavaDoc;
34
35 import org.apache.directory.shared.ldap.ldif.LdifReader;
36 import org.apache.directory.shared.ldap.message.AttributesImpl;
37 import org.apache.directory.shared.ldap.util.StringTools;
38 import org.dom4j.Attribute;
39 import org.dom4j.Document;
40 import org.dom4j.Element;
41 import org.dom4j.io.SAXReader;
42
43
44 /**
45  * This class represents the Server Configuration Parser. It can be used to parse a 'server.xml' file
46  * and get Server Configuration Object from it.
47  *
48  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
49  * @version $Rev$, $Date$
50  */

51 public class ServerConfigurationParser
52 {
53     /**
54      * Parses a 'server.xml' file located at the given path and returns
55      * the corresponding ServerConfiguration Object.
56      *
57      * @param path
58      * the path of the file to parse
59      * @return
60      * the corresponding ServerConfiguration Object
61      * @throws ServerConfigurationParserException
62      * if an error occurrs when reading the Server Configuration file
63      */

64     public ServerConfiguration parse( String JavaDoc path ) throws ServerConfigurationParserException
65     {
66         try
67         {
68             SAXReader reader = new SAXReader();
69             Document document = reader.read( path );
70
71             ServerConfiguration serverConfiguration = new ServerConfiguration();
72             serverConfiguration.setPath( path );
73
74             parse( document, serverConfiguration );
75
76             return serverConfiguration;
77         }
78         catch ( Exception JavaDoc e )
79         {
80             if ( e instanceof ServerConfigurationParserException )
81             {
82                 throw ( ServerConfigurationParserException ) e;
83             }
84             else
85             {
86                 ServerConfigurationParserException exception = new ServerConfigurationParserException( e.getMessage(),
87                     e.getCause() );
88                 exception.setStackTrace( e.getStackTrace() );
89                 throw exception;
90             }
91         }
92     }
93
94
95     /**
96      * Parses a 'server.xml' file located at the given path and returns
97      * the corresponding ServerConfiguration Object.
98      *
99      * @param inputStream
100      * the Input Stream of the file to parse
101      * @return
102      * the corresponding ServerConfiguration Object
103      * @throws ServerConfigurationParserException
104      * if an error occurrs when reading the Server Configuration file
105      */

106     public ServerConfiguration parse( InputStream JavaDoc inputStream ) throws ServerConfigurationParserException
107     {
108         try
109         {
110             SAXReader reader = new SAXReader();
111             Document document = reader.read( inputStream );
112
113             ServerConfiguration serverConfiguration = new ServerConfiguration();
114
115             parse( document, serverConfiguration );
116
117             return serverConfiguration;
118         }
119         catch ( Exception JavaDoc e )
120         {
121             if ( e instanceof ServerConfigurationParserException )
122             {
123                 throw ( ServerConfigurationParserException ) e;
124             }
125             else
126             {
127                 ServerConfigurationParserException exception = new ServerConfigurationParserException( e.getMessage(),
128                     e.getCause() );
129                 exception.setStackTrace( e.getStackTrace() );
130                 throw exception;
131             }
132         }
133     }
134
135
136     /**
137      * Parses the Document.
138      *
139      * @param document
140      * the Document
141      * @param serverConfiguration
142      * the Server Configuration
143      * @throws NumberFormatException
144      * @throws BooleanFormatException
145      * @throws ServerConfigurationParserException
146      */

147     private void parse( Document document, ServerConfiguration serverConfiguration ) throws NumberFormatException JavaDoc,
148         BooleanFormatException, ServerConfigurationParserException
149     {
150         // Reading the 'Environment' Bean
151
readEnvironmentBean( document, serverConfiguration );
152
153         // Reading the 'Configuration' Bean
154
readConfigurationBean( document, serverConfiguration );
155     }
156
157
158     /**
159      * Reads the "Environment" Bean and store its values in the given ServerConfiguration.
160      *
161      * @param document
162      * the document to use
163      * @param serverConfiguration
164      * the Server Configuration
165      */

166     private void readEnvironmentBean( Document document, ServerConfiguration serverConfiguration )
167     {
168         Element environmentBean = getBeanElementById( document, "environment" );
169
170         // Principal
171
String JavaDoc principal = readEnvironmentBeanProperty( "java.naming.security.principal", environmentBean );
172         if ( principal != null )
173         {
174             serverConfiguration.setPrincipal( principal );
175         }
176
177         // Password
178
String JavaDoc password = readEnvironmentBeanProperty( "java.naming.security.credentials", environmentBean );
179         if ( password != null )
180         {
181             serverConfiguration.setPassword( password );
182         }
183
184         // Binary Attributes
185
String JavaDoc binaryAttributes = readEnvironmentBeanProperty( "java.naming.ldap.attributes.binary", environmentBean );
186         if ( binaryAttributes != null )
187         {
188             String JavaDoc[] attributes = binaryAttributes.split( " " );
189             
190             for( String JavaDoc attribute : attributes)
191             {
192                 serverConfiguration.addBinaryAttribute( attribute );
193             }
194         }
195     }
196
197
198     /**
199      * Reads the given property in the 'Environment' Bean and returns it.
200      *
201      * @param property
202      * the property
203      * @param element
204      * the Environment Bean Element
205      * @return
206      * the value of the property, or null if the property has not been found
207      */

208     private String JavaDoc readEnvironmentBeanProperty( String JavaDoc property, Element element )
209     {
210         Element propertyElement = element.element( "property" );
211         if ( propertyElement != null )
212         {
213             Element propsElement = propertyElement.element( "props" );
214             if ( propsElement != null )
215             {
216                 for ( Iterator JavaDoc i = propsElement.elementIterator( "prop" ); i.hasNext(); )
217                 {
218                     Element propElement = ( Element ) i.next();
219                     Attribute keyAttribute = propElement.attribute( "key" );
220                     if ( keyAttribute != null && ( keyAttribute.getValue().equals( property ) ) )
221                     {
222                         return propElement.getText();
223                     }
224                 }
225             }
226         }
227
228         return null;
229     }
230
231
232     /**
233      * Reads the "Configuration" Bean and store its values in the given ServerConfiguration.
234      *
235      * @param document
236      * the document to use
237      * @param serverConfiguration
238      * the Server Configuration
239      * @throws NumberFormatException
240      * @throws BooleanFormatException
241      * @throws ServerConfigurationParserException
242      */

243     private void readConfigurationBean( Document document, ServerConfiguration serverConfiguration )
244         throws NumberFormatException JavaDoc, BooleanFormatException, ServerConfigurationParserException
245     {
246         Element configurationBean = getBeanElementById( document, "configuration" );
247
248         // LdapPort
249
String JavaDoc ldapPort = readBeanProperty( "ldapPort", configurationBean );
250         if ( ldapPort != null )
251         {
252             serverConfiguration.setPort( Integer.parseInt( ldapPort ) );
253         }
254
255         // SynchPeriodMillis
256
String JavaDoc synchPeriodMillis = readBeanProperty( "synchPeriodMillis", configurationBean );
257         if ( synchPeriodMillis != null )
258         {
259             serverConfiguration.setSynchronizationPeriod( Long.parseLong( synchPeriodMillis ) );
260         }
261
262         // MaxTimeLimit
263
String JavaDoc maxTimeLimit = readBeanProperty( "maxTimeLimit", configurationBean );
264         if ( maxTimeLimit != null )
265         {
266             serverConfiguration.setMaxTimeLimit( Integer.parseInt( maxTimeLimit ) );
267         }
268
269         // MaxSizeLimit
270
String JavaDoc maxSizeLimit = readBeanProperty( "maxSizeLimit", configurationBean );
271         if ( maxSizeLimit != null )
272         {
273             serverConfiguration.setMaxSizeLimit( Integer.parseInt( maxSizeLimit ) );
274         }
275
276         // MaxThreads
277
String JavaDoc maxThreads = readBeanProperty( "maxThreads", configurationBean );
278         if ( maxThreads != null )
279         {
280             serverConfiguration.setMaxThreads( Integer.parseInt( maxThreads ) );
281         }
282
283         // AllowAnonymousAccess
284
String JavaDoc allowAnonymousAccess = readBeanProperty( "allowAnonymousAccess", configurationBean );
285         if ( allowAnonymousAccess != null )
286         {
287             serverConfiguration.setAllowAnonymousAccess( parseBoolean( allowAnonymousAccess ) );
288         }
289
290         // AccessControlEnabled
291
String JavaDoc accessControlEnabled = readBeanProperty( "accessControlEnabled", configurationBean );
292         if ( accessControlEnabled != null )
293         {
294             serverConfiguration.setEnableAccessControl( parseBoolean( accessControlEnabled ) );
295         }
296
297         // EnableNtp
298
String JavaDoc enableNtp = readBeanProperty( "enableNtp", configurationBean );
299         if ( enableNtp != null )
300         {
301             serverConfiguration.setEnableNTP( parseBoolean( enableNtp ) );
302         }
303
304         // EnableKerberos
305
String JavaDoc enableKerberos = readBeanProperty( "enableKerberos", configurationBean );
306         if ( enableKerberos != null )
307         {
308             serverConfiguration.setEnableKerberos( parseBoolean( enableKerberos ) );
309         }
310
311         // EnableChangePassword
312
String JavaDoc enableChangePassword = readBeanProperty( "enableChangePassword", configurationBean );
313         if ( enableChangePassword != null )
314         {
315             serverConfiguration.setEnableChangePassword( parseBoolean( enableChangePassword ) );
316         }
317
318         // EnableChangePassword
319
String JavaDoc denormalizeOpAttrsEnabled = readBeanProperty( "denormalizeOpAttrsEnabled", configurationBean );
320         if ( denormalizeOpAttrsEnabled != null )
321         {
322             serverConfiguration.setDenormalizeOpAttr( parseBoolean( denormalizeOpAttrsEnabled ) );
323         }
324
325         // SystemPartition
326
String JavaDoc systemPartitionConfiguration = readBeanProperty( "systemPartitionConfiguration", configurationBean );
327         if ( systemPartitionConfiguration != null )
328         {
329             Partition systemPartition = readPartition( document, systemPartitionConfiguration, true );
330             if ( systemPartition != null )
331             {
332                 serverConfiguration.addPartition( systemPartition );
333             }
334         }
335         else
336         {
337             throw new ServerConfigurationParserException(
338                 "The Server Configuration does not contain a 'systemPartitionConfiguration' property." );
339         }
340
341         // Other Partitions
342
readOtherPartitions( configurationBean, serverConfiguration );
343
344         // Interceptors
345
readInterceptors( configurationBean, serverConfiguration );
346
347         // ExtendedOperations
348
readExtendedOperations( configurationBean, serverConfiguration );
349     }
350
351
352     /**
353      * Reads and adds Partitions (other than the SystemPartition) to the Server Configuration.
354      *
355      * @param configurationBean
356      * the Configuration Bean Element
357      * @param serverConfiguration
358      * the Server Configuration
359      * @throws BooleanFormatException
360      * @throws NumberFormatException
361      */

362     private void readOtherPartitions( Element configurationBean, ServerConfiguration serverConfiguration )
363         throws NumberFormatException JavaDoc, BooleanFormatException
364     {
365         Element propertyElement = getBeanPropertyElement( "partitionConfigurations", configurationBean );
366         if ( propertyElement != null )
367         {
368             Element setElement = propertyElement.element( "set" );
369             if ( setElement != null )
370             {
371                 for ( Iterator JavaDoc i = setElement.elementIterator( "ref" ); i.hasNext(); )
372                 {
373                     Element element = ( Element ) i.next();
374                     Attribute beanAttribute = element.attribute( "bean" );
375                     if ( beanAttribute != null )
376                     {
377                         Partition partition = readPartition( configurationBean.getDocument(), beanAttribute.getValue(),
378                             false );
379                         if ( partition != null )
380                         {
381                             serverConfiguration.addPartition( partition );
382                         }
383                     }
384                 }
385             }
386         }
387     }
388
389
390     /**
391      * Reads the partition associated with the given Bean ID and return it.
392      *
393      * @param document
394      * the document
395      * @param id
396      * the Bean ID of the partition
397      * @param isSystemPartition
398      * true if this partition is the System Partition
399      * @return
400      * the partition associated with the given Bean ID
401      * @throws BooleanFormatException
402      */

403     private Partition readPartition( Document document, String JavaDoc id, boolean isSystemPartition )
404         throws BooleanFormatException, NumberFormatException JavaDoc
405     {
406         Element partitionBean = getBeanElementById( document, id );
407         if ( partitionBean != null )
408         {
409             Partition partition = new Partition();
410             partition.setSystemPartition( isSystemPartition );
411
412             // Name
413
String JavaDoc name = readBeanProperty( "name", partitionBean );
414             if ( name != null )
415             {
416                 partition.setName( name );
417             }
418
419             // CacheSize
420
String JavaDoc cacheSize = readBeanProperty( "cacheSize", partitionBean );
421             if ( cacheSize != null )
422             {
423                 partition.setCacheSize( Integer.parseInt( cacheSize ) );
424             }
425
426             // Suffix
427
String JavaDoc suffix = readBeanProperty( "suffix", partitionBean );
428             if ( suffix != null )
429             {
430                 partition.setSuffix( suffix );
431             }
432
433             // OptimizerEnabled
434
String JavaDoc optimizerEnabled = readBeanProperty( "optimizerEnabled", partitionBean );
435             if ( optimizerEnabled != null )
436             {
437                 partition.setEnableOptimizer( parseBoolean( optimizerEnabled ) );
438             }
439
440             // SynchOnWrite
441
String JavaDoc synchOnWrite = readBeanProperty( "synchOnWrite", partitionBean );
442             if ( synchOnWrite != null )
443             {
444                 partition.setSynchronizationOnWrite( parseBoolean( synchOnWrite ) );
445             }
446
447             // IndexedAttributes
448
partition.setIndexedAttributes( readPartitionIndexedAttributes( partitionBean ) );
449
450             // ContextEntry
451
partition.setContextEntry( readPartitionContextEntry( partitionBean ) );
452
453             return partition;
454         }
455
456         return null;
457     }
458
459
460     /**
461      * Reads the Indexed Attributes of the given Partition Bean Element
462      *
463      * @param partitionBean
464      * the Partition Bean Element
465      * @return
466      * the Indexed Attributes
467      */

468     private List JavaDoc<IndexedAttribute> readPartitionIndexedAttributes( Element partitionBean ) throws NumberFormatException JavaDoc
469     {
470         List JavaDoc<IndexedAttribute> indexedAttributes = new ArrayList JavaDoc<IndexedAttribute>();
471
472         Element propertyElement = getBeanPropertyElement( "indexedAttributes", partitionBean );
473         if ( propertyElement != null )
474         {
475             Element setElement = propertyElement.element( "set" );
476             if ( setElement != null )
477             {
478                 for ( Iterator JavaDoc i = setElement.elementIterator( "bean" ); i.hasNext(); )
479                 {
480                     Element beanElement = ( Element ) i.next();
481                     IndexedAttribute ia = readIndexedAttribute( beanElement );
482                     if ( ia != null )
483                     {
484                         indexedAttributes.add( ia );
485                     }
486                 }
487             }
488         }
489
490         return indexedAttributes;
491     }
492
493
494     /**
495      * Reads an Indexed Attribute.
496      *
497      * @param beanElement
498      * the Bean Element of the Indexed Attribute
499      * @return
500      * the corresponding Indexed Attribute or null if it could not be parsed
501      * @throws NumberFormatException
502      */

503     private IndexedAttribute readIndexedAttribute( Element beanElement ) throws NumberFormatException JavaDoc
504     {
505         Attribute classAttribute = beanElement.attribute( "class" );
506         if ( classAttribute != null
507             && classAttribute.getValue().equals(
508                 "org.apache.directory.server.core.partition.impl.btree.MutableIndexConfiguration" ) )
509         {
510             String JavaDoc attributeId = readBeanProperty( "attributeId", beanElement );
511             String JavaDoc cacheSize = readBeanProperty( "cacheSize", beanElement );
512             if ( ( attributeId != null ) && ( cacheSize != null ) )
513             {
514                 return new IndexedAttribute( attributeId, Integer.parseInt( cacheSize ) );
515             }
516
517         }
518
519         return null;
520     }
521
522
523     /**
524      * Reads the Context Entry of the given Partition Bean Element
525      *
526      * @param partitionBean
527      * the Partition Bean Element
528      * @return
529      * the Context Entry
530      */

531     private Attributes JavaDoc readPartitionContextEntry( Element partitionBean )
532     {
533         Element propertyElement = getBeanPropertyElement( "contextEntry", partitionBean );
534         if ( propertyElement != null )
535         {
536             Element valueElement = propertyElement.element( "value" );
537             if ( valueElement != null )
538             {
539                 return readContextEntry( valueElement.getText() );
540             }
541         }
542
543         return new BasicAttributes JavaDoc( true );
544     }
545
546
547     /**
548      * Read an entry (without DN)
549      *
550      * @param text
551      * The ldif format text
552      * @return An Attributes.
553      */

554     private Attributes JavaDoc readContextEntry( String JavaDoc text )
555     {
556         StringReader JavaDoc strIn = new StringReader JavaDoc( text );
557         BufferedReader JavaDoc in = new BufferedReader JavaDoc( strIn );
558
559         String JavaDoc line = null;
560         Attributes JavaDoc attributes = new AttributesImpl( true );
561
562         try
563         {
564             while ( ( line = ( ( BufferedReader JavaDoc ) in ).readLine() ) != null )
565             {
566                 if ( line.length() == 0 )
567                 {
568                     continue;
569                 }
570
571                 String JavaDoc addedLine = line.trim();
572
573                 if ( StringTools.isEmpty( addedLine ) )
574                 {
575                     continue;
576                 }
577
578                 javax.naming.directory.Attribute JavaDoc attribute = LdifReader.parseAttributeValue( addedLine );
579                 javax.naming.directory.Attribute JavaDoc oldAttribute = attributes.get( attribute.getID() );
580
581                 if ( oldAttribute != null )
582                 {
583                     try
584                     {
585                         oldAttribute.add( attribute.get() );
586                         attributes.put( oldAttribute );
587                     }
588                     catch ( NamingException JavaDoc ne )
589                     {
590                         // Do nothing
591
}
592                 }
593                 else
594                 {
595                     attributes.put( attribute );
596                 }
597             }
598         }
599         catch ( IOException JavaDoc ioe )
600         {
601             // Do nothing : we can't reach this point !
602
}
603
604         return attributes;
605     }
606
607
608     /**
609      * Reads and adds the Interceptors to the Server Configuration.
610      *
611      * @param configurationBean
612      * the Configuration Bean Element
613      * @param serverConfiguration
614      * the Server Configuration
615      */

616     private void readInterceptors( Element configurationBean, ServerConfiguration serverConfiguration )
617     {
618         Element propertyElement = getBeanPropertyElement( "interceptorConfigurations", configurationBean );
619         if ( propertyElement != null )
620         {
621             Element listElement = propertyElement.element( "list" );
622             if ( listElement != null )
623             {
624                 for ( Iterator JavaDoc i = listElement.elementIterator( "bean" ); i.hasNext(); )
625                 {
626                     Interceptor interceptor = readInterceptor( ( Element ) i.next() );
627                     if ( interceptor != null )
628                     {
629                         serverConfiguration.addInterceptor( interceptor );
630                     }
631                 }
632             }
633         }
634     }
635
636
637     /**
638      * Reads an Interceptor.
639      *
640      * @param element
641      * the Interceptor Element
642      * @return
643      * the Interceptor or null if it could not be parsed
644      */

645     private Interceptor readInterceptor( Element element )
646     {
647         Attribute classAttribute = element.attribute( "class" );
648         if ( classAttribute != null
649             && classAttribute.getValue().equals(
650                 "org.apache.directory.server.core.configuration.MutableInterceptorConfiguration" ) )
651         {
652             String JavaDoc name = readBeanProperty( "name", element );
653
654             for ( Iterator JavaDoc i = element.elementIterator( "property" ); i.hasNext(); )
655             {
656                 Element propertyElement = ( Element ) i.next();
657                 Attribute nameAttribute = propertyElement.attribute( "name" );
658                 if ( nameAttribute != null && ( nameAttribute.getValue().equals( "interceptor" ) ) )
659                 {
660                     Element beanElement = propertyElement.element( "bean" );
661                     if ( beanElement != null )
662                     {
663                         Attribute beanClassAttribute = beanElement.attribute( "class" );
664                         if ( beanClassAttribute != null )
665                         {
666                             Interceptor interceptor = new Interceptor( name );
667                             interceptor.setClassType( beanClassAttribute.getValue() );
668                             return interceptor;
669                         }
670                     }
671                 }
672             }
673         }
674
675         return null;
676     }
677
678
679     /**
680      * Reads and adds the ExtendedOperations to the Server Configuration.
681      *
682      * @param configurationBean
683      * the Configuration Bean Element
684      * @param serverConfiguration
685      * the Server Configuration
686      */

687     private void readExtendedOperations( Element configurationBean, ServerConfiguration serverConfiguration )
688     {
689         Element propertyElement = getBeanPropertyElement( "extendedOperationHandlers", configurationBean );
690         if ( propertyElement != null )
691         {
692             Element listElement = propertyElement.element( "list" );
693             if ( listElement != null )
694             {
695                 for ( Iterator JavaDoc i = listElement.elementIterator( "bean" ); i.hasNext(); )
696                 {
697                     ExtendedOperation extendedOperation = readExtendedOperation( ( Element ) i.next() );
698                     if ( extendedOperation != null )
699                     {
700                         serverConfiguration.addExtendedOperation( extendedOperation );
701                     }
702                 }
703             }
704         }
705     }
706
707
708     /**
709      * Reads an Extended Operation.
710      *
711      * @param element
712      * the Extended Operation Element
713      * @return
714      * the Extended Operation or null if it could not be parsed
715      */

716     private ExtendedOperation readExtendedOperation( Element element )
717     {
718         Attribute classAttribute = element.attribute( "class" );
719         if ( classAttribute != null )
720         {
721             return new ExtendedOperation( classAttribute.getValue() );
722         }
723
724         return null;
725     }
726
727
728     /**
729      * Gets the Bean element corresponding to the given ID.
730      *
731      * @param document
732      * the document to use
733      * @param id
734      * the id
735      * @return
736      * the Bean element corresponding to the given ID or null if the bean was not found
737      */

738     private Element getBeanElementById( Document document, String JavaDoc id )
739     {
740         for ( Iterator JavaDoc i = document.getRootElement().elementIterator( "bean" ); i.hasNext(); )
741         {
742             Element element = ( Element ) i.next();
743             Attribute idAttribute = element.attribute( "id" );
744             if ( idAttribute != null && ( idAttribute.getValue().equals( id ) ) )
745             {
746                 return element;
747             }
748         }
749
750         return null;
751     }
752
753
754     /**
755      * Reads the given property in the Bean and returns its value.
756      *
757      * @param property
758      * the property
759      * @param element
760      * the Bean Element
761      * @return
762      * the value of the property, or null if the property has not been found
763      */

764     private String JavaDoc readBeanProperty( String JavaDoc property, Element element )
765     {
766         Element propertyElement = getBeanPropertyElement( property, element );
767         if ( propertyElement != null )
768         {
769             Attribute valueAttribute = propertyElement.attribute( "value" );
770             if ( valueAttribute != null )
771             {
772                 return valueAttribute.getValue();
773             }
774
775             Attribute refAttribute = propertyElement.attribute( "ref" );
776             if ( refAttribute != null )
777             {
778                 return refAttribute.getValue();
779             }
780         }
781
782         return null;
783     }
784
785
786     /**
787      * Gets the given property Element in the the bean
788      *
789      * @param property
790      * the propery
791      * @param element
792      * the bean Element
793      * @return
794      * the associated property, or null if the property has not been found
795      */

796     private Element getBeanPropertyElement( String JavaDoc property, Element element )
797     {
798         for ( Iterator JavaDoc i = element.elementIterator( "property" ); i.hasNext(); )
799         {
800             Element propertyElement = ( Element ) i.next();
801             Attribute nameAttribute = propertyElement.attribute( "name" );
802             if ( nameAttribute != null && ( nameAttribute.getValue().equals( property ) ) )
803             {
804                 return propertyElement;
805             }
806         }
807
808         return null;
809     }
810
811
812     /**
813      * Parses the string argument as a boolean.
814      *
815      * @param s
816      * a String containing the boolean representation to be parsed
817      * @return
818      * the boolean value represented by the argument.
819      * @throws BooleanFormatException
820      * if the string does not contain a parsable boolean.
821      */

822     private boolean parseBoolean( String JavaDoc s ) throws BooleanFormatException
823     {
824         if ( "true".equals( s ) )
825         {
826             return true;
827         }
828         else if ( "false".equals( s ) )
829         {
830             return false;
831         }
832         else
833         {
834             throw new BooleanFormatException( "The String '" + s + "' could not be parsed as a boolean." );
835         }
836     }
837
838     /**
839      * Thrown to indicate that the application has attempted to convert a string to a boolean,
840      * but that the string does not have the appropriate format.
841      *
842      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
843      * @version $Rev$, $Date$
844      */

845     private class BooleanFormatException extends Exception JavaDoc
846     {
847         /** The Serial Version UID */
848         private static final long serialVersionUID = -6426955193802317452L;
849
850
851         /**
852          * Creates a new instance of BooleanFormatException.
853          *
854          * @param message
855          * @param cause
856          */

857         public BooleanFormatException( String JavaDoc message )
858         {
859             super( message );
860         }
861     }
862 }
863
Popular Tags