org.jboss.dna.connector.federation
Class Projection

java.lang.Object
  extended by org.jboss.dna.connector.federation.Projection
All Implemented Interfaces:
Serializable, Comparable<Projection>

@Immutable
public class Projection
extends Object
implements Comparable<Projection>, Serializable

A projection of content from a source into the integrated/federated repository. Each project consists of a set of rules for a particular source, where each rule defines how content within a source is is project into the repository and how the repository content is projected into the source. Different rule subclasses are used for different types.

Author:
Randall Hauch
See Also:
Serialized Form

Nested Class Summary
static class Projection.PathRule
          A rule that is defined with a single path in source and a single path in repository, and which has a set of path exceptions (relative paths below the path in source).
static class Projection.Rule
          A rule used within a project do define how content within a source is projected into the federated repository.
 
Constructor Summary
Projection(String sourceName, String workspaceName, Projection.Rule... rules)
          Create a new federated projection for the supplied source, using the supplied rules.
 
Method Summary
static void addRuleParser(ClassLoader classLoader, String className, String methodName)
          Add a static method that can be used to parse rule definition strings.
static void addRuleParser(Method method)
          Add a static method that can be used to parse rule definition strings.
 int compareTo(Projection that)
          
 boolean equals(Object obj)
          
static Projection.Rule fromString(String definition, ExecutionContext context)
          Parse the string form of a rule definition and return the rule
 Set<Path> getPathsInRepository(Path canonicalPathInSource, PathFactory factory)
          Get the paths in the repository that correspond to the supplied path within the source.
 Set<Path> getPathsInSource(Path canonicalPathInRepository, PathFactory factory)
          Get the paths in the source that correspond to the supplied path within the repository.
 List<Projection.Rule> getRules()
          Get the rules that define this projection.
 String getSourceName()
          Get the name of the source to which this projection applies.
 List<Path> getTopLevelPathsInRepository(PathFactory factory)
          Get the paths in the repository that serve as top-level nodes exposed by this projection.
 String getWorkspaceName()
          Get the name of the workspace in the source to which this projection applies.
 int hashCode()
          
 boolean isSimple()
          Determine whether this project is a simple projection that only involves for any one repository path no more than a single source path.
static Projection.PathRule parsePathRule(String definition, ExecutionContext context)
          Parse the string definition of a Projection.PathRule.
static boolean removeRuleParser(Method method)
          Remove the rule parser method.
static boolean removeRuleParser(String declaringClassName, String methodName)
          Remove the rule parser method.
 String toString()
          
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Projection

public Projection(String sourceName,
                  String workspaceName,
                  Projection.Rule... rules)
Create a new federated projection for the supplied source, using the supplied rules.

Parameters:
sourceName - the name of the source
workspaceName - the name of the workspace in the source; may be null if the default workspace is to be used
rules - the projection rules
Throws:
IllegalArgumentException - if the source name or rule array is null, empty, or contains all nulls
Method Detail

addRuleParser

