in src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java [274:323]
protected synchronized void activate(Map<String, Object> properties) throws LoginException, RepositoryException {
// check enabled state
this.enabled = config.enabled();
log.info("Config: Enabled={} ", enabled);
if (!isEnabled()) {
return;
}
Collection<String> observationPaths = new ArrayList<>(Arrays.asList(config.observationPaths()));
// merge with old configuration property key (with typo)
if (properties.containsKey(PROPERTY_KEY_OLD_OBSERVATION_PATHS)) {
log.warn("Using deprecated configuration property {}, please switch to the new key {}", PROPERTY_KEY_OLD_OBSERVATION_PATHS, PROPERTY_KEY_OBSERVATION_PATHS);
observationPaths.addAll(Arrays.asList(PropertiesUtil.toStringArray(properties.get(PROPERTY_KEY_OLD_OBSERVATION_PATHS))));
}
// get "find all" queries
this.findAllQueries = config.findAllQueries();
if (null == resolver) {
bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
resolver = resolverFactory.getAdministrativeResourceResolver(null);
}
// Watch for events on the root to register/deregister superimposings at runtime
// For each observed path create an event listener object which redirects the event to the main class
final Session session = resolver.adaptTo(Session.class);
if (session!=null) {
this.observationEventListeners = new EventListener[observationPaths.size()];
int i=0;
for (String observationPath : observationPaths) {
this.observationEventListeners[i] = this;
session.getWorkspace().getObservationManager().addEventListener(
this.observationEventListeners[i++],
Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED,
observationPath, // absolute path
true, // isDeep
null, // uuids
null, // node types
true); // noLocal
}
}
// register all superimposing definitions that already exist
initialization = Executors.newSingleThreadExecutor().submit(() -> {
try {
registerAllSuperimposings();
}
catch (Exception ex) {
log.warn("Error registering existing superimposing resources on service startup.", ex);
}
});
}