01: /**********************************************************************
02: Copyright (c) 2005 Erik Bengtson 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.net.URI;
20:
21: import org.jpox.ClassLoaderResolver;
22:
23: /**
24: * SCO Mapping for java.net.URI type.
25: *
26: * @version $Revision: 1.15 $
27: **/
28: public class URIMapping extends ObjectAsStringMapping {
29: private static URI mappingSampleValue = URI
30: .create("http://jpox.org");
31:
32: public Object getSampleValue(ClassLoaderResolver clr) {
33: return mappingSampleValue;
34: }
35:
36: public Class getJavaType() {
37: return URI.class;
38: }
39:
40: /**
41: * Method to set the datastore string value based on the object value.
42: * @param object The object
43: * @return The string value to pass to the datastore
44: */
45: protected String objectToString(Object object) {
46: String url;
47: if (object instanceof URI) {
48: url = ((URI) object).toString();
49: } else {
50: url = (String) object;
51: }
52: return url;
53: }
54:
55: /**
56: * Method to extract the objects value from the datastore string value.
57: * @param datastoreValue Value obtained from the datastore
58: * @return The value of this object (derived from the datastore string value)
59: */
60: protected Object stringToObject(String datastoreValue) {
61: return java.net.URI.create(datastoreValue.trim());
62: }
63: }
|