Search in sources :

Example 1 with DynamicClassLoaderManager

use of org.apache.sling.commons.classloader.DynamicClassLoaderManager in project sling by apache.

the class JcrItemResourceFactoryTest method compareGetItemOrNull.

private void compareGetItemOrNull(String path, String expectedPath) throws RepositoryException {
    HelperData helper = new HelperData(new AtomicReference<DynamicClassLoaderManager>());
    Item item1 = new JcrItemResourceFactory(session, helper).getItemOrNull(path);
    Item item2 = new JcrItemResourceFactory(nonJackrabbitSession, helper).getItemOrNull(path);
    if (expectedPath == null) {
        assertNull(item1);
        assertNull(item2);
    } else {
        assertNotNull(item1);
        assertEquals(expectedPath, item1.getPath());
        assertNotNull(item2);
        assertEquals(expectedPath, item2.getPath());
    }
}
Also used : Item(javax.jcr.Item) HelperData(org.apache.sling.jcr.resource.internal.HelperData) DynamicClassLoaderManager(org.apache.sling.commons.classloader.DynamicClassLoaderManager)

Example 2 with DynamicClassLoaderManager

use of org.apache.sling.commons.classloader.DynamicClassLoaderManager in project sling by apache.

the class AdaptToTag method getClassLoader.

/**
	 * Method for retrieving the classloader from the OSGi console.
	 * 
	 * @return the classloader
	 */
protected ClassLoader getClassLoader() {
    final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
    final SlingScriptHelper scriptHelper = bindings.getSling();
    final DynamicClassLoaderManager dynamicClassLoaderManager = scriptHelper.getService(DynamicClassLoaderManager.class);
    final ClassLoader classLoader = dynamicClassLoaderManager.getDynamicClassLoader();
    return classLoader;
}
Also used : SlingBindings(org.apache.sling.api.scripting.SlingBindings) SlingScriptHelper(org.apache.sling.api.scripting.SlingScriptHelper) DynamicClassLoaderManager(org.apache.sling.commons.classloader.DynamicClassLoaderManager)

Example 3 with DynamicClassLoaderManager

use of org.apache.sling.commons.classloader.DynamicClassLoaderManager in project sling by apache.

the class RhinoJavaScriptEngineFactory method activate.

// ---------- SCR integration
@Activate
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);
    optimizationLevel = readOptimizationLevel(configuration);
    // setup the wrap factory
    wrapFactory = new SlingWrapFactory();
    // initialize the Rhino Context Factory
    SlingContextFactory.setup(this);
    Context cx = Context.enter();
    setEngineName(getEngineName() + " (" + cx.getImplementationVersion() + ")");
    languageVersion = String.valueOf(cx.getLanguageVersion());
    Context.exit();
    setExtensions(ECMA_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
    setMimeTypes("text/javascript", "application/ecmascript", "application/javascript");
    setNames("javascript", ECMA_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
    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);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Context(org.mozilla.javascript.Context) BundleContext(org.osgi.framework.BundleContext) SlingContextFactory(org.apache.sling.scripting.javascript.helper.SlingContextFactory) ContextFactory(org.mozilla.javascript.ContextFactory) SlingContextFactory(org.apache.sling.scripting.javascript.helper.SlingContextFactory) SlingWrapFactory(org.apache.sling.scripting.javascript.helper.SlingWrapFactory) DynamicClassLoaderManager(org.apache.sling.commons.classloader.DynamicClassLoaderManager) Activate(org.osgi.service.component.annotations.Activate)

Example 4 with DynamicClassLoaderManager

use of org.apache.sling.commons.classloader.DynamicClassLoaderManager in project sling by apache.

the class DynamicClassLoaderIT method getDynamicClassLoader.

protected ClassLoader getDynamicClassLoader() {
    if (classLoaderManagerReference == null || classLoaderManagerReference.getBundle() == null) {
        dynamicClassLoader = null;
        classLoaderManagerReference = bundleContext.getServiceReference(DynamicClassLoaderManager.class);
    }
    if (dynamicClassLoader == null && classLoaderManagerReference != null) {
        final DynamicClassLoaderManager dclm = bundleContext.getService(classLoaderManagerReference);
        if (dclm != null) {
            dynamicClassLoader = dclm.getDynamicClassLoader();
        }
    }
    return dynamicClassLoader;
}
Also used : DynamicClassLoaderManager(org.apache.sling.commons.classloader.DynamicClassLoaderManager)

Example 5 with DynamicClassLoaderManager

use of org.apache.sling.commons.classloader.DynamicClassLoaderManager in project sling by apache.

the class FSClassLoaderProvider method getClassLoader.

/**
	 * @see org.apache.sling.commons.classloader.ClassLoaderWriter#getClassLoader()
	 */
@Override
public ClassLoader getClassLoader() {
    synchronized (this) {
        if (loader == null || !loader.isLive()) {
            this.destroyClassLoader();
            // get the dynamic class loader for the bundle using this
            // class loader writer
            final DynamicClassLoaderManager dclm = this.callerBundle.getBundleContext().getService(this.dynamicClassLoaderManager);
            loader = new FSDynamicClassLoader(new URL[] { this.rootURL }, dclm.getDynamicClassLoader());
        }
        return this.loader;
    }
}
Also used : DynamicClassLoaderManager(org.apache.sling.commons.classloader.DynamicClassLoaderManager) URL(java.net.URL)

Aggregations

DynamicClassLoaderManager (org.apache.sling.commons.classloader.DynamicClassLoaderManager)11 CacheKey (com.adobe.acs.commons.httpcache.keys.CacheKey)2 SlingBindings (org.apache.sling.api.scripting.SlingBindings)2 SlingScriptHelper (org.apache.sling.api.scripting.SlingScriptHelper)2 HttpCacheConfig (com.adobe.acs.commons.httpcache.config.HttpCacheConfig)1 URL (java.net.URL)1 Item (javax.jcr.Item)1 HelperData (org.apache.sling.jcr.resource.internal.HelperData)1 SlingContextFactory (org.apache.sling.scripting.javascript.helper.SlingContextFactory)1 SlingWrapFactory (org.apache.sling.scripting.javascript.helper.SlingWrapFactory)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Context (org.mozilla.javascript.Context)1 ContextFactory (org.mozilla.javascript.ContextFactory)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 ComponentContext (org.osgi.service.component.ComponentContext)1 Activate (org.osgi.service.component.annotations.Activate)1