@Override public String toString() { return xpath.toString(); } }
@VisibleForTesting static Matcher getWhenConditionMatcher(final String prefix, final RevisionAwareXPath whenConstraint) { String xpathRegex = MODULE_CONDITION_XPATH_TEMPLATE.replace(MAGIC_STRING, prefix); Pattern pattern = Pattern.compile(xpathRegex); return pattern.matcher(whenConstraint.toString()); }
/** * Removes conditions from xPath pointed to target node. * * @param pathStatement * xPath to target node * @return string representation of xPath without conditions */ @VisibleForTesting static String stripConditionsFromXPathString(final RevisionAwareXPath pathStatement) { return STRIP_PATTERN.matcher(pathStatement.toString()).replaceAll(""); }
/** * Removes conditions from xPath pointed to target node. * * @param pathStatement * xPath to target node * @return string representation of xPath without conditions */ @VisibleForTesting static String stripConditionsFromXPathString(final RevisionAwareXPath pathStatement) { return STRIP_PATTERN.matcher(pathStatement.toString()).replaceAll(""); }
@Override public void writeArgument(final RevisionAwareXPath xpath) { checkArgumentApplicable(); // FIXME: This implementation assumes prefixes are unchanged // and were not changed in schema context. writeArgument0(xpath.toString()); }
private static NormalizedNode<?, ?> getNodeReferencedByRelativeLeafref(final RevisionAwareXPath xpath, final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) { NormalizedNodeContext relativeNodeContext = currentNodeContext; final StringBuilder xPathStringBuilder = new StringBuilder(xpath.toString()); // strip the relative path of all ../ at the beginning while (xPathStringBuilder.indexOf("../") == 0) { xPathStringBuilder.delete(0, 3); relativeNodeContext = relativeNodeContext.getParent(); } // add / to the beginning of the path so that it can be processed the same way as an absolute path xPathStringBuilder.insert(0, '/'); final LeafrefXPathStringParsingPathArgumentBuilder builder = new LeafrefXPathStringParsingPathArgumentBuilder( xPathStringBuilder.toString(), schemaContext, correspondingSchemaNode, currentNodeContext); final List<PathArgument> pathArguments = builder.build(); final NormalizedNode<?, ?> relativeNode = relativeNodeContext.getNode(); final Optional<NormalizedNode<?, ?>> possibleNode = NormalizedNodes.findNode(relativeNode, pathArguments); if (possibleNode.isPresent()) { return possibleNode.get(); } return null; }
private static NormalizedNode<?, ?> getNodeReferencedByRelativeLeafref(final RevisionAwareXPath xpath, final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) { NormalizedNodeContext relativeNodeContext = currentNodeContext; final StringBuilder xPathStringBuilder = new StringBuilder(xpath.toString()); // strip the relative path of all ../ at the beginning while (xPathStringBuilder.indexOf("../") == 0) { xPathStringBuilder.delete(0, 3); relativeNodeContext = relativeNodeContext.getParent(); } // add / to the beginning of the path so that it can be processed the same way as an absolute path xPathStringBuilder.insert(0, '/'); final LeafrefXPathStringParsingPathArgumentBuilder builder = new LeafrefXPathStringParsingPathArgumentBuilder( xPathStringBuilder.toString(), schemaContext, correspondingSchemaNode, currentNodeContext); final List<PathArgument> pathArguments = builder.build(); final NormalizedNode<?, ?> relativeNode = relativeNodeContext.getNode(); final Optional<NormalizedNode<?, ?>> possibleNode = NormalizedNodes.findNode(relativeNode, pathArguments); if (possibleNode.isPresent()) { return possibleNode.get(); } return null; }
"Schema Path reference for Leafref cannot be NULL"); final Iterable<String> xpaths = SLASH_SPLITTER.split(relativeXPath.toString());
checkArgument(nonCondXPath != null, "Non Conditional Revision Aware XPath cannot be NULL"); final String strXPath = nonCondXPath.toString(); if (strXPath != null) { checkArgument(strXPath.indexOf('[') == -1, "Revision Aware XPath may not contain a condition");
"Schema Path reference for Leafref cannot be NULL"); final Iterable<String> xpaths = SLASH_SPLITTER.split(relativeXPath.toString());
checkArgument(nonCondXPath != null, "Non Conditional Revision Aware XPath cannot be NULL"); final String strXPath = nonCondXPath.toString(); if (strXPath != null) { checkArgument(strXPath.indexOf('[') == -1, "Revision Aware XPath may not contain a condition");
private static NormalizedNode<?, ?> getNodeReferencedByAbsoluteLeafref(final RevisionAwareXPath xpath, final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) { final LeafrefXPathStringParsingPathArgumentBuilder builder = new LeafrefXPathStringParsingPathArgumentBuilder( xpath.toString(), schemaContext, correspondingSchemaNode, currentNodeContext); final List<PathArgument> pathArguments = builder.build(); final NormalizedNodeNavigator navigator = (NormalizedNodeNavigator) currentNodeContext.getNavigator(); final NormalizedNode<?, ?> rootNode = navigator.getDocument().getRootNode(); if (pathArguments.get(0).getNodeType().equals(rootNode.getNodeType())) { final List<PathArgument> relPath = pathArguments.subList(1, pathArguments.size()); final Optional<NormalizedNode<?, ?>> possibleNode = NormalizedNodes.findNode(rootNode, relPath); if (possibleNode.isPresent()) { return possibleNode.get(); } } return null; }
private static NormalizedNode<?, ?> getNodeReferencedByAbsoluteLeafref(final RevisionAwareXPath xpath, final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) { final LeafrefXPathStringParsingPathArgumentBuilder builder = new LeafrefXPathStringParsingPathArgumentBuilder( xpath.toString(), schemaContext, correspondingSchemaNode, currentNodeContext); final List<PathArgument> pathArguments = builder.build(); final NormalizedNodeNavigator navigator = (NormalizedNodeNavigator) currentNodeContext.getNavigator(); final NormalizedNode<?, ?> rootNode = navigator.getDocument().getRootNode(); if (pathArguments.get(0).getNodeType().equals(rootNode.getNodeType())) { final List<PathArgument> relPath = pathArguments.subList(1, pathArguments.size()); final Optional<NormalizedNode<?, ?>> possibleNode = NormalizedNodes.findNode(rootNode, relPath); if (possibleNode.isPresent()) { return possibleNode.get(); } } 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); } 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 RevisionAwareXPath leafRefXPath = leafref.getPathStatement(); final RevisionAwareXPath leafRefStrippedXPath = new RevisionAwareXPathImpl( GROUPS_PATTERN.matcher(leafRefXPath.toString()).replaceAll(""), leafRefXPath.isAbsolute());
final String strXPath = xpath.toString();
final String strXPath = xpath.toString(); Type returnType = 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),
final String leafRefPathString = leafrefType.getPathStatement().toString(); final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(schemaContext, checkNotNull(getBaseTypeModule(leafrefType), "Unable to find base module for leafref %s", node),