You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hivemind.apache.org by Steve Gibson <St...@cowww.com> on 2004/06/11 16:04:11 UTC
PropertyTranslator
Hi,
I have implemented a rudimentary translator that can load in a
properties file and I want to a) share it and b) get some tips on
getting the Location right for errors.
Feel free to critique my code. I am sure I could learn a thing or two
about robustness.
package sandbox;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.internal.ApplicationRuntimeException;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.schema.Translator;
public class PropertyTranslator implements Translator
{
private static final Log log =
LogFactory.getLog(PropertyTranslator.class);
public PropertyTranslator()
{
}
/*
* Placeholder - options can be passed as a comma-separated list
public PropertyTranslator(String options)
{
}
*/
public Object translate(Module contributingModule, Class
propertyType,
String inputValue)
{
Properties props = new Properties();
String location = contributingModule.expandSymbols(inputValue,
contributingModule.getLocation()); // <-- is this cheating?
try
{
props.load(new FileInputStream(location));
}
catch (IOException ioe)
{
log.error("Could not load properties file at: " + location,
ioe);
throw new ApplicationRuntimeException("Could not load
properties file at: "
+ location, ioe);
}
// Specific to my prototype code - I wanted to be able to report
which configuration files are loaded
props.setProperty("PROPERTIES.NAME",
inputValue.substring(location.lastIndexOf("/") + 1));
return props;
}
}
Thanks,
Steve Gibson
Software Engineer
COWWW Software
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org