org.compass.core.mapping
Class ResourcePropertyLookup

java.lang.Object
  extended by org.compass.core.mapping.ResourcePropertyLookup

public final class ResourcePropertyLookup
extends Object

A simple lookup class, for a given path, will provide simple access to it's path and value converter. Also supports path escaping ('a.b' or will result in a.b and not alias a and resource property b).


Constructor Summary
ResourcePropertyLookup(CompassMapping compassMapping, String name)
           
 
Method Summary
 String attemptNormalizeString(String value)
          Tries to normalize the string using normalizeString(String), and if it fails, will return the original value.
 Object fromString(String value)
          Returns the Object converted from the String value.
 AliasMapping getAliasMapping()
          Returns the alias mapping if using dot path notation.
 String getAnalyzer()
          Returns the analyzer associated with the resource property.
 String getDotPathAlias()
          Returns the alias used if using dot path notation.
 String getLookupName()
          Returns the lookup name used in order to find the meta-data/property name.
 String getPath()
          Returns the path matching the provided name.
 ResourcePropertyMapping getResourcePropertyMapping()
          Returns the property mapping for the provided name.
 ResourcePropertyMapping[] getResourcePropertyMappings()
          Returns a list of property mappings for the provided name.
 String getValue(Object value)
          Returns the String representation of the provided value Object.
 boolean hasSpecificConverter()
          Returns true if there is a specific converter that can be used to convert the value.
 String normalizeString(String value)
          Normalizes a given String value to a (hopefully) String value that mathces the one stored in the index.
 void setConvertOnlyWithDotPath(boolean convertOnlyWithDotPath)
          Perform specialized convert only when dot path is used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourcePropertyLookup

public ResourcePropertyLookup(CompassMapping compassMapping,
                              String name)
Method Detail

setConvertOnlyWithDotPath

public void setConvertOnlyWithDotPath(boolean convertOnlyWithDotPath)
Perform specialized convert only when dot path is used. Defaults to true.

Sometimes, several meta-data names are used with different converteres. For example map to title both a pure String value and also a numeric value. If using dot path notation, Compass will narrow down to the specfic converter (for example a.title.title). When not using dot path notation, Compass now has two options for conversion. If this flag is set to true (and not using dot path notation), Compass will use a converter based on the object type. If this flag is set to false, the first mapping is used to convert.


getAnalyzer

public String getAnalyzer()
Returns the analyzer associated with the resource property. null if none is configured on the resource property or resource level.


getLookupName

public String getLookupName()
Returns the lookup name used in order to find the meta-data/property name.


getDotPathAlias

public String getDotPathAlias()
Returns the alias used if using dot path notation. Returns null if dot path notation was not used.


getAliasMapping

public AliasMapping getAliasMapping()
Returns the alias mapping if using dot path notation. Returns null if dot path notation was not used.


getPath

public String getPath()
Returns the path matching the provided name. The path is the actual name used to store in the index.


getResourcePropertyMapping

public ResourcePropertyMapping getResourcePropertyMapping()
Returns the property mapping for the provided name. If not using dot path notation, will return the first one that match the "meta-data" name within all of Compass mappings.


getResourcePropertyMappings

public ResourcePropertyMapping[] getResourcePropertyMappings()
Returns a list of property mappings for the provided name. When not using "dot path" which allows to narrows down to a specific property mapping, and a general meta-data name is used (such as title), will return all the property mappings for it within Compass mappings.


hasSpecificConverter

public boolean hasSpecificConverter()
Returns true if there is a specific converter that can be used to convert the value.

Note, when setConvertOnlyWithDotPath(boolean) is set the true, and the name passed to the lookup does not contain "dot notation", false will be returned.


getValue

public String getValue(Object value)
Returns the String representation of the provided value Object. If hasSpecificConverter() return true, will use the first mapping definition for the given name in order to convert it from Object to String. If it returns false, will use a Converter assigned to the given parameter class. If a String is passed, will normalize it using normalizeString(String).

See Also:
ResourcePropertyConverter

fromString

public Object fromString(String value)
Returns the Object converted from the String value. If the hasSpecificConverter() returns true, will use the first mapping definition for the given name in order to conver it from String to Object. If it returns false, will use a Converter assigned to the given parameter class.

See Also:
ResourcePropertyConverter

attemptNormalizeString

public String attemptNormalizeString(String value)
Tries to normalize the string using normalizeString(String), and if it fails, will return the original value.


normalizeString

public String normalizeString(String value)
                       throws ConversionException
Normalizes a given String value to a (hopefully) String value that mathces the one stored in the index.

If hasSpecificConverter() return false (note setConvertOnlyWithDotPath(boolean)) will simply return the given value.

If the ResourcePropertyConverter states that it should not be used for normalization (ResourcePropertyConverter.canNormalize() returns false), the provided value will be returned.

If none of the above happens, will convert it ResourcePropertyConverter.fromString(String, org.compass.core.mapping.ResourcePropertyMapping) and then ResourcePropertyConverter.toString(Object, org.compass.core.mapping.ResourcePropertyMapping).

Throws:
ConversionException


Copyright (c) 2004-2008 The Compass Project.