1 package org
.argeo
.api
.acr
;
3 import java
.util
.function
.Supplier
;
5 import javax
.xml
.XMLConstants
;
6 import javax
.xml
.namespace
.NamespaceContext
;
7 import javax
.xml
.namespace
.QName
;
9 /** An optionally qualified name. Primarily meant to be used in enums. */
10 public interface QNamed
extends Supplier
<String
> {
13 /** To be overridden when XML naming is not compatible with Java naming. */
14 default String
localName() {
19 * A {@link QName} corresponding to this definition. Calls
20 * {@link #createQName()} by default, but it could return a cached value.
22 default QName
qName() {
27 * A prefixed representation of this qualified name within the provided
28 * {@link NamespaceContext}.
30 default String
get(NamespaceContext namespaceContext
) {
31 return namespaceContext
.getPrefix(getNamespace()) + ":" + localName();
35 * Create a {@link QName} corresponding on this definition. Can typically be
36 * used to cache the {@link QName} in enums.
38 default QName
createQName() {
39 return new ContentName(getNamespace(), localName(), getDefaultPrefix());
43 * This qualified named with its default prefix. If it is unqualified this
44 * method should be overridden, or QNamed.Unqualified be used.
46 default String
get() {
47 return getDefaultPrefix() + ":" + localName();
50 /** The namespace URI of this qualified name. */
51 String
getNamespace();
54 * The default prefix of this qualified name, as expected to be found in
55 * {@link RuntimeNamespaceContext}.
57 String
getDefaultPrefix();
59 /** Compares to a plain {@link QName}. */
60 default boolean equals(QName qName
) {
61 return qName().equals(qName
);
64 /** To be used by enums without namespace (typically XML attributes). */
65 static interface Unqualified
extends QNamed
{
67 default String
getNamespace() {
68 return XMLConstants
.NULL_NS_URI
;
72 default String
getDefaultPrefix() {
73 return XMLConstants
.DEFAULT_NS_PREFIX
;
77 default String
get() {