private Codec<Object, Object> getCodec(final Class<?> valueType, final DataSchemaNode schema) { checkArgument(schema instanceof TypedDataSchemaNode, "Unsupported leaf node type %s", schema); return getCodec(valueType, ((TypedDataSchemaNode)schema).getType()); }
private Codec<Object, Object> getCodec(final Class<?> valueType, final DataSchemaNode schema) { Preconditions.checkArgument(schema instanceof TypedDataSchemaNode, "Unsupported leaf node type %s", schema); return getCodec(valueType, ((TypedDataSchemaNode) schema).getType()); }
@Override public ImmutableMap<String, LeafNodeCodecContext<?>> getLeafNodes(final Class<?> parentClass, final DataNodeContainer childSchema) { final Map<String, DataSchemaNode> getterToLeafSchema = new HashMap<>(); for (final DataSchemaNode leaf : childSchema.getChildNodes()) { if (leaf instanceof TypedDataSchemaNode) { getterToLeafSchema.put(getGetterName(leaf, ((TypedDataSchemaNode) leaf).getType()), leaf); } } return getLeafNodesUsingReflection(parentClass, getterToLeafSchema); }
private static boolean bitIsSet(final Context context, final List<?> args) throws FunctionCallException { if (args == null || args.size() != 1) { throw new FunctionCallException("bit-is-set() takes two arguments: node-set nodes, string bit-name"); } if (!(args.get(0) instanceof String)) { throw new FunctionCallException("Argument bit-name of bit-is-set() function should be a String"); } final String bitName = (String) args.get(0); Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass()); final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context; final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext); final TypeDefinition<?> nodeType = correspondingSchemaNode.getType(); if (!(nodeType instanceof BitsTypeDefinition)) { return false; } final Object nodeValue = currentNodeContext.getNode().getValue(); if (!(nodeValue instanceof Set)) { return false; } final BitsTypeDefinition bitsType = (BitsTypeDefinition) nodeType; Preconditions.checkState(containsBit(bitsType, bitName), "Bit %s does not belong to bits %s.", bitName, bitsType); return ((Set<?>)nodeValue).contains(bitName); }
private static boolean bitIsSet(final Context context, final List<?> args) throws FunctionCallException { if (args == null || args.size() != 1) { throw new FunctionCallException("bit-is-set() takes two arguments: node-set nodes, string bit-name"); } if (!(args.get(0) instanceof String)) { throw new FunctionCallException("Argument bit-name of bit-is-set() function should be a String"); } final String bitName = (String) args.get(0); Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass()); final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context; final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext); final TypeDefinition<?> nodeType = correspondingSchemaNode.getType(); if (!(nodeType instanceof BitsTypeDefinition)) { return false; } final Object nodeValue = currentNodeContext.getNode().getValue(); if (!(nodeValue instanceof Set)) { return false; } final BitsTypeDefinition bitsType = (BitsTypeDefinition) nodeType; Preconditions.checkState(containsBit(bitsType, bitName), "Bit %s does not belong to bits %s.", bitName, bitsType); return ((Set<?>)nodeValue).contains(bitName); }
private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext, final SchemaNode schemaNode) { checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!"); checkArgument(schemaNode instanceof TypedDataSchemaNode, "Unsupported node %s", schemaNode); TypeDefinition<?> nodeType = ((TypedDataSchemaNode) schemaNode).getType(); if (nodeType.getBaseType() != null) { while (nodeType.getBaseType() != null) { nodeType = nodeType.getBaseType(); } return schemaContext.findModule(nodeType.getQName().getModule()).orElse(null); } return SchemaContextUtil.findParentModule(schemaContext, schemaNode); }
private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext, final SchemaNode schemaNode) { checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!"); checkArgument(schemaNode instanceof TypedDataSchemaNode, "Unsupported node %s", schemaNode); TypeDefinition<?> nodeType = ((TypedDataSchemaNode) schemaNode).getType(); if (nodeType.getBaseType() != null) { while (nodeType.getBaseType() != null) { nodeType = nodeType.getBaseType(); } return schemaContext.findModule(nodeType.getQName().getModule()).orElse(null); } return SchemaContextUtil.findParentModule(schemaContext, schemaNode); }
private static Object enumValueFunction(final Context context, final List<?> args) throws FunctionCallException { if (!args.isEmpty()) { throw new FunctionCallException("enum-value() takes one argument: node-set nodes."); } Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass()); final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context; final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext); final TypeDefinition<?> nodeType = correspondingSchemaNode.getType(); if (!(nodeType instanceof EnumTypeDefinition)) { return DOUBLE_NAN; } final Object nodeValue = currentNodeContext.getNode().getValue(); if (!(nodeValue instanceof String)) { return DOUBLE_NAN; } final EnumTypeDefinition enumerationType = (EnumTypeDefinition) nodeType; final String enumName = (String) nodeValue; return getEnumValue(enumerationType, enumName); }
private static @Nullable Entry<IdentitySchemaNode, IdentitySchemaNode> commonDerivedFrom(final String functionName, final Context context, final List<?> args) throws FunctionCallException { if (args == null || args.size() != 1) { throw new FunctionCallException(functionName + "() takes two arguments: node-set nodes, string identity"); } if (!(args.get(0) instanceof String)) { throw new FunctionCallException("Argument 'identity' of " + functionName + "() function should be a String."); } Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass()); final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context; final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext); final SchemaContext schemaContext = getSchemaContext(currentNodeContext); return correspondingSchemaNode.getType() instanceof IdentityrefTypeDefinition && currentNodeContext.getNode().getValue() instanceof QName ? new SimpleImmutableEntry<>( getIdentitySchemaNodeFromString((String) args.get(0), schemaContext, correspondingSchemaNode), getIdentitySchemaNodeFromQName((QName) currentNodeContext.getNode().getValue(), schemaContext)) : null; }
private static Object enumValueFunction(final Context context, final List<?> args) throws FunctionCallException { if (!args.isEmpty()) { throw new FunctionCallException("enum-value() takes one argument: node-set nodes."); } Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass()); final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context; final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext); final TypeDefinition<?> nodeType = correspondingSchemaNode.getType(); if (!(nodeType instanceof EnumTypeDefinition)) { return DOUBLE_NAN; } final Object nodeValue = currentNodeContext.getNode().getValue(); if (!(nodeValue instanceof String)) { return DOUBLE_NAN; } final EnumTypeDefinition enumerationType = (EnumTypeDefinition) nodeType; final String enumName = (String) nodeValue; return getEnumValue(enumerationType, enumName); }
final TypeDefinition<?> type = schema.getType(); T ret = cache.lookupSimple(type); if (ret != null) {
final TypeDefinition<?> type = schema.getType(); T ret = cache.lookupSimple(type); if (ret != null) {
private static @Nullable Entry<IdentitySchemaNode, IdentitySchemaNode> commonDerivedFrom(final String functionName, final Context context, final List<?> args) throws FunctionCallException { if (args == null || args.size() != 1) { throw new FunctionCallException(functionName + "() takes two arguments: node-set nodes, string identity"); } if (!(args.get(0) instanceof String)) { throw new FunctionCallException("Argument 'identity' of " + functionName + "() function should be a String."); } Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass()); final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context; final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext); final SchemaContext schemaContext = getSchemaContext(currentNodeContext); return correspondingSchemaNode.getType() instanceof IdentityrefTypeDefinition && currentNodeContext.getNode().getValue() instanceof QName ? new SimpleImmutableEntry<>( getIdentitySchemaNodeFromString((String) args.get(0), schemaContext, correspondingSchemaNode), getIdentitySchemaNodeFromQName((QName) currentNodeContext.getNode().getValue(), schemaContext)) : null; }
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)); } }
/** * Write a value into a XML stream writer. This method assumes the start and end of element is * emitted by the caller. * * @param writer XML Stream writer * @param schemaNode Schema node that describes the value * @param value data value * @param parent module QName owning the leaf definition * @throws XMLStreamException if an encoding problem occurs */ void writeValue(final @NonNull ValueWriter writer, final @NonNull SchemaNode schemaNode, final @NonNull Object value, final QNameModule parent) throws XMLStreamException { checkArgument(schemaNode instanceof TypedDataSchemaNode, "Unable to write value for node %s, only nodes of type: leaf and leaf-list can be written at this point", schemaNode.getQName()); TypeDefinition<?> type = ((TypedDataSchemaNode) schemaNode).getType(); if (type instanceof LeafrefTypeDefinition) { type = getBaseTypeForLeafRef(schemaNode, (LeafrefTypeDefinition) type); } writeValue(writer, type, value, parent); }
private static NormalizedNode<?, ?> deref(final Context context, final List<?> args) throws FunctionCallException { if (!args.isEmpty()) { throw new FunctionCallException("deref() takes only one argument: node-set nodes."); } Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass()); final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context; final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext); final Object nodeValue = currentNodeContext.getNode().getValue(); final TypeDefinition<?> type = correspondingSchemaNode.getType(); if (type instanceof InstanceIdentifierTypeDefinition) { return nodeValue instanceof YangInstanceIdentifier ? getNodeReferencedByInstanceIdentifier((YangInstanceIdentifier) nodeValue, currentNodeContext) : null; } if (type instanceof LeafrefTypeDefinition) { final RevisionAwareXPath xpath = ((LeafrefTypeDefinition) type).getPathStatement(); return getNodeReferencedByLeafref(xpath, currentNodeContext, getSchemaContext(currentNodeContext), correspondingSchemaNode, nodeValue); } return null; }
private static NormalizedNode<?, ?> deref(final Context context, final List<?> args) throws FunctionCallException { if (!args.isEmpty()) { throw new FunctionCallException("deref() takes only one argument: node-set nodes."); } Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass()); final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context; final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext); final Object nodeValue = currentNodeContext.getNode().getValue(); final TypeDefinition<?> type = correspondingSchemaNode.getType(); if (type instanceof InstanceIdentifierTypeDefinition) { return nodeValue instanceof YangInstanceIdentifier ? getNodeReferencedByInstanceIdentifier((YangInstanceIdentifier) nodeValue, currentNodeContext) : null; } if (type instanceof LeafrefTypeDefinition) { final RevisionAwareXPath xpath = ((LeafrefTypeDefinition) type).getPathStatement(); return getNodeReferencedByLeafref(xpath, currentNodeContext, getSchemaContext(currentNodeContext), correspondingSchemaNode, nodeValue); } return null; }
private static String getGetterName(final DataSchemaNode node) { final TypeDefinition<?> type; if (node instanceof TypedDataSchemaNode) { type = ((TypedDataSchemaNode) node).getType(); } else { type = null; } final String prefix; // Bug 8903: If it is a derived type of boolean, not a built-in type, then the return type // of method would be the generated type and the prefix should be 'get'. if (type instanceof BooleanTypeDefinition && (type.getPath().equals(node.getPath()) || type.getBaseType() == null)) { prefix = "is"; } else { prefix = "get"; } return prefix + JavaIdentifierNormalizer.normalizeSpecificIdentifier(node.getQName().getLocalName(), JavaIdentifier.CLASS); }
final TypeDefinition<?> type = ((TypedDataSchemaNode) node).getType();
final TypeDefinition<?> type = ((TypedDataSchemaNode) node).getType();