/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.odysseus.calyxo.forms.convert;
import java.math.BigInteger;
import java.text.ParseException;
/**
* BigInteger converter.
*
* @author Oliver Stuhr
*/
public class BigIntegerConverter extends SimpleConverter {
private int radix;
/**
* Default constructor.
*/
public BigIntegerConverter() {
this(10);
}
/**
* Constructor.
*/
public BigIntegerConverter(int radix) {
super();
this.radix = radix;
}
/**
* @return Returns the radix.
*/
public int getRadix() {
return radix;
}
/**
* @param radix The radix to set.
*/
public void setRadix(int radix) {
this.radix = radix;
}
public String format(Object value) {
return value == null ? null : ((BigInteger) value).toString(radix);
}
public Object parse(String value) throws ParseException {
if (value == null || value.length() == 0)
return null;
try {
return new BigInteger(value, radix);
} catch (Exception e) {
throw new ParseException("", 0);
}
}
}