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 package info.magnolia.config.registry;
35
36 import info.magnolia.config.source.ConfigurationSourceType;
37
38 import lombok.Getter;
39 import lombok.Value;
40
41
42
43
44
45
46
47
48
49 @Getter
50 public abstract class DefinitionMetadataBuilder {
51
52
53
54 public static DefinitionMetadataBuilder usingModuleAndRelativePathAsId() {
55 return new ModuleAndRelativePathMetadataBuilder();
56 }
57
58
59
60
61 public static DefinitionMetadataBuilder usingNameAsId() {
62 return new NameMetadataBuilder();
63 }
64
65 private static class ModuleAndRelativePathMetadataBuilder extends DefinitionMetadataBuilder {
66 @Override
67 protected String buildReferenceId() {
68 return getModule() + ":" + getRelativeLocation();
69 }
70 }
71
72 private static class NameMetadataBuilder extends DefinitionMetadataBuilder {
73 @Override
74 protected String buildReferenceId() {
75 return getName();
76 }
77 }
78
79 private DefinitionType type;
80 private String name;
81 private String module;
82 private String location;
83 private String relativeLocation;
84 private ConfigurationSourceType configurationSourceType;
85
86 protected DefinitionMetadataBuilder() {
87 }
88
89 public DefinitionMetadataBuilder type(DefinitionType type) {
90 this.type = type;
91 return this;
92 }
93
94 public DefinitionMetadataBuilder name(String name) {
95 this.name = name;
96 return this;
97 }
98
99 public DefinitionMetadataBuilder module(String module) {
100 this.module = module;
101 return this;
102 }
103
104 public DefinitionMetadataBuilder location(String location) {
105 this.location = location;
106 return this;
107 }
108
109 public DefinitionMetadataBuilder relativeLocation(String relativeLocation) {
110 this.relativeLocation = relativeLocation;
111 return this;
112 }
113
114 public DefinitionMetadataBuilder configurationSourceType(ConfigurationSourceType configurationSourceType) {
115 this.configurationSourceType = configurationSourceType;
116 return this;
117 }
118
119 public DefinitionMetadata build() {
120 final String referenceId = buildReferenceId();
121 return new DefinitionMetadataImpl(this.type, referenceId, this.name, this.module, this.location, this.relativeLocation, this.configurationSourceType);
122 }
123
124 protected abstract String buildReferenceId();
125
126
127
128
129 @Value
130 public static class DefinitionMetadataImpl implements DefinitionMetadata {
131 private final DefinitionType type;
132 private final String referenceId;
133 private final String name;
134 private final String module;
135 private final String location;
136 private final String relativeLocation;
137 private final ConfigurationSourceType configurationSourceType;
138
139 @Override
140 public String toString() {
141 return String.format("[%s] definition [%s] with reference id: [%s] from module [%s] at [%s]",
142 type.getName(), name, referenceId, module, relativeLocation);
143 }
144 }
145
146 }