2 * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.config.facade.xml;
11 import com.google.common.collect.Multimap;
13 import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry;
14 import org.opendaylight.controller.config.facade.xml.mapping.config.Config;
15 import org.opendaylight.controller.config.facade.xml.mapping.config.ModuleElementDefinition;
16 import org.opendaylight.controller.config.facade.xml.mapping.config.ModuleElementResolved;
17 import org.opendaylight.controller.config.facade.xml.mapping.config.ServiceRegistryWrapper;
18 import org.opendaylight.controller.config.facade.xml.mapping.config.Services;
19 import org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType;
20 import org.opendaylight.controller.config.util.xml.DocumentedException;
21 import org.opendaylight.controller.config.util.xml.XmlElement;
23 public class ConfigExecution {
25 private final TestOption testOption;
26 private final EditStrategyType defaultEditStrategyType;
27 private final Services services;
28 private final Config configResolver;
29 private final XmlElement configElement;
31 public ConfigExecution(final Config configResolver, final XmlElement configElement, final TestOption testOption,
32 final EditStrategyType defaultStrategy) throws DocumentedException {
33 Config.checkUnrecognisedChildren(configElement);
34 this.configResolver = configResolver;
35 this.configElement = configElement;
36 this.services = configResolver.fromXmlServices(configElement);
37 this.testOption = testOption;
38 this.defaultEditStrategyType = defaultStrategy;
41 public boolean shouldTest() {
42 return testOption == TestOption.testOnly || testOption == TestOption.testThenSet;
45 public boolean shouldSet() {
46 return testOption == TestOption.set || testOption == TestOption.testThenSet;
49 public Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(
50 final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
51 return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType,
52 getServiceRegistryWrapper(serviceRegistry));
55 public ServiceRegistryWrapper getServiceRegistryWrapper(final ServiceReferenceReadableRegistry serviceRegistry) {
56 // TODO cache service registry
57 return new ServiceRegistryWrapper(serviceRegistry);
60 public Map<String, Multimap<String, ModuleElementDefinition>> getModulesDefinition(
61 final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
62 return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType,
63 getServiceRegistryWrapper(serviceRegistry));
66 public EditStrategyType getDefaultStrategy() {
67 return defaultEditStrategyType;
70 public Services getServices() {
74 public XmlElement getConfigElement() {