01: /**********************************************************************
02: Copyright (c) 2004 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.Currency;
20:
21: import org.jpox.ClassLoaderResolver;
22:
23: /**
24: * SCO Mapping for Currency type.
25: *
26: * @version $Revision: 1.18 $
27: **/
28: public class CurrencyMapping extends ObjectAsStringMapping {
29: private static Currency mappingSampleValue = Currency
30: .getInstance("GBP");
31:
32: public Object getSampleValue(ClassLoaderResolver clr) {
33: return mappingSampleValue;
34: }
35:
36: public Class getJavaType() {
37: return Currency.class;
38: }
39:
40: /**
41: * Method to return the default length of this type in the datastore.
42: * ISO4217 currencies use 3 character codes, so return 3.
43: * @param index The index position
44: * @return The default length
45: */
46: public int getDefaultLength(int index) {
47: return 3;
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 currency;
57: if (object instanceof Currency) {
58: currency = ((Currency) object).toString();
59: } else {
60: currency = (String) object;
61: }
62: return currency;
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 java.util.Currency.getInstance(datastoreValue);
72: }
73: }
|