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.math.BigInteger;
19: import java.text.ParseException;
20:
21: /**
22: * BigInteger converter.
23: *
24: * @author Oliver Stuhr
25: */
26: public class BigIntegerConverter extends SimpleConverter {
27: private int radix;
28:
29: /**
30: * Default constructor.
31: */
32: public BigIntegerConverter() {
33: this (10);
34: }
35:
36: /**
37: * Constructor.
38: */
39: public BigIntegerConverter(int radix) {
40: super ();
41:
42: this .radix = radix;
43: }
44:
45: /**
46: * @return Returns the radix.
47: */
48: public int getRadix() {
49: return radix;
50: }
51:
52: /**
53: * @param radix The radix to set.
54: */
55: public void setRadix(int radix) {
56: this .radix = radix;
57: }
58:
59: public String format(Object value) {
60: return value == null ? null : ((BigInteger) value)
61: .toString(radix);
62: }
63:
64: public Object parse(String value) throws ParseException {
65: if (value == null || value.length() == 0)
66: return null;
67: try {
68: return new BigInteger(value, radix);
69: } catch (Exception e) {
70: throw new ParseException("", 0);
71: }
72: }
73: }
|