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, Object root, MarshallingContext context, Resource resource)
           
 DynamicConverter copy()
          Copies over the dynamic converter.
protected  Object doFromString(String str, ResourcePropertyMapping resourcePropertyMapping, MarshallingContext context)
          Does nothing since there is no meaning for un-marshalling for dynamic converters
protected abstract  Object evaluate(Object o, ResourcePropertyMapping resourcePropertyMapping)
          Evaluates the given data object using the configured expression.
 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.
 Property.Index suggestIndex()
          By default for all converters simply return null.
 Boolean suggestOmitNorms()
          By default for all converters simply return null.
 Property.Store suggestStore()
          The converter can suggest the store type for this type in case no explicit one is configured.
 Property.TermVector suggestTermVector()
          The converter can suggest if term vectors should be saved for this type in case no explicit one is configured.
 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
canNormalize, createProperty, doSetBoost, doToString, fromString, fromString, getNullValue, handleNulls, isNullValue, toString, 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,
                           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

doFromString

protected Object doFromString(String str,
                              ResourcePropertyMapping resourcePropertyMapping,
                              MarshallingContext context)
                       throws ConversionException
Does nothing since there is no meaning for un-marshalling for dynamic converters

Specified by:
doFromString in class AbstractBasicConverter
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

suggestIndex

public Property.Index suggestIndex()
Description copied from class: AbstractBasicConverter
By default for all converters simply return null.

Specified by:
suggestIndex in interface ResourcePropertyConverter
Overrides:
suggestIndex in class AbstractBasicConverter

suggestTermVector

public Property.TermVector suggestTermVector()
Description copied from interface: ResourcePropertyConverter
The converter can suggest if term vectors should be saved for this type in case no explicit one is configured. Can return null and will let global Compass defaults to be used.

Specified by:
suggestTermVector in interface ResourcePropertyConverter
Overrides:
suggestTermVector in class AbstractBasicConverter

suggestStore

public Property.Store suggestStore()
Description copied from interface: ResourcePropertyConverter
The converter can suggest the store type for this type in case no explicit one is configured. Can return null and will let global Compass defaults to be used.

Specified by:
suggestStore in interface ResourcePropertyConverter
Overrides:
suggestStore in class AbstractBasicConverter

suggestOmitNorms

public Boolean suggestOmitNorms()
Description copied from class: AbstractBasicConverter
By default for all converters simply return null.

Specified by:
suggestOmitNorms in interface ResourcePropertyConverter
Overrides:
suggestOmitNorms in class AbstractBasicConverter


Copyright (c) 2004-2008 The Compass Project.