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());
}
}
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;
}
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);
}
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;
}
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;
}
}
Aggregations