com.cc.framework.convert.imp
Class NumberConverter

java.lang.Object
  extended bycom.cc.framework.convert.imp.NumberConverter
All Implemented Interfaces:
Converter, StatefullConverter

public class NumberConverter
extends java.lang.Object
implements StatefullConverter

Converter for Numbers (as in the Java Server Faces Specification) Converter implementation for java.lang.Number values. The getAsObject() method parses a String into an java.lang.Double or java.lang.Long, according to the following algorithm:

The getAsString() method expects a value of type java.lang.Number (or a subclass), and creates a formatted String according to the following algorithm:

Version:
$Revision$
Author:
Harald Schulz

Field Summary
static java.lang.String CONVERTER_ID
          Converter Id
private static java.lang.Class currencyClass
           
private  java.lang.String currencyCode
           
private  java.lang.String currencySymbol
           
private static java.lang.Class[] GET_INSTANCE_PARAM_TYPES
           
private  boolean groupingUsed
           
private  boolean integerOnly
           
private  java.util.Locale locale
           
private  int maxFractionDigits
           
private  boolean maxFractionDigitsSpecified
           
private  int maxIntegerDigits
           
private  boolean maxIntegerDigitsSpecified
           
private  int minFractionDigits
           
private  boolean minFractionDigitsSpecified
           
private  int minIntegerDigits
           
private  boolean minIntegerDigitsSpecified
           
private  java.lang.String pattern
           
private  java.lang.String type
           
 
Constructor Summary
NumberConverter()
          Constructor
 
Method Summary
private  void configureCurrency(java.text.NumberFormat formatter)
           
private  void configureFormatter(java.text.NumberFormat formatter)
           
 java.lang.Object getAsObject(RequestContext context, java.lang.String value)
          Converts the given String value into the Converters Datatype
 java.lang.String getAsString(RequestContext context, java.lang.Object value)
          Converts the Object of the converters Datatype into it's String representation
 java.lang.String getCurrencyCode()
           
 java.lang.String getCurrencySymbol()
           
private  java.util.Locale getLocale(RequestContext context)
          Retrieves the Locale for this Converter
 int getMaxFractionDigits()
           
 int getMaxIntegerDigits()
           
 int getMinFractionDigits()
           
 int getMinIntegerDigits()
           
