summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java
Publish
Diffstat (limited to 'config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java')
-rw-r--r--config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java b/config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java
new file mode 100644
index 00000000000..2735b9f7fdf
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/config/model/ConfigModelRegistry.java
@@ -0,0 +1,51 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.config.model;
+
+import com.yahoo.config.model.builder.xml.ConfigModelBuilder;
+import com.yahoo.config.model.builder.xml.ConfigModelId;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A resolver of implementations of named config models.
+ * Registries may be chained in a chain of command.
+ *
+ * @author bratseth
+ */
+public abstract class ConfigModelRegistry {
+
+ private final ConfigModelRegistry chained;
+
+ public ConfigModelRegistry() {
+ this(new EmptyTerminalRegistry());
+ }
+
+ /** Creates a config model class registry which forwards unresolved requests to the argument instance */
+ public ConfigModelRegistry(ConfigModelRegistry chained) {
+ this.chained=chained;
+ }
+
+ /**
+ * Returns the builders this id resolves to both in this and any chained registry.
+ *
+ * @return the resolved config model builders, or an empty list (never null) if none
+ */
+ public abstract Collection<ConfigModelBuilder> resolve(ConfigModelId id);
+
+ public ConfigModelRegistry chained() { return chained; }
+
+ /** An empty registry which does not support chaining */
+ private static class EmptyTerminalRegistry extends ConfigModelRegistry {
+
+ public EmptyTerminalRegistry() {
+ super(null);
+ }
+
+ @Override
+ public Collection<ConfigModelBuilder> resolve(ConfigModelId id) {
+ return Collections.emptyList();
+ }
+ }
+
+}