process((WatchEvent.Kind<Path>)event.kind(), directory.resolve((Path)event.context()));
}
}
private void process(WatchEvent.Kind<Path> kind, Path path){
ModelRegistry modelRegistry = getModelRegistry();
String id = (path.getFileName()).toString();
// Remove file name extension
// Start the search from the beginning of the file name, in case there are multiple extensions
int dot = id.indexOf('.');
if(dot > -1){
id = id.substring(0, dot);
} // End if
if(!ModelRegistry.validateId(id)){
return;
} // End if
if((StandardWatchEventKinds.ENTRY_CREATE).equals(kind)){
ModelEvaluator<?> evaluator;
try {
InputStream is = Files.newInputStream(path);
try {
evaluator = ModelRegistry.unmarshal(is);
} finally {
is.close();
}
} catch(Exception e){
// Ignored
return;
}
modelRegistry.put(id, evaluator);
} else
if((StandardWatchEventKinds.ENTRY_DELETE).equals(kind)){
ModelEvaluator<?> evaluator = modelRegistry.get(id);
modelRegistry.remove(id, evaluator);
}
}