Class QName
- java.lang.Object
-
- org.opendaylight.yangtools.yang.common.AbstractQName
-
- org.opendaylight.yangtools.yang.common.QName
-
- All Implemented Interfaces:
Serializable
,Comparable<QName>
,Identifier
,Immutable
,MutationBehaviour<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:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NonNull QName
bindTo(QNameModule namespace)
Returns a QName with the specified namespace and the same local name as this one.int
compareTo(QName o)
static @NonNull QName
create(String input)
static @NonNull QName
create(String namespace, String localName)
Creates new QName.static @NonNull QName
create(String namespace, String revision, String localName)
Creates new QName.static @NonNull QName
create(String namespace, String localName, Revision revision)
Creates new QName.static @NonNull QName
create(URI namespace, @Nullable Revision revision, String localName)
Creates new QName.static @NonNull QName
create(URI namespace, String localName)
Creates new QName.static @NonNull QName
create(URI namespace, Optional<Revision> revision, String localName)
Creates new QName.static @NonNull QName
create(QNameModule qnameModule, String localName)
Creates new QName.static @NonNull QName
create(QName base, String localName)
boolean
equals(Object obj)
Compares the specified object with this list for equality.static @Nullable String
formattedRevision(Optional<Revision> revision)
FormatsRevision
representing revision to formatYYYY-mm-dd
@NonNull QNameModule
getModule()
Get the module component of the QName.@NonNull URI
getNamespace()
Returns XMLNamespace assigned to the YANG module.@NonNull Optional<Revision>
getRevision()
Returns revision of the YANG module if the module has defined revision.int
hashCode()
@NonNull QName
intern()
Return an interned reference to an equivalent object.boolean
isEqualWithoutRevision(QName other)
Compares this QName to other, without comparing revision.static @NonNull QName
readFrom(DataInput in)
Read a QName from a DataInput.@NonNull String
toString()
static @NonNull QName
unsafeOf(@NonNull QNameModule qnameModule, @NonNull String localName)
Creates new QName composed of specified module and local name.@NonNull QName
withoutRevision()
Returns a QName with the same namespace and local name, but with no revision.void
writeTo(DataOutput out)
Serialize this object into aDataOutput
as a fixed-format stream.-
Methods inherited from class org.opendaylight.yangtools.yang.common.AbstractQName
getLocalName
-
-
-
-
Method Detail
-
create
public static @NonNull QName create(QNameModule qnameModule, String localName)
Creates new QName.- Parameters:
qnameModule
- Namespace and revision enclosed as a QNameModulelocalName
- Local name part of QName. MUST NOT BE null.- Returns:
- Instance of QName
- Throws:
NullPointerException
- if any argument is nullIllegalArgumentException
- if localName is not a valid YANG identifier
-
create
public static @NonNull QName create(URI 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(URI 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.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(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 formatYYYY-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
- Ifnamespace
is not valid URI orrevision
does not conform toYYYY-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
- Ifnamespace
is not valid URI.
-
create
public static @NonNull QName create(URI 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
- Ifnamespace
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 ofwriteTo(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 QNameModulelocalName
- 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 URI 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 classAbstractQName
- Returns:
- Interned reference, or this object if it was interned.
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceIdentifier
- Specified by:
hashCode
in classAbstractQName
-
equals
public boolean equals(Object obj)
Compares the specified object with this list for equality. Returnstrue
if and only if the specified object is also instance ofQName
and itsAbstractQName.getLocalName()
,getNamespace()
andgetRevision()
are equals to same properties of this instance.- Specified by:
equals
in interfaceIdentifier
- Specified by:
equals
in classAbstractQName
- 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 interfaceIdentifier
- Specified by:
toString
in classAbstractQName
-
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 classAbstractQName
- 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)
FormatsRevision
representing revision to formatYYYY-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
- ifother
is null.
-
compareTo
public int compareTo(QName o)
- Specified by:
compareTo
in interfaceComparable<QName>
-
writeTo
public void writeTo(DataOutput out) throws IOException
Description copied from interface:WritableObject
Serialize this object into aDataOutput
as a fixed-format stream.- Specified by:
writeTo
in interfaceWritableObject
- Parameters:
out
- Data output- Throws:
IOException
- if an I/O error occurs
-
-