Remove unnecessary declaration of <prerequisites> in features
[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 javax.annotation.Nullable;
11 import org.opendaylight.controller.config.api.ModuleIdentifier;
12 import org.opendaylight.controller.config.manager.impl.ModuleInternalInfo;
13 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
14 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration;
15 import org.opendaylight.controller.config.spi.Module;
16 import org.opendaylight.controller.config.spi.ModuleFactory;
17 import org.opendaylight.yangtools.concepts.Identifiable;
18 import org.osgi.framework.BundleContext;
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     private final BundleContext bundleContext;
29
30     public ModuleInternalTransactionalInfo(ModuleIdentifier name, Module proxiedModule,
31                                            ModuleFactory moduleFactory,
32                                            ModuleInternalInfo maybeOldInternalInfo,
33                                            TransactionModuleJMXRegistration transactionModuleJMXRegistration,
34                                            boolean isDefaultBean, Module realModule, BundleContext bundleContext) {
35         this.name = name;
36         this.proxiedModule = proxiedModule;
37         this.moduleFactory = moduleFactory;
38         this.maybeOldInternalInfo = maybeOldInternalInfo;
39         this.transactionModuleJMXRegistration = transactionModuleJMXRegistration;
40         this.isDefaultBean = isDefaultBean;
41         this.realModule = realModule;
42         this.bundleContext = bundleContext;
43     }
44
45
46     public boolean hasOldModule() {
47         return maybeOldInternalInfo != null;
48     }
49
50     public DestroyedModule toDestroyedModule() {
51         if (maybeOldInternalInfo == null) {
52             throw new IllegalStateException("Cannot destroy uncommitted module");
53         }
54         DynamicReadableWrapper oldModule = maybeOldInternalInfo
55                 .getReadableModule();
56         return new DestroyedModule(name, oldModule.getInstance(),
57                 maybeOldInternalInfo.getModuleJMXRegistrator(),
58                 maybeOldInternalInfo.getOsgiRegistration(),
59                 maybeOldInternalInfo.getOrderingIdx());
60     }
61
62
63     public Module getProxiedModule() {
64         return proxiedModule;
65     }
66
67     public ModuleFactory getModuleFactory() {
68         return moduleFactory;
69     }
70
71     @Nullable
72     public ModuleInternalInfo getOldInternalInfo() {
73         if (maybeOldInternalInfo == null) {
74             throw new NullPointerException();
75         }
76         return maybeOldInternalInfo;
77     }
78
79     public TransactionModuleJMXRegistration getTransactionModuleJMXRegistration() {
80         return transactionModuleJMXRegistration;
81     }
82
83     @Override
84     public ModuleIdentifier getIdentifier() {
85         return name;
86     }
87
88     public boolean isDefaultBean() {
89         return isDefaultBean;
90     }
91
92     public Module getRealModule() {
93         return realModule;
94     }
95
96     public BundleContext getBundleContext() {
97         return bundleContext;
98     }
99 }