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