1 package org.objectweb.rentacar.util; 2 3 import java.util.List ; 4 5 import org.jdom.Document; 6 import org.jdom.Element; 7 8 12 public class RentacarConfiguration{ 13 private Document document; 14 15 public RentacarConfiguration(Document doc) { 16 this.document = doc; 17 } 18 24 public String getProperty(String component,String property) throws RentacarUtilException { 25 Element racine = getComponent(component); 26 27 List 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 component) throws RentacarUtilException { 37 List 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 |