@Override TypeDefinition<?> getBaseTypeForLeafRef(final SchemaNode schemaNode, final LeafrefTypeDefinition type) { final TypeDefinition<?> ret = SchemaContextUtil.getBaseTypeForLeafRef(type, schemaContext, schemaNode); return verifyNotNull(ret, "Unable to find base type for leafref node '%s'.", schemaNode.getPath()); }
private void addKeyValue(final HashMap<QName, Object> map, final DataSchemaNode node, final String uriValue, final DOMMountPoint mountPoint) { Preconditions.checkNotNull(uriValue); Preconditions.checkArgument((node instanceof LeafSchemaNode)); final String urlDecoded = urlPathArgDecode(uriValue); TypeDefinition<?> typedef = ((LeafSchemaNode) node).getType(); final TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(typedef); if (baseType instanceof LeafrefTypeDefinition) { typedef = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) baseType, globalSchema, node); } Codec<Object, Object> codec = RestCodec.from(typedef, mountPoint); Object decoded = codec.deserialize(urlDecoded); String additionalInfo = ""; if (decoded == null) { if ((baseType instanceof IdentityrefTypeDefinition)) { decoded = toQName(urlDecoded, null); additionalInfo = "For key which is of type identityref it should be in format module_name:identity_name."; } } if (decoded == null) { throw new RestconfDocumentedException(uriValue + " from URI can't be resolved. " + additionalInfo, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } map.put(node.getQName(), decoded); }
/** * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qname}. This handle * the case when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other * module as typedef which is then imported to referenced module. * * <p> * Because {@code typeDefinition} is definied via typedef statement, only absolute path is meaningful. */ public static TypeDefinition<?> getBaseTypeForLeafRef(final LeafrefTypeDefinition typeDefinition, final SchemaContext schemaContext, final QName qname) { final RevisionAwareXPath pathStatement = typeDefinition.getPathStatement(); final RevisionAwareXPath strippedPathStatement = new RevisionAwareXPathImpl( stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute()); if (!strippedPathStatement.isAbsolute()) { return null; } final Optional<Module> parentModule = schemaContext.findModule(qname.getModule()); checkArgument(parentModule.isPresent(), "Failed to find parent module for %s", qname); final DataSchemaNode dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule.get(), strippedPathStatement); final TypeDefinition<?> targetTypeDefinition = typeDefinition(dataSchemaNode); if (targetTypeDefinition instanceof LeafrefTypeDefinition) { return getBaseTypeForLeafRef((LeafrefTypeDefinition) targetTypeDefinition, schemaContext, dataSchemaNode); } return targetTypeDefinition; }
/** * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qname}. This handle * the case when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other * module as typedef which is then imported to referenced module. * * <p> * Because {@code typeDefinition} is definied via typedef statement, only absolute path is meaningful. */ public static TypeDefinition<?> getBaseTypeForLeafRef(final LeafrefTypeDefinition typeDefinition, final SchemaContext schemaContext, final QName qname) { final RevisionAwareXPath pathStatement = typeDefinition.getPathStatement(); final RevisionAwareXPath strippedPathStatement = new RevisionAwareXPathImpl( stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute()); if (!strippedPathStatement.isAbsolute()) { return null; } final Optional<Module> parentModule = schemaContext.findModule(qname.getModule()); checkArgument(parentModule.isPresent(), "Failed to find parent module for %s", qname); final DataSchemaNode dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule.get(), strippedPathStatement); final TypeDefinition<?> targetTypeDefinition = typeDefinition(dataSchemaNode); if (targetTypeDefinition instanceof LeafrefTypeDefinition) { return getBaseTypeForLeafRef((LeafrefTypeDefinition) targetTypeDefinition, schemaContext, dataSchemaNode); } return targetTypeDefinition; }
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); } }
return getBaseTypeForLeafRef((LeafrefTypeDefinition) targetTypeDefinition, schemaContext, dataSchemaNode);
return getBaseTypeForLeafRef((LeafrefTypeDefinition) targetTypeDefinition, schemaContext, dataSchemaNode);