KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rentacar > util > RentacarConfiguration


1 package org.objectweb.rentacar.util;
2
3 import java.util.List JavaDoc;
4
5 import org.jdom.Document;
6 import org.jdom.Element;
7
8 /**
9  * @author mcarpentier
10  *
11  */

12 public class RentacarConfiguration{
13     private Document document;
14     
15     public RentacarConfiguration(Document doc) {
16         this.document = doc;
17     }
18     /**
19      * @param the component : bonita-configuration, mail-configuration,...
20      * @param the property to retrieve
21      * @return a Properties object containing all properties name and value
22      * @throws Exception if XML document doesn't follow the associated DTD or if an error occured while parsing the configuration file
23      */

24     public String JavaDoc getProperty(String JavaDoc component,String JavaDoc property) throws RentacarUtilException {
25         Element racine = getComponent(component);
26
27         List JavaDoc propertyList = racine.getChildren("property");
28         for (int i=0;i < propertyList.size();i++) {
29             if (((Element) propertyList.get(i)).getAttributeValue("name").equalsIgnoreCase(property)) {
30                 return ((Element) propertyList.get(i)).getText();
31             }
32         }
33         throw new RentacarUtilException("Property not found in configuration file : "+component+"/"+property);
34     }
35     
36     public Element getComponent(String JavaDoc component) throws RentacarUtilException {
37         List JavaDoc propertyList = document.getRootElement().getChildren("component");
38         for (int i=0;i < propertyList.size();i++) {
39             if (((Element) propertyList.get(i)).getAttributeValue("name").equalsIgnoreCase(component)) {
40                 return ((Element) propertyList.get(i));
41             }
42         }
43         throw new RentacarUtilException("Component not found in configuration file : "+component);
44     }
45     
46 }
47
Popular Tags