private  java.text.NumberFormat getNumberFormat(java.util.Locale locale)
           
 java.lang.String getPattern()
           
 java.lang.String getType()
           
 boolean isGroupingUsed()
           
 boolean isIntegerOnly()
           
 void restoreState(RequestContext context, java.lang.Object state)
          Perform any processing required to restore the state from the entries in the state Object.
 java.lang.Object saveState(RequestContext context)
          Gets the state of the instance as a Serializable Object.
 void setCurrencyCode(java.lang.String currencyCode)
           
 void setCurrencySymbol(java.lang.String currencySymbol)
           
 void setGroupingUsed(boolean groupingUsed)
           
 void setIntegerOnly(boolean integerOnly)
           
 void setLocale(java.util.Locale locale)
           
 void setMaxFractionDigits(int maxFractionDigits)
           
 void setMaxIntegerDigits(int maxIntegerDigits)
           
 void setMinFractionDigits(int minFractionDigits)
           
 void setMinIntegerDigits(int minIntegerDigits)
           
 void setPattern(java.lang.String pattern)
           
 void setType(java.lang.String type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERTER_ID

public static final java.lang.String CONVERTER_ID
Converter Id

See Also:
Constant Field Values

currencyCode

private java.lang.String currencyCode

currencySymbol

private java.lang.String currencySymbol

groupingUsed

private boolean groupingUsed

integerOnly

private boolean integerOnly

maxFractionDigits

private int maxFractionDigits

maxFractionDigitsSpecified

private boolean maxFractionDigitsSpecified

maxIntegerDigits

private int maxIntegerDigits

maxIntegerDigitsSpecified

private boolean maxIntegerDigitsSpecified

minFractionDigits

private int minFractionDigits

minFractionDigitsSpecified

private boolean minFractionDigitsSpecified

minIntegerDigits

private int minIntegerDigits

minIntegerDigitsSpecified

private boolean minIntegerDigitsSpecified

locale

private java.util.Locale locale

pattern

private java.lang.String pattern

type

private java.lang.String type

currencyClass

private static java.lang.Class currencyClass

GET_INSTANCE_PARAM_TYPES

private static final java.lang.Class[] GET_INSTANCE_PARAM_TYPES
Constructor Detail

NumberConverter

public NumberConverter()
Constructor

Method Detail

getCurrencyCode

public java.lang.String getCurrencyCode()
Returns:
ISO 4217 currency code, applied only when formatting currencies.

setCurrencyCode

public void setCurrencyCode(java.lang.String currencyCode)
Parameters:
currencyCode - ISO 4217 currency code, applied only when formatting currencies.

getCurrencySymbol

public java.lang.String getCurrencySymbol()
Returns:
Currency symbol, applied only when formatting currencies.

setCurrencySymbol

public void setCurrencySymbol(java.lang.String currencySymbol)
Parameters:
currencySymbol - Currency symbol, applied only when formatting currencies.

isGroupingUsed

public boolean isGroupingUsed()
Returns:
Flag specifying whether formatted output will contain grouping separators. Expressions must evaluate to a boolean. Default value is true.

setGroupingUsed

public void setGroupingUsed(boolean groupingUsed)
Parameters:
groupingUsed - Flag specifying whether formatted output will contain grouping separators. Expressions must evaluate to a boolean. Default value is true.

isIntegerOnly

public boolean isIntegerOnly()
Returns:
Flag specifying whether only the integer part of the value will be formatted and parsed. Expressions must evaluate to a boolean. Default value is false.

setIntegerOnly

public void setIntegerOnly(boolean integerOnly)
Parameters:
integerOnly - Flag specifying whether only the integer part of the value will be formatted and parsed. Expressions must evaluate to a boolean. Default value is false.

getMaxFractionDigits

public int getMaxFractionDigits()
Returns:
Maximum number of digits that will be formatted in the fractional portion of the output. Expressions must evaluate to an int.

setMaxFractionDigits

public void setMaxFractionDigits(int maxFractionDigits)
Parameters:
maxFractionDigits - Maximum number of digits that will be formatted in the fractional portion of the output. Expressions must evaluate to an int.

getMaxIntegerDigits

public int getMaxIntegerDigits()
Returns:
Maximum number of digits that will be formatted in the integer portion of the output. Expressions must evaluate to an int.

setMaxIntegerDigits

public void setMaxIntegerDigits(int maxIntegerDigits)
Parameters:
maxIntegerDigits - Maximum number of digits that will be formatted in the integer portion of the output. Expressions must evaluate to an int.

getMinFractionDigits

public int getMinFractionDigits()
Returns:
Minimum number of digits that will be formatted in the fractional portion of the output. Expressions must evaluate to an int.

setMinFractionDigits

public void setMinFractionDigits(int minFractionDigits)
Parameters:
minFractionDigits - Minimum number of digits that will be formatted in the fractional portion of the output. Expressions must evaluate to an int.

getMinIntegerDigits

public int getMinIntegerDigits()
Returns:
Minimum number of digits that will be formatted in the integer portion of the output. Expressions must evaluate to an int.

setMinIntegerDigits

public void setMinIntegerDigits(int minIntegerDigits)
Parameters:
minIntegerDigits - Minimum number of digits that will be formatted in the integer portion of the output. Expressions must evaluate to an int.

setLocale

public void setLocale(java.util.Locale locale)
Parameters:
locale - Locale whose predefined styles for numbers are used during formatting and parsing. If not specified, the Locale returned by FacesContext.getViewRoot().getLocale() will be used. Expressions must evaluate to a java.util.Locale.

getPattern

public java.lang.String getPattern()
Returns:
Custom formatting pattern which determins how the number string should be formatted and parsed.

setPattern

public void setPattern(java.lang.String pattern)
Parameters:
pattern - Custom formatting pattern which determins how the number string should be formatted and parsed.

getType

public java.lang.String getType()
Returns:
Specifies how the number string will be formatted and parsed. Valid values are "number", "currency", and "percentage". Default value is "number".

setType

public void setType(java.lang.String type)
Parameters:
type - Specifies how the number string will be formatted and parsed. Valid values are "number", "currency", and "percentage". Default value is "number".

getAsObject

public java.lang.Object getAsObject(RequestContext context,
                                    java.lang.String value)
                             throws ConverterException
Description copied from interface: Converter
Converts the given String value into the Converters Datatype

Specified by:
getAsObject in interface Converter
Parameters:
context - Request Context
value - The String Value to convert
Returns:
Object of the Converters Datatype
Throws:
ConverterException - is thrown when a conversion error occurs
See Also:
Converter.getAsObject(com.cc.framework.adapter.RequestContext, java.lang.String)

getAsString

public java.lang.String getAsString(RequestContext context,
                                    java.lang.Object value)
                             throws ConverterException
Description copied from interface: Converter
Converts the Object of the converters Datatype into it's String representation

Specified by:
getAsString in interface Converter
Parameters:
context - Request Context
value - The Object to convert
Returns:
String
Throws:
ConverterException - is thrown when a conversion error occurs
See Also:
Converter.getAsString(com.cc.framework.adapter.RequestContext, java.lang.Object)

configureCurrency

private void configureCurrency(java.text.NumberFormat formatter)
                        throws java.lang.Exception
Throws:
java.lang.Exception

configureFormatter

private void configureFormatter(java.text.NumberFormat formatter)

getLocale

private java.util.Locale getLocale(RequestContext context)
Retrieves the Locale for this Converter

Parameters:
context - The RequestContext
Returns:
Locale

getNumberFormat

private java.text.NumberFormat getNumberFormat(java.util.Locale locale)
                                        throws ConverterException
Throws:
ConverterException

saveState

public java.lang.Object saveState(RequestContext context)
Description copied from interface: StatefullConverter
Gets the state of the instance as a Serializable Object. This method must not alter the state of the implementing object. In other words, after executing this code:
 Object state = component.saveState(ctx);
 
Component should be the same as before executing it.

Specified by:
saveState in interface StatefullConverter
Parameters:
context - The RequestContext object
Returns:
The return from this method must be Serializable
See Also:
StatefullConverter.saveState(com.cc.framework.adapter.RequestContext)

restoreState

public void restoreState(RequestContext context,
                         java.lang.Object state)
Description copied from interface: StatefullConverter
Perform any processing required to restore the state from the entries in the state Object.

Specified by:
restoreState in interface StatefullConverter
Parameters:
context - The RequestContext object
state - the serialized state
See Also:
StatefullConverter.restoreState(com.cc.framework.adapter.RequestContext, java.lang.Object)


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.