DefaultFunctionLibrary.java

  1. /*
  2.  * Portions of this software was developed by employees of the National Institute
  3.  * of Standards and Technology (NIST), an agency of the Federal Government and is
  4.  * being made available as a public service. Pursuant to title 17 United States
  5.  * Code Section 105, works of NIST employees are not subject to copyright
  6.  * protection in the United States. This software may be subject to foreign
  7.  * copyright. Permission in the United States and in foreign countries, to the
  8.  * extent that NIST may hold copyright, to use, copy, modify, create derivative
  9.  * works, and distribute this software and its documentation without fee is hereby
  10.  * granted on a non-exclusive basis, provided that this notice and disclaimer
  11.  * of warranty appears in all copies.
  12.  *
  13.  * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
  14.  * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
  15.  * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
  16.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
  17.  * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
  18.  * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE.  IN NO EVENT
  19.  * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
  20.  * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
  21.  * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
  22.  * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
  23.  * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
  24.  * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
  25.  */

  26. package gov.nist.secauto.metaschema.core.metapath.function.library;

  27. import com.google.auto.service.AutoService;

  28. import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
  29. import gov.nist.secauto.metaschema.core.metapath.function.FunctionLibrary;
  30. import gov.nist.secauto.metaschema.core.metapath.function.IFunctionLibrary;
  31. import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem;
  32. import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem;
  33. import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem;
  34. import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDecimalItem;
  35. import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDurationItem;
  36. import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem;
  37. import gov.nist.secauto.metaschema.core.metapath.item.atomic.INcNameItem;
  38. import gov.nist.secauto.metaschema.core.metapath.item.atomic.INonNegativeIntegerItem;
  39. import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem;
  40. import gov.nist.secauto.metaschema.core.metapath.item.atomic.IPositiveIntegerItem;
  41. import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem;

  42. @AutoService(IFunctionLibrary.class)
  43. public class DefaultFunctionLibrary
  44.     extends FunctionLibrary {

  45.   /**
  46.    * Initialize the built-in function library.
  47.    */
  48.   public DefaultFunctionLibrary() { // NOPMD - intentional
  49.     // https://www.w3.org/TR/xpath-functions-31/#func-abs
  50.     registerFunction(NumericFunction.signature(MetapathConstants.NS_XPATH_FUNCTIONS, "abs", INumericItem::abs));
  51.     // https://www.w3.org/TR/xpath-functions-31/#func-adjust-dateTime-to-timezone
  52.     // https://www.w3.org/TR/xpath-functions-31/#func-adjust-date-to-timezone
  53.     // https://www.w3.org/TR/xpath-functions-31/#func-adjust-time-to-timezone
  54.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-avg
  55.     // https://www.w3.org/TR/xpath-functions-31/#func-base-uri
  56.     registerFunction(FnBaseUri.SIGNATURE_NO_ARG);
  57.     registerFunction(FnBaseUri.SIGNATURE_ONE_ARG);
  58.     // https://www.w3.org/TR/xpath-functions-31/#func-boolean
  59.     registerFunction(FnBoolean.SIGNATURE);
  60.     // https://www.w3.org/TR/xpath-functions-31/#func-ceiling
  61.     registerFunction(NumericFunction.signature(MetapathConstants.NS_XPATH_FUNCTIONS, "ceiling", INumericItem::ceiling));
  62.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-compare
  63.     registerFunction(FnCompare.SIGNATURE);
  64.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-concat
  65.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-contains
  66.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-count
  67.     // https://www.w3.org/TR/xpath-functions-31/#func-current-date
  68.     // https://www.w3.org/TR/xpath-functions-31/#func-current-dateTime
  69.     // https://www.w3.org/TR/xpath-functions-31/#func-current-time
  70.     // https://www.w3.org/TR/xpath-functions-31/#func-data
  71.     registerFunction(FnData.SIGNATURE_NO_ARG);
  72.     registerFunction(FnData.SIGNATURE_ONE_ARG);
  73.     // https://www.w3.org/TR/xpath-functions-31/#func-day-from-date
  74.     // https://www.w3.org/TR/xpath-functions-31/#func-day-from-dateTime
  75.     // https://www.w3.org/TR/xpath-functions-31/#func-days-from-duration
  76.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-deep-equal
  77.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-distinct-values
  78.     // https://www.w3.org/TR/xpath-functions-31/#func-doc
  79.     registerFunction(FnDoc.SIGNATURE);
  80.     // https://www.w3.org/TR/xpath-functions-31/#func-doc-available
  81.     // https://www.w3.org/TR/xpath-functions-31/#func-document-uri
  82.     registerFunction(FnDocumentUri.SIGNATURE_NO_ARG);
  83.     registerFunction(FnDocumentUri.SIGNATURE_ONE_ARG);
  84.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-empty
  85.     // https://www.w3.org/TR/xpath-functions-31/#func-encode-for-uri
  86.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-ends-with
  87.     // https://www.w3.org/TR/xpath-functions-31/#func-exactly-one
  88.     // https://www.w3.org/TR/xpath-functions-31/#func-exists
  89.     registerFunction(FnExists.SIGNATURE);
  90.     registerFunction(FnFalse.SIGNATURE);
  91.     // https://www.w3.org/TR/xpath-functions-31/#func-floor
  92.     registerFunction(NumericFunction.signature(MetapathConstants.NS_XPATH_FUNCTIONS, "floor", INumericItem::floor));
  93.     // https://www.w3.org/TR/xpath-functions-31/#func-format-date
  94.     // https://www.w3.org/TR/xpath-functions-31/#func-format-dateTime
  95.     // https://www.w3.org/TR/xpath-functions-31/#func-format-integer
  96.     // https://www.w3.org/TR/xpath-functions-31/#func-format-number
  97.     // https://www.w3.org/TR/xpath-functions-31/#func-format-time
  98.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-generate-id
  99.     // https://www.w3.org/TR/xpath-functions-31/#func-has-children
  100.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-head
  101.     // https://www.w3.org/TR/xpath-functions-31/#func-hours-from-dateTime
  102.     // https://www.w3.org/TR/xpath-functions-31/#func-hours-from-duration
  103.     // https://www.w3.org/TR/xpath-functions-31/#func-hours-from-time
  104.     // https://www.w3.org/TR/xpath-functions-31/#func-implicit-timezone
  105.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-index-of
  106.     // https://www.w3.org/TR/xpath-functions-31/#func-innermost
  107.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-insert-before
  108.     // https://www.w3.org/TR/xpath-functions-31/#func-iri-to-uri
  109.     // https://www.w3.org/TR/xpath-functions-31/#func-last
  110.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-lower-case
  111.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-matches
  112.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-max
  113.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-min
  114.     // https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-dateTime
  115.     // https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-duration
  116.     // https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-time
  117.     // https://www.w3.org/TR/xpath-functions-31/#func-month-from-date
  118.     // https://www.w3.org/TR/xpath-functions-31/#func-month-from-dateTime
  119.     // https://www.w3.org/TR/xpath-functions-31/#func-months-from-duration
  120.     // https://www.w3.org/TR/xpath-functions-31/#func-normalize-space
  121.     // https://www.w3.org/TR/xpath-functions-31/#func-normalize-unicode
  122.     // https://www.w3.org/TR/xpath-functions-31/#func-not
  123.     registerFunction(FnNot.SIGNATURE);
  124.     // https://www.w3.org/TR/xpath-functions-31/#func-number
  125.     // https://www.w3.org/TR/xpath-functions-31/#func-one-or-more
  126.     // https://www.w3.org/TR/xpath-functions-31/#func-outermost
  127.     // https://www.w3.org/TR/xpath-functions-31/#func-parse-ietf-date
  128.     // https://www.w3.org/TR/xpath-functions-31/#func-path
  129.     registerFunction(FnPath.SIGNATURE_NO_ARG);
  130.     registerFunction(FnPath.SIGNATURE_ONE_ARG);
  131.     // https://www.w3.org/TR/xpath-functions-31/#func-position
  132.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-remove
  133.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-replace
  134.     // https://www.w3.org/TR/xpath-functions-31/#func-resolve-uri
  135.     registerFunction(FnResolveUri.SIGNATURE_ONE_ARG);
  136.     registerFunction(FnResolveUri.SIGNATURE_TWO_ARG);
  137.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-reverse
  138.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-root
  139.     // https://www.w3.org/TR/xpath-functions-31/#func-round
  140.     registerFunction(FnRound.SIGNATURE);
  141.     registerFunction(FnRound.SIGNATURE_WITH_PRECISION);
  142.     // https://www.w3.org/TR/xpath-functions-31/#func-round-half-to-even
  143.     // https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-dateTime
  144.     // https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-duration
  145.     // https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-time
  146.     // https://www.w3.org/TR/xpath-functions-31/#func-starts-with
  147.     registerFunction(FnStartsWith.SIGNATURE);
  148.     // https://www.w3.org/TR/xpath-functions-31/#func-static-base-uri
  149.     registerFunction(FnStaticBaseUri.SIGNATURE);
  150.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-string-join
  151.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-string-length
  152.     // https://www.w3.org/TR/xpath-functions-31/#func-subsequence
  153.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-substring
  154.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-substring-after
  155.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-substring-before
  156.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-sum
  157.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-tail
  158.     // https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-date
  159.     // https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-dateTime
  160.     // https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-time
  161.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-tokenize
  162.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-translate
  163.     registerFunction(FnTrue.SIGNATURE);
  164.     // https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text
  165.     // https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text-available
  166.     // https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text-lines
  167.     // P1: https://www.w3.org/TR/xpath-functions-31/#func-upper-case
  168.     // https://www.w3.org/TR/xpath-functions-31/#func-year-from-date
  169.     // https://www.w3.org/TR/xpath-functions-31/#func-year-from-dateTime
  170.     // https://www.w3.org/TR/xpath-functions-31/#func-years-from-duration
  171.     // https://www.w3.org/TR/xpath-functions-31/#func-zero-or-one

  172.     // xpath casting functions
  173.     registerFunction(
  174.         CastFunction.signature(MetapathConstants.NS_XML_SCHEMA, "boolean", IBooleanItem.class, IBooleanItem::cast));
  175.     registerFunction(CastFunction.signature(
  176.         MetapathConstants.NS_XML_SCHEMA, "date", IDateItem.class, IDateItem::cast));
  177.     registerFunction(CastFunction.signature(
  178.         MetapathConstants.NS_XML_SCHEMA, "dateTime", IDateTimeItem.class, IDateTimeItem::cast));
  179.     registerFunction(CastFunction.signature(
  180.         MetapathConstants.NS_XML_SCHEMA, "decimal", IDecimalItem.class, IDecimalItem::cast));
  181.     registerFunction(CastFunction.signature(
  182.         MetapathConstants.NS_XML_SCHEMA, "duration", IDurationItem.class, IDurationItem::cast));
  183.     registerFunction(CastFunction.signature(
  184.         MetapathConstants.NS_XML_SCHEMA, "integer", IIntegerItem.class, IIntegerItem::cast));
  185.     registerFunction(CastFunction.signature(
  186.         MetapathConstants.NS_XML_SCHEMA, "NCName", INcNameItem.class, INcNameItem::cast));
  187.     registerFunction(CastFunction.signature(
  188.         MetapathConstants.NS_XML_SCHEMA, "nonNegativeInteger", INonNegativeIntegerItem.class,
  189.         INonNegativeIntegerItem::cast));
  190.     registerFunction(CastFunction.signature(
  191.         MetapathConstants.NS_XML_SCHEMA, "positiveInteger", IPositiveIntegerItem.class,
  192.         IPositiveIntegerItem::cast));
  193.     registerFunction(CastFunction.signature(
  194.         MetapathConstants.NS_XML_SCHEMA, "string", IStringItem.class, IStringItem::cast));

  195.     // metapath casting functions
  196.     registerFunction(CastFunction.signature(
  197.         MetapathConstants.NS_METAPATH, "boolean", IBooleanItem.class, IBooleanItem::cast));
  198.     registerFunction(CastFunction.signature(
  199.         MetapathConstants.NS_METAPATH, "date", IDateItem.class, IDateItem::cast));
  200.     registerFunction(CastFunction.signature(
  201.         MetapathConstants.NS_METAPATH, "date-time", IDateTimeItem.class, IDateTimeItem::cast));
  202.     registerFunction(CastFunction.signature(
  203.         MetapathConstants.NS_METAPATH, "decimal", IDecimalItem.class, IDecimalItem::cast));
  204.     registerFunction(CastFunction.signature(
  205.         MetapathConstants.NS_METAPATH, "duration", IDurationItem.class, IDurationItem::cast));
  206.     registerFunction(CastFunction.signature(
  207.         MetapathConstants.NS_METAPATH, "integer", IIntegerItem.class, IIntegerItem::cast));
  208.     registerFunction(CastFunction.signature(
  209.         MetapathConstants.NS_METAPATH, "ncname", INcNameItem.class, INcNameItem::cast));
  210.     registerFunction(CastFunction.signature(
  211.         MetapathConstants.NS_METAPATH, "non-negative-integer", INonNegativeIntegerItem.class,
  212.         INonNegativeIntegerItem::cast));
  213.     registerFunction(CastFunction.signature(
  214.         MetapathConstants.NS_METAPATH, "positive-integer", IPositiveIntegerItem.class,
  215.         IPositiveIntegerItem::cast));
  216.     registerFunction(CastFunction.signature(
  217.         MetapathConstants.NS_METAPATH, "string", IStringItem.class, IStringItem::cast));

  218.     // extra functions
  219.     registerFunction(MpRecurseDepth.SIGNATURE_ONE_ARG);
  220.     registerFunction(MpRecurseDepth.SIGNATURE_TWO_ARG);
  221.   }

  222. }