01: /**********************************************************************
02: Copyright (c) 2006 Michael Brown 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: 2006 Michael Brown (AssetHouse Technology Ltd) - Added UUID support
17: 2006 Andy Jefferson - changed to extend ObjectAsStringMapping
18: **********************************************************************/package org.jpox.store.mapping;
19:
20: import java.util.UUID;
21:
22: import org.jpox.ClassLoaderResolver;
23:
24: /**
25: * Mapping for java.util.UUID type.
26: *
27: * @version $Revision: 1.1 $
28: */
29: public class UUIDMapping extends ObjectAsStringMapping {
30: public Object getSampleValue(ClassLoaderResolver clr) {
31: throw new UnsupportedOperationException();
32: }
33:
34: /* (non-Javadoc)
35: * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
36: */
37: public Class getJavaType() {
38: return UUID.class;
39: }
40:
41: /**
42: * Method to set the datastore string value based on the object value.
43: * @param object The object
44: * @return The string value to pass to the datastore
45: */
46: protected String objectToString(Object object) {
47: String uuid;
48: if (object instanceof UUID) {
49: uuid = ((UUID) object).toString();
50: } else {
51: uuid = (String) object;
52: }
53: return uuid;
54: }
55:
56: /**
57: * Method to extract the objects value from the datastore string value.
58: * @param datastoreValue Value obtained from the datastore
59: * @return The value of this object (derived from the datastore string value)
60: */
61: protected Object stringToObject(String datastoreValue) {
62: return UUID.fromString(datastoreValue);
63: }
64: }
|