eu.xtreemos.xosd.utilities.resmng
Class ConditionTreeBuilder

java.lang.Object
  extended by eu.xtreemos.xosd.utilities.resmng.ConditionTreeBuilder

public class ConditionTreeBuilder
extends java.lang.Object

A helper class for building condition trees for resource matching queries.

Author:
matej.artac@xlab.si

Field Summary
(package private) static org.apache.log4j.Logger logger
           
static java.lang.String ValueKey
           
 
Constructor Summary
ConditionTreeBuilder()
           
 
Method Summary
static IConditionTreeNode buildTree(ParsedCommand xconsoleCommand)
           
static IConditionTreeNode buildTreeFromJSDL(java.util.Hashtable<java.lang.String,java.lang.Object> jsdl)
          Builds a condition tree from a structure representing an XML formatted according to the JSDL schema.
static void dumpConditionTree(IConditionTreeNode node)
          A helper method for dumping a tree starting at the provided node to stdout.
protected static void dumpConditionTree(IConditionTreeNode node, int level)
          A helper method for dumping a subtree at a certain depth level.
private static boolean getBoundExclusive(java.lang.Object bound)
          Checks if the bound expressed by the RangeValue_Type should be exclusive.
protected static double getBoundValue(java.lang.Object bound, java.lang.String key)
          Extracts the bound value from the hashtable representing a RangeValue_type.
protected static java.lang.String getElementValue(java.lang.Object element)
          Extract the value from the element that is assumed to be the leaf node in the XML structure.
private static IConditionTreeNode getExactSubtree(java.lang.Object exact, int nodeAttribute)
          Returns a subtree that checks whether the value matches the condition represented by Exact_type structure.
protected static IConditionTreeNode getMatchInterval(java.lang.String refValues, int nodeAttribute)
           
protected static IConditionTreeNode getMatchRangeConditionNode(java.util.ArrayList list, int nodeAttribute)
          Generate a condition subtree representing the range structure of a JSDL.
protected static IConditionTreeNode getMatchStringNode(java.util.ArrayList list, int nodeAttribute)
           
protected static INodeEvaluation getNodeEvaluation(int nodeAttribute)
          A helper method for creating attribute-type-dependent functions for evaluating the records by the attribute values.
private static IConditionTreeNode getRangeSubtree(java.lang.Object range, int nodeAttribute)
          Returns a subtree that checks whether the value is within one of the intervals provided in the Range_type JSDL structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ValueKey

public static final java.lang.String ValueKey
See Also:
Constant Field Values

logger

static org.apache.log4j.Logger logger
Constructor Detail

ConditionTreeBuilder

public ConditionTreeBuilder()
Method Detail

buildTreeFromJSDL

public static IConditionTreeNode buildTreeFromJSDL(java.util.Hashtable<java.lang.String,java.lang.Object> jsdl)
Builds a condition tree from a structure representing an XML formatted according to the JSDL schema.

Parameters:
jsdl - The structure containing the JSLD-formatted XML.
Returns:
The root node of the condition tree. If the JSDL contains multiple resource structures, the node is a member of ConditionTreeOperator representing an && operator. If only one structure exists, the return value is a parent of the subtree representing the structure. If no valid structures exist within JSDL, the function returns null.

getBoundValue

protected static double getBoundValue(java.lang.Object bound,
                                      java.lang.String key)
Extracts the bound value from the hashtable representing a RangeValue_type.

Parameters:
bound - A RangeValue_type structure that can either be the end value or a hashtable representing the structure.
key - The name of the type of the bound.
Returns:
The value representing the bound.

getElementValue

protected static java.lang.String getElementValue(java.lang.Object element)
Extract the value from the element that is assumed to be the leaf node in the XML structure. This means that the element is either a String or a Hashtable that contains an entry with the key "value". If the key does not exist or the element is of any other type, the method returns null.

Parameters:
element - The element to extract the value from. Should be of type String or a Hashtable that contains an entry with the key "value".
Returns:
The string with the value if it exists, and null otherwise.

getBoundExclusive

