+ private Dictionary<String, ?> getNodeConfigFromFrameworkProperties() {
+ String repoType = KernelUtils.getFrameworkProp(KernelConstants.NODE_REPO_PROP_PREFIX + RepoConf.type.name());
+ if (repoType == null)
+ return null;
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ for (RepoConf repoConf : RepoConf.values()) {
+ String value = KernelUtils.getFrameworkProp(KernelConstants.NODE_REPO_PROP_PREFIX + repoConf.name());
+ if (value != null)
+ props.put(repoConf.name(), value);
+ }
+ return props;
+ }
+
+ private void prepareDataModel(ManagedJackrabbitRepository nodeRepo) {
+ Session adminSession = null;
+ try {
+ Set<String> processed = new HashSet<String>();
+ adminSession = nodeRepo.login();
+ bundles: for (Bundle bundle : bc.getBundles()) {
+ BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ if (wiring == null) {
+ if (log.isTraceEnabled())
+ log.error("No wiring for " + bundle.getSymbolicName());
+ continue bundles;
+ }
+ processWiring(adminSession, wiring, processed);
+ }
+ } catch (RepositoryException e) {
+ throw new CmsException("Cannot prepare data model", e);
+ } finally {
+ JcrUtils.logoutQuietly(adminSession);
+ }
+ }
+
+ private void processWiring(Session adminSession, BundleWiring wiring, Set<String> processed) {
+ // recursively process requirements first
+ List<BundleWire> requiredWires = wiring.getRequiredWires(CMS_DATA_MODEL_NAMESPACE);
+ for (BundleWire wire : requiredWires) {
+ processWiring(adminSession, wire.getProviderWiring(), processed);
+ // registerCnd(adminSession, wire.getCapability(), processed);
+ }
+ List<BundleCapability> capabilities = wiring.getCapabilities(CMS_DATA_MODEL_NAMESPACE);
+ for (BundleCapability capability : capabilities) {
+ registerCnd(adminSession, capability, processed);
+ }
+ }
+
+ private void registerCnd(Session adminSession, BundleCapability capability, Set<String> processed) {
+ Map<String, Object> attrs = capability.getAttributes();
+ String name = attrs.get(DataModelNamespace.CAPABILITY_NAME_ATTRIBUTE).toString();
+ if (processed.contains(name)) {
+ if (log.isTraceEnabled())
+ log.trace("Data model " + name + " has already been processed");
+ return;
+ }
+ String path = attrs.get(DataModelNamespace.CAPABILITY_CND_ATTRIBUTE).toString();
+ URL url = capability.getRevision().getBundle().getResource(path);
+ try (Reader reader = new InputStreamReader(url.openStream())) {
+ CndImporter.registerNodeTypes(reader, adminSession, true);
+ processed.add(name);
+ if (log.isDebugEnabled())
+ log.debug("Registered CND " + url);
+ } catch (Exception e) {
+ throw new CmsException("Cannot read cnd " + url, e);
+ }
+
+ Hashtable<String, Object> properties = new Hashtable<>();
+ properties.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS, name);
+ bc.registerService(Repository.class, adminSession.getRepository(), properties);
+ if (log.isDebugEnabled())
+ log.debug("Published data model " + name);
+ }
+