01: package com.silvermindsoftware.hitch.handlers.type;
02:
03: /**
04: * Copyright 2007 Brandon Goodin
05: * <p/>
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: * <p/>
10: * http://www.apache.org/licenses/LICENSE-2.0
11: * <p/>
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: public class LongTypeHandler implements TypeHandler {
20: public Object convert(Object value) {
21: if (value == null)
22: return value;
23: if (value instanceof Long) {
24: return value;
25: } else {
26: String stringValue = String.valueOf(value);
27: if (stringValue.trim().length() == 0) {
28: return null;
29: } else {
30: return new Long(stringValue);
31: }
32:
33: }
34: }
35: }
|