+ /**
+ * Method attempts to find DataSchemaNode inside of provided Schema Context and Yang Module accordingly to
+ * Non-conditional relative Revision Aware XPath. The specified Module MUST be present in Schema Context otherwise
+ * the operation would fail and return <code>null</code>.
+ * <br>
+ * The relative Revision Aware XPath MUST be specified WITHOUT the conditional statement (i.e. without [cond]) in
+ * path, because in this state the Schema Context is completely unaware of data state and will be not able to
+ * properly resolve XPath. If the XPath contains condition the method will return IllegalArgumentException.
+ * <br>
+ * The Actual Schema Node MUST be specified correctly because from this Schema Node will search starts. If the
+ * Actual Schema Node is not correct the operation will simply fail, because it will be unable to find desired
+ * DataSchemaNode.
+ * <br>
+ * In case that Schema Context or Module or Actual Schema Node or relative Revision Aware XPath contains
+ * <code>null</code> references the method will throw IllegalArgumentException
+ * <br>
+ * If the Revision Aware XPath doesn't have flag <code>isAbsolute == false</code> the method will
+ * throw IllegalArgumentException.
+ * <br>
+ * If the relative Revision Aware XPath is correct and desired Data Schema Node is present in Yang module or in
+ * depending module in Schema Context the method will return specified Data Schema Node,
+ * otherwise the operation will fail
+ * and method will return <code>null</code>.
+ *
+ * @throws IllegalArgumentException
+ *
+ * @param context Schema Context
+ * @param module Yang Module
+ * @param actualSchemaNode Actual Schema Node
+ * @param relativeXPath Relative Non Conditional Revision Aware XPath
+ * @return DataSchemaNode if is present in specified Schema Context for given relative Revision Aware XPath,
+ * otherwise will return <code>null</code>.
+ */
+ public static DataSchemaNode findDataSchemaNodeForRelativeXPath(final SchemaContext context, final Module module,
+ final SchemaNode actualSchemaNode, final RevisionAwareXPath relativeXPath) {
+ if (context == null) {
+ throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
+ }
+ if (module == null) {
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
+ }
+ if (actualSchemaNode == null) {
+ throw new IllegalArgumentException("Actual Schema Node reference cannot be NULL!");
+ }
+ if (relativeXPath == null) {
+ throw new IllegalArgumentException("Non Conditional Revision Aware XPath cannot be NULL!");
+ }
+ if (relativeXPath.isAbsolute()) {
+ throw new IllegalArgumentException("Revision Aware XPath MUST be relative i.e. MUST contains ../, "
+ + "for non relative Revision Aware XPath use findDataSchemaNode method!");
+ }
+
+ final SchemaPath actualNodePath = actualSchemaNode.getPath();
+ if (actualNodePath != null) {
+ final Queue<QName> qnamePath = resolveRelativeXPath(context, module, relativeXPath, actualNodePath);
+
+ if (qnamePath != null) {
+ final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context, module, qnamePath);
+ return dataNode;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Retrieve information from Schema Path and returns the module reference to which Schema Node belongs. The
+ * search for correct Module is based on namespace within the last item in Schema Path. If schema context
+ * contains module with namespace specified in last item of Schema Path, then operation will returns Module
+ * reference, otherwise returns <code>null</code>
+ * <br>
+ * If Schema Context or Schema Node contains <code>null</code> references the method will throw IllegalArgumentException
+ *
+ * @throws IllegalArgumentException
+ *
+ * @param context Schema Context
+ * @param schemaPath Schema Path
+ * @return Module reference for given Schema Path if module is present in Schema Context,
+ * otherwise returns <code>null</code>
+ */
+ private static Module resolveModuleFromSchemaPath(final SchemaContext context, final SchemaPath schemaPath) {
+ if (context == null) {
+ throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
+ }
+ if (schemaPath == null) {
+ throw new IllegalArgumentException("Schema Path reference cannot be NULL");
+ }