static boolean equals(final @NonNull LeafrefTypeDefinition type, final @Nullable Object obj) { if (type == obj) { return true; } final LeafrefTypeDefinition other = TypeDefinitions.castIfEquals(LeafrefTypeDefinition.class, type, obj); return other != null && type.getPathStatement().equals(other.getPathStatement()); }
static boolean equals(final @NonNull LeafrefTypeDefinition type, final @Nullable Object obj) { if (type == obj) { return true; } final LeafrefTypeDefinition other = TypeDefinitions.castIfEquals(LeafrefTypeDefinition.class, type, obj); return other != null && type.getPathStatement().equals(other.getPathStatement()); }
@Override public RevisionAwareXPath getPathStatement() { return getBaseType().getPathStatement(); }
@Override public RevisionAwareXPath getPathStatement() { return baseType().getPathStatement(); }
@Override public RevisionAwareXPath getPathStatement() { return baseType().getPathStatement(); }
@Override public RevisionAwareXPath getPathStatement() { return getBaseType().getPathStatement(); }
static String toString(final @NonNull LeafrefTypeDefinition type) { return TypeDefinitions.toStringHelper(type).add("pathStatement", type.getPathStatement()).toString(); } }
static String toString(final @NonNull LeafrefTypeDefinition type) { return TypeDefinitions.toStringHelper(type).add("pathStatement", type.getPathStatement()).toString(); } }
private void emitLeafrefSpecification(final LeafrefTypeDefinition typeDefinition) { emitPathNode(typeDefinition.getPathStatement()); if (YangVersion.VERSION_1_1 == super.yangVersion) { emitRequireInstanceNode(typeDefinition.requireInstance()); } }
static int hashCode(final @NonNull LeafrefTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getPathStatement()); }
static int hashCode(final @NonNull LeafrefTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getPathStatement()); }
private String leafrefToDef(final LeafSchemaNode parentNode, final LeafrefTypeDefinition leafrefType, final String defaultValue) { Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!"); Preconditions.checkArgument(leafrefType.getPathStatement() != null, "The Path Statement for Leafref Type Definition cannot be NULL!"); final RevisionAwareXPath xpath = leafrefType.getPathStatement(); final String strXPath = xpath.toString(); if (strXPath != null) { if (strXPath.indexOf('[') == -1) { final Module module = findParentModule(schemaContext, parentNode); if (module != null) { final SchemaNode dataNode; if (xpath.isAbsolute()) { dataNode = findDataSchemaNode(schemaContext, module, xpath); } else { dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath); } final String result = getTypeDefaultConstruction((LeafSchemaNode) dataNode, defaultValue); return result; } } else { return "new java.lang.Object()"; } } return null; }
private String leafrefToDef(final LeafSchemaNode parentNode, final LeafrefTypeDefinition leafrefType, final String defaultValue) { Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!"); Preconditions.checkArgument(leafrefType.getPathStatement() != null, "The Path Statement for Leafref Type Definition cannot be NULL!"); final RevisionAwareXPath xpath = leafrefType.getPathStatement(); final String strXPath = xpath.toString(); if (strXPath != null) { if (strXPath.indexOf('[') == -1) { final Module module = findParentModule(schemaContext, parentNode); if (module != null) { final SchemaNode dataNode; if (xpath.isAbsolute()) { dataNode = findDataSchemaNode(schemaContext, module, xpath); } else { dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath); } String result = getTypeDefaultConstruction((LeafSchemaNode) dataNode, defaultValue); return result; } } else { return "new java.lang.Object()"; } } return null; }
final SchemaContext schemaContext = bindingCodecContext.getRuntimeContext().getSchemaContext(); final Module module = schemaContext.findModule(subtype.getQName().getModule()).get(); final RevisionAwareXPath xpath = ((LeafrefTypeDefinition) subtype).getPathStatement();
/** * 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 boolean isLeafRefSelfReference(final LeafrefTypeDefinition leafref, final SchemaNode parentNode) { final SchemaNode leafRefValueNode; final RevisionAwareXPath leafRefXPath = leafref.getPathStatement(); final RevisionAwareXPath leafRefStrippedXPath = new RevisionAwareXPathImpl( GROUPS_PATTERN.matcher(leafRefXPath.toString()).replaceAll(""), leafRefXPath.isAbsolute());
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; }
final String leafRefPathString = leafrefType.getPathStatement().toString(); final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(schemaContext, checkNotNull(getBaseTypeModule(leafrefType), "Unable to find base module for leafref %s", node),