if (defaultsFile != null) {
defaults.load(Thread.currentThread().getContextClassLoader().
getResourceAsStream(defaultsFile));
}
} catch (IOException e) {
throw new ParameterException("Failure loading cache defaults",e);
}
this.properties = new Properties(defaults);
String[] names = parameters.getNames();
for (int i = 0; i < names.length; i++) {
if (names[i].startsWith("jcs.")) {
this.properties.put(names[i], parameters.getParameter(names[i]));
}
}
int maxobjects = parameters.getParameterAsInteger("maxobjects", -1);
if (maxobjects != -1) {
String key = "jcs.region." + region + ".cacheattributes.MaxObjects";
this.properties.setProperty(key, String.valueOf(maxobjects));
}
// get the directory to use
try {
final File workDir = (File) context.get(Constants.CONTEXT_WORK_DIR);
if (parameters.getParameterAsBoolean("use-cache-directory", false)) {
final File cacheDir = (File) context.get(Constants.CONTEXT_CACHE_DIR);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Using cache directory: " + cacheDir);
}
setDirectory(cacheDir);
} else if (parameters.getParameterAsBoolean("use-work-directory", false)) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Using work directory: " + workDir);
}
setDirectory(workDir);
} else if (parameters.getParameter("directory", null) != null) {
String dir = parameters.getParameter("directory");
dir = IOUtils.getContextFilePath(workDir.getPath(), dir);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Using directory: " + dir);
}
setDirectory(new File(dir));
} else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Using default directory: " + workDir);
}
setDirectory(workDir);
}
} catch (ContextException ce) {
throw new ParameterException("Unable to get directory information from context.", ce);
} catch (IOException e) {
throw new ParameterException("Unable to set directory", e);
}
}