Merge "Optimizations, Monitoring and Logging"
[controller.git] / opendaylight / config / config-persister-feature-adapter / src / main / java / org / opendaylight / controller / configpusherfeature / internal / AbstractFeatureWrapper.java
1 /*
2  * Copyright (c) 2014 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.configpusherfeature.internal;
9
10 import java.util.LinkedHashSet;
11 import java.util.List;
12 import java.util.Map;
13
14 import javax.xml.bind.JAXBException;
15
16 import org.apache.karaf.features.BundleInfo;
17 import org.apache.karaf.features.Conditional;
18 import org.apache.karaf.features.ConfigFileInfo;
19 import org.apache.karaf.features.Dependency;
20 import org.apache.karaf.features.Feature;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import com.google.common.base.Preconditions;
25
26 /*
27  * Wrap a Feature for the purposes of extracting the FeatureConfigSnapshotHolders from
28  * its underlying ConfigFileInfo's
29  *
30  * Delegates the the contained feature and provides additional methods.
31  */
32 public class AbstractFeatureWrapper implements Feature {
33     private static final Logger logger = LoggerFactory.getLogger(AbstractFeatureWrapper.class);
34     protected Feature feature = null;
35
36     protected AbstractFeatureWrapper() {
37         // prevent instantiation without Feature
38     }
39
40     /*
41      * @param f Feature to wrap
42      */
43     public AbstractFeatureWrapper(Feature f) {
44         Preconditions.checkNotNull(f,"FeatureWrapper requires non-null Feature in constructor");
45         this.feature = f;
46     }
47
48     /*
49      * Get FeatureConfigSnapshotHolders appropriate to feed to the config subsystem
50      * from the underlying Feature Config files
51      */
52     public LinkedHashSet<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
53         LinkedHashSet <FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<FeatureConfigSnapshotHolder>();
54         for(ConfigFileInfo c: getConfigurationFiles()) {
55             try {
56                 snapShotHolders.add(new FeatureConfigSnapshotHolder(c,this));
57             } catch (JAXBException e) {
58                 logger.debug("{} is not a config subsystem config file",c.getFinalname());
59             }
60         }
61         return snapShotHolders;
62     }
63
64     @Override
65     public int hashCode() {
66         final int prime = 31;
67         int result = 1;
68         result = prime * result + ((feature == null) ? 0 : feature.hashCode());
69         return result;
70     }
71
72     @Override
73     public boolean equals(Object obj) {
74         if (this == obj)
75             return true;
76         if (obj == null)
77             return false;
78         if (getClass() != obj.getClass())
79             return false;
80         AbstractFeatureWrapper other = (AbstractFeatureWrapper) obj;
81         if (feature == null) {
82             if (other.feature != null)
83                 return false;
84         } else if (!feature.equals(other.feature))
85             return false;
86         return true;
87     }
88
89     @Override
90     public String toString() {
91         return feature.getName();
92     }
93
94     /**
95      * @return
96      * @see org.apache.karaf.features.Feature#getId()
97      */
98     public String getId() {
99         return feature.getId();
100     }
101
102     /**
103      * @return
104      * @see org.apache.karaf.features.Feature#getName()
105      */
106     public String getName() {
107         return feature.getName();
108     }
109
110     /**
111      * @return
112      * @see org.apache.karaf.features.Feature#getDescription()
113      */
114     public String getDescription() {
115         return feature.getDescription();
116     }
117
118     /**
119      * @return
120      * @see org.apache.karaf.features.Feature#getDetails()
121      */
122     public String getDetails() {
123         return feature.getDetails();
124     }
125
126     /**
127      * @return
128      * @see org.apache.karaf.features.Feature#getVersion()
129      */
130     public String getVersion() {
131         return feature.getVersion();
132     }
133
134     /**
135      * @return
136      * @see org.apache.karaf.features.Feature#hasVersion()
137      */
138     public boolean hasVersion() {
139         return feature.hasVersion();
140     }
141
142     /**
143      * @return
144      * @see org.apache.karaf.features.Feature#getResolver()
145      */
146     public String getResolver() {
147         return feature.getResolver();
148     }
149
150     /**
151      * @return
152      * @see org.apache.karaf.features.Feature#getInstall()
153      */
154     public String getInstall() {
155         return feature.getInstall();
156     }
157
158     /**
159      * @return
160      * @see org.apache.karaf.features.Feature#getDependencies()
161      */
162     public List<Dependency> getDependencies() {
163         return feature.getDependencies();
164     }
165
166     /**
167      * @return
168      * @see org.apache.karaf.features.Feature#getBundles()
169      */
170     public List<BundleInfo> getBundles() {
171         return feature.getBundles();
172     }
173
174     /**
175      * @return
176      * @see org.apache.karaf.features.Feature#getConfigurations()
177      */
178     public Map<String, Map<String, String>> getConfigurations() {
179         return feature.getConfigurations();
180     }
181
182     /**
183      * @return
184      * @see org.apache.karaf.features.Feature#getConfigurationFiles()
185      */
186     public List<ConfigFileInfo> getConfigurationFiles() {
187         return feature.getConfigurationFiles();
188     }
189
190     /**
191      * @return
192      * @see org.apache.karaf.features.Feature#getConditional()
193      */
194     public List<? extends Conditional> getConditional() {
195         return feature.getConditional();
196     }
197
198     /**
199      * @return
200      * @see org.apache.karaf.features.Feature#getStartLevel()
201      */
202     public int getStartLevel() {
203         return feature.getStartLevel();
204     }
205
206     /**
207      * @return
208      * @see org.apache.karaf.features.Feature#getRegion()
209      */
210     public String getRegion() {
211         return feature.getRegion();
212     }
213
214 }