01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.calyxo.forms.convert;
17:
18: import java.text.ParseException;
19:
20: /**
21: * Long converter.
22: *
23: * @author Christoph Beck
24: * @author Oliver Stuhr
25: */
26: public class LongConverter extends NumberConverter {
27: /**
28: * Default constructor.
29: */
30: public LongConverter() {
31: super ();
32:
33: setParseIntegerOnly(true);
34: }
35:
36: public Long getDefault() {
37: return (Long) getParsedNullOrEmpty();
38: }
39:
40: public void setDefault(Long value) {
41: setParsedNullOrEmpty(value);
42: }
43:
44: /**
45: * Format method.
46: */
47: public String format(Object value) {
48: return super .format((Long) value);
49: }
50:
51: /**
52: * Parse method.
53: */
54: public Object parse(String value) throws ParseException {
55: Number d = (Number) super .parse(value);
56: if (d == null || d instanceof Long)
57: return d;
58: return new Long(d.longValue());
59: }
60: }
|