KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > version > common > VersionImpl


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.version.common;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Date JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.alfresco.repo.version.VersionModel;
24 import org.alfresco.service.cmr.repository.NodeRef;
25 import org.alfresco.service.cmr.repository.StoreRef;
26 import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
27 import org.alfresco.service.cmr.repository.datatype.TypeConverter;
28 import org.alfresco.service.cmr.version.Version;
29 import org.alfresco.service.cmr.version.VersionServiceException;
30 import org.alfresco.service.cmr.version.VersionType;
31
32
33 /**
34  * Version class implementation.
35  *
36  * Used to represent the data about a version stored in a version store.
37  *
38  * @author Roy Wetherall
39  */

40 public class VersionImpl implements Version
41 {
42     /**
43      * Serial version UID
44      */

45     private static final long serialVersionUID = 3257567304324888881L;
46     
47     /**
48      * Error message(s)
49      */

50     private static final String JavaDoc ERR_NO_NODE_REF = "A valid node reference must be supplied when creating a verison.";
51     
52     /**
53      * The properties of the version
54      */

55     private Map JavaDoc<String JavaDoc, Serializable JavaDoc> versionProperties = null;
56     
57     /**
58      * The node reference that represents the frozen state of the versioned object
59      */

60     private NodeRef nodeRef = null;
61     
62     /**
63      * Constructor that initialises the state of the version object.
64      *
65      * @param versionProperties the version properties
66      * @param nodeRef the forzen state node reference
67      */

68     public VersionImpl(
69             Map JavaDoc<String JavaDoc, Serializable JavaDoc> versionProperties,
70             NodeRef nodeRef)
71     {
72         if (nodeRef == null)
73         {
74             // Exception - a node ref must be specified
75
throw new VersionServiceException(VersionImpl.ERR_NO_NODE_REF);
76         }
77         
78         this.versionProperties = versionProperties;
79         this.nodeRef = nodeRef;
80     }
81     
82
83     /**
84      * Helper method to get the created date from the version property data.
85      *
86      * @return the date the version was created
87      */

88     public Date JavaDoc getCreatedDate()
89     {
90         return (Date JavaDoc)this.versionProperties.get(VersionModel.PROP_CREATED_DATE);
91     }
92     
93     public String JavaDoc getCreator()
94     {
95         return (String JavaDoc)this.versionProperties.get(VersionModel.PROP_CREATOR);
96     }
97
98     /**
99      * Helper method to get the version label from the version property data.
100      *
101      * @return the version label
102      */

103     public String JavaDoc getVersionLabel()
104     {
105         return (String JavaDoc)this.versionProperties.get(VersionModel.PROP_VERSION_LABEL);
106     }
107     
108     /**
109      * Helper method to get the version type.
110      *
111      * @return the value of the version type as an enum value
112      */

113     public VersionType getVersionType()
114     {
115         return (VersionType)this.versionProperties.get(VersionModel.PROP_VERSION_TYPE);
116     }
117     
118     /**
119      * Helper method to get the version description.
120      *
121      * @return the version description
122      */

123     public String JavaDoc getDescription()
124     {
125         return (String JavaDoc)this.versionProperties.get(PROP_DESCRIPTION);
126     }
127     
128     /**
129      * @see org.alfresco.service.cmr.version.Version#getVersionProperties()
130      */

131     public Map JavaDoc<String JavaDoc, Serializable JavaDoc> getVersionProperties()
132     {
133         return this.versionProperties;
134     }
135
136     /**
137      * @see org.alfresco.service.cmr.version.Version#getVersionProperty(java.lang.String)
138      */

139     public Serializable JavaDoc getVersionProperty(String JavaDoc name)
140     {
141         Serializable JavaDoc result = null;
142         if (this.versionProperties != null)
143         {
144             result = this.versionProperties.get(name);
145         }
146         return result;
147     }
148     
149     /**
150      * @see org.alfresco.service.cmr.version.Version#getVersionedNodeRef()
151      */

152     public NodeRef getVersionedNodeRef()
153     {
154         String JavaDoc storeProtocol = (String JavaDoc)this.versionProperties.get(VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL);
155         String JavaDoc storeId = (String JavaDoc)this.versionProperties.get(VersionModel.PROP_FROZEN_NODE_STORE_ID);
156         String JavaDoc nodeId = (String JavaDoc)this.versionProperties.get(VersionModel.PROP_FROZEN_NODE_ID);
157         return new NodeRef(new StoreRef(storeProtocol, storeId), nodeId);
158     }
159
160     /**
161      * @see org.alfresco.service.cmr.version.Version#getFrozenStateNodeRef()
162      */

163     public NodeRef getFrozenStateNodeRef()
164     {
165         return this.nodeRef;
166     }
167     
168     /**
169      * Static block to register the version type converters
170      */

171     static
172     {
173         DefaultTypeConverter.INSTANCE.addConverter(
174                 String JavaDoc.class,
175                 VersionType.class,
176                 new TypeConverter.Converter<String JavaDoc, VersionType>()
177                 {
178                     public VersionType convert(String JavaDoc source)
179                     {
180                         return VersionType.valueOf(source);
181                     }
182         
183                 });
184         
185         DefaultTypeConverter.INSTANCE.addConverter(
186                 VersionType.class,
187                 String JavaDoc.class,
188                 new TypeConverter.Converter<VersionType, String JavaDoc>()
189                 {
190                     public String JavaDoc convert(VersionType source)
191                     {
192                         return source.toString();
193                     }
194         
195                 });
196     }
197  }
198
Popular Tags