acf9fa215137bdecc933fadea6eb749339d101ac
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / ConfigExecution.java
1
2 /*
3  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.config.facade.xml;
11
12 import com.google.common.collect.Multimap;
13 import java.util.Map;
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;
23
24 public class ConfigExecution {
25
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;
31
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;
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(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
50         return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
51     }
52
53     public ServiceRegistryWrapper getServiceRegistryWrapper(ServiceReferenceReadableRegistry serviceRegistry) {
54         // TODO cache service registry
55         return new ServiceRegistryWrapper(serviceRegistry);
56     }
57
58     public Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
59         return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
60     }
61
62     public EditStrategyType getDefaultStrategy() {
63         return defaultEditStrategyType;
64     }
65
66     public Services getServices() {
67         return services;
68     }
69
70     public XmlElement getConfigElement() {
71         return configElement;
72     }
73 }