Merge "Exception for URI /restconf/operations/module_name:rpc ended with slash"
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / dependencyresolver / ModuleInternalTransactionalInfo.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.controller.config.manager.impl.dependencyresolver;
9
10 import org.opendaylight.controller.config.api.ModuleIdentifier;
11 import org.opendaylight.controller.config.manager.impl.ModuleInternalInfo;
12 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
13 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration;
14 import org.opendaylight.controller.config.spi.Module;
15 import org.opendaylight.controller.config.spi.ModuleFactory;
16 import org.opendaylight.yangtools.concepts.Identifiable;
17
18 import javax.annotation.Nullable;
19
20 public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdentifier> {
21     private final ModuleIdentifier name;
22     private final Module proxiedModule, realModule;
23     private final ModuleFactory moduleFactory;
24     @Nullable
25     private final ModuleInternalInfo maybeOldInternalInfo;
26     private final TransactionModuleJMXRegistration transactionModuleJMXRegistration;
27     private final boolean isDefaultBean;
28
29     public ModuleInternalTransactionalInfo(ModuleIdentifier name, Module proxiedModule,
30                                            ModuleFactory moduleFactory,
31                                            ModuleInternalInfo maybeOldInternalInfo,
32                                            TransactionModuleJMXRegistration transactionModuleJMXRegistration,
33                                            boolean isDefaultBean, Module realModule) {
34         this.name = name;
35         this.proxiedModule = proxiedModule;
36         this.moduleFactory = moduleFactory;
37         this.maybeOldInternalInfo = maybeOldInternalInfo;
38         this.transactionModuleJMXRegistration = transactionModuleJMXRegistration;
39         this.isDefaultBean = isDefaultBean;
40         this.realModule = realModule;
41     }
42
43
44     public boolean hasOldModule() {
45         return maybeOldInternalInfo != null;
46     }
47
48     public DestroyedModule toDestroyedModule() {
49         if (maybeOldInternalInfo == null) {
50             throw new IllegalStateException("Cannot destroy uncommitted module");
51         }
52         DynamicReadableWrapper oldModule = maybeOldInternalInfo
53                 .getReadableModule();
54         return new DestroyedModule(name, oldModule.getInstance(),
55                 maybeOldInternalInfo.getModuleJMXRegistrator(),
56                 maybeOldInternalInfo.getOsgiRegistration(),
57                 maybeOldInternalInfo.getOrderingIdx());
58     }
59
60
61     public Module getProxiedModule() {
62         return proxiedModule;
63     }
64
65     public ModuleFactory getModuleFactory() {
66         return moduleFactory;
67     }
68
69     @Nullable
70     public ModuleInternalInfo getOldInternalInfo() {
71         if (maybeOldInternalInfo == null) {
72             throw new NullPointerException();
73         }
74         return maybeOldInternalInfo;
75     }
76
77     public TransactionModuleJMXRegistration getTransactionModuleJMXRegistration() {
78         return transactionModuleJMXRegistration;
79     }
80
81     @Override
82     public ModuleIdentifier getIdentifier() {
83         return name;
84     }
85
86     public boolean isDefaultBean() {
87         return isDefaultBean;
88     }
89
90     public Module getRealModule() {
91         return realModule;
92     }
93 }