KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.blandware.atleap.common.util.CompositeID;
19 import com.blandware.atleap.common.util.ConvertUtil;
20
21 import java.io.Serializable JavaDoc;
22
23 /**
24  * <p>Class that holds application resource in form <code>localized_key=value</code>
25  * where <code>localized_key</code> is unique identifier, which consists of <code>key<code> itself and
26  * locale identifier
27  * </p>
28  * <p><a HREF="ApplicationResource.java.htm"><i>View Source</i></a></p>
29  * <p/>
30  *
31  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
32  * @version $Revision: 1.13 $ $Date: 2005/12/18 16:43:41 $
33  * @hibernate.class table="`al_core_app_resource`" lazy="false"
34  */

35 public class ApplicationResource extends BaseObject {
36
37     //~ Instance fields ========================================================
38

39     /**
40      * Composite ID of this resource
41      */

42     protected ApplicationResourceID id;
43
44     /**
45      * Value of this resource (associated with key and locale)
46      */

47     protected byte[] value;
48
49     /**
50      * Version of object
51      */

52     protected Long JavaDoc version;
53
54     //~ Constructors ===========================================================
55

56     /**
57      * Creates new instance of ApplicationResource
58      */

59     public ApplicationResource() {
60     }
61
62     /**
63      * Creates new instance of ApplicationResource
64      *
65      * @param locale Locale of message
66      * @param key Key to associate value with
67      * @param value Value to associate with specified ID
68      */

69     public ApplicationResource(ContentLocale locale, String JavaDoc key, String JavaDoc value) {
70         this.id = new ApplicationResourceID(locale, key);
71         this.value = ConvertUtil.convertToByteArray(value);
72     }
73
74     //~ Methods ================================================================
75

76     /**
77      * Returns ID of this resource
78      *
79      * @return ID of resource
80      * @hibernate.id generator-class="assigned" class="com.blandware.atleap.model.core.ApplicationResource$ApplicationResourceID"
81      */

82     public ApplicationResourceID getId() {
83         return id;
84     }
85
86     /**
87      * Sets ID of this resource
88      *
89      * @param id resource ID
90      */

91     public void setId(ApplicationResourceID id) {
92         this.id = id;
93     }
94
95     /**
96      * Returns version of this resource
97      *
98      * @return version
99      * @hibernate.version column="`version`" type="long" unsaved-value="null"
100      */

101     public Long JavaDoc getVersion() {
102         return version;
103     }
104
105     /**
106      * Sets version of this resource
107      *
108      * @param version new version
109      */

110     public void setVersion(Long JavaDoc version) {
111         this.version = version;
112     }
113
114     /**
115      * Returns value corresponding to this resource
116      *
117      * @return value
118      * @hibernate.property type="com.blandware.atleap.persistence.hibernate.util.BinaryBlobType" column="`resource_value`" not-null="false" unique="false" length="16777215"
119      */

120     public byte[] getValue() {
121         return value;
122     }
123
124     /**
125      * Sets value of this resource
126      *
127      * @param value new value
128      */

129     public void setValue(byte[] value) {
130         this.value = value;
131     }
132
133     public boolean equals(Object JavaDoc o) {
134         if ( this == o ) {
135             return true;
136         }
137         if ( !(o instanceof ApplicationResource) ) {
138             return false;
139         }
140
141         final ApplicationResource applicationResource = (ApplicationResource) o;
142
143         if ( !id.equals(applicationResource.id) ) {
144             return false;
145         }
146
147         return true;
148     }
149
150     public int hashCode() {
151         return id.hashCode();
152     }
153
154     /**
155      * <p>Class represents composite ID of ApplicationResource.</p>
156      * Composite ID consists of two fields: <ul>
157      * <li>key - key in bundle</li>
158      * <li>language - bundle language</li>
159      * </ul>
160      *
161      * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
162      * @version $Revision: 1.13 $ $Date: 2005/12/18 16:43:41 $
163      */

164     public static class ApplicationResourceID implements CompositeID, Serializable JavaDoc, Comparable JavaDoc {
165
166         /**
167          * Key of this resource in bundle
168          */

169         protected String JavaDoc key;
170
171         /**
172          * Locale associated with resource
173          */

174         protected ContentLocale locale;
175
176         /**
177          * Creates new instance of ApplicationResourceID
178          */

179         public ApplicationResourceID() {
180         }
181
182         /**
183          * Creates new instance of ApplicationResourceID
184          *
185          * @param locale Locale of resourcef x
186          * @param key Key of resource
187          */

188         public ApplicationResourceID(ContentLocale locale, String JavaDoc key) {
189             this.key = key;
190             this.locale = locale;
191         }
192
193         /**
194          * Returns key
195          *
196          * @return the key
197          * @hibernate.id
198          * @hibernate.property column="`resource_key`" not-null="true" unique="false" length="188"
199          */

200         public String JavaDoc getKey() {
201             return key;
202         }
203
204         /**
205          * Sets key of resource
206          *
207          * @param key the key
208          */

209         public void setKey(String JavaDoc key) {
210             this.key = key;
211         }
212
213         /**
214          * Returns locale
215          *
216          * @return the locale
217          * @hibernate.many-to-one class="com.blandware.atleap.model.core.ContentLocale" column="`locale_identifier`" outer-join="false"
218          */

219         public ContentLocale getLocale() {
220             return locale;
221         }
222
223         /**
224          * Sets locale of resource
225          *
226          * @param locale the locale
227          */

228         public void setLocale(ContentLocale locale) {
229             this.locale = locale;
230         }
231
232         /**
233          * Compares this application resource to another one. The comparison
234          * is made in two steps: first on <code>key</code>, than on <code>locale</code>,
235          * if keys are equal.
236          *
237          * @param o the object to compare to
238          * @return a negative integer, zero, or a positive integer as this object
239          * is less than, equal to, or greater than the specified object.
240          */

241         public int compareTo(Object JavaDoc o) {
242             if ( !(o instanceof ApplicationResourceID) ) {
243                 throw new ClassCastException JavaDoc("Cannot compare instance of '" + getClass().getName() + "' to the instance of '" + o.getClass().getName() + "'");
244             }
245
246             ApplicationResourceID id = (ApplicationResourceID) o;
247             if ( key.equalsIgnoreCase(id.key) ) {
248                 return locale.compareTo(id.locale);
249             } else {
250                 return key.compareTo(id.key);
251             }
252         }
253
254         public boolean equals(Object JavaDoc o) {
255             if ( this == o ) {
256                 return true;
257             }
258             if ( !(o instanceof ApplicationResourceID) ) {
259                 return false;
260             }
261
262             final ApplicationResourceID applicationResourceID = (ApplicationResourceID) o;
263
264             if ( !key.equals(applicationResourceID.key) ) {
265                 return false;
266             }
267             if ( !locale.equals(applicationResourceID.locale) ) {
268                 return false;
269             }
270
271             return true;
272         }
273
274         public int hashCode() {
275             int result;
276             result = key.hashCode();
277             result = 29 * result + locale.hashCode();
278             return result;
279         }
280
281     }
282
283
284 }
285
Popular Tags