- @VisibleForTesting
- static enum TestOption {
- testOnly, set, testThenSet;
-
- static TestOption getFromXmlName(String testOptionXmlName) {
- switch (testOptionXmlName) {
- case "test-only":
- return testOnly;
- case "test-then-set":
- return testThenSet;
- case "set":
- return set;
- default:
- throw new IllegalArgumentException("Unsupported test option " + testOptionXmlName + " supported: "
- + Arrays.toString(TestOption.values()));
- }
- }
-
- public static TestOption getDefault() {
- return testThenSet;
- }
-
- }
-
- @VisibleForTesting
- static class EditConfigExecution {
-
- private final TestOption testOption;
- private final EditStrategyType defaultEditStrategyType;
- private final Services services;
- private final Config configResolver;
- private final XmlElement configElement;
-
- EditConfigExecution(Config configResolver, XmlElement configElement, TestOption testOption, EditStrategyType defaultStrategy) throws NetconfDocumentedException {
- Config.checkUnrecognisedChildren(configElement);
- this.configResolver = configResolver;
- this.configElement = configElement;
- this.services = configResolver.fromXmlServices(configElement);
- this.testOption = testOption;
- this.defaultEditStrategyType = defaultStrategy;
- }
-
- boolean shouldTest() {
- return testOption == TestOption.testOnly || testOption == TestOption.testThenSet;
- }
-
- boolean shouldSet() {
- return testOption == TestOption.set || testOption == TestOption.testThenSet;
- }
-
- Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(ServiceReferenceReadableRegistry serviceRegistry) throws NetconfDocumentedException {
- return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
- }
-
- ServiceRegistryWrapper getServiceRegistryWrapper(ServiceReferenceReadableRegistry serviceRegistry) {
- // TODO cache service registry
- return new ServiceRegistryWrapper(serviceRegistry);
- }
-
- Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(ServiceReferenceReadableRegistry serviceRegistry) throws NetconfDocumentedException {
- return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
- }
-
- EditStrategyType getDefaultStrategy() {
- return defaultEditStrategyType;
- }
-
- Services getServices() {
- return services;
- }