Class SimpleElementFacade

java.lang.Object
uk.blankaspect.common.jsonxml.SimpleElementFacade
All Implemented Interfaces:
IElementFacade

public class SimpleElementFacade extends Object implements IElementFacade
This class provides methods that can be used to create JSON-XML elements and to access the attributes of JSON-XML elements. The JSON-XML elements that are created by this class must be associated with an XML document. Some of the constructors of this class create an XML document for this purpose; the remaining constructors expect an XML document to be supplied as an argument.

An instance of this class may be used to apply a namespace prefix to the name of a JSON-XML element and to the names of attributes of a JSON-XML element.

  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleElementFacade(String documentElementName)
    Creates a new instance of a facade that provides methods for creating a JSON-XML element and accessing the attributes of a JSON-XML element.
    SimpleElementFacade(String namespaceUri, String namespacePrefix, String documentElementName)
    Creates a new instance of a facade that provides methods for creating a JSON-XML element and accessing the attributes of a JSON-XML element.
    SimpleElementFacade(String namespaceUri, String namespacePrefix, Document document)
    Creates a new instance of a facade that provides methods for creating a JSON-XML element and accessing the attributes of a JSON-XML element.
    Creates a new instance of a facade that provides methods for creating a JSON-XML element and accessing the attributes of a JSON-XML element.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Document
    createDocument(String namespaceUri, String documentElementName)
    Creates and returns a new instance of a XML document whose document element has the specified namespace URI and the specified qualified name.
    Creates and returns a new instance of a JSON-XML element whose name is the specified name or is derived from it in some way (for example, by applying a namespace prefix to it).
    getAttribute(Element element, String name)
    Returns the value of a named attribute of the specified element.
    Returns the XML document that is associated with the elements and attributes that are created by the methods of this facade.
    void
    setAttribute(Element element, String name, String value)
    Sets the value of a named attribute of the specified element.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SimpleElementFacade

      public SimpleElementFacade(String documentElementName) throws BaseException
      Creates a new instance of a facade that provides methods for creating a JSON-XML element and accessing the attributes of a JSON-XML element. No namespace URI is associated with the JSON-XML elements and attributes.

      The JSON-XML elements and attributes are associated with an XML document that is created by this constructor. The document element of the document has no namespace URI and the specified qualified name.

      Parameters:
      documentElementName - the qualified name of the document element of the XML document that is created.
      Throws:
      BaseException - if an error occurs when creating the XML document.
    • SimpleElementFacade

      public SimpleElementFacade(String namespaceUri, String namespacePrefix, String documentElementName) throws BaseException
      Creates a new instance of a facade that provides methods for creating a JSON-XML element and accessing the attributes of a JSON-XML element. The specified namespace URI is associated with the JSON-XML elements and attributes, and the specified namespace prefix is applied to the names of the JSON-XML elements and attributes.

      The JSON-XML elements and attributes are associated with an XML document that is created by this constructor. The document element of the document has the specified namespace URI and the specified qualified name.

      Parameters:
      namespaceUri - the namespace URI that will be associated with JSON-XML elements and attributes. It will also be set on the document element of the XML document that is created.
      namespacePrefix - the namespace prefix that will be applied to the names of JSON-XML elements and attributes. If the prefix is null or empty or it contains only whitespace characters, no prefix will be applied.
      documentElementName - the qualified name of the document element of the XML document that is created.
      Throws:
      BaseException - if an error occurs when creating the XML document.
      IllegalArgumentException - if
      • documentElementName is null, or
      • namespaceUri is null and namespacePrefix is not null and namespacePrefix is not empty and namespacePrefix does not contain only whitespace, or
      • namespaceUri is not null and any of the following is true:
        • namespacePrefix is null,
        • namespacePrefix is empty,
        • namespacePrefix contains only whitespace characters.
    • SimpleElementFacade

      public SimpleElementFacade(Document document)
      Creates a new instance of a facade that provides methods for creating a JSON-XML element and accessing the attributes of a JSON-XML element. No namespace URI is associated with the JSON-XML elements and attributes.

      The JSON-XML elements and attributes are associated with the specified XML document.

      Parameters:
      document - the XML document with which JSON-XML elements and attributes will be associated.
    • SimpleElementFacade

      public SimpleElementFacade(String namespaceUri, String namespacePrefix, Document document)
      Creates a new instance of a facade that provides methods for creating a JSON-XML element and accessing the attributes of a JSON-XML element. The specified namespace URI is associated with the JSON-XML elements and attributes, and the specified namespace prefix is applied to the names of the JSON-XML elements and attributes.

      The JSON-XML elements and attributes are associated with the specified XML document.

      Parameters:
      namespaceUri - the namespace URI that will be associated with JSON-XML elements and attributes.
      namespacePrefix - the namespace prefix that will be applied to the names of JSON-XML elements and attributes. If the prefix is null or empty or it contains only whitespace characters, no prefix will be applied.
      document - the XML document with which JSON-XML elements and attributes will be associated.
      Throws:
      IllegalArgumentException - if
      • document is null, or
      • namespaceUri is null and namespacePrefix is not null and namespacePrefix is not empty and namespacePrefix does not contain only whitespace, or
      • namespaceUri is not null and any of the following is true:
        • namespacePrefix is null,
        • namespacePrefix is empty,
        • namespacePrefix contains only whitespace characters.
  • Method Details

    • createDocument

      public static Document createDocument(String namespaceUri, String documentElementName) throws BaseException
      Creates and returns a new instance of a XML document whose document element has the specified namespace URI and the specified qualified name.
      Parameters:
      namespaceUri - the namespace URI of the document element of the XML document, which may be null.
      documentElementName - the qualified name of the document element of the XML document, which may be null.
      Returns:
      a new instance of a XML document. The namespace URI of the document element is namespaceUri and the qualified name of the document element is documentElementName.
      Throws:
      BaseException - if an error occurs when creating the XML document.
    • createElement

      public Element createElement(String name)
      Creates and returns a new instance of a JSON-XML element whose name is the specified name or is derived from it in some way (for example, by applying a namespace prefix to it).
      Specified by:
      createElement in interface IElementFacade
      Parameters:
      name - the name from which the name of the new JSON-XML element will be derived.
      Returns:
      a new instance of a JSON-XML element whose name is derived from name.
    • getAttribute

      public String getAttribute(Element element, String name)
      Returns the value of a named attribute of the specified element. The name of the attribute is the specified name or is derived from it in some way (for example, by applying a namespace prefix to it).
      Specified by:
      getAttribute in interface IElementFacade
      Parameters:
      element - the JSON-XML element whose specified attribute is of interest.
      name - the name from which the name of the target attribute will be derived.
      Returns:
      the value of the attribute of element whose name is derived from name.
    • setAttribute

      public void setAttribute(Element element, String name, String value)
      Sets the value of a named attribute of the specified element. The name of the attribute is the specified name or is derived from it in some way (for example, by applying a namespace prefix to it).
      Specified by:
      setAttribute in interface IElementFacade
      Parameters:
      element - the JSON-XML element whose specified attribute is of interest.
      name - the name from which the name of the target attribute will be derived.
      value - the value to which the target attribute will be set.
    • getDocument

      public Document getDocument()
      Returns the XML document that is associated with the elements and attributes that are created by the methods of this facade.
      Returns:
      the XML document that is associated with the elements and attributes that are created by the methods of this facade.