Changeset 72
- Timestamp:
- 02/13/08 17:42:56 (7 months ago)
- Files:
-
- trunk/pom.xml (modified) (1 diff)
- trunk/src/main/java/net/schst/XJConf/XmlReader.java (modified) (2 diffs)
- trunk/src/main/java/net/schst/XJConf/exceptions/ValueNotAvailableException.java (added)
- trunk/src/test/java/net/schst/XJConf/tests/XmlReaderGetTestCase.java (added)
- trunk/src/test/java/net/schst/XJConf/tests/helpers/IPrimitivesContainer.java (added)
- trunk/src/test/java/net/schst/XJConf/tests/helpers/PrimitivesContainer.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pom.xml
r71 r72 5 5 <groupId>net.schst</groupId> 6 6 <artifactId>XJConf</artifactId> 7 <version>0.10. 5</version>7 <version>0.10.6</version> 8 8 <packaging>jar</packaging> 9 9 trunk/src/main/java/net/schst/XJConf/XmlReader.java
r62 r72 14 14 import net.schst.XJConf.exceptions.UnknownNamespaceException; 15 15 import net.schst.XJConf.exceptions.UnknownTagException; 16 import net.schst.XJConf.exceptions.ValueNotAvailableException; 16 17 import net.schst.XJConf.exceptions.XJConfException; 17 18 … … 390 391 return this.config.get(name); 391 392 } 393 394 /** 395 * fetch a configuration option 396 * 397 * @param name of the option 398 * @return value 399 * @throws XJConfException if the value has not been set, or does not have the desired type 400 */ 401 public <T extends Object> T get(String name, Class<T> clazz) throws XJConfException { 402 Object val = this.config.get(name); 403 if (val == null) { 404 throw new ValueNotAvailableException("Value with name " + name + " not available in the configuration."); 405 } 406 if (!clazz.isAssignableFrom(val.getClass())) { 407 throw new ValueNotAvailableException("Value with name " + name + " is not of the desired type " + clazz.getName() + "."); 408 } 409 return (T)val; 410 } 392 411 } trunk/src/test/java/net/schst/XJConf/tests/helpers/PrimitivesContainer.java
r60 r72 1 1 package net.schst.XJConf.tests.helpers; 2 2 3 public class PrimitivesContainer {3 public class PrimitivesContainer implements IPrimitivesContainer { 4 4 private boolean booleanValue; 5 5 private int intValue; … … 9 9 private short shortValue; 10 10 11 /* *12 * @ return Returns the booleanValue.11 /* (non-Javadoc) 12 * @see net.schst.XJConf.tests.helpers.IPrimitivesContainer#getBooleanValue() 13 13 */ 14 14 public boolean getBooleanValue() { … … 21 21 this.booleanValue = booleanValue; 22 22 } 23 /* *24 * @ return Returns the floatValue.23 /* (non-Javadoc) 24 * @see net.schst.XJConf.tests.helpers.IPrimitivesContainer#getFloatValue() 25 25 */ 26 26 public float getFloatValue() { … … 33 33 this.floatValue = floatValue; 34 34 } 35 /* *36 * @ return Returns the intValue.35 /* (non-Javadoc) 36 * @see net.schst.XJConf.tests.helpers.IPrimitivesContainer#getIntValue() 37 37 */ 38 38 public int getIntValue() { … … 45 45 this.intValue = intValue; 46 46 } 47 /* *48 * @ return Returns the longValue.47 /* (non-Javadoc) 48 * @see net.schst.XJConf.tests.helpers.IPrimitivesContainer#getLongValue() 49 49 */ 50 50 public long getLongValue() { … … 57 57 this.longValue = longValue; 58 58 } 59 /* *60 * @ return Returns the doubleParam.59 /* (non-Javadoc) 60 * @see net.schst.XJConf.tests.helpers.IPrimitivesContainer#getDoubleValue() 61 61 */ 62 62 public double getDoubleValue() {
