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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.