JsonDomDocument.java

  1. // Generated by delombok at Fri Nov 29 09:48:08 UTC 2024
  2. package de.larssh.json.dom;

  3. import static de.larssh.utils.Finals.constant;
  4. import static java.util.Collections.singletonList;
  5. import org.w3c.dom.CDATASection;
  6. import org.w3c.dom.Comment;
  7. import org.w3c.dom.DOMConfiguration;
  8. import org.w3c.dom.DOMImplementation;
  9. import org.w3c.dom.Document;
  10. import org.w3c.dom.DocumentFragment;
  11. import org.w3c.dom.DocumentType;
  12. import org.w3c.dom.EntityReference;
  13. import org.w3c.dom.Node;
  14. import org.w3c.dom.ProcessingInstruction;
  15. import org.w3c.dom.Text;
  16. import de.larssh.json.dom.values.JsonDomValue;
  17. import edu.umd.cs.findbugs.annotations.NonNull;
  18. import edu.umd.cs.findbugs.annotations.Nullable;

  19. /**
  20.  * JSON DOM implementation of {@link Document}.
  21.  *
  22.  * @param <T> implementation specific JSON element type
  23.  */
  24. public class JsonDomDocument<T> extends JsonDomNode<T> implements Document {
  25.     /**
  26.      * Node name of the document element
  27.      */
  28.     public static final String DOCUMENT_ELEMENT_NODE_NAME = constant("root");
  29.     /**
  30.      * Document element with node name {@code root}
  31.      */
  32.     private final JsonDomElement<T> documentElement;

  33.     /**
  34.      * Constructor of {@link JsonDomDocument}.
  35.      *
  36.      * @param jsonDomValue wrapped JSON element
  37.      */
  38.     public JsonDomDocument(final JsonDomValue<T> jsonDomValue) {
  39.         super(null, "#document");
  40.         documentElement = new JsonDomElement<>(this, DOCUMENT_ELEMENT_NODE_NAME, jsonDomValue);
  41.     }

  42.     /**
  43.      * {@inheritDoc}
  44.      */
  45.     @Nullable
  46.     @Override
  47.     public Node adoptNode(@Nullable @SuppressWarnings("unused") final Node source) {
  48.         throw new JsonDomNotSupportedException();
  49.     }

  50.     /**
  51.      * {@inheritDoc}
  52.      */
  53.     @NonNull
  54.     @Override
  55.     public JsonDomAttribute<T> createAttribute(@Nullable @SuppressWarnings("unused") final String name) {
  56.         throw new JsonDomNotSupportedException();
  57.     }

  58.     /**
  59.      * {@inheritDoc}
  60.      */
  61.     @NonNull
  62.     @Override
  63.     public JsonDomAttribute<T> createAttributeNS(@Nullable @SuppressWarnings("unused") final String namespaceURI, @Nullable @SuppressWarnings("unused") final String qualifiedName) {
  64.         throw new JsonDomNotSupportedException();
  65.     }

  66.     /**
  67.      * {@inheritDoc}
  68.      */
  69.     @NonNull
  70.     @Override
  71.     public CDATASection createCDATASection(@Nullable @SuppressWarnings("unused") final String data) {
  72.         throw new JsonDomNotSupportedException();
  73.     }

  74.     /**
  75.      * {@inheritDoc}
  76.      */
  77.     @NonNull
  78.     @Override
  79.     public Comment createComment(@Nullable @SuppressWarnings("unused") final String data) {
  80.         throw new JsonDomNotSupportedException();
  81.     }

  82.     /**
  83.      * {@inheritDoc}
  84.      */
  85.     @NonNull
  86.     @Override
  87.     public DocumentFragment createDocumentFragment() {
  88.         throw new JsonDomNotSupportedException();
  89.     }

  90.     /**
  91.      * {@inheritDoc}
  92.      */
  93.     @NonNull
  94.     @Override
  95.     public JsonDomElement<T> createElement(@Nullable @SuppressWarnings("unused") final String tagName) {
  96.         throw new JsonDomNotSupportedException();
  97.     }

  98.     /**
  99.      * {@inheritDoc}
  100.      */
  101.     @NonNull
  102.     @Override
  103.     public JsonDomElement<T> createElementNS(@Nullable @SuppressWarnings("unused") final String namespaceURI, @Nullable @SuppressWarnings("unused") final String qualifiedName) {
  104.         throw new JsonDomNotSupportedException();
  105.     }

  106.     /**
  107.      * {@inheritDoc}
  108.      */
  109.     @NonNull
  110.     @Override
  111.     public EntityReference createEntityReference(@Nullable @SuppressWarnings("unused") final String name) {
  112.         throw new JsonDomNotSupportedException();
  113.     }

  114.     /**
  115.      * {@inheritDoc}
  116.      */
  117.     @NonNull
  118.     @Override
  119.     public ProcessingInstruction createProcessingInstruction(@Nullable @SuppressWarnings("unused") final String target, @Nullable @SuppressWarnings("unused") final String data) {
  120.         throw new JsonDomNotSupportedException();
  121.     }

  122.     /**
  123.      * {@inheritDoc}
  124.      */
  125.     @NonNull
  126.     @Override
  127.     public Text createTextNode(@Nullable @SuppressWarnings("unused") final String data) {
  128.         throw new JsonDomNotSupportedException();
  129.     }

  130.     /**
  131.      * {@inheritDoc}
  132.      */
  133.     @Nullable
  134.     @Override
  135.     @SuppressWarnings("PMD.ReturnEmptyCollectionRatherThanNull")
  136.     public JsonDomNamedNodeMap<JsonDomAttribute<T>> getAttributes() {
  137.         return null;
  138.     }

  139.     /**
  140.      * {@inheritDoc}
  141.      */
  142.     @NonNull
  143.     @Override
  144.     public JsonDomNodeList<JsonDomNode<T>> getChildNodes() {
  145.         return new JsonDomNodeList<>(singletonList(getDocumentElement()));
  146.     }

  147.     /**
  148.      * {@inheritDoc}
  149.      */
  150.     @Nullable
  151.     @Override
  152.     public DocumentType getDoctype() {
  153.         return null;
  154.     }

  155.     /**
  156.      * {@inheritDoc}
  157.      */
  158.     @Nullable
  159.     @Override
  160.     public String getDocumentURI() {
  161.         return null;
  162.     }

  163.     /**
  164.      * {@inheritDoc}
  165.      */
  166.     @Nullable
  167.     @Override
  168.     public DOMConfiguration getDomConfig() {
  169.         return null;
  170.     }

  171.     /**
  172.      * {@inheritDoc}
  173.      */
  174.     @Nullable
  175.     @Override
  176.     public JsonDomElement<T> getElementById(@Nullable @SuppressWarnings("unused") final String elementId) {
  177.         return null;
  178.     }

  179.     /**
  180.      * {@inheritDoc}
  181.      */
  182.     @NonNull
  183.     @Override
  184.     public JsonDomNodeList<JsonDomElement<T>> getElementsByTagName(@Nullable final String tagName) {
  185.         return getDocumentElement().getElementsByTagName(tagName);
  186.     }

  187.     /**
  188.      * {@inheritDoc}
  189.      */
  190.     @NonNull
  191.     @Override
  192.     public JsonDomNodeList<JsonDomElement<T>> getElementsByTagNameNS(@Nullable @SuppressWarnings("unused") final String namespaceURI, @Nullable @SuppressWarnings("unused") final String localName) {
  193.         throw new JsonDomNotSupportedException();
  194.     }

  195.     /**
  196.      * {@inheritDoc}
  197.      */
  198.     @Nullable
  199.     @Override
  200.     public DOMImplementation getImplementation() {
  201.         return null;
  202.     }

  203.     /**
  204.      * {@inheritDoc}
  205.      */
  206.     @Nullable
  207.     @Override
  208.     public String getInputEncoding() {
  209.         return null;
  210.     }

  211.     /**
  212.      * {@inheritDoc}
  213.      */
  214.     @Override
  215.     public T getJsonElement() {
  216.         return getDocumentElement().getJsonElement();
  217.     }

  218.     /**
  219.      * {@inheritDoc}
  220.      */
  221.     @Nullable
  222.     @Override
  223.     public JsonDomNode<T> getNextSibling() {
  224.         return null;
  225.     }

  226.     /**
  227.      * {@inheritDoc}
  228.      */
  229.     @Override
  230.     public short getNodeType() {
  231.         return DOCUMENT_NODE;
  232.     }

  233.     /**
  234.      * {@inheritDoc}
  235.      */
  236.     @Nullable
  237.     @Override
  238.     public String getNodeValue() {
  239.         return null;
  240.     }

  241.     /**
  242.      * {@inheritDoc}
  243.      */
  244.     @NonNull
  245.     @Override
  246.     public JsonDomDocument<T> getOwnerDocument() {
  247.         return this;
  248.     }

  249.     /**
  250.      * {@inheritDoc}
  251.      */
  252.     @Nullable
  253.     @Override
  254.     public JsonDomNode<T> getPreviousSibling() {
  255.         return null;
  256.     }

  257.     /**
  258.      * {@inheritDoc}
  259.      */
  260.     @Override
  261.     public boolean getStrictErrorChecking() {
  262.         return true;
  263.     }

  264.     /**
  265.      * {@inheritDoc}
  266.      */
  267.     @Nullable
  268.     @Override
  269.     public String getTextContent() {
  270.         return null;
  271.     }

  272.     /**
  273.      * {@inheritDoc}
  274.      */
  275.     @Nullable
  276.     @Override
  277.     public String getXmlEncoding() {
  278.         return null;
  279.     }

  280.     /**
  281.      * {@inheritDoc}
  282.      */
  283.     @Override
  284.     public boolean getXmlStandalone() {
  285.         return false;
  286.     }

  287.     /**
  288.      * {@inheritDoc}
  289.      */
  290.     @Nullable
  291.     @Override
  292.     public String getXmlVersion() {
  293.         return null;
  294.     }

  295.     /**
  296.      * {@inheritDoc}
  297.      */
  298.     @NonNull
  299.     @Override
  300.     public JsonDomNode<T> importNode(@Nullable @SuppressWarnings("unused") final Node importedNode, @SuppressWarnings("unused") final boolean deep) {
  301.         throw new JsonDomNotSupportedException();
  302.     }

  303.     /**
  304.      * {@inheritDoc}
  305.      */
  306.     @Override
  307.     public void normalizeDocument() {
  308.         // do nothing
  309.     }

  310.     /**
  311.      * {@inheritDoc}
  312.      */
  313.     @NonNull
  314.     @Override
  315.     public JsonDomNode<T> renameNode(@Nullable @SuppressWarnings("unused") final Node node, @Nullable @SuppressWarnings("unused") final String namespaceURI, @Nullable @SuppressWarnings("unused") final String qualifiedName) {
  316.         throw new JsonDomNotSupportedException();
  317.     }

  318.     /**
  319.      * {@inheritDoc}
  320.      */
  321.     @Override
  322.     public void setDocumentURI(@Nullable @SuppressWarnings("unused") final String documentURI) {
  323.         throw new JsonDomNotSupportedException();
  324.     }

  325.     /**
  326.      * {@inheritDoc}
  327.      */
  328.     @Override
  329.     public void setStrictErrorChecking(@SuppressWarnings("unused") final boolean strictErrorChecking) {
  330.         throw new JsonDomNotSupportedException();
  331.     }

  332.     /**
  333.      * {@inheritDoc}
  334.      */
  335.     @Override
  336.     public void setXmlStandalone(@SuppressWarnings("unused") final boolean xmlStandalone) {
  337.         throw new JsonDomNotSupportedException();
  338.     }

  339.     /**
  340.      * {@inheritDoc}
  341.      */
  342.     @Override
  343.     public void setXmlVersion(@Nullable @SuppressWarnings("unused") final String xmlVersion) {
  344.         throw new JsonDomNotSupportedException();
  345.     }

  346.     /**
  347.      * Document element with node name {@code root}
  348.      *
  349.      * @return document element
  350.      */
  351.     @java.lang.SuppressWarnings("all")
  352.     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
  353.     @lombok.Generated
  354.     public JsonDomElement<T> getDocumentElement() {
  355.         return this.documentElement;
  356.     }

  357.     @java.lang.Override
  358.     @java.lang.SuppressWarnings("all")
  359.     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
  360.     @lombok.Generated
  361.     public boolean equals(@edu.umd.cs.findbugs.annotations.Nullable final java.lang.Object o) {
  362.         if (o == this) return true;
  363.         if (!(o instanceof JsonDomDocument)) return false;
  364.         final JsonDomDocument<?> other = (JsonDomDocument<?>) o;
  365.         if (!other.canEqual((java.lang.Object) this)) return false;
  366.         if (!super.equals(o)) return false;
  367.         final java.lang.Object this$documentElement = this.getDocumentElement();
  368.         final java.lang.Object other$documentElement = other.getDocumentElement();
  369.         if (this$documentElement == null ? other$documentElement != null : !this$documentElement.equals(other$documentElement)) return false;
  370.         return true;
  371.     }

  372.     @java.lang.SuppressWarnings("all")
  373.     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
  374.     @lombok.Generated
  375.     protected boolean canEqual(@edu.umd.cs.findbugs.annotations.Nullable final java.lang.Object other) {
  376.         return other instanceof JsonDomDocument;
  377.     }

  378.     @java.lang.Override
  379.     @java.lang.SuppressWarnings("all")
  380.     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
  381.     @lombok.Generated
  382.     public int hashCode() {
  383.         final int PRIME = 59;
  384.         int result = super.hashCode();
  385.         final java.lang.Object $documentElement = this.getDocumentElement();
  386.         result = result * PRIME + ($documentElement == null ? 43 : $documentElement.hashCode());
  387.         return result;
  388.     }
  389. }