public final class QualifiedName extends Object implements Comparable<QualifiedName>, Serializable
A QualifiedName is created by combining the name of a method and the name of the type that declares the method. This class also contains many static utility methods to manage QualifiedName instances.
NOTE: Unless you do very generic libraries, entity stores and other extensions that is deeply coupled into the Zest runtime, it is very unlikely you will need to use this class directly.
It is also important to notice that the QualifiedName needs to be long-term stable, as the names are written to persistent storage. So any changes in the formatting must be made in a backward-compatible manner .
The QualifiedName has two intrinsic parts, one being the type
and the other the name
. The
type
comes from the class where the QualifiedName originates from and internally kept as a TypeName
instance. The name is the name from the method name. When the QualifiedName instance is converted to an external
string representation, via the offical and formal toString()
method, the type
is normalized, i.e.
any dollar characters ($) in the name are replaced by dashes (-), to make them URI friendly.
QualifiedName instances are immutable, implements hashCode()
and equals(Object)
as a value
object and can safely be used as keys in Map
.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(QualifiedName other) |
boolean |
equals(Object o) |
static QualifiedName |
fromAccessor(AccessibleObject method)
Creates a QualifiedName from a method.
|
static QualifiedName |
fromClass(Class type,
String name)
Creates a QualifiedName instance from the Class and a given name.
|
static QualifiedName |
fromFQN(String fullQualifiedName)
Creates a QualifiedName from the external string format of QualifiedName.
|
static QualifiedName |
fromName(String type,
String name)
Creates a Qualified name from a type as string and a name qualifier.
|
int |
hashCode() |
String |
name()
Returns the name component of the QualifiedName.
|
String |
toNamespace()
Return the URI of the
TypeName component of the QualifiedName. |
String |
toString()
Return the formal and official, long-term stable, external string representation of a QualifiedName.
|
String |
toURI()
Returns the URI of the QualifiedName.
|
String |
type()
Returns the normalized string of the type part of the QualifiedName.
|
public static QualifiedName fromAccessor(AccessibleObject method)
This factory method will create a QualifiedName from the Method itself.
method
- Type method that returns a Property, for which the QualifiedName will be representing.NullArgumentException
- If the method
argument passed is null.public static QualifiedName fromClass(Class type, String name)
This factory method converts the type
to a TypeName
and appends the given name
.
type
- The Class that is the base of the QualifiedName.name
- The qualifier name which will be appended to the base name derived from the type
argument.type
and name
arguments.NullArgumentException
- if any of the two arguments are null
, or if the name string is empty.public static QualifiedName fromName(String type, String name)
type
- The type name as a a string, which must be properly formatted. No checks for correctly formatted
type name is performed.name
- The qualifier name which will be appended to the base name derived from the type
argument.type
and name
arguments.NullArgumentException
- if any of the two arguments are null
or either string is empty.public static QualifiedName fromFQN(String fullQualifiedName)
This factory method is the reverse of toString()
method, and creates a new QualifiedName
instance from the string representation of the QualifiedName.
fullQualifiedName
- The QualifiedName external string representation to be converted back into a QualifiedName
instance.qualifiedName
argument.IllegalArgumentException
- If the qualifiedName
argument has wrong format.public String type()
The normalized type name means that all dollar ($) characters have been replaced by dashes (-).
public String name()
public String toURI()
The URI is the toNamespace()
followed by the name
component.
toNamespace()
public String toNamespace()
TypeName
component of the QualifiedName.
The URI of the TypeName
component is in the form of;
"urn:qi4j:type:" normalizedClassName
where normalizedClassName
is the fully-qualified class name having had any dollar ($) characters replaced
by URI friendly dashes (-), with a trailing hash (#). Examples;
urn:qi4j:type:org.qi4j.api.common.QualifiedName# urn:qi4j:type:org.qi4j.samples.MyClass-MyInnerClass#
TypeName
component of the QualifiedName.public String toString()
This returns the TypeName.toString()
followed by the name
component.
public int compareTo(QualifiedName other)
compareTo
in interface Comparable<QualifiedName>