org.compass.core.converter.basic
Class AbstractBasicConverter

java.lang.Object
  extended by org.compass.core.converter.basic.AbstractBasicConverter
All Implemented Interfaces:
Converter, ResourcePropertyConverter
Direct Known Subclasses:
AbstractDynamicConverter, AbstractFormatConverter, BooleanConverter, ByteConverter, CharConverter, EnumConverter, FileConverter, LocaleConverter, StringBufferConverter, StringBuilderConverter, StringConverter, URLConverter

public abstract class AbstractBasicConverter
extends Object
implements ResourcePropertyConverter

An easy to use abstact class for Basic converters. Handles converters that usually deals with String as a result of the conversion.

This base class will create a simple Property when marshalling, calling toString(Object, org.compass.core.mapping.ResourcePropertyMapping) as the Property value. And will use the ResourcePropertyConverter.fromString(String, org.compass.core.mapping.ResourcePropertyMapping) when unmarhslling.

If special null values handling is required, the handleNulls(org.compass.core.marshall.MarshallingContext), and getNullValue(org.compass.core.marshall.MarshallingContext) can be overriden. Note, that it is best to call base implementations and extend the base funtionallity, since the base class takes special care when using collections.

Author:
kimchy

Constructor Summary
AbstractBasicConverter()
           
 
Method Summary
protected  void doSetBoost(Property property, Object root, ResourcePropertyMapping resourcePropertyMapping, MarshallingContext context)
          A simple extension point that allows to set the boost value for the created Property.
protected  String getNullValue(MarshallingContext context)
          If the converter handle nulls, the value that will be stored in the search engine for null values (during the marshall process).
protected  boolean handleNulls(MarshallingContext context)
          Should the converter handle nulls?
protected  boolean isNullValue(MarshallingContext context, String value)
          Is the value read from the search engine is a null value during the unmarshall process.
 boolean marshall(Resource resource, Object root, Mapping mapping, MarshallingContext context)
          Marshall the given Object to the given Resource.
 String toString(Object o, ResourcePropertyMapping resourcePropertyMapping)
          Default implementation of toString, simply calls the Object toString.
 Object unmarshall(Resource resource, Mapping mapping, MarshallingContext context)
          Unmarshall the given Resource to the appropiate Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.compass.core.converter.ResourcePropertyConverter
fromString
 

Constructor Detail

AbstractBasicConverter

public AbstractBasicConverter()
Method Detail

marshall

public boolean marshall(Resource resource,
                        Object root,
                        Mapping mapping,
                        MarshallingContext context)
                 throws ConversionException
Description copied from interface: Converter
Marshall the given Object to the given Resource. Will use the mapping definition as to how to marshall the object.

Returns true if data was saved in the index, and it can be read as well (i.e. stored).

Specified by:
marshall in interface Converter
Parameters:
resource - The resource to marhsall the object to
root - The Object to marshall to the resource
mapping - The mapping definition of how to marshall the Object to the resoruce
context - The context for the current marhslling process
Returns:
true if data was saved in the the index that can be read.
Throws:
ConversionException

unmarshall

public Object unmarshall(Resource resource,
                         Mapping mapping,
                         MarshallingContext context)
                  throws ConversionException
Description copied from interface: Converter
Unmarshall the given Resource to the appropiate Object.

Specified by:
unmarshall in interface Converter
Parameters:
resource - The resource to unmarshall into an Object
mapping - The mapping definition of how to unmarshall the Resource into an Object
context - The context for the current marshalling process
Returns:
The object unmarshalled
Throws:
ConversionException

handleNulls

protected boolean handleNulls(MarshallingContext context)
Should the converter handle nulls? Handling nulls means should the converter process nulls or not. Usually the converter will not persist null values, but sometimes it might be needed (MarshallingContext.handleNulls()).

Extracted to a method so special converters can control null handling.

Parameters:
context -
Returns:
true if the converter should handle null values

getNullValue

protected String getNullValue(MarshallingContext context)
If the converter handle nulls, the value that will be stored in the search engine for null values (during the marshall process).

Parameters:
context -
Returns:
Null value that will be inserted for nulls.

isNullValue

protected boolean isNullValue(MarshallingContext context,
                              String value)
Is the value read from the search engine is a null value during the unmarshall process.

Parameters:
context -
value - The value to check for null value.
Returns:
true if the value represents a null value.

doSetBoost

protected void doSetBoost(Property property,
                          Object root,
                          ResourcePropertyMapping resourcePropertyMapping,
                          MarshallingContext context)
                   throws ConversionException
A simple extension point that allows to set the boost value for the created Property.

The default implemenation uses the statically defined boost value in the mapping definition (ResourcePropertyMapping.getBoost()) to set the boost level using Property.setBoost(float)

Parameters:
property - The property to set the boost on
root - The object that is marshalled into a property
resourcePropertyMapping - The Resource Property Mapping definition
Throws:
ConversionException

toString

public String toString(Object o,
                       ResourcePropertyMapping resourcePropertyMapping)
Default implementation of toString, simply calls the Object toString.

Specified by:
toString in interface ResourcePropertyConverter
Parameters:
o - The Object to convert from
resourcePropertyMapping - The resource proeprty mapping
Returns:
The String converted from the Object


Copyright (c) 2004-2006 The Compass Project.