public static void addRuleParser(Method method)
Add a static method that can be used to parse rule definition strings. These methods must be static, must accept a String definition as the first parameter and an ExecutionContext environment reference as the second parameter, and should return the resulting Projection.Rule (or null if the definition format could not be understood by the method. Any exceptions during invocation will be logged at the trace level.

Parameters:
method - the method to be added
See Also:
addRuleParser(ClassLoader, String, String)

addRuleParser

public static void addRuleParser(ClassLoader classLoader,
                                 String className,
                                 String methodName)
                          throws SecurityException,
                                 NoSuchMethodException,
                                 ClassNotFoundException
Add a static method that can be used to parse rule definition strings. These methods must be static, must accept a String definition as the first parameter and an ExecutionContext environment reference as the second parameter, and should return the resulting Projection.Rule (or null if the definition format could not be understood by the method. Any exceptions during invocation will be logged at the trace level.

Parameters:
classLoader - the class loader that should be used to load the class on which the method is defined; may not be null
className - the name of the class on which the static method is defined; may not be null
methodName - the name of the method
Throws:
SecurityException - if there is a security exception while loading the class or getting the method
NoSuchMethodException - if the method does not exist on the class
ClassNotFoundException - if the class could not be found given the supplied class loader
IllegalArgumentException - if the class loader reference is null, or if the class name or method name are null or empty
See Also:
addRuleParser(Method)

removeRuleParser

public static boolean removeRuleParser(Method method)
Remove the rule parser method.

Parameters:
method - the method to remove
Returns:
true if the method was removed, or false if the method was not a registered rule parser method

removeRuleParser

public static boolean removeRuleParser(String declaringClassName,
                                       String methodName)
Remove the rule parser method.

Parameters:
declaringClassName - the name of the class on which the static method is defined; may not be null
methodName - the name of the method
Returns:
true if the method was removed, or false if the method was not a registered rule parser method
Throws:
IllegalArgumentException - if the class loader reference is null, or if the class name or method name are null or empty

fromString

public static Projection.Rule fromString(String definition,
                                         ExecutionContext context)
Parse the string form of a rule definition and return the rule

Parameters:
definition - the definition of the rule that is to be parsed
context - the environment in which this method is being executed; may not be null
Returns:
the rule, or null if the definition could not be parsed

parsePathRule

public static Projection.PathRule parsePathRule(String definition,
                                                ExecutionContext context)
Parse the string definition of a Projection.PathRule. This method is automatically registered in the parser methods by the static initializer of Projection.

Parameters:
definition - the definition
context - the environment
Returns:
the path rule, or null if the definition is not in the right form

getSourceName

public String getSourceName()
Get the name of the source to which this projection applies.

Returns:
the source name
See Also:
RepositorySource.getName()

getWorkspaceName

public String getWorkspaceName()
Get the name of the workspace in the source to which this projection applies.

Returns:
the workspace name, or null if the default workspace of the source is to be used

getRules

public List<Projection.Rule> getRules()
Get the rules that define this projection.

Returns:
the unmodifiable list of immutable rules; never null

getPathsInSource

public Set<Path> getPathsInSource(Path canonicalPathInRepository,
                                  PathFactory factory)
Get the paths in the source that correspond to the supplied path within the repository. This method computes the paths given all of the rules. In general, most sources will probably project a node onto a single repository node. However, some sources may be configured such that the same node in the repository is a projection of multiple nodes within the source.

Parameters:
canonicalPathInRepository - the canonical path of the node within the repository; may not be null
factory - the path factory; may not be null
Returns:
the set of unique paths in the source projected from the repository path; never null
Throws:
IllegalArgumentException - if the factory reference is null

getPathsInRepository

public Set<Path> getPathsInRepository(Path canonicalPathInSource,
                                      PathFactory factory)
Get the paths in the repository that correspond to the supplied path within the source. This method computes the paths given all of the rules. In general, most sources will probably project a node onto a single repository node. However, some sources may be configured such that the same node in the source is projected into multiple nodes within the repository.

Parameters:
canonicalPathInSource - the canonical path of the node within the source; may not be null
factory - the path factory; may not be null
Returns:
the set of unique paths in the repository projected from the source path; never null
Throws:
IllegalArgumentException - if the factory reference is null

getTopLevelPathsInRepository

public List<Path> getTopLevelPathsInRepository(PathFactory factory)
Get the paths in the repository that serve as top-level nodes exposed by this projection.

Parameters:
factory - the path factory that can be used to create new paths; may not be null
Returns:
the list of top-level paths, in the proper order and containing no duplicates; never null

isSimple

public boolean isSimple()
Determine whether this project is a simple projection that only involves for any one repository path no more than a single source path.

Returns:
true if this projection is a simple projection, or false if the projection is not simple (or it cannot be determined if it is simple)

hashCode

public int hashCode()

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

equals

public boolean equals(Object obj)

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

compareTo

public int compareTo(Projection that)

Specified by:
compareTo in interface Comparable<Projection>
See Also:
Comparable.compareTo(java.lang.Object)

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2008-Present JBoss a division of Red Hat. All Rights Reserved.