use of org.jaggeryjs.jaggery.core.Module in project jaggery by wso2.
the class ModuleManager method initModule.
private void initModule(InputStream modulesXML, boolean isCustom) throws ScriptException {
try {
Context cx = RhinoEngine.enterGlobalContext();
JAXBContext jaxbContext = JAXBContext.newInstance(Module.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Module moduleObject = (Module) jaxbUnmarshaller.unmarshal(modulesXML);
String moduleName = moduleObject.getName();
if (modules.get(moduleName) != null) {
log.info("A module with the name : " + moduleName + " already exists and it will be overwritten.");
}
String namespace = moduleObject.getNamespace();
boolean expose = (Boolean.parseBoolean(moduleObject.getExpose()) == true);
JavaScriptModule module = new JavaScriptModule(moduleName);
module.setNamespace(namespace);
module.setExpose(expose);
initHostObjects(moduleObject, module);
initMethods(moduleObject, module);
initScripts(moduleObject, cx, module, isCustom);
modules.put(moduleName, module);
} catch (JAXBException e) {
String msg = "Error while reading the module.xml";
log.error(msg, e);
throw new ScriptException(msg, e);
} finally {
RhinoEngine.exitContext();
}
}
Aggregations