/** * Little helper for subclasses (i.e. the ConfigGroups). This method adds the value of the parameter * to the given map only if the getValue() method of this Module doesn't return * null (Java null-type) or the String representation of null, i.e. "null" or "NULL". * If the value is null, the string "null" is added to the map to document the parameter. * * @param map * @param paramName */ protected void addParameterToMap(final Map<String, String> map, final String paramName) { String value = this.getValue(paramName); if (!((value == null) || value.equalsIgnoreCase("null"))) { map.put(paramName, value); } else { map.put(paramName, "null"); } }
/** * Returns the value of the specified parameter if it exists, or * <code>null</code> otherwise. * * @param moduleName * name of the config-module * @param paramName * name of parameter in the specified module * @return value of the parameter if it exists, <code>null</code> otherwise * * @see #getParam(String, String) */ @Deprecated // use "typed" config group instead public final String findParam(final String moduleName, final String paramName) { ConfigGroup m = this.modules.get(moduleName); if (m == null) { return null; } try { String str = m.getValue(paramName); if (str == null) { return null; } return str; } catch (IllegalArgumentException e) { return null; } }
/** * Returns the requested parameter. If the module or parameter is not known, * an error is logged and an IllegalArgumentException is thrown. * * @param moduleName * @param paramName * @return the requested parameter * * @throws IllegalArgumentException * if the module or parameter does not exist * @see #findParam(String, String) */ @Deprecated // use "typed" config group instead public final String getParam(final String moduleName, final String paramName) { ConfigGroup m = this.modules.get(moduleName); if (m == null) { log.error("Module \"" + moduleName + "\" is not known."); throw new IllegalArgumentException("Module \"" + moduleName + "\" is not known."); } String str = m.getValue(paramName); if (str == null) { String message = "Parameter \"" + paramName + "\" of module \"" + moduleName + "\" is not known"; log.error(message); throw new IllegalArgumentException(message); } return str; }
return super.getValue( param_name );
@Test public void testBehaviorWhenAcceptingUnknownParameters() { final ConfigGroup testee = new ReflectiveConfigGroup( "name" , true ) { @StringSetter( "field" ) public void setStuff(String s) {} @StringGetter( "field" ) public Object getStuff() { return null; } }; final String param = "my unknown param"; final String value = "my val"; testee.addParam( param , value ); Assert.assertEquals( "unexpected stored value", value, testee.getValue( param ) ); }
testee.getValue( param );
m.getValue( "field" ); Assert.fail( "no transmition of exception!" );