org.apache.cocoon.faces.samples.carstore
Class CarBean

java.lang.Object
  extended by org.apache.cocoon.faces.samples.carstore.CarBean

public class CarBean
extends Object

This bean encapsulates a car model, including pricing and package choices. The system allows the user to customize the properties of this bean with the help of the CarCustomizer.

Data Access

This is the only bean in the system that has complicated access to the persistent store of data. In the present implementation, this persistent store is in ResourceBundle instances.

There are three data source ResourceBundle files used:

  1. <ModelName>

    This contains the localized content for this model. There is a variant of this file for each supported locale, for example, Jalopy_de.properties

  2. <Common_properties>

    This contains the localized content common to all models.

  3. <ModelName_options>

    This contains the non-localized content for this model, including the non-localized options. There is only one variant of this file for all locales for example, Jalopy_options.properties

All files conform to the following convention:

 key
 key_componentType
 key_valueType
 

Where key is the name of an attribute of this car. For example, basePrice, or description. key_componentType is the component type of the UIComponent subclass to be used to represent this attribute in the page, for example SelectManyMenu. key_valueType is the data type of the value of the UIComponent, for example java.lang.Integer. For all non-String valueTypes.

When the bean is instantiated, we load both of the above properties files and iterate over the keys in each one. For each key, we look at the componentType and ask the Application to create a component of that type. We store that UIComponent instance in our components Map under the name key. We look at the valueType for the key. For non java.lang.String types, we ask the Application for a Converter instance for that class. If found, we use it to convert the value for the key to the appropriate type and store that as the value of the UIComponent instance.


Field Summary
static String CONVERTER_ERROR_MESSAGE_ID
          The message identifier of the Message to be created if the conversion fails.
protected static org.apache.commons.logging.Log log
           
 
Constructor Summary
CarBean()
           
CarBean(String bundleName)
           
 
Method Summary
 Map getAttributes()
           
 Map getComponents()
           
 Integer getCurrentPrice()
           
 ArrayList parseStringIntoArrayList(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String value, String valueType, javax.faces.convert.Converter converter)
          Tokenizes the passed in String which is a comma separated string of option values that serve as keys into the main resources file.
 String updatePricing()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log

CONVERTER_ERROR_MESSAGE_ID

public static final String CONVERTER_ERROR_MESSAGE_ID

The message identifier of the Message to be created if the conversion fails. The message format string for this message may optionally include a {0} placeholder, which will be replaced by the object and value.

See Also:
Constant Field Values
Constructor Detail

CarBean

public CarBean()

CarBean

public CarBean(String bundleName)
Method Detail

parseStringIntoArrayList

public ArrayList parseStringIntoArrayList(javax.faces.context.FacesContext context,
                                          javax.faces.component.UIComponent component,
                                          String value,
                                          String valueType,
                                          javax.faces.convert.Converter converter)
Tokenizes the passed in String which is a comma separated string of option values that serve as keys into the main resources file. For example, optionStr could be "Disc,Drum", which corresponds to brake options available for the chosen car. This String is tokenized and used as key into the main resource file to get the localized option values and stored in the passed in ArrayList.


updatePricing

public String updatePricing()

getCurrentPrice

public Integer getCurrentPrice()

getComponents

public Map getComponents()

getAttributes

public Map getAttributes()


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.