/*
ItsNat Java Web Application Framework
Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
Author: Jose Maria Arranz Santamaria
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. See the GNU Affero General Public
License for more details. See the copy of the GNU Affero General Public License
included in this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.itsnat.impl.comp;
import org.itsnat.comp.ItsNatFormattedTextField;
import java.lang.reflect.Constructor;
import java.text.ParseException;
/**
*
* @author jmarranz
*/
public class ItsNatFormatterDefaultImpl implements ItsNatFormattedTextField.ItsNatFormatter
{
/** Creates a new instance of ItsNatFormatterDefaultImpl */
public ItsNatFormatterDefaultImpl()
{
}
public Class getValueClass(ItsNatFormattedTextField comp)
{
// Devuelve la clase del valor actual
Object value = comp.getValue();
if (value != null)
return value.getClass();
else
return null;
}
public Object stringToValue(String str,ItsNatFormattedTextField comp) throws ParseException
{
Class vc = getValueClass(comp);
if (vc != null)
{
Constructor cons;
try
{
cons = vc.getConstructor(new Class[] { String.class });
}
catch (NoSuchMethodException nsme)
{
cons = null;
}
if (cons != null)
{
try
{
return cons.newInstance(new Object[] { str });
}
catch (Throwable ex)
{
throw new ParseException("Error creating instance", 0);
}
}
}
return str;
}
public String valueToString(Object value,ItsNatFormattedTextField comp) throws ParseException
{
if (value == null)
{
return "";
}
return value.toString();
}
}
|