KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collection JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 /**
26  * <p>Abstract class to make some virtual fields of child localizable.</p>
27  * <p>It has {@link ContentField}s that contain localized content for different
28  * languages, represented with {@link ContentLocale}s.</p> Localizable has a
29  * menu attached to it. That menu is formed with {@link MenuItem}s.</p>
30  * <p>Set of Content Fields and menu are inherited by {@link Layout}s, {@link Page}s
31  * and so on.</p>
32  * <p><a HREF="Localizable.java.htm"><i>View Source</i></a></p>
33  * <p/>
34  *
35  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
36  * @version $Revision: 1.32 $ $Date: 2005/12/18 16:43:43 $
37  * @hibernate.class table="`al_core_localizable`" lazy="false"
38  * @hibernate.cache usage="read-write"
39  */

40 public abstract class Localizable extends BaseObject {
41
42     //~ Instance fields ========================================================
43

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

47     protected Long JavaDoc id;
48     /**
49      * List of content fields that are owned by this localizable
50      */

51     protected List JavaDoc contentFields = new ArrayList JavaDoc();
52     /**
53      * List of menu items that are owned by this localizable
54      */

55     protected List JavaDoc menuItems = new ArrayList JavaDoc();
56     /**
57      * Version of this localizable (used in optimistic locking)
58      */

59     protected Long JavaDoc version;
60
61     /**
62      * Name of this class
63      */

64     protected String JavaDoc className = getClass().getName();
65
66     //~ Methods ================================================================
67

68     /**
69      * Returns the id of this localizable
70      *
71      * @return id
72      * @struts.form-field
73      * @hibernate.id column="`id`"
74      * generator-class="increment" unsaved-value="null"
75      */

76     public Long JavaDoc getId() {
77         return id;
78     }
79
80     /**
81      * Sets the id of this localizable
82      *
83      * @param id new id
84      */

85     public void setId(Long JavaDoc id) {
86         this.id = id;
87     }
88
89     /**
90      * Gets list of content fields that belong to this layout
91      *
92      * @return list of content fields
93      * @hibernate.bag name="fields" inverse="true" lazy="true" cascade="delete" outer-join="false"
94      * @hibernate.collection-key column="`localizable_id`"
95      * @hibernate.collection-one-to-many class="com.blandware.atleap.model.core.ContentField"
96      */

97     public List JavaDoc getContentFields() {
98         return contentFields;
99     }
100
101     /**
102      * Sets list of content fields that belong to this layout
103      *
104      * @param contentFields list of content fields
105      */

106     public void setContentFields(List JavaDoc contentFields) {
107         this.contentFields = contentFields;
108     }
109
110     /**
111      * Adds content field to this localizable
112      *
113      * @param contentField the field to be added
114      */

115     public void addContentField(ContentField contentField) {
116         contentField.setOwner(this);
117         contentFields.add(contentField);
118     }
119
120     /**
121      * Updates changed content field
122      *
123      * @param contentField the field to be updated
124      * @return content field that has been replaced
125      */

126     public ContentField updateContentField(ContentField contentField) {
127         ContentField oldContentField = null;
128         if ( !contentField.getOwner().equals(this) ) {
129             int index = contentField.getOwner().contentFields.indexOf(contentField);
130             if (index != -1)
131                 oldContentField = (ContentField)contentField.getOwner().contentFields.remove(index);
132             contentFields.add(contentField);
133             contentField.setOwner(this);
134         }
135         return oldContentField;
136     }
137
138     /**
139      * Removes content field from this localizable
140      *
141      * @param contentField the field to be removed
142      */

143     public void removeContentField(ContentField contentField) {
144         contentFields.remove(contentField);
145     }
146
147     /**
148      * Returns map with keys - contentField identifier and values - contentField
149      *
150      * @return mapping from CF identifiers to CFs
151      */

152     public Map JavaDoc getContentFieldsMap() {
153         Collection JavaDoc collection = getContentFields();
154         Map JavaDoc map = new HashMap JavaDoc();
155         for ( Iterator JavaDoc iterator = collection.iterator(); iterator.hasNext(); ) {
156             ContentField contentField = (ContentField) iterator.next();
157             map.put(contentField.getIdentifier(), contentField);
158         }
159         return map;
160     }
161
162     /**
163      * Returns list of menu items which lie in the menu layer of this owner
164      *
165      * @return list of menu items
166      * @hibernate.bag name="menuItems" inverse="true" lazy="true" cascade="delete" outer-join="false"
167      * @hibernate.collection-key column="`owner_id`"
168      * @hibernate.collection-one-to-many class="com.blandware.atleap.model.core.MenuItem"
169      */

170     protected List JavaDoc getMenuItems() {
171         return menuItems;
172     }
173
174     /**
175      * Sets list of menu items which lie in the menu layer of this owner
176      *
177      * @param menuItems list of menu items
178      */

179     protected void setMenuItems(List JavaDoc menuItems) {
180         this.menuItems = menuItems;
181     }
182
183     /**
184      * Returns fully-qualified Java class name of this class
185      *
186      * @return fully-qualified Java class name
187      * @hibernate.property column="`class_name`" length="252"
188      */

189     public String JavaDoc getClassName() {
190         return className;
191     }
192
193     /**
194      * Actually, does nothing (how can you change class of object at runtime?).
195      * This is just a stub.
196      *
197      * @param className ignored
198      */

199     public void setClassName(String JavaDoc className) {
200     }
201
202     /**
203      * Returns version of this localizable
204      *
205      * @return version
206      * @struts.form-field
207      * @hibernate.version column="`version`" type="long" unsaved-value="null"
208      */

209     public Long JavaDoc getVersion() {
210         return version;
211     }
212
213     /**
214      * Sets version of this localizable
215      *
216      * @param version new version
217      */

218     public void setVersion(Long JavaDoc version) {
219         this.version = version;
220     }
221
222
223 }
224
Popular Tags