org.compass.core.mapping.internal
Class DefaultCompassMapping

java.lang.Object
  extended by org.compass.core.mapping.internal.DefaultCompassMapping
All Implemented Interfaces:
CompassMapping, InternalCompassMapping

public class DefaultCompassMapping
extends Object
implements InternalCompassMapping

Author:
kimchy

Constructor Summary
DefaultCompassMapping()
           
 
Method Summary
 void addMapping(AliasMapping mapping)
          Adds the given Alias mapping.
 void clearCache()
           
 void clearMappings()
           
 InternalCompassMapping copy(ConverterLookup converterLookup)
           
 ResourceMapping findNonRootMappingByClass(Class clazz)
          Finds a non root mapping by the class name.
 ResourceMapping findRootMappingByClass(Class clazz)
          Finds a root mapping by the class name.
 AliasMapping getAliasMapping(String alias)
          Returns the alias mapping for the given alias (most if not all of the times, this will be a ResourceMapping).
 List<ResourceMapping> getAllDirectMappingByClass(Class clazz)
          Returns all the direct class mapping for the given class (root or not).
 ConverterLookup getConverterLookup()
          Returns the converter lookup.
 ResourceMapping getDirectMappingByClass(Class clazz)
          Returns the direct class mapping for the given class (root or not).
 ResourceMapping getMappingByAlias(String alias)
          Returns the resource mapping for the given alias.
 ResourceMapping getMappingByClass(Class clazz)
          Finds the Resource mapping that is the "nearest" to the provided class.
 AliasMapping[] getMappings()
          Returns an array of all the current mappings.
 ResourceMapping getNonRootMappingByAlias(String alias)
          Returns the non root resource mapping associated with the alias.
 ResourceMapping getNonRootMappingByClass(Class clazz)
          Does exactly the same as findNonRootMappingByClass(Class), but returns null if nothing is found (does not throw an exception).
 PropertyPath getPath()
          Returns the root path of the mappings.
 ResourcePropertyLookup getResourcePropertyLookup(String name)
          Returns a resoruce lookup for a specific name.
 ResourcePropertyMapping getResourcePropertyMappingByPath(String path)
          Finds the ResourcePropertyMapping definition for the specified path.
 ResourcePropertyMapping[] getResourcePropertyMappingsByPath(String path)
          Returns an array of all the given ResourcePropertyMapping for the given path.
 ResourceMapping getRootMappingByAlias(String alias)
          Returns the root resource mapping associated with the alias.
 ResourceMapping getRootMappingByClass(Class clazz)
          Does exactly the same as findRootMappingByClass(Class), but returns null if nothing is found (does not throw an exception).
 ResourceMapping[] getRootMappings()
          Returns all the root resource mappings.
 boolean hasMappingForAlias(String alias, Cascade cascade)
          Returns true if the given alias has either root mappings, or if it has a non root mapping, it has mappings for the given cascade operation.
 boolean hasMappingForClass(Class clazz, Cascade cascade)
          Returns true if the given class has either root mappings, or if it has a non root mapping, it has mappings for the given cascade operation.
 boolean hasMultipleRootClassMapping(String className)
          Returns true if the given className has multiple class mappings.
 boolean hasRootClassMapping(String alias)
          Returns true if there is a root ClassMapping for the given alias.
 boolean hasRootMappingByAlias(String alias)
          Returns true if the given alias has a root resource mapping.
 boolean hasRootRawResourceMapping(String alias)
          Returns true if there is a root RawResourceMapping for the given alias.
 void postProcess()
           
 boolean removeMappingByAlias(String alias)
           
 boolean removeMappingByClass(String className)
           
 void setPath(PropertyPath path)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCompassMapping

public DefaultCompassMapping()
Method Detail

copy

public InternalCompassMapping copy(ConverterLookup converterLookup)
Specified by:
copy in interface InternalCompassMapping

postProcess

public void postProcess()
Specified by:
postProcess in interface InternalCompassMapping

clearMappings

