]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.acr/src/org/argeo/api/acr/AttributeFormatter.java
Introduce UUID identified and openForEdit/freeze cycle
[lgpl/argeo-commons.git] / org.argeo.api.acr / src / org / argeo / api / acr / AttributeFormatter.java
1 package org.argeo.api.acr;
2
3 import javax.xml.namespace.NamespaceContext;
4
5 /**
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.
11 */
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);
16 }
17
18 /**
19 * Parses a String to a Java object, possibly using the namespace context to
20 * resolve QName or CURIE.
21 */
22 T parse(NamespaceContext namespaceContext, String str) throws IllegalArgumentException;
23
24 /** Default implementation returns {@link Object#toString()} on the argument. */
25 default String format(T obj) {
26 return obj.toString();
27 }
28 }