@Override public boolean isPatternNamespace(String namespace) { NamespaceProperties properties = this.namespaceProperties.get(namespace); if (Objects.nonNull(properties)) { return properties.isPatternCollection(); } else { return false; } }
@Override public boolean isSecureCollection(String namespace) { NamespaceProperties properties = this.namespaceProperties.get(namespace); if (Objects.nonNull(properties)) { return properties.isSecureCollection(); } else { return false; } } }
@Override public NamespaceProperties getNamespaceProperties(String namespace) { String prefix = this.getPrefix(namespace); return new NamespaceProperties(namespace, prefix); }
@Override public void addAllPermanent(Collection<NamespaceProperties> properties) { properties.forEach(prop -> this.namespaceProperties.put(prop.getNamespace(), prop)); this.save(); }
public JsonBasedNamespaceManager(File file) { Objects.requireNonNull(file); this.file = file; this.objectMapper = new ObjectMapper(); this.objectMapper.enable(SerializationFeature.INDENT_OUTPUT); this.namespaceProperties = this.loadNamespacePropertiesFromFile(); this.namespaceProperties.put(Namespaces.TOSCA_NAMESPACE, new NamespaceProperties(Namespaces.TOSCA_NAMESPACE, "tosca", "Predefined TOSCA elements", "", false) ); this.namespaceProperties.put(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, new NamespaceProperties(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "winery", "TOSCA extension by Eclipse Winery", "", false) ); this.namespaceProperties.put(Namespaces.W3C_NAMESPACE_URI, new NamespaceProperties(Namespaces.W3C_NAMESPACE_URI, "xmlns", "W3C XML namespace", "", false) ); this.namespaceProperties.put(Namespaces.W3C_XML_SCHEMA_NS_URI, new NamespaceProperties(Namespaces.W3C_XML_SCHEMA_NS_URI, "xsd", "W3C XML schema namespace", "", false) ); this.namespaceProperties.put(Namespaces.EXAMPLE_NAMESPACE_URI, new NamespaceProperties(Namespaces.EXAMPLE_NAMESPACE_URI, "ex", "Namespace for creating examples", "", false) ); }
@Override public void addAllPermanent(Collection<NamespaceProperties> properties) { this.clear(); for (NamespaceProperties nsp : properties) { this.setNamespaceProperties(nsp.getNamespace(), nsp); } }
@NonNull public NamespaceProperties getNamespaceProperties(String namespace) { NamespaceProperties properties = this.namespaceProperties.get(namespace); if (Objects.isNull(properties)) { properties = new NamespaceProperties(namespace, generatePrefix(namespace)); } return properties; }
@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); } }
@Override public Map<String, NamespaceProperties> getAllNamespaces() { Iterator<String> keys = this.configuration.getKeys(); Map<String, NamespaceProperties> map = new HashMap<>(); while (keys.hasNext()) { String next = keys.next(); map.put(next, new NamespaceProperties(next, this.configuration.getString(next))); } return map; }
@Override protected Set<String> getAllPrefixes(String namespace) { return this.namespaceProperties.entrySet().stream() .map(entry -> entry.getValue().getPrefix()) .collect(Collectors.toSet()); }
namespaceManager.setNamespaceProperties(namespace, new NamespaceProperties(namespace, prefix));
@Override public String getPrefix(String namespace) { return getNamespaceProperties(Objects.isNull(namespace) ? "" : namespace).getPrefix(); }