public void clearMappings()
Specified by:
clearMappings in interface InternalCompassMapping

clearCache

public void clearCache()

addMapping

public void addMapping(AliasMapping mapping)
                throws MappingException
Adds the given Alias mapping.

Specified by:
addMapping in interface InternalCompassMapping
Throws:
MappingException

removeMappingByClass

public boolean removeMappingByClass(String className)
                             throws MappingException
Specified by:
removeMappingByClass in interface InternalCompassMapping
Throws:
MappingException

removeMappingByAlias

public boolean removeMappingByAlias(String alias)
                             throws MappingException
Specified by:
removeMappingByAlias in interface InternalCompassMapping
Throws:
MappingException

getResourcePropertyLookup

public ResourcePropertyLookup getResourcePropertyLookup(String name)
                                                 throws IllegalArgumentException
Returns a resoruce lookup for a specific name. Supports dot path notation ([alias].[class property].). Allows to get the meta-data/resource property mapping through it (or a list of mappings).

Specified by:
getResourcePropertyLookup in interface CompassMapping
Throws:
IllegalArgumentException

getResourcePropertyMappingByPath

public ResourcePropertyMapping getResourcePropertyMappingByPath(String path)
Finds the ResourcePropertyMapping definition for the specified path. The path is in the format of: [alias].[class property mapping].[meta data mapping] in case of class mapping, and [alias].[resource property mapping] in case of resource mapping. The format of [alias].[class property mapping] can also be applied, and will result in the meta data id of the given class property mapping.

Specified by:
getResourcePropertyMappingByPath in interface CompassMapping
Parameters:
path - the path to the resource property mapping
Returns:
the resource property mapping for the given path

getResourcePropertyMappingsByPath

public ResourcePropertyMapping[] getResourcePropertyMappingsByPath(String path)
Returns an array of all the given ResourcePropertyMapping for the given path. If the path is in "dot path" notation, will reutrn a single mappings matching it (see getResourcePropertyMappingByPath(String)). Otherwise will return all the ones mapped to the given name.

Specified by:
getResourcePropertyMappingsByPath in interface CompassMapping

getMappings

public AliasMapping[] getMappings()
Returns an array of all the current mappings.

Specified by:
getMappings in interface CompassMapping

getAliasMapping

public AliasMapping getAliasMapping(String alias)
Returns the alias mapping for the given alias (most if not all of the times, this will be a ResourceMapping).

Specified by:
getAliasMapping in interface CompassMapping

getMappingByAlias

public ResourceMapping getMappingByAlias(String alias)
Returns the resource mapping for the given alias.

Specified by:
getMappingByAlias in interface CompassMapping

getRootMappingByAlias

public ResourceMapping getRootMappingByAlias(String alias)
Returns the root resource mapping associated with the alias. Retruns null if no root mapping (or no mapping) is associated with the alias.

Specified by:
getRootMappingByAlias in interface CompassMapping

getNonRootMappingByAlias

public ResourceMapping getNonRootMappingByAlias(String alias)
Returns the non root resource mapping associated with the alias. Retruns null if no non root mapping (or no mapping) is associated with the alias.

Specified by:
getNonRootMappingByAlias in interface CompassMapping

hasRootMappingByAlias

public boolean hasRootMappingByAlias(String alias)
Returns true if the given alias has a root resource mapping.

Specified by:
hasRootMappingByAlias in interface CompassMapping

hasRootClassMapping

public boolean hasRootClassMapping(String alias)
Returns true if there is a root ClassMapping for the given alias.

Specified by:
hasRootClassMapping in interface CompassMapping

hasRootRawResourceMapping

public boolean hasRootRawResourceMapping(String alias)
Returns true if there is a root RawResourceMapping for the given alias.

Specified by:
hasRootRawResourceMapping in interface CompassMapping

hasMultipleRootClassMapping

public boolean hasMultipleRootClassMapping(String className)
Returns true if the given className has multiple class mappings.

Specified by:
hasMultipleRootClassMapping in interface CompassMapping

