e84e75aa4d8fe0378de11c99973a00b1726b3670
[controller.git] / opendaylight / config / config-persister-file-xml-adapter / src / main / java / org / opendaylight / controller / config / persist / storage / file / xml / model / ConfigSnapshot.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.persist.storage.file.xml.model;
9
10 import java.util.HashSet;
11 import java.util.Set;
12 import java.util.SortedSet;
13 import java.util.TreeSet;
14 import javax.xml.bind.annotation.XmlAnyElement;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlElementWrapper;
17 import javax.xml.bind.annotation.XmlRootElement;
18 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
19 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
20
21 @XmlRootElement(name = ConfigSnapshot.SNAPSHOT_ROOT_ELEMENT_NAME)
22 public class ConfigSnapshot {
23
24     public static final String SNAPSHOT_ROOT_ELEMENT_NAME = "snapshot";
25
26     private String configXml;
27     private SortedSet<String> capabilities = new TreeSet<>();
28     private Set<String> features = new HashSet<>();
29
30     ConfigSnapshot(final String configXml, final SortedSet<String> capabilities) {
31         this.configXml = configXml;
32         this.capabilities = capabilities;
33     }
34
35     ConfigSnapshot(final String configXml, final SortedSet<String> capabilities, final Set<String> features) {
36         this.configXml = configXml;
37         this.capabilities = capabilities;
38         this.features = features;
39     }
40
41     ConfigSnapshot() {
42     }
43
44     public static ConfigSnapshot fromConfigSnapshot(final ConfigSnapshotHolder cfg) {
45         return new ConfigSnapshot(cfg.getConfigSnapshot(), cfg.getCapabilities());
46     }
47
48     public static ConfigSnapshot fromConfigSnapshot(final ConfigSnapshotHolder cfg, final Set<String> features) {
49         return new ConfigSnapshot(cfg.getConfigSnapshot(), cfg.getCapabilities(), features);
50     }
51
52     @XmlAnyElement(SnapshotHandler.class)
53     public String getConfigSnapshot() {
54         return configXml;
55     }
56
57     public void setConfigSnapshot(final String configSnapshot) {
58         this.configXml = configSnapshot;
59     }
60
61     @XmlElement(name = "capability")
62     @XmlElementWrapper(name = "required-capabilities")
63     @XmlJavaTypeAdapter(value=StringTrimAdapter.class)
64     public SortedSet<String> getCapabilities() {
65         return capabilities;
66     }
67
68     public void setCapabilities(final SortedSet<String> capabilities) {
69         this.capabilities = capabilities;
70     }
71
72     @XmlElement(name = "feature")
73     @XmlElementWrapper(name = "features")
74     @XmlJavaTypeAdapter(value=StringTrimAdapter.class)
75     public Set<String> getFeatures() {
76         return features;
77     }
78
79     public void setFeatures(final Set<String> features) {
80         this.features = features;
81     }
82
83     @Override
84     public String toString() {
85         final StringBuilder sb = new StringBuilder("ConfigSnapshot{");
86         sb.append("configSnapshot='").append(configXml).append('\'');
87         sb.append(", capabilities=").append(capabilities);
88         sb.append(", features=").append(features);
89         sb.append('}');
90         return sb.toString();
91     }
92 }
93

©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.