KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > model > core > ContentFieldValue


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.model.core;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * <p>Content Field Value (CFV) represents locale-dependent content of some {@link ContentField}.
24  * It has a {@link ContentLocale} attached to it. That Content Locale is one
25  * that corresponds to this Content Field Value.</p>
26  * <p>Each Content Field Value belongs to some Content Field, which may have one
27  * of three types: <b>LINE_TYPE</b>, <b>MULTILINE_TYPE</b> and <b>HTML_TYPE</b>.
28  * If field has first of this types, CFV's value is stored as <b>simpleValue</b>,
29  * else it's stored in <b>value</b>.</p>
30  * <p><a HREF="ContentFieldValue.java.htm"><i>View Source</i></a>
31  * </p>
32  * <p/>
33  *
34  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
35  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
36  * @version $Revision: 1.33 $ $Date: 2005/12/18 16:43:42 $
37  * @see ContentLocale
38  * @see ContentField
39  * @hibernate.class table="`al_core_field_value`" lazy="false" dynamic-update="true" dynamic-insert="true"
40  */

41 public class ContentFieldValue extends BaseObject {
42     //~ Instance fields ========================================================
43

44     /**
45      * The ID of this CFV
46      */

47     protected Long JavaDoc id;
48     /**
49      * Content locale that corresponds to this value
50      */

51     protected ContentLocale contentLocale;
52     /**
53      * The value of this CFV if field type is not <code>LINE_TYPE</code>
54      */

55     protected byte[] value;
56     /**
57      * The value of this CFV if field type is <code>LINE_TYPE</code>
58      */

59     protected String JavaDoc simpleValue;
60     /**
61      * Content field to which this CFV belong
62      */

63     protected ContentField contentField;
64     /**
65      * Date and time of last update of this CFV
66      */

67     protected Date JavaDoc lastUpdatedDatetime = null;
68     /**
69      * Version of this field (used in optimistic locking)
70      */

71     protected Long JavaDoc version;
72
73     /**
74      * List of pages that are linked to this CFV
75      */

76     protected List JavaDoc linkedPages = new ArrayList JavaDoc();
77     /**
78      * List of content resources that are linked to this CFV
79      */

80     protected List JavaDoc linkedResources = new ArrayList JavaDoc();
81
82     //~ Methods ================================================================
83
/**
84      * Returns the id of this content field value
85      *
86      * @return the id
87      * @struts.form-field
88      * @hibernate.id column="`id`"
89      * generator-class="increment" unsaved-value="null"
90      */

91     public Long JavaDoc getId() {
92         return id;
93     }
94
95     /**
96      * Sets the id of this content field value
97      *
98      * @param id new id
99      */

100     public void setId(Long JavaDoc id) {
101         this.id = id;
102     }
103
104     /**
105      * Returns the content locale of this content field value
106      *
107      * @return the content locale
108      * @struts.form-field
109      * @hibernate.many-to-one column="`locale_identifier`" not-null="false" outer-join="false" lazy="false"
110      */

111     public ContentLocale getContentLocale() {
112         return contentLocale;
113     }
114
115     /**
116      * Sets the content locale of this content field value
117      *
118      * @param contentLocale new content locale
119      */

120     public void setContentLocale(ContentLocale contentLocale) {
121         this.contentLocale = contentLocale;
122     }
123
124     /**
125      * Returns the content for field with type <code>LINE_TYPE</code>
126      *
127      * @return value as of single-line
128      * @struts.form-field
129      * @hibernate.property
130      * @hibernate.column name="`simple_value`" not-null="false" length="252"
131      */

132     public String JavaDoc getSimpleValue() {
133         return simpleValue;
134     }
135
136     /**
137      * Sets the content for field with type <code>LINE_TYPE</code>
138      *
139      * @param simpleValue the value to be set as a simple value
140      */

141     public void setSimpleValue(String JavaDoc simpleValue) {
142         this.simpleValue = simpleValue;
143     }
144
145     /**
146      * Returns the field to which this CFV belong
147      *
148      * @return a field
149      * @hibernate.many-to-one column="`field_id`" not-null="false" outer-join="false" lazy="false"
150      */

151     public ContentField getContentField() {
152         return contentField;
153     }
154
155     /**
156      * Sets the field to which this CFV belong
157      *
158      * @param contentField new master field
159      */

160     public void setContentField(ContentField contentField) {
161         this.contentField = contentField;
162     }
163
164     /**
165      * Gets date/time when this content field value was created/last updated
166      *
167      * @return last updated datetime
168      * @hibernate.property
169      * @hibernate.column name="`last_updated`" not-null="true" unique="false"
170      */

171     public Date JavaDoc getLastUpdatedDatetime() {
172         return lastUpdatedDatetime;
173     }
174
175     /**
176      * Sets date/time when this content field value was created/last updated
177      *
178      * @param lastUpdatedDatetime the date/time of creation/last update
179      */

180     public void setLastUpdatedDatetime(Date JavaDoc lastUpdatedDatetime) {
181         this.lastUpdatedDatetime = lastUpdatedDatetime;
182     }
183
184     /**
185      * Returns version of this content field value
186      *
187      * @return the version
188      * @struts.form-field
189      * @hibernate.version column="`version`" type="long" unsaved-value="null"
190      */

191     public Long JavaDoc getVersion() {
192         return version;
193     }
194
195     /**
196      * Sets version of this content field value
197      *
198      * @param version new version
199      */

200     public void setVersion(Long JavaDoc version) {
201         this.version = version;
202     }
203
204     /**
205      * Gets list of pages this CFV is linked with
206      *
207      * @return the list of linked pages
208      * @hibernate.bag table="`al_core_field_value_page`" cascade="none" lazy="true" inverse="false" outer-join="false"
209      * @hibernate.collection-key column="`field_value_id`"
210      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.Page" column="`page_id`" outer-join="false"
211      */

212     public List JavaDoc getLinkedPages() {
213         return linkedPages;
214     }
215
216     /**
217      * Sets list of pages this CFV is linked with
218      *
219      * @param linkedPages the list of linked pages
220      */

221     public void setLinkedPages(List JavaDoc linkedPages) {
222         this.linkedPages = linkedPages;
223     }
224
225     /**
226      * Adds a connection between this CFV and a given page
227      *
228      * @param page the page to connect with
229      */

230     public void addLinkedPage(Page page) {
231         if ( !page.getLinkedContentFieldValues().contains(this) ) {
232             page.getLinkedContentFieldValues().add(this);
233         }
234         if ( !getLinkedPages().contains(page) ) {
235             getLinkedPages().add(page);
236         }
237     }
238
239     /**
240      * Removes a connection between this CFV and a given page
241      *
242      * @param page the page
243      */

244     public void removeLinkedPage(Page page) {
245         page.getLinkedContentFieldValues().remove(this);
246         getLinkedPages().remove(page);
247     }
248
249     /**
250      * Gets list of content resources this CFV is linked with
251      *
252      * @return the list of linked content resources
253      * @hibernate.bag table="`al_core_field_value_resource`" cascade="none" lazy="true" inverse="false" outer-join="false"
254      * @hibernate.collection-key column="`field_value_id`"
255      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.ContentResource" column="`resource_id`" outer-join="false"
256      */

257     public List JavaDoc getLinkedResources() {
258         return linkedResources;
259     }
260
261     /**
262      * Sets list of content resources this CFV is linked with
263      *
264      * @param linkedResources the list of linked content resources
265      */

266     public void setLinkedResources(List JavaDoc linkedResources) {
267         this.linkedResources = linkedResources;
268     }
269
270     /**
271      * Adds a connection between this CFV and a given content resource
272      *
273      * @param resource the resource to connect with
274      */

275     public void addLinkedResource(ContentResource resource) {
276         if ( !resource.getLinkedContentFieldValues().contains(this) ) {
277             resource.getLinkedContentFieldValues().add(this);
278         }
279         if ( !getLinkedPages().contains(resource) ) {
280             getLinkedPages().add(resource);
281         }
282     }
283
284     /**
285      * Removes a connection between this CFV and a given content resource
286      *
287      * @param resource the resource
288      */

289     public void removeLinkedResource(ContentResource resource) {
290         resource.getLinkedContentFieldValues().remove(this);
291         getLinkedResources().remove(resource);
292     }
293
294     /**
295      * Returns the content for field with type <code>MULTILINE_TYPE</code> and <code>HTML_TYPE</code>
296      *
297      * @return byte array of the content
298      * @struts.form-field
299      * @hibernate.property type="com.blandware.atleap.persistence.hibernate.util.BinaryBlobType"
300      * @hibernate.column name="`value`" not-null="false" length="16777215"
301      */

302     public byte[] getValue() {
303         return value;
304     }
305
306     /**
307      * Sets the content for field with type <code>MULTILINE_TYPE</code> and <code>HTML_TYPE</code>
308      *
309      * @param value byte array of the content
310      */

311     public void setValue(byte[] value) {
312         this.value = value;
313     }
314
315     public boolean equals(Object JavaDoc o) {
316         if ( this == o ) {
317             return true;
318         }
319         if ( !(o instanceof ContentFieldValue) ) {
320             return false;
321         }
322
323         final ContentFieldValue contentFieldValue = (ContentFieldValue) o;
324
325         if ( contentField != null ? !contentField.equals(contentFieldValue.contentField) : contentFieldValue.contentField != null ) {
326             return false;
327         }
328         if ( contentLocale != null ? !contentLocale.equals(contentFieldValue.contentLocale) : contentFieldValue.contentLocale != null ) {
329             return false;
330         }
331
332         return true;
333     }
334
335     public int hashCode() {
336         int result;
337         result = (contentLocale != null ? contentLocale.hashCode() : 0);
338         result = 29 * result + (contentField != null ? contentField.hashCode() : 0);
339         return result;
340     }
341
342 }
343
Popular Tags