org.compass.core.marshall
Class DefaultMarshallingStrategy

java.lang.Object
  extended by org.compass.core.marshall.DefaultMarshallingStrategy
All Implemented Interfaces:
MarshallingStrategy

public class DefaultMarshallingStrategy
extends Object
implements MarshallingStrategy

Author:
kimchy

Constructor Summary
DefaultMarshallingStrategy(CompassMapping mapping, SearchEngine searchEngine, ConverterLookup converterLookup, InternalCompassSession session)
           
 
Method Summary
 Resource marshall(Object root)
          Marshalls the given Object into a Resource based on the ResourceMapping associated with the provided object.
 Resource marshall(String alias, Object root)
          Marshalls the given Object into a Resource based on the ResourceMapping associated with the provided alias.
 Resource marshallIds(Class clazz, Object id)
          Marshalls the give id object into a Resource (a resource having only its ids set).
 Resource marshallIds(Object id)
          Marshalls the given id object into a Resource (a resource having only its ids set).
 void marshallIds(Object root, Object id)
          Marhsalls the give id into the actual object.
 Resource marshallIds(ResourceMapping resourceMapping, Object id)
          Marshalls the give id object into a Resource (a resource having only its ids set).
 void marshallIds(ResourceMapping resourceMapping, Object root, Object id)
          Marhsalls the give id into the actual object.
 boolean marshallIds(Resource resource, ResourceMapping resourceMapping, Object id, MarshallingContext context)
          Marshalls the give id object into the provided Resource (a resource having only its ids set).
 Resource marshallIds(String alias, Object id)
          Marshalls the give id object into a Resource (a resource having only its ids set).
 Object unmarshall(Resource resource)
          Unmarshalls the given resource to an Object based on the ResourceMapping regsitered under the Resource alias.
 Object unmarshall(Resource resource, MarshallingContext context)
          Unmarshalls the given resource to an Object based on the ResourceMapping regsitered under the Resource alias WITHIN the given marshalling context.
 Object[] unmarshallIds(Class clazz, Object id)
          Unmarshalls the given id object into an array of all the id values.
 Object[] unmarshallIds(ResourceMapping resourceMapping, Object id, MarshallingContext context)
          Unmarshalls the given id object into an array of all the id values.
 Object[] unmarshallIds(String alias, Object id)
          Unmarshalls the given id object into an array of all the id values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMarshallingStrategy

public DefaultMarshallingStrategy(CompassMapping mapping,
                                  SearchEngine searchEngine,
                                  ConverterLookup converterLookup,
                                  InternalCompassSession session)
Method Detail

marshallIds

public Resource marshallIds(Object id)
Description copied from interface: MarshallingStrategy

Marshalls the given id object into a Resource (a resource having only its ids set). Note, that the id can be several types, depending on the mapping. For example, for class mapping, it can be the root Object itself (with its ids set), an array of ids, or if a single id, the actual id object.

The ResourceMapping are looked up based on the given object.

Will return null if no mappins are found

Specified by:
marshallIds in interface MarshallingStrategy
Parameters:
id - The id to marshall into a Resource
Returns:
A resource having its id properties set

marshallIds

public Resource marshallIds(String alias,
                            Object id)
Description copied from interface: MarshallingStrategy

Marshalls the give id object into a Resource (a resource having only its ids set). Note, that the id can be several types, depending on the mapping. For example, for class mapping, it can be the root Object itself (with its ids set), an array of ids, or if a single id, the actual id object.

The ResourceMapping are looked up based on the given alias.

Will return null if no mappins are found

Specified by:
marshallIds in interface MarshallingStrategy
Parameters:
alias - The alias to look up the ResourceMapping based
id - The id to marshall into a Resource
Returns:
A resource having its id properties set

marshallIds

public Resource marshallIds(Class clazz,
                            Object id)
Description copied from interface: MarshallingStrategy

Marshalls the give id object into a Resource (a resource having only its ids set). Note, that the id can be several types, depending on the mapping. For example, for class mapping, it can be the root Object itself (with its ids set), an array of ids, or if a single id, the actual id object.

The ResourceMapping are looked up based on the given class.

Will return null if no mappins are found

Specified by:
marshallIds in interface MarshallingStrategy
Parameters:
clazz - The class to look up the ResourceMapping based
id - The id to marshall into a Resource
Returns:
A resource having its id properties set

marshallIds

public Resource marshallIds(ResourceMapping resourceMapping,
                            Object id)
Description copied from interface: MarshallingStrategy
Marshalls the give id object into a Resource (a resource having only its ids set). Note, that the id can be several types, depending on the mapping. For example, for class mapping, it can be the root Object itself (with its ids set), an array of ids, or if a single id, the actual id object.

Specified by:
marshallIds in interface MarshallingStrategy
Parameters:
resourceMapping - The resource mapping holding how to marhsall the ids
id - The id to marshall into a Resource
Returns:
A resource having its id properties set

