Issue fix for config subsystem
[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         }
77         if (obj == null) {
78             return false;
79         }
80         if (getClass() != obj.getClass()) {
81             return false;
82         }
83         AbstractFeatureWrapper other = (AbstractFeatureWrapper) obj;
84         if (feature == null) {
85             if (other.feature != null) {
86                 return false;
87             }
88         } else if (!feature.equals(other.feature)) {
89             return false;
90         }
91         return true;
92     }
93
94     @Override
95     public String toString() {
96         return feature.getName();
97     }
98
99     /**
100      * @return
101      * @see org.apache.karaf.features.Feature#getId()
102      */
103     public String getId() {
104         return feature.getId();
105     }
106
107     /**
108      * @return
109      * @see org.apache.karaf.features.Feature#getName()
110      */
111     public String getName() {
112         return feature.getName();
113     }
114
115     /**
116      * @return
117      * @see org.apache.karaf.features.Feature#getDescription()
118      */
119     public String getDescription() {
120         return feature.getDescription();
121     }
122
123     /**
124      * @return
125      * @see org.apache.karaf.features.Feature#getDetails()
126      */
127     public String getDetails() {
128         return feature.getDetails();
129     }
130
131     /**
132      * @return
133      * @see org.apache.karaf.features.Feature#getVersion()
134      */
135     public String getVersion() {
136         return feature.getVersion();
137     }
138
139     /**
140      * @return
141      * @see org.apache.karaf.features.Feature#hasVersion()
142      */
143     public boolean hasVersion() {
144         return feature.hasVersion();
145     }
146
147     /**
148      * @return
149      * @see org.apache.karaf.features.Feature#getResolver()
150      */
151     public String getResolver() {
152         return feature.getResolver();
153     }
154
155     /**
156      * @return
157      * @see org.apache.karaf.features.Feature#getInstall()
158      */
159     public String getInstall() {
160         return feature.getInstall();
161     }
162
163     /**
164      * @return
165      * @see org.apache.karaf.features.Feature#getDependencies()
166      */
167     public List<Dependency> getDependencies() {
168         return feature.getDependencies();
169     }
170
171     /**
172      * @return
173      * @see org.apache.karaf.features.Feature#getBundles()
174      */
175     public List<BundleInfo> getBundles() {
176         return feature.getBundles();
177     }
178
179     /**
180      * @return
181      * @see org.apache.karaf.features.Feature#getConfigurations()
182      */
183     public Map<String, Map<String, String>> getConfigurations() {
184         return feature.getConfigurations();
185     }
186
187     /**
188      * @return
189      * @see org.apache.karaf.features.Feature#getConfigurationFiles()
190      */
191     public List<ConfigFileInfo> getConfigurationFiles() {
192         return feature.getConfigurationFiles();
193     }
194
195     /**
196      * @return
197      * @see org.apache.karaf.features.Feature#getConditional()
198      */
199     public List<? extends Conditional> getConditional() {
200         return feature.getConditional();
201     }
202
203     /**
204      * @return
205      * @see org.apache.karaf.features.Feature#getStartLevel()
206      */
207     public int getStartLevel() {
208         return feature.getStartLevel();
209     }
210
211     /**
212      * @return
213      * @see org.apache.karaf.features.Feature#getRegion()
214      */
215     public String getRegion() {
216         return feature.getRegion();
217     }
218
219 }