private QName createQName(final String prefix, final String localName) { final Module module = schemaContext.findModule(schemaNode.getQName().getModule()).get(); if (prefix.isEmpty() || module.getPrefix().equals(prefix)) { return QName.create(module.getQNameModule(), localName); } for (final ModuleImport moduleImport : module.getImports()) { if (prefix.equals(moduleImport.getPrefix())) { final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get(); return QName.create(importedModule.getQNameModule(),localName); } } throw new IllegalArgumentException(String.format("Failed to lookup a module for prefix %s", prefix)); }
private QName createQName(final String prefix, final String localName) { final Module module = schemaContext.findModule(schemaNode.getQName().getModule()).get(); if (prefix.isEmpty() || module.getPrefix().equals(prefix)) { return QName.create(module.getQNameModule(), localName); } for (final ModuleImport moduleImport : module.getImports()) { if (prefix.equals(moduleImport.getPrefix())) { final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get(); return QName.create(importedModule.getQNameModule(),localName); } } throw new IllegalArgumentException(String.format("Failed to lookup a module for prefix %s", prefix)); }
private static IdentitySchemaNode getIdentitySchemaNodeFromString(final String identity, final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) { final List<String> identityPrefixAndName = COLON_SPLITTER.splitToList(identity); final Module module = schemaContext.findModule(correspondingSchemaNode.getQName().getModule()).get(); if (identityPrefixAndName.size() == 2) { // prefix of local module if (identityPrefixAndName.get(0).equals(module.getPrefix())) { return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(), identityPrefixAndName.get(1))); } // prefix of imported module for (final ModuleImport moduleImport : module.getImports()) { if (identityPrefixAndName.get(0).equals(moduleImport.getPrefix())) { final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get(); return findIdentitySchemaNodeInModule(importedModule, QName.create( importedModule.getQNameModule(), identityPrefixAndName.get(1))); } } throw new IllegalArgumentException(String.format("Cannot resolve prefix '%s' from identity '%s'.", identityPrefixAndName.get(0), identity)); } if (identityPrefixAndName.size() == 1) { // without prefix return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(), identityPrefixAndName.get(0))); } throw new IllegalArgumentException(String.format("Malformed identity argument: %s.", identity)); }
private static IdentitySchemaNode getIdentitySchemaNodeFromString(final String identity, final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) { final List<String> identityPrefixAndName = COLON_SPLITTER.splitToList(identity); final Module module = schemaContext.findModule(correspondingSchemaNode.getQName().getModule()).get(); if (identityPrefixAndName.size() == 2) { // prefix of local module if (identityPrefixAndName.get(0).equals(module.getPrefix())) { return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(), identityPrefixAndName.get(1))); } // prefix of imported module for (final ModuleImport moduleImport : module.getImports()) { if (identityPrefixAndName.get(0).equals(moduleImport.getPrefix())) { final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get(); return findIdentitySchemaNodeInModule(importedModule, QName.create( importedModule.getQNameModule(), identityPrefixAndName.get(1))); } } throw new IllegalArgumentException(String.format("Cannot resolve prefix '%s' from identity '%s'.", identityPrefixAndName.get(0), identity)); } if (identityPrefixAndName.size() == 1) { // without prefix return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(), identityPrefixAndName.get(0))); } throw new IllegalArgumentException(String.format("Malformed identity argument: %s.", identity)); }
public static String getGetterMethodName(final TypedDataSchemaNode node) { // Bug 8903: If it is a derived type of boolean or empty, not an inner type, then the return type // of method would be the generated type of typedef not build-in types, so here it should be 'get'. final TypeDefinition<?> type = node.getType(); return BindingMapping.getGetterMethodName(node.getQName(), (type instanceof BooleanTypeDefinition || type instanceof EmptyTypeDefinition) && (type.getPath().equals(node.getPath()) || type.getBaseType() == null)); } }
private T createComplexCodecFor(final TypedDataSchemaNode schema, final TypeDefinition<?> type) { if (type instanceof UnionTypeDefinition) { return createComplexUnion(schema, (UnionTypeDefinition) type); } else if (type instanceof LeafrefTypeDefinition) { final TypeDefinition<?> target = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) type, schemaContext, schema); verifyNotNull(target, "Unable to find base type for leafref node %s type %s.", schema.getPath(), target); final T ret = getSimpleCodecFor(target); return ret != null ? ret : createComplexCodecFor(schema, target); } else if (type instanceof IdentityrefTypeDefinition) { return identityRefCodec((IdentityrefTypeDefinition) type, schema.getQName().getModule()); } else { throw new IllegalArgumentException("Unsupported type " + type); } }
private T createComplexCodecFor(final TypedDataSchemaNode schema, final TypeDefinition<?> type) { if (type instanceof UnionTypeDefinition) { return createComplexUnion(schema, (UnionTypeDefinition) type); } else if (type instanceof LeafrefTypeDefinition) { final TypeDefinition<?> target = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) type, schemaContext, schema); verifyNotNull(target, "Unable to find base type for leafref node %s type %s.", schema.getPath(), target); final T ret = getSimpleCodecFor(target); return ret != null ? ret : createComplexCodecFor(schema, target); } else if (type instanceof IdentityrefTypeDefinition) { return identityRefCodec((IdentityrefTypeDefinition) type, schema.getQName().getModule()); } else { throw new IllegalArgumentException("Unsupported type " + type); } }