net.craftforge.essential.controller.allocation
Class ResourceNode

java.lang.Object
  extended by net.craftforge.essential.controller.allocation.ResourceNode

public class ResourceNode
extends Object

A resource node is the framework representation of a resource.

For a resource '/my/simple/path'

the following resource nodes are created:

For every resource, a resource node holds information on

Since:
30.07.11
Author:
Christian Bick

Constructor Summary
ResourceNode(String[] pathParts, int level)
          Initializes the resource node.
 
Method Summary
 void addResourceMethod(String[] pathParts, int level, Class<?> resourceClass, Method resourceMethod)
          Adds a resource method to this node or one of its sub nodes.
 List<ResourceNode> findAllSubNodes()
          Finds all direct and indirect sub nodes including this node
 List<ResourceNode> findAllSubNodesSkippingRoot()
          Finds all direct and indirect sub nodes including this node
 ResourceNode findResourceNode(String[] pathParts)
          Finds the sub node matching the last node of a path represented by the path parts.
 List<ResourceNode> findResourceNodesAlongPath(String[] pathParts)
          Finds all sub nodes along a path represented by the path parts.
 int getLevel()
          Gets the level of the node in the node tree with 0 being the root level.
 String getPath()
          Gets the complete (virtual) path from root to node.
 String getPathPart()
          Gets the path part.
 Pattern getPattern()
          Gets the pattern for matching against variable path parts.
 Class<?> getResourceClass()
          Gets the resource class being responsible for this node.
 List<Method> getResourceMethods()
          Gets the resource methods associated to this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceNode

public ResourceNode(String[] pathParts,
                    int level)
Initializes the resource node. Resource nodes are usually created from a path which is split into its parts. To be aware in which level of the path creation process the constructor has been called it is specified, too.

Parameters:
pathParts - The path parts of the original path
level - The current level
Method Detail

getLevel

public int getLevel()
Gets the level of the node in the node tree with 0 being the root level.

Returns:
The level in the node tree

getPath

public String getPath()
Gets the complete (virtual) path from root to node.

Returns:
The (virtual) path from root to node

getPathPart

public String getPathPart()
Gets the path part.

Returns:
The path part

getPattern

public Pattern getPattern()
Gets the pattern for matching against variable path parts.

Returns:
The pattern

getResourceClass

public Class<?> getResourceClass()
Gets the resource class being responsible for this node.

Returns:
The responsible resource class

getResourceMethods

public List<Method> getResourceMethods()
Gets the resource methods associated to this node.

Returns:
The responsible resource methods

addResourceMethod

public void addResourceMethod(String[] pathParts,
                              int level,
                              Class<?> resourceClass,
                              Method resourceMethod)
Adds a resource method to this node or one of its sub nodes. If no responsible sub node exists then a new sub node will be created along the path parts. If the this operation's maximum level (number of sub parts minus one) is reached then the given resource method is added to this node's resource methods.

Parameters:
pathParts - The path parts
level - The current level
resourceClass - The resource class
resourceMethod - The resource method

findResourceNode

public ResourceNode findResourceNode(String[] pathParts)
Finds the sub node matching the last node of a path represented by the path parts.

Parameters:
pathParts - The path parts
Returns:
The resource node

findResourceNodesAlongPath

public List<ResourceNode> findResourceNodesAlongPath(String[] pathParts)
Finds all sub nodes along a path represented by the path parts.

Parameters:
pathParts - The path parts
Returns:
List of all resource nodes along the path

findAllSubNodes

public List<ResourceNode> findAllSubNodes()
Finds all direct and indirect sub nodes including this node

Returns:
List of all sub nodes

findAllSubNodesSkippingRoot

public List<ResourceNode> findAllSubNodesSkippingRoot()
Finds all direct and indirect sub nodes including this node

Returns:
List of all sub nodes


Copyright © 2011. All Rights Reserved.