protected void activate()

in src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngineFactory.java [265:330]


    protected void activate(final ComponentContext context, final RhinoJavaScriptEngineFactoryConfiguration configuration) {
        Dictionary<?, ?> props = context.getProperties();
        boolean debugging = getProperty("org.apache.sling.scripting.javascript.debug", props, context.getBundleContext(), false);

        // try to get the manifest
        String rhinoVersion = null;
        InputStream ins = null;
        try {
            Enumeration<URL> resources = RhinoJavaScriptEngineFactory.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
            while (resources.hasMoreElements()) {
                try {
                    URL url = resources.nextElement();
                    ins = url.openStream();
                    if (ins != null) {
                        Manifest manifest = new Manifest(ins);
                        Attributes attrs = manifest.getMainAttributes();
                        rhinoVersion = attrs.getValue("Rhino-Version");
                        if (rhinoVersion != null) {
                            break;
                        }
                    }
                } finally {
                    if (ins != null) {
                        try {
                            ins.close();
                        } catch (IOException ignore) {
                        }
                    }
                }
            }
        } catch (IOException ioe) {
            log.warn("Unable to read Rhino version.", ioe);
        }

        optimizationLevel = readOptimizationLevel(configuration);

        writeLock.lock();
        try {
            // setup the wrap factory
            wrapFactory = new SlingWrapFactory();

            // initialize the Rhino Context Factory
            SlingContextFactory.setup(this, RHINO_LANGUAGE_VERSION);

            setEngineName(getEngineName() + " (Rhino " + (rhinoVersion != null ? rhinoVersion : "unknown") + ")");

            setExtensions(PropertiesUtil.toStringArray(props.get("extensions")));
            setMimeTypes(PropertiesUtil.toStringArray(props.get("mimeTypes")));
            setNames(PropertiesUtil.toStringArray(props.get("names")));

            final ContextFactory contextFactory = ContextFactory.getGlobal();
            if (contextFactory instanceof SlingContextFactory) {
                ((SlingContextFactory) contextFactory).setDebugging(debugging);
            }
            // set the dynamic class loader as the application class loader
            final DynamicClassLoaderManager dclm = this.dynamicClassLoaderManager;
            if (dclm != null) {
                contextFactory.initApplicationClassLoader(dynamicClassLoaderManager.getDynamicClassLoader());
            }

            log.info("Activated with optimization level {}", optimizationLevel);
            active = true;
        } finally {
            writeLock.unlock();
        }
    }