config-manager-facade-xml: final parameters
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / ConfigExecution.java
1 /*
2  * Copyright (c) 2015 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, final 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;
38     }
39
40     public boolean shouldTest() {
41         return testOption == TestOption.testOnly || testOption == TestOption.testThenSet;
42     }
43
44     public boolean shouldSet() {
45         return testOption == TestOption.set || testOption == TestOption.testThenSet;
46     }
47
48     public Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(
49             final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
50         return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
51     }
52
53     public ServiceRegistryWrapper getServiceRegistryWrapper(final ServiceReferenceReadableRegistry serviceRegistry) {
54         // TODO cache service registry
55         return new ServiceRegistryWrapper(serviceRegistry);
56     }
57
58     public Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(
59             final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
60         return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
61     }
62
63     public EditStrategyType getDefaultStrategy() {
64         return defaultEditStrategyType;
65     }
66
67     public Services getServices() {
68         return services;
69     }
70
71     public XmlElement getConfigElement() {
72         return configElement;
73     }
74 }