1 16 package javax.faces.convert; 17 18 import javax.faces.component.UIComponent; 19 import javax.faces.context.FacesContext; 20 import java.math.BigInteger ; 21 22 37 public class BigIntegerConverter 38 implements Converter 39 { 40 private static final String CONVERSION_MESSAGE_ID = "javax.faces.convert.BigIntegerConverter.CONVERSION"; 41 42 public static final String CONVERTER_ID = "javax.faces.BigInteger"; 44 45 public BigIntegerConverter() 47 { 48 } 49 50 public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) 52 { 53 if (facesContext == null) throw new NullPointerException ("facesContext"); 54 if (uiComponent == null) throw new NullPointerException ("uiComponent"); 55 56 if (value != null) 57 { 58 value = value.trim(); 59 if (value.length() > 0) 60 { 61 try 62 { 63 return new BigInteger (value.trim()); 64 } 65 catch (NumberFormatException e) 66 { 67 throw new ConverterException(_MessageUtils.getErrorMessage(facesContext, 68 CONVERSION_MESSAGE_ID, 69 new Object []{uiComponent.getId(),value}), e); 70 } 71 } 72 } 73 return null; 74 } 75 76 public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) 77 { 78 if (facesContext == null) throw new NullPointerException ("facesContext"); 79 if (uiComponent == null) throw new NullPointerException ("uiComponent"); 80 81 if (value == null) 82 { 83 return ""; 84 } 85 if (value instanceof String ) 86 { 87 return (String )value; 88 } 89 try 90 { 91 return ((BigInteger )value).toString(); 92 } 93 catch (Exception e) 94 { 95 throw new ConverterException(e); 96 } 97 } 98 99 } 100 | Popular Tags |