-
Notifications
You must be signed in to change notification settings - Fork 612
/
ElementDefinition.java
68 lines (57 loc) · 2.06 KB
/
ElementDefinition.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.infinispan.commons.configuration.elements;
import org.infinispan.commons.configuration.ConfigurationInfo;
import org.infinispan.commons.configuration.attributes.Attribute;
/**
* Defines a container for a set of configuration {@link Attribute}. It is usually represented as a top level element
* when serialized as XML or a top level object for JSON and is associated with a Configuration instance.
*
* An ElementDefinition can contain zero or more sub-elements representing nested configurations.
*
*/
public interface ElementDefinition<C extends ConfigurationInfo> {
/**
* @return true if the ElementDefinition is top-level or false if its attributes and children should be merged with the
* parent element when serializing.
*/
boolean isTopLevel();
/**
* @return the {@link ElementOutput} for serialization purposes of the configuration element.
*/
ElementOutput toExternalName(C configuration);
default boolean omitIfEmpty() {
return true;
}
/**
* @return true if the attributeName inside the element is not mapped to any {@link Attribute}, but
* as a helper to identify the element when reading it back.
*/
default boolean isSynthetic(String attributeName) {
return false;
}
/**
* @return true if a serialized elementName matches this ElementDefinition.
*/
boolean supports(String elementName);
/**
* An ElementOutput specifies the name and optionally the class that an element must be serialized.
* When className is present, it will be serialized as a 'class' attribute inside the element.
*/
class ElementOutput {
private final String name;
private final String className;
public ElementOutput(String name, String className) {
this.name = name;
this.className = className;
}
public ElementOutput(String name) {
this.name = name;
this.className = null;
}
public String getName() {
return name;
}
public String getClassName() {
return className;
}
}
}