3 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.config.facade.xml;
12 import com.google.common.collect.Multimap;
14 import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry;
15 import org.opendaylight.controller.config.facade.xml.mapping.config.Config;
16 import org.opendaylight.controller.config.facade.xml.mapping.config.ModuleElementDefinition;
17 import org.opendaylight.controller.config.facade.xml.mapping.config.ModuleElementResolved;
18 import org.opendaylight.controller.config.facade.xml.mapping.config.ServiceRegistryWrapper;
19 import org.opendaylight.controller.config.facade.xml.mapping.config.Services;
20 import org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType;
21 import org.opendaylight.controller.config.util.xml.DocumentedException;
22 import org.opendaylight.controller.config.util.xml.XmlElement;
24 public class ConfigExecution {
26 private final TestOption testOption;
27 private final EditStrategyType defaultEditStrategyType;
28 private final Services services;
29 private final Config configResolver;
30 private final XmlElement configElement;
32 public ConfigExecution(Config configResolver, XmlElement configElement, TestOption testOption, 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(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
50 return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
53 public ServiceRegistryWrapper getServiceRegistryWrapper(ServiceReferenceReadableRegistry serviceRegistry) {
54 // TODO cache service registry
55 return new ServiceRegistryWrapper(serviceRegistry);
58 public Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
59 return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
62 public EditStrategyType getDefaultStrategy() {
63 return defaultEditStrategyType;
66 public Services getServices() {
70 public XmlElement getConfigElement() {