01: /**********************************************************************
02: Copyright (c) 2003 Andy Jefferson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15: Contributors:
16: ...
17: **********************************************************************/package org.jpox.store.mapping;
18:
19: import java.util.TimeZone;
20:
21: import org.jpox.ClassLoaderResolver;
22:
23: /**
24: * SCO Mapping for java TimeZone type.
25: * TODO : This needs modifying to support mutable TimeZone objects.
26: *
27: * @version $Revision: 1.16 $
28: **/
29: public class TimeZoneMapping extends ObjectAsStringMapping {
30: private static TimeZone mappingSampleValue = TimeZone.getDefault();
31:
32: public Object getSampleValue(ClassLoaderResolver clr) {
33: return mappingSampleValue;
34: }
35:
36: public Class getJavaType() {
37: return TimeZone.class;
38: }
39:
40: /**
41: * Method to return the default length of this type in the datastore.
42: * Timezones require 30 chars.
43: * @param index The index position
44: * @return The default length
45: */
46: public int getDefaultLength(int index) {
47: return 30;
48: }
49:
50: /**
51: * Method to set the datastore string value based on the object value.
52: * @param object The object
53: * @return The string value to pass to the datastore
54: */
55: protected String objectToString(Object object) {
56: String locale;
57: if (object instanceof TimeZone) {
58: locale = ((TimeZone) object).getID();
59: } else {
60: locale = (String) object;
61: }
62: return locale;
63: }
64:
65: /**
66: * Method to extract the objects value from the datastore string value.
67: * @param datastoreValue Value obtained from the datastore
68: * @return The value of this object (derived from the datastore string value)
69: */
70: protected Object stringToObject(String datastoreValue) {
71: return TimeZone.getTimeZone(datastoreValue.trim());
72: }
73: }
|