Fix license header violations in controller
[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(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;
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(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
49         return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
50     }
51
52     public ServiceRegistryWrapper getServiceRegistryWrapper(ServiceReferenceReadableRegistry serviceRegistry) {
53         // TODO cache service registry
54         return new ServiceRegistryWrapper(serviceRegistry);
55     }
56
57     public Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
58         return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
59     }
60
61     public EditStrategyType getDefaultStrategy() {
62         return defaultEditStrategyType;
63     }
64
65     public Services getServices() {
66         return services;
67     }
68
69     public XmlElement getConfigElement() {
70         return configElement;
71     }
72 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.