getDirectMappingByClass

public ResourceMapping getDirectMappingByClass(Class clazz)
Returns the direct class mapping for the given class (root or not). Will not try to navigate up the interface/superclass in order to find the "nearset" class mapping.

If a class has more than one mappings (using differnet aliases) will return the first one.

Specified by:
getDirectMappingByClass in interface CompassMapping

getAllDirectMappingByClass

public List<ResourceMapping> getAllDirectMappingByClass(Class clazz)
Returns all the direct class mapping for the given class (root or not). Will not try to navigate up the interface/superclass in order to find the "nearest" class mapping.

Specified by:
getAllDirectMappingByClass in interface CompassMapping

hasMappingForClass

public boolean hasMappingForClass(Class clazz,
                                  Cascade cascade)
Description copied from interface: CompassMapping
Returns true if the given class has either root mappings, or if it has a non root mapping, it has mappings for the given cascade operation.

Specified by:
hasMappingForClass in interface CompassMapping

hasMappingForAlias

public boolean hasMappingForAlias(String alias,
                                  Cascade cascade)
Description copied from interface: CompassMapping
Returns true if the given alias has either root mappings, or if it has a non root mapping, it has mappings for the given cascade operation.

Specified by:
hasMappingForAlias in interface CompassMapping

getMappingByClass

public ResourceMapping getMappingByClass(Class clazz)
Finds the Resource mapping that is the "nearest" to the provided class. Similar way that findRootMappingByClass(Class) except the search is on all the ClassMappings (even ones that are not marked as root).

Specified by:
getMappingByClass in interface CompassMapping

findRootMappingByClass

public ResourceMapping findRootMappingByClass(Class clazz)
                                       throws MappingException
Finds a root mapping by the class name. If a root mapping is not found for the class name, than searches for mappings for the interfaces, if not found, checks for subclasses, and subclassess interfaces. Note: If there is no direct mapping that match the class name, then the mapping that is found should be marked as poly.

Specified by:
findRootMappingByClass in interface CompassMapping
Parameters:
clazz - The class to find root mapping for
Returns:
The resource mapping
Throws:
MappingException

getRootMappingByClass

public ResourceMapping getRootMappingByClass(Class clazz)
                                      throws MappingException
Does exactly the same as findRootMappingByClass(Class), but returns null if nothing is found (does not throw an exception).

Specified by:
getRootMappingByClass in interface CompassMapping
Throws:
MappingException

findNonRootMappingByClass

public ResourceMapping findNonRootMappingByClass(Class clazz)
                                          throws MappingException
Finds a non root mapping by the class name. If a non root mapping is not found for the class name, than searches for mappings for the interfaces, if not found, checks for subclasses, and subclassess interfaces. Note: If there is no direct mapping that match the class name, then the mapping that is found should be marked as poly.

Specified by:
findNonRootMappingByClass in interface CompassMapping
Parameters:
clazz - The class to find root mapping for
Returns:
The resource mapping
Throws:
MappingException

getNonRootMappingByClass

public ResourceMapping getNonRootMappingByClass(Class clazz)
                                         throws MappingException
Does exactly the same as findNonRootMappingByClass(Class), but returns null if nothing is found (does not throw an exception).

Specified by:
getNonRootMappingByClass in interface CompassMapping
Throws:
MappingException

getRootMappings

public ResourceMapping[] getRootMappings()
Description copied from interface: CompassMapping
Returns all the root resource mappings.

Specified by:
getRootMappings in interface CompassMapping

getConverterLookup

public ConverterLookup getConverterLookup()
Description copied from interface: CompassMapping
Returns the converter lookup.

Specified by:
getConverterLookup in interface CompassMapping

getPath

public PropertyPath getPath()
Description copied from interface: CompassMapping
Returns the root path of the mappings.

Specified by:
getPath in interface CompassMapping

setPath

public void setPath(PropertyPath path)
Specified by:
setPath in interface InternalCompassMapping


Copyright (c) 2004-2009 The Compass Project.