Remove yang-test
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / ConfigExecution.java
1 /*
2  * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.config.facade.xml;
10
11 import com.google.common.collect.Multimap;
12 import java.util.Map;
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;
22
23 public class ConfigExecution {
24
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;
30
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;
39     }
40
41     public boolean shouldTest() {
42         return testOption == TestOption.testOnly || testOption == TestOption.testThenSet;
43     }
44
45     public boolean shouldSet() {
46         return testOption == TestOption.set || testOption == TestOption.testThenSet;
47     }
48
49     public Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(
50             final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
51         return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType,
52                 getServiceRegistryWrapper(serviceRegistry));
53     }
54
55     public ServiceRegistryWrapper getServiceRegistryWrapper(final ServiceReferenceReadableRegistry serviceRegistry) {
56         // TODO cache service registry
57         return new ServiceRegistryWrapper(serviceRegistry);
58     }
59
60     public Map<String, Multimap<String, ModuleElementDefinition>> getModulesDefinition(
61             final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
62         return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType,
63                 getServiceRegistryWrapper(serviceRegistry));
64     }
65
66     public EditStrategyType getDefaultStrategy() {
67         return defaultEditStrategyType;
68     }
69
70     public Services getServices() {
71         return services;
72     }
73
74     public XmlElement getConfigElement() {
75         return configElement;
76     }
77 }