marshallIds

public boolean marshallIds(Resource resource,
                           ResourceMapping resourceMapping,
                           Object id,
                           MarshallingContext context)
Description copied from interface: MarshallingStrategy
Marshalls the give id object into the provided Resource (a resource having only its ids set). Note, that the id can be several types, depending on the mapping. For example, for class mapping, it can be the root Object itself (with its ids set), an array of ids, or if a single id, the actual id object.

Specified by:
marshallIds in interface MarshallingStrategy
Parameters:
resource - The resource to marhsll the ids into
resourceMapping - The resource mapping holding how to marhsall the ids
id - The id to marshall into a Resource
Returns:
true if stored properties were added to the Resource.

marshallIds

public void marshallIds(Object root,
                        Object id)
Description copied from interface: MarshallingStrategy
Marhsalls the give id into the actual object. Kindda hacky... .

Specified by:
marshallIds in interface MarshallingStrategy
Parameters:
root - The object to marshall the ids into
id - The id to marshall into the root object

marshallIds

public void marshallIds(ResourceMapping resourceMapping,
                        Object root,
                        Object id)
Description copied from interface: MarshallingStrategy
Marhsalls the give id into the actual object. Kindda hacky... .

Specified by:
marshallIds in interface MarshallingStrategy
Parameters:
resourceMapping - The resource mapping for the given object
root - The object to marshall the ids into
id - The id to marshall into the root object

unmarshallIds

public Object[] unmarshallIds(String alias,
                              Object id)
Description copied from interface: MarshallingStrategy
Unmarshalls the given id object into an array of all the id values. The results depends on the type of the mappings (raw resource/class).

The unmarshalling is performed based on ResourceMapping associated with the given alias.

Specified by:
unmarshallIds in interface MarshallingStrategy
Parameters:
alias - The alias to lookup the ResourceMapping
id - The id to unmarshall
Returns:
An array of all the ids

unmarshallIds

public Object[] unmarshallIds(Class clazz,
                              Object id)
Description copied from interface: MarshallingStrategy
Unmarshalls the given id object into an array of all the id values. The results depends on the type of the mappings (raw resource/class).

The unmarshalling is performed based on ResourceMapping associated with the given class.

Specified by:
unmarshallIds in interface MarshallingStrategy
Parameters:
clazz - The class to lookup the ResourceMapping
id - The id to unmarshall
Returns:
An array of all the ids

unmarshallIds

public Object[] unmarshallIds(ResourceMapping resourceMapping,
                              Object id,
                              MarshallingContext context)
Description copied from interface: MarshallingStrategy
Unmarshalls the given id object into an array of all the id values. The results depends on the type of the mappings (raw resource/class).

The unmarshalling is performed based on ResourceMapping provided.

Specified by:
unmarshallIds in interface MarshallingStrategy
Parameters:
resourceMapping - The resource to perform the unmarshalling based on
id - The id to unmarshall
Returns:
An array of all the ids

marshall

public Resource marshall(String alias,
                         Object root)
Description copied from interface: MarshallingStrategy
Marshalls the given Object into a Resource based on the ResourceMapping associated with the provided alias. Returns null if there are no mappings.

Specified by:
marshall in interface MarshallingStrategy
Parameters:
alias - The alias to look up the ResourceMapping
root - The object to marshall into the resource
Returns:
The resource result of marshalling the object or null if has no mapping

marshall

public Resource marshall(Object root)
Description copied from interface: MarshallingStrategy
Marshalls the given Object into a Resource based on the ResourceMapping associated with the provided object. If the object implements AliasedObject, the alias will be used to look up the ResourceMapping, otherwise, the object class will be used.

Specified by:
marshall in interface MarshallingStrategy
Parameters:
root - The object to marshall into a resource
Returns:
The resource result of marshalling the object

unmarshall

public Object unmarshall(Resource resource)
                  throws CompassException
Description copied from interface: MarshallingStrategy
Unmarshalls the given resource to an Object based on the ResourceMapping regsitered under the Resource alias.

Specified by:
unmarshall in interface MarshallingStrategy
Parameters:
resource - The resource to unmarshall from
Returns:
The object unmarshalled from the resource
Throws:
CompassException

unmarshall

public Object unmarshall(Resource resource,
                         MarshallingContext context)
                  throws CompassException
Description copied from interface: MarshallingStrategy
Unmarshalls the given resource to an Object based on the ResourceMapping regsitered under the Resource alias WITHIN the given marshalling context.

Specified by:
unmarshall in interface MarshallingStrategy
Parameters:
resource - The resource to unmarshall from
context - The context to unmarshall the resource within
Returns:
The object unmarshalled from the resource
Throws:
CompassException


Copyright (c) 2004-2009 The Compass Project.