1 package org
.argeo
.api
.acr
;
3 import javax
.xml
.namespace
.NamespaceContext
;
6 * An attribute type MUST consistently parse a string to an object so that
7 * <code>parse(obj.toString()).equals(obj)</code> is verified.
8 * {@link #format(Object)} can be overridden to provide more efficient
9 * implementations but the returned <code>String</code> MUST be the same, that
10 * is <code>format(obj).equals(obj.toString())</code> is verified.
12 public interface AttributeFormatter
<T
> {
13 /** Parses a String to a Java object. */
14 default T
parse(String str
) throws IllegalArgumentException
{
15 return parse(RuntimeNamespaceContext
.getNamespaceContext(), str
);
19 * Parses a String to a Java object, possibly using the namespace context to
20 * resolve QName or CURIE.
22 T
parse(NamespaceContext namespaceContext
, String str
) throws IllegalArgumentException
;
24 /** Default implementation returns {@link Object#toString()} on the argument. */
25 default String
format(T obj
) {
26 return obj
.toString();