org.compass.core
Interface Resource

All Superinterfaces:
AliasedObject, Serializable
All Known Subinterfaces:
InternalResource, MultiResource
All Known Implementing Classes:
CollectionResourceWrapper, LuceneMultiResource, LuceneResource

public interface Resource
extends AliasedObject, Serializable

A Resource holds a list of meta data properties. The Resource is the basic data that is saved in Compass. Compass provides object to Resource mapping as well in the CompassSession object.

Author:
kimchy

Method Summary
 Resource addProperty(Property property)
          Add a property to the resource.
 Resource addProperty(String name, Object value)
          Adds a property to the resource based on resource mapping definitions.
 Resource addProperty(String name, Reader value)
          Adds a property to the resource based on resource mapping definitions.
 void copy(Resource resource)
          Copies the content of the give Resource into the current one
 String getAlias()
          Returns the mapping alias of the associated Resource
 float getBoost()
          Returns the boost for the property.
 String getId()
          Returns the id of the resource.
 Property[] getIdProperties()
          Returns the id properties of the resource
 Property getIdProperty()
          Returns the id property of the resource
 String[] getIds()
          Returns the id values of the resource.
 Object getObject(String name)
          Returns the object value of the property with the given name if any exists in the resource, or null.
 Object[] getObjects(String name)
          Returns an array of values of the proeprty with the given name.
 Property[] getProperties()
          Returns all the properties for the resource.
 Property[] getProperties(String name)
          Returns all the properties under the given name.
 Property getProperty(String name)
          Returns the first property under the name.
 String getUID()
          Returns the unique id of the resource.
 String getValue(String name)
          Returns the string value of the property with the given name if any exist in this resource, or null.
 String[] getValues(String name)
          Returns an array of values of the property specified as the method parameter.
 Resource removeProperties(String name)
          Removes all the properties under the given name.
 Resource removeProperty(String name)
          Remove the latest property added under the given name.
 Resource setBoost(float boost)
          Sets the boost level for the resource.
 Resource setProperty(Property property)
          Sest a property to the resource (removes then adds).
 Resource setProperty(String name, Object value)
          Sets a property to the resource (removes then adds) based on resource mapping definitions.
 Resource setProperty(String name, Reader value)
          Sets a property to the resource (removes then adds) based on resource mapping definitions.
 

Method Detail

getAlias

String getAlias()
Returns the mapping alias of the associated Resource

Specified by:
getAlias in interface AliasedObject
Returns:
The alias

getUID

String getUID()
              throws CompassException
Returns the unique id of the resource. Note, the ids must be set on this resource in order to get the uid, if not a CompassException will be thrown.

Throws:
CompassException

getId

String getId()
Returns the id of the resource. Used when there is only one id for the resource.

Returns:
The id of the resource.

getIds

String[] getIds()
Returns the id values of the resource.

Returns:
The id values of the resource

getIdProperty

Property getIdProperty()
Returns the id property of the resource

Returns:
The id properties of the resource

getIdProperties

Property[] getIdProperties()
Returns the id properties of the resource

Returns:
The id properties of the resource

getValue

String getValue(String name)
Returns the string value of the property with the given name if any exist in this resource, or null. If multiple properties exist with this name, this method returns the first value added.

Parameters:
name - The name of the property
Returns:
The first value that match the name

getObject

Object getObject(String name)
Returns the object value of the property with the given name if any exists in the resource, or null. If multiple properties exists with this name, this methods returns the first value added.

If a converter is associated with the property in one of Compass mapping definitions, it will be used to convert the string value to an object value. If there is no converter associated with the property, the string value will be returned.

Parameters:
name - The name of the property
Returns:
The first object value that match the name (converted if possible)

getObjects

Object[] getObjects(String name)
Returns an array of values of the proeprty with the given name. This method returns an empty array if no values are associated with the given name.

If a converter is associated with the property in one of Compass mapping definitions, it will be used to convert the string value to an object value. If there is no converter associated with the property, the string value will be returned.


getValues

String[] getValues(String name)
Returns an array of values of the property specified as the method parameter. This method can return null.

Parameters:
name - the name of the property
Returns:
a String[] of property values

addProperty

Resource addProperty(String name,
                     Object value)
                     throws SearchEngineException
Adds a property to the resource based on resource mapping definitions. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). ONLY use this method with resource mapping.

Parameters:
name - the name of the property
value - the value to be set (will be converted to a string).
Throws:
SearchEngineException

addProperty

Resource addProperty(String name,
                     Reader value)
                     throws SearchEngineException
Adds a property to the resource based on resource mapping definitions. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). ONLY use this method with resource mapping.

Parameters:
name - the name of the property
value - the value to be set (will be converted to a string).
Throws:
SearchEngineException

addProperty

Resource addProperty(Property property)
Add a property to the resource. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). Note: Compass adds all properties specified in mapping file, adding extra properties to a Resource will make the index out of sync with mapping.

Parameters:
property - The properyt to add

setProperty

Resource setProperty(String name,
                     Object value)
                     throws SearchEngineException
Sets a property to the resource (removes then adds) based on resource mapping definitions. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). ONLY use this method with resource mapping.

Parameters:
name - the name of the property
value - the value to be set (will be converted to a string).
Throws:
SearchEngineException

setProperty

Resource setProperty(String name,
                     Reader value)
                     throws SearchEngineException
Sets a property to the resource (removes then adds) based on resource mapping definitions. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). ONLY use this method with resource mapping.

Parameters:
name - the name of the property
value - the value to be set (will be converted to a string).
Throws:
SearchEngineException

setProperty

Resource setProperty(Property property)
Sest a property to the resource (removes then adds). If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). Note: Compass adds all properties specified in mapping file, adding extra properties to a Resource will make the index out of sync with mapping.

Parameters:
property - The properyt to add

removeProperty

Resource removeProperty(String name)
Remove the latest property added under the given name.

Parameters:
name - The last property name to remove

removeProperties

Resource removeProperties(String name)
Removes all the properties under the given name.

Parameters:
name - The properties name to remove

getProperty

Property getProperty(String name)
Returns the first property under the name.

Parameters:
name - The name of the property
Returns:
The first proeprty that match the name

getProperties

Property[] getProperties(String name)
Returns all the properties under the given name.

Parameters:
name - The name of the properties
Returns:
An array of properties that match the name

getProperties

Property[] getProperties()
Returns all the properties for the resource.

Returns:
All the properties

getBoost

float getBoost()
Returns the boost for the property.

Returns:
The boost value

setBoost

Resource setBoost(float boost)
Sets the boost level for the resource.

Parameters:
boost - The boost level for the resource

copy

void copy(Resource resource)
Copies the content of the give Resource into the current one

Parameters:
resource - The resource to copy from


Copyright (c) 2004-2008 The Compass Project.