Search in sources :

Example 1 with Module

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();
    }
}
Also used : ScriptCachingContext(org.jaggeryjs.scriptengine.cache.ScriptCachingContext) JAXBContext(javax.xml.bind.JAXBContext) Context(org.mozilla.javascript.Context) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Module(org.jaggeryjs.jaggery.core.Module)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Module (org.jaggeryjs.jaggery.core.Module)1 ScriptCachingContext (org.jaggeryjs.scriptengine.cache.ScriptCachingContext)1 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)1 Context (org.mozilla.javascript.Context)1