@Override protected Module moduleForPrefix(final String prefix) { final Iterator<Module> modules = context.findModules(prefix).iterator(); return modules.hasNext() ? modules.next() : null; }
@Override protected Module moduleForPrefix(final String prefix) { final Iterator<Module> modules = context.findModules(prefix).iterator(); return modules.hasNext() ? modules.next() : null; }
@Override protected String prefixForNamespace(final URI namespace) { final Iterator<Module> modules = context.findModules(namespace).iterator(); return modules.hasNext() ? modules.next().getName() : null; } }
@Override protected String prefixForNamespace(final URI namespace) { final Iterator<Module> modules = context.findModules(namespace).iterator(); return modules.hasNext() ? modules.next().getName() : null; }
@Override protected Module moduleForPrefix(final String prefix) { final String prefixedNS = getNamespaceContext().getNamespaceURI(prefix); final Iterator<Module> modules = context.findModules(URI.create(prefixedNS)).iterator(); return modules.hasNext() ? modules.next() : null; }
/** * Returns module instance (from the context) with specified name and an optional revision. * * @param name * string with the module name * @param revision * date of the module revision * @return module instance which has name and revision the same as are the values specified in parameters * <code>name</code> and <code>revision</code>. */ default Optional<Module> findModule(final String name, final Optional<Revision> revision) { return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny(); }
@Override protected String prefixForNamespace(final URI namespace) { final Iterator<Module> modules = context.findModules(namespace).iterator(); return modules.hasNext() ? modules.next().getName() : null; }
@Override protected String prefixForNamespace(final URI namespace) { final Iterator<Module> modules = context.findModules(namespace).iterator(); return modules.hasNext() ? modules.next().getName() : null; } }
@Override protected String prefixForNamespace(final URI namespace) { final Iterator<Module> modules = context.findModules(namespace).iterator(); return modules.hasNext() ? modules.next().getName() : null; }
/** * Returns module instance (from the context) with specified name and an optional revision. * * @param name * string with the module name * @param revision * date of the module revision * @return module instance which has name and revision the same as are the values specified in parameters * <code>name</code> and <code>revision</code>. */ default Optional<Module> findModule(final String name, final Optional<Revision> revision) { return findModules(name).stream().filter(module -> revision.equals(module.getRevision())).findAny(); }
private String toModuleNames(final Set<URI> potentialUris) { final StringBuilder builder = new StringBuilder(); for (final URI potentialUri : potentialUris) { builder.append('\n'); //FIXME how to get information about revision from JSON input? currently first available is used. builder.append(codecs.getSchemaContext().findModules(potentialUri).iterator().next().getName()); } return builder.toString(); }
private String toModuleNames(final Set<URI> potentialUris) { final StringBuilder builder = new StringBuilder(); for (final URI potentialUri : potentialUris) { builder.append('\n'); //FIXME how to get information about revision from JSON input? currently first available is used. builder.append(codecs.getSchemaContext().findModules(potentialUri).iterator().next().getName()); } return builder.toString(); }
@Override public QName parseValue(final NamespaceContext ctx, final String str) { return IdentityCodecUtil.parseIdentity(str, schemaContext, prefix -> { if (prefix.isEmpty()) { return parentModule; } final String prefixedNS = ctx.getNamespaceURI(prefix); final Iterator<Module> modules = schemaContext.findModules(URI.create(prefixedNS)).iterator(); checkArgument(modules.hasNext(), "Could not find module for namespace %s", prefixedNS); return modules.next().getQNameModule(); }).getQName(); }
@Override public QName parseValue(final Object ctx, final String value) { return IdentityCodecUtil.parseIdentity(value, schemaContext, prefix -> { if (prefix.isEmpty()) { return parentModule; } final Iterator<Module> modules = schemaContext.findModules(prefix).iterator(); checkArgument(modules.hasNext(), "Could not find module %s", prefix); return modules.next().getQNameModule(); }).getQName(); }
@Override public QName parseValue(final Object ctx, final String value) { return IdentityCodecUtil.parseIdentity(value, schemaContext, prefix -> { if (prefix.isEmpty()) { return parentModule; } final Iterator<Module> modules = schemaContext.findModules(prefix).iterator(); checkArgument(modules.hasNext(), "Could not find module %s", prefix); return modules.next().getQNameModule(); }).getQName(); }
private Entry<String, URI> resolveNamespace(final String childName, final DataSchemaNode dataSchemaNode) { final int lastIndexOfColon = childName.lastIndexOf(':'); String moduleNamePart = null; String nodeNamePart = null; URI namespace = null; if (lastIndexOfColon != -1) { moduleNamePart = childName.substring(0, lastIndexOfColon); nodeNamePart = childName.substring(lastIndexOfColon + 1); final Iterator<Module> m = codecs.getSchemaContext().findModules(moduleNamePart).iterator(); namespace = m.hasNext() ? m.next().getNamespace() : null; } else { nodeNamePart = childName; } if (namespace == null) { final Set<URI> potentialUris = resolveAllPotentialNamespaces(nodeNamePart, dataSchemaNode); if (potentialUris.contains(getCurrentNamespace())) { namespace = getCurrentNamespace(); } else if (potentialUris.size() == 1) { namespace = potentialUris.iterator().next(); } else if (potentialUris.size() > 1) { throw new IllegalStateException("Choose suitable module name for element " + nodeNamePart + ":" + toModuleNames(potentialUris)); } else if (potentialUris.isEmpty()) { throw new IllegalStateException("Schema node with name " + nodeNamePart + " was not found under " + dataSchemaNode.getQName() + "."); } } return new SimpleImmutableEntry<>(nodeNamePart, namespace); }
private Entry<String, URI> resolveNamespace(final String childName, final DataSchemaNode dataSchemaNode) { final int lastIndexOfColon = childName.lastIndexOf(':'); String moduleNamePart = null; String nodeNamePart = null; URI namespace = null; if (lastIndexOfColon != -1) { moduleNamePart = childName.substring(0, lastIndexOfColon); nodeNamePart = childName.substring(lastIndexOfColon + 1); final Iterator<Module> m = codecs.getSchemaContext().findModules(moduleNamePart).iterator(); namespace = m.hasNext() ? m.next().getNamespace() : null; } else { nodeNamePart = childName; } if (namespace == null) { final Set<URI> potentialUris = resolveAllPotentialNamespaces(nodeNamePart, dataSchemaNode); if (potentialUris.contains(getCurrentNamespace())) { namespace = getCurrentNamespace(); } else if (potentialUris.size() == 1) { namespace = potentialUris.iterator().next(); } else if (potentialUris.size() > 1) { throw new IllegalStateException("Choose suitable module name for element " + nodeNamePart + ":" + toModuleNames(potentialUris)); } else if (potentialUris.isEmpty()) { throw new IllegalStateException("Schema node with name " + nodeNamePart + " was not found under " + dataSchemaNode.getQName() + "."); } } return new SimpleImmutableEntry<>(nodeNamePart, namespace); }
/** * Returns value namespace for leaf value. * * @param value value of the leaf * @param ctx schema context * @return value namespace * @throws SvcLogicException if identity/module could not be found */ static Namespace getValueNamespace(String value, SchemaContext ctx) throws SvcLogicException { String prefix = getPrefixFromValue(value); if (prefix == null) { return null; } IdentitySchemaNode id = IdentityCodecUtil.parseIdentity(value, ctx, prefixToModule -> { final Iterator<Module> modules = ctx.findModules(prefix).iterator(); checkArgument(modules.hasNext(), "Could not find " + "module %s", prefix); return modules.next().getQNameModule(); }); if (id == null) { throw new SvcLogicException("Could not find identity"); } return getModuleNamespace(id.getQName(), ctx); }
/** * Returns namespace. * * @param childName name of the property * @param ctx schema context * @param parent parent property node * @return namespace */ public static Namespace getNamespace(String childName, SchemaContext ctx, PropertiesNode parent) { int lastIndexOfColon = childName.lastIndexOf(":"); if (lastIndexOfColon != -1) { String moduleName = childName.substring(0, lastIndexOfColon); Iterator<Module> it = ctx.findModules(moduleName).iterator(); if (!it.hasNext()) { // module is not present in context return null; } Module m = it.next(); return new Namespace(moduleName, m.getQNameModule().getNamespace(), getRevision(m.getRevision())); } Namespace parentNs = parent.namespace(); return new Namespace(parentNs.moduleName(), parentNs.moduleNs(), parentNs.revision()); }
final QName typeQName = type.getQName(); Module module = null; final Set<Module> modules = schemaContext.findModules(typeQName.getNamespace()); if (modules.size() > 1) { for (Module m : modules) {