use of org.apache.sling.scripting.javascript.SlingWrapper in project sling by apache.
the class RhinoJavaScriptEngineFactory method addHostObjects.
// ---------- internal
private void addHostObjects(Scriptable scope, Class<? extends Scriptable>[] classes) {
if (classes != null) {
for (Class<? extends Scriptable> clazz : classes) {
try {
// register the host object
ScriptableObject.defineClass(scope, clazz);
if (SlingWrapper.class.isAssignableFrom(clazz)) {
// SlingWrappers can map to several classes if needed
final SlingWrapper hostWrapper = (SlingWrapper) clazz.newInstance();
for (Class<?> c : hostWrapper.getWrappedClasses()) {
getWrapFactory().registerWrapper(c, hostWrapper.getClassName());
}
} else {
// but other Scriptable host objects need to be
// registered as well
final Scriptable host = clazz.newInstance();
getWrapFactory().registerWrapper(host.getClass(), host.getClassName());
}
} catch (Throwable t) {
log.warn("addHostObjects: Cannot prepare host object " + clazz, t);
}
}
}
}
Aggregations