KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > components > VersionContainer


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.components;
25
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28
29 /**
30  * Class to support staging and versioning of components. Each
31  * {@link ComponentList ComponentList} has two collections of VersionContainers,
32  * one containing the published (live) components, the other one containing
33  * preview versions. Each container may in turn have a live and a preview
34  * version of the actual component data.
35  */

36 public class VersionContainer {
37
38     private Long JavaDoc id;
39
40     private ComponentList liveList;
41
42     private ComponentList previewList;
43
44     private ComponentVersion liveVersion;
45
46     private ComponentVersion previewVersion;
47
48     private Set JavaDoc versions;
49
50     private Set JavaDoc childLists;
51
52     public VersionContainer() {
53     }
54
55     public Long JavaDoc getId() {
56         return this.id;
57     }
58
59     public void setId(Long JavaDoc id) {
60         this.id = id;
61     }
62
63     public ComponentList getList() {
64         return this.previewList != null ? previewList : liveList;
65     }
66
67     public void setList(ComponentList list) {
68         this.liveList = list;
69         this.previewList = list;
70     }
71
72     public ComponentVersion getLiveVersion() {
73         return this.liveVersion;
74     }
75
76     public void setLiveVersion(ComponentVersion liveVersion) {
77         this.liveVersion = liveVersion;
78         if (liveVersion != null) {
79             liveVersion.setContainer(this);
80         }
81     }
82
83     public ComponentVersion getPreviewVersion() {
84         return this.previewVersion;
85     }
86
87     public void setPreviewVersion(ComponentVersion previewVersion) {
88         this.previewVersion = previewVersion;
89         if (previewVersion != null) {
90             previewVersion.setContainer(this);
91         }
92     }
93
94     public Set JavaDoc getVersions() {
95         return this.versions;
96     }
97
98     public void setVersions(Set JavaDoc versions) {
99         this.versions = versions;
100     }
101
102     public Set JavaDoc getChildLists() {
103         return this.childLists;
104     }
105
106     public void setChildLists(Set JavaDoc childLists) {
107         this.childLists = childLists;
108     }
109
110     public ComponentVersion getLatestVersion() {
111         return previewVersion != null ? previewVersion : liveVersion;
112     }
113
114     public boolean isDirty() {
115         return previewVersion != null;
116     }
117
118     public boolean isPublished() {
119         return liveVersion != null;
120     }
121
122     public Map JavaDoc getProperties(boolean preview) {
123         if (preview) {
124             return getLatestVersion().getProperties();
125         }
126         return liveVersion != null ? liveVersion.getProperties() : null;
127     }
128
129     public String JavaDoc getProperty(String JavaDoc key, boolean preview) {
130         ComponentVersion version = preview ? getLatestVersion() : liveVersion;
131         return version != null ? version.getProperty(key) : null;
132     }
133
134 }
135
Popular Tags