@Override public void addAllPermanent(Collection<NamespaceProperties> properties) { this.clear(); for (NamespaceProperties nsp : properties) { this.setNamespaceProperties(nsp.getNamespace(), nsp); } }
@Override protected Set<String> getAllPrefixes(String namespace) { Set<String> allPrefixes = new HashSet<>(); allPrefixes.addAll(this.getAllPermanentPrefixes()); allPrefixes.addAll(this.namespaceToPrefixMap.values()); return allPrefixes; }
@Override public NamespaceProperties getNamespaceProperties(String namespace) { String prefix = this.getPrefix(namespace); return new NamespaceProperties(namespace, prefix); }
@Override public NamespaceManager getNamespaceManager() { NamespaceManager manager; RepositoryFileReference ref = BackendUtils.getRefOfJsonConfiguration(new NamespacesId()); manager = new JsonBasedNamespaceManager(ref2AbsolutePath(ref).toFile()); Configuration configuration = this.getConfiguration(new NamespacesId()); if (!configuration.isEmpty()) { ConfigurationBasedNamespaceManager old = new ConfigurationBasedNamespaceManager(configuration); manager.replaceAll(old.getAllNamespaces()); try { forceDelete(BackendUtils.getRefOfConfiguration(new NamespacesId())); } catch (IOException e) { LOGGER.error("Could not remove old namespace configuration.", e); } } return manager; }
@Override public void replaceAll(Map<String, NamespaceProperties> map) { this.clear(); map.forEach(this::setNamespaceProperties); }
@Override public String getPrefix(String namespace) { if (namespace == null) { namespace = ""; } // configuration stores the permanent mapping // this has precedence String prefix = configuration.getString(namespace); if (prefix == null || prefix.isEmpty()) { // in case no permanent mapping is found - or the prefix is invalid, check the in-memory ones prefix = this.namespaceToPrefixMap.get(namespace); if (prefix == null) { prefix = this.generatePrefix(namespace); this.namespaceToPrefixMap.put(namespace, prefix); } } return prefix; }
try (final BufferedReader propertyReader = Files.newBufferedReader(properties)) { pconf.read(propertyReader); localNamespaceManager = new ConfigurationBasedNamespaceManager(pconf); } catch (IOException | ConfigurationException e) { CsarImporter.LOGGER.debug(e.getMessage(), e);
@Override public void setNamespaceProperties(String namespace, NamespaceProperties properties) { if (Objects.isNull(namespace) || namespace.isEmpty() || Objects.isNull(properties) || Objects.isNull(properties.getPrefix()) || properties.getPrefix().isEmpty()) { return; } if (!this.getAllPermanentPrefixes().contains(properties.getPrefix())) { this.configuration.setProperty(namespace, properties.getPrefix()); // ensure that in-memory mapping does not have the key any more this.namespaceToPrefixMap.remove(namespace); } }