001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package dev.metaschema.core.metapath;
007
008import edu.umd.cs.findbugs.annotations.NonNull;
009import edu.umd.cs.findbugs.annotations.Nullable;
010
011/**
012 * MPDY: Exceptions related to the Metapath dynamic context and dynamic
013 * evaluation.
014 */
015public class DynamicMetapathException
016    extends MetapathException {
017  @NonNull
018  private static final String PREFIX = "MPDY";
019
020  /**
021   * the serial version UID.
022   */
023  private static final long serialVersionUID = 1L;
024
025  /**
026   * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPDY0002">err:MPDY0002</a>: It
027   * is a <a href="https://www.w3.org/TR/xpath-31/#dt-dynamic-error">dynamic
028   * error</a> if evaluation of an expression relies on some part of the
029   * <a href="https://www.w3.org/TR/xpath-31/#dt-dynamic-context">dynamic
030   * context</a> that is
031   * <a href="https://www.w3.org/TR/xpath-datamodel-31/#dt-absent">absent</a>.
032   */
033  protected static final int DYNAMIC_CONTEXT_ABSENT = 2;
034
035  /**
036   * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPDY0050">err:MPDY0050</a>: It
037   * is a <a href="https://www.w3.org/TR/xpath-31/#dt-dynamic-error">dynamic
038   * error</a> if the
039   * <a href="https://www.w3.org/TR/xpath-31/#dt-dynamic-type">dynamic type</a> of
040   * the operand of a <code>treat</code> expression does not match the
041   * <a href="https://www.w3.org/TR/xpath-31/#dt-sequence-type">sequence type</a>
042   * specified by the <code>treat</code> expression. This error might also be
043   * raised by a path expression beginning with "/" or "//" if the context node is
044   * not in a tree that is rooted at a document node. This is because a leading
045   * "/" or "//" in a path expression is an abbreviation for an initial step that
046   * includes the clause <code>treat as document-node()</code>.
047   */
048  protected static final int TREAT_DOES_NOT_MATCH_TYPE = 50;
049
050  /**
051   * Constructs a new exception with the provided {@code code}, {@code message},
052   * and no cause.
053   *
054   * @param code
055   *          the error code value
056   * @param message
057   *          the exception message
058   */
059  public DynamicMetapathException(
060      int code,
061      @Nullable String message) {
062    super(IErrorCode.of(PREFIX, code), message);
063  }
064
065  /**
066   * Constructs a new exception with the provided {@code code}, {@code message},
067   * and {@code cause}.
068   *
069   * @param code
070   *          the error code value
071   * @param message
072   *          the exception message
073   * @param cause
074   *          the original exception cause
075   */
076  public DynamicMetapathException(
077      int code,
078      @Nullable String message,
079      @Nullable Throwable cause) {
080    super(IErrorCode.of(PREFIX, code), message, cause);
081  }
082
083  /**
084   * Constructs a new exception with the provided {@code code}, no message, and
085   * the {@code cause}.
086   *
087   * @param code
088   *          the error code value
089   * @param cause
090   *          the original exception cause
091   */
092  public DynamicMetapathException(
093      int code,
094      @Nullable Throwable cause) {
095    super(IErrorCode.of(PREFIX, code), cause);
096  }
097}