org.compass.core.converter.dynamic
Class AbstractDynamicConverter

java.lang.Object
  extended by org.compass.core.converter.basic.AbstractBasicConverter
      extended by org.compass.core.converter.dynamic.AbstractDynamicConverter
All Implemented Interfaces:
Converter, DynamicConverter, ResourcePropertyConverter
Direct Known Subclasses:
GroovyDynamicConverter, JakartaElDynamicConverter, JexlDynamicConverter, OgnlDynamicConverter, VelocityDynamicConverter

public abstract class AbstractDynamicConverter
extends AbstractBasicConverter
implements DynamicConverter

A simple base class for DynamicConverter. Requires implementation of evaluate(Object,org.compass.core.mapping.ResourcePropertyMapping).

Also holds a FormatConverter for expression that return formatable objects (like Date).

Author:
kimchy

Field Summary
 
Fields inherited from interface org.compass.core.converter.dynamic.DynamicConverter
DATA_CONTEXT_KEY
 
Constructor Summary
AbstractDynamicConverter()
           
 
Method Summary
protected  void addProperty(Object value, ResourcePropertyMapping resourcePropertyMapping, SearchEngine searchEngine, Object root, MarshallingContext context, Resource resource)
           
 DynamicConverter copy()
          Copies over the dynamic converter.
protected abstract  Object evaluate(Object o, ResourcePropertyMapping resourcePropertyMapping)
          Evaluates the given data object using the configured expression.
 Object fromString(String str, ResourcePropertyMapping resourcePropertyMapping)
          Does nothing since there is no meaning for un-marshalling for dynamic converters
 Class getType()
          The return type of the evaluated expression.
 boolean marshall(Resource resource, Object root, Mapping mapping, MarshallingContext context)
          Marshall the given Object to the given Resource.
 void setFormatConverter(FormatConverter formatConverter)
          If the dynamic expression evaluates to a formatable object (like Date), the format converter that will be used to format it.
 void setType(Class type)
          The return type of the evaluated expression.
 Object unmarshall(Resource resource, Mapping mapping, MarshallingContext context)
          Does nothing since there is no meaning for un-marshalling for dynamic converters
 
Methods inherited from class org.compass.core.converter.basic.AbstractBasicConverter
doSetBoost, getNullValue, handleNulls, isNullValue, toString
 
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.dynamic.DynamicConverter
setExpression
 

Constructor Detail

AbstractDynamicConverter

public AbstractDynamicConverter()
Method Detail

copy

public DynamicConverter copy()
Description copied from interface: DynamicConverter
Copies over the dynamic converter.

Specified by:
copy in interface DynamicConverter

setFormatConverter

public void setFormatConverter(FormatConverter formatConverter)
Description copied from interface: DynamicConverter
If the dynamic expression evaluates to a formatable object (like Date), the format converter that will be used to format it.

Specified by:
setFormatConverter in interface DynamicConverter

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
Overrides:
marshall in class AbstractBasicConverter
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

addProperty

protected void addProperty(Object value,
                           ResourcePropertyMapping resourcePropertyMapping,
                           SearchEngine searchEngine,
                           Object root,
                           MarshallingContext context,
                           Resource resource)

evaluate

protected abstract Object evaluate(Object o,
                                   ResourcePropertyMapping resourcePropertyMapping)
                            throws ConversionException
Evaluates the given data object using the configured expression.

Parameters:
o - The data object
resourcePropertyMapping - The resource mapping
Returns:
The object returned as a result of expression evaluation
Throws:
ConversionException

unmarshall

public Object unmarshall(Resource resource,
                         Mapping mapping,
                         MarshallingContext context)
                  throws ConversionException
Does nothing since there is no meaning for un-marshalling for dynamic converters

Specified by:
unmarshall in interface Converter
Overrides:
unmarshall in class AbstractBasicConverter
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

fromString

public Object fromString(String str,
                         ResourcePropertyMapping resourcePropertyMapping)
                  throws ConversionException
Does nothing since there is no meaning for un-marshalling for dynamic converters

Specified by:
fromString in interface ResourcePropertyConverter
Parameters:
str - The string to convert from
resourcePropertyMapping - The resource property mapping
Returns:
Theh object converterd from the String
Throws:
ConversionException

getType

public Class getType()
Description copied from interface: DynamicConverter
The return type of the evaluated expression.

Specified by:
getType in interface DynamicConverter

setType

public void setType(Class type)
Description copied from interface: DynamicConverter
The return type of the evaluated expression.

Specified by:
setType in interface DynamicConverter


Copyright (c) 2004-2006 The Compass Project.