java.lang.Object
org.opendaylight.yangtools.yang.common.AbstractQName
org.opendaylight.yangtools.yang.common.QName
All Implemented Interfaces:
Serializable, Comparable<QName>, Identifier, Immutable, WritableObject

public final class QName extends AbstractQName implements Comparable<QName>
The QName from XML consists of local name of element and XML namespace, but for our use, we added module revision to it.

In YANG context QName is full name of defined node, type, procedure or notification. QName consists of XML namespace, YANG model revision and local name of defined type. It is used to prevent name clashes between nodes with same local name, but from different schemas.

The local name must conform to RFC7950 Section 6.2.

  • XMLNamespace - getNamespace() - the namespace assigned to the YANG module which defined element, type, procedure or notification.
  • Revision - getRevision() - the revision of the YANG module which describes the element
  • LocalName - AbstractQName.getLocalName() - the YANG schema identifier which were defined for this node in the YANG module
See Also:
  • Method Details

    • create

      public static @NonNull QName create(String input)
    • create

      public static @NonNull QName create(QName base, String localName)
    • create

      public static @NonNull QName create(QNameModule qnameModule, String localName)
      Creates new QName.
      Parameters:
      qnameModule - Namespace and revision enclosed as a QNameModule
      localName - Local name part of QName. MUST NOT BE null.
      Returns:
      Instance of QName
      Throws:
      NullPointerException - if any argument is null
      IllegalArgumentException - if localName is not a valid YANG identifier
    • create

      public static @NonNull QName create(XMLNamespace namespace, @Nullable Revision revision, String localName)
      Creates new QName.
      Parameters:
      namespace - Namespace of QName or null if namespace is undefined.
      revision - Revision of namespace or null if revision is unspecified.
      localName - Local name part of QName. MUST NOT BE null.
      Returns:
      Instance of QName
    • create

      public static @NonNull QName create(XMLNamespace namespace, Optional<Revision> revision, String localName)
      Creates new QName.
      Parameters:
      namespace - Namespace of QName or null if namespace is undefined.
      revision - Revision of namespace.
      localName - Local name part of QName. MUST NOT BE null.
      Returns:
      Instance of QName
    • create

      public static @NonNull QName create(String namespace, String localName, Revision revision)
      Creates new QName.
      Parameters:
      namespace - Namespace of QName or null if namespace is undefined.
      localName - Local name part of QName. MUST NOT BE null.
      revision - Revision of namespace or null if revision is unspecified.
      Returns:
      Instance of QName
    • create

      public static @NonNull QName create(String namespace, String revision, String localName)
      Creates new QName.
      Parameters:
      namespace - Namespace of QName, MUST NOT BE Null.
      revision - Revision of namespace / YANG module. MUST NOT BE null, MUST BE in format YYYY-mm-dd.
      localName - Local name part of QName. MUST NOT BE null.
      Returns:
      A new QName
      Throws:
      NullPointerException - If any of parameters is null.
      IllegalArgumentException - If namespace is not valid URI or revision does not conform to YYYY-mm-dd.
    • create

      public static @NonNull QName create(String namespace, String localName)
      Creates new QName.
      Parameters:
      namespace - Namespace of QName, MUST NOT BE Null.
      localName - Local name part of QName. MUST NOT BE null.
      Returns:
      A new QName
      Throws:
      NullPointerException - If any of parameters is null.
      IllegalArgumentException - If namespace is not valid URI.
    • create

      public static @NonNull QName create(XMLNamespace namespace, String localName)
      Creates new QName.
      Parameters:
      namespace - Namespace of QName, MUST NOT BE null.
      localName - Local name part of QName. MUST NOT BE null.
      Returns:
      A new QName
      Throws:
      NullPointerException - If any of parameters is null.
      IllegalArgumentException - If namespace is not valid URI.
    • readFrom

      public static @NonNull QName readFrom(DataInput in) throws IOException
      Read a QName from a DataInput. The format is expected to match the output format of writeTo(DataOutput).
      Parameters:
      in - DataInput to read
      Returns:
      A QName instance
      Throws:
      IOException - if I/O error occurs
    • unsafeOf

      @Beta public static @NonNull QName unsafeOf(@NonNull QNameModule qnameModule, @NonNull String localName)
      Creates new QName composed of specified module and local name. This method does not perform lexical checking of localName, and it is the caller's responsibility to performs these checks.

      When in doubt, use create(QNameModule, String) instead.

      Parameters:
      qnameModule - Namespace and revision enclosed as a QNameModule
      localName - Local name part of QName, required to have been validated
      Returns:
      Instance of QName
      Throws:
      NullPointerException - if any of the arguments is null
    • getModule

      public @NonNull QNameModule getModule()
      Get the module component of the QName.
      Returns:
      Module component
    • getNamespace

      public @NonNull XMLNamespace getNamespace()
      Returns XMLNamespace assigned to the YANG module.
      Returns:
      XMLNamespace assigned to the YANG module.
    • getRevision

      public @NonNull Optional<Revision> getRevision()
      Returns revision of the YANG module if the module has defined revision.
      Returns:
      revision of the YANG module if the module has defined revision.
    • intern

      public @NonNull QName intern()
      Description copied from class: AbstractQName
      Return an interned reference to an equivalent object.
      Specified by:
      intern in class AbstractQName
      Returns:
      Interned reference, or this object if it was interned.
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Identifier
      Specified by:
      hashCode in class AbstractQName
    • equals

      public boolean equals(Object obj)
      Compares the specified object with this list for equality. Returns true if and only if the specified object is also instance of QName and its AbstractQName.getLocalName(), getNamespace() and getRevision() are equals to same properties of this instance.
      Specified by:
      equals in interface Identifier
      Specified by:
      equals in class AbstractQName
      Parameters:
      obj - the object to be compared for equality with this QName
      Returns:
      true if the specified object is equal to this QName
    • toString

      public @NonNull String toString()
      Specified by:
      toString in interface Identifier
      Specified by:
      toString in class AbstractQName
    • bindTo

      public @NonNull QName bindTo(QNameModule namespace)
      Description copied from class: AbstractQName
      Returns a QName with the specified namespace and the same local name as this one.
      Overrides:
      bindTo in class AbstractQName
      Parameters:
      namespace - New namespace to use
      Returns:
      a QName with specified QNameModule and same local name as this one
    • withoutRevision

      public @NonNull QName withoutRevision()
      Returns a QName with the same namespace and local name, but with no revision. If this QName does not have a Revision, this object is returned.
      Returns:
      a QName with the same namespace and local name, but with no revision.
    • formattedRevision

      public static @Nullable String formattedRevision(Optional<Revision> revision)
      Formats Revision representing revision to format YYYY-mm-dd

      YANG Specification defines format for revision< as YYYY-mm-dd. This format for revision is reused across multiple places such as capabilities URI, YANG modules, etc.

      Parameters:
      revision - Date object to format
      Returns:
      String representation or null if the input was null.
    • isEqualWithoutRevision

      public boolean isEqualWithoutRevision(QName other)
      Compares this QName to other, without comparing revision.

      Compares instance of this to other instance of QName and returns true if both instances have equal localName (AbstractQName.getLocalName()) and @{code namespace} (getNamespace()).

      Parameters:
      other - Other QName. Must not be null.
      Returns:
      true if this instance and other have equals localName and namespace.
      Throws:
      NullPointerException - if other is null.
    • compareTo

      public int compareTo(QName o)
      Specified by:
      compareTo in interface Comparable<QName>
    • writeTo

      public void writeTo(DataOutput out) throws IOException
      Description copied from interface: WritableObject
      Serialize this object into a DataOutput as a fixed-format stream.
      Specified by:
      writeTo in interface WritableObject
      Parameters:
      out - Data output
      Throws:
      IOException - if an I/O error occurs