2 * Copyright (c) 2015 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(Config configResolver, XmlElement configElement, TestOption testOption, EditStrategyType defaultStrategy) throws DocumentedException {
32 Config.checkUnrecognisedChildren(configElement);
33 this.configResolver = configResolver;
34 this.configElement = configElement;
35 this.services = configResolver.fromXmlServices(configElement);
36 this.testOption = testOption;
37 this.defaultEditStrategyType = defaultStrategy;
40 public boolean shouldTest() {
41 return testOption == TestOption.testOnly || testOption == TestOption.testThenSet;
44 public boolean shouldSet() {
45 return testOption == TestOption.set || testOption == TestOption.testThenSet;
48 public Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
49 return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
52 public ServiceRegistryWrapper getServiceRegistryWrapper(ServiceReferenceReadableRegistry serviceRegistry) {
53 // TODO cache service registry
54 return new ServiceRegistryWrapper(serviceRegistry);
57 public Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
58 return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
61 public EditStrategyType getDefaultStrategy() {
62 return defaultEditStrategyType;
65 public Services getServices() {
69 public XmlElement getConfigElement() {