private static boolean getBoundExclusive(java.lang.Object bound)
Checks if the bound expressed by the RangeValue_Type should be exclusive.

Parameters:
bound - A RangeValue_type structure that can either be the end value or a hashtable representing the structure.
Returns:
True if the bound is set to be exclusive, or false otherwise. False is the default return value.

getExactSubtree

private static IConditionTreeNode getExactSubtree(java.lang.Object exact,
                                                  int nodeAttribute)
Returns a subtree that checks whether the value matches the condition represented by Exact_type structure.

Parameters:
exact - The Exact_type structure.
nodeAttribute - The identifier denoting which attribute of the JSDL / GLUE the condition refers to.
Returns:
A parent node of the subtree expressing the JSDL Exact structure. The returned node is a ConditionTreeOperator instance denoting || if there are multiple structures of Exact present in the condition, each child representing a separate recursive call return value. If the function receives a single structure Exact which has a non-zero epsilon attribute, the return value returns a ConditionTreeOperator instance denoting && between two ConditionTreeConditions, one for lower (ex - eps) and one for upper (ex + eps) boundary. If the function receives a single structure Exact which has a zero or a non-existent epsilon value, it returns an instance of ConditionTreeCondition that checks for equality.

getRangeSubtree

private static IConditionTreeNode getRangeSubtree(java.lang.Object range,
                                                  int nodeAttribute)
Returns a subtree that checks whether the value is within one of the intervals provided in the Range_type JSDL structure.

Parameters:
range - A Range_type structure containing an arraylist or a hashtable of ranges.
nodeAttribute - The identifier denoting which attribute of the JSDL / GLUE the condition refers to.
Returns:
A parent node of the subtree expressing the JSDL Range_type structure. The returned node is a ConditionTreeOperator instance denoting || if there are multiple structures of Exact present in the condition, each child representing a separate recursive call return value. If the function receives a single structure Range_type which has a non-zero epsilon attribute, the return value returns a ConditionTreeOperator instance denoting && between two ConditionTreeConditions, one for lower and one for upper boundary. If the function receives a single structure Range_type which has a zero or a non-existent epsilon value, it returns an instance of ConditionTreeCondition that checks for equality.

getMatchRangeConditionNode

protected static IConditionTreeNode getMatchRangeConditionNode(java.util.ArrayList list,
                                                               int nodeAttribute)
Generate a condition subtree representing the range structure of a JSDL.

Parameters:
list - The ArrayList containing the XML substructure representing the RangeType.
nodeAttribute - The identifier denoting which attribute of the JSDL / GLUE the condition refers to.
Returns:
The parent node of the subtree representing the Range_type structure of the JSDL. If multile elements of the structure exist in the JSDL structure, the node is a ConditionTreeOperator representing an || node. If a single structure exists, the function returns the child off the || node. If no structures exist in JSDL, the function returns null.

getNodeEvaluation

protected static INodeEvaluation getNodeEvaluation(int nodeAttribute)
A helper method for creating attribute-type-dependent functions for evaluating the records by the attribute values.

Parameters:
nodeAttribute - The attribute to initialise the evaluation function for.
Returns:
An instance of the node attribute evaluation class.

getMatchStringNode

protected static IConditionTreeNode getMatchStringNode(java.util.ArrayList list,
                                                       int nodeAttribute)

dumpConditionTree

public static void dumpConditionTree(IConditionTreeNode node)
A helper method for dumping a tree starting at the provided node to stdout.

Parameters:
node - The node to start the dumping of the tree at.

dumpConditionTree

protected static void dumpConditionTree(IConditionTreeNode node,
                                        int level)
A helper method for dumping a subtree at a certain depth level.

Parameters:
node - The node to start the dumping of the tree at.
level - The node's depth (0 - root, 1 - child of the root, etc.), reflected in the level of indentation of the dump.

buildTree

public static IConditionTreeNode buildTree(ParsedCommand xconsoleCommand)

getMatchInterval

protected static IConditionTreeNode getMatchInterval(java.lang.String refValues,
                                                     int nodeAttribute)