From: Martin D. <mar...@te...> - 2003-04-11 20:50:37
|
James Macgill a =E9crit: > public Object getValue(Feature feature) { > Object tempAttribute =3D null; > try { > tempAttribute =3D feature.getAttribute(attributePath); > } > catch (IllegalFeatureException e) { > LOGGER.warning(attributePath + " not found in schema " +=20 > feature.getSchema()); > } > return tempAttribute; > } As for this specific exemple, I suggest to replace it by something=20 similar to java.lang.System.getProperty(String, String) or=20 java.util.prefs.Preference.getXXX(String, Object): public Object getValue(Feature feature, Object defaultValue) { try { return feature.getAttribute(attributePath); } catch (IllegalFeatureException e) { LOGGER.fine(attributePath + " not found in schema " +=20 feature.getSchema()); return defaultValue: } } Changes: * Added a 'defaultValue' argument. It make very clear that some special action (return the default value) is taken if the attribute is not found. In order to get the behaviour provided by the old method, user just have to write: getValue(feature, null); * I think it is okay to eat the exception in this case, because the user expect to get the default value if the attribute was not found (because of the explicit 'defaultValue' argument). * Kick down the log message from 'warning' to 'fine', since this exception may be normal. Martin. |