eu.xtreemos.xosd.factory.utils.parsers
Class XMLSearchEngine

java.lang.Object
  extended by eu.xtreemos.xosd.factory.utils.parsers.XMLSearchEngine

public class XMLSearchEngine
extends java.lang.Object

Search engine for the output of the XMLValidatorAndParser

See Also:
XMLValidatorAndParser

Field Summary
private  java.util.Hashtable<java.lang.String,java.lang.Object> data
           
(package private) static org.apache.log4j.Logger logger
           
 
Constructor Summary
XMLSearchEngine(java.util.Hashtable<java.lang.String,java.lang.Object> data)
          Constructor for XMLSearchEngine class
 
Method Summary
 java.util.ArrayList get(java.lang.String key)
          Returns an ArrayList object of the XML subtrees whose keys match the provided key.
private  java.util.ArrayList get(java.lang.String key, java.util.Hashtable<java.lang.String,java.lang.Object> inData)
          Returns an ArrayList object of the XML subtrees whose keys match the provided key.
 java.util.ArrayList get(java.lang.String key, java.lang.String whereKey, java.lang.String whereValue)
          Returns an ArrayList object of the XML subtrees whose keys first match the key and then in a subtree there must exist another key (whereKey) which value must equeal to the provided value (whereValue) This method is simple equivalent of the SELECT ...
 java.util.ArrayList getFirst(java.lang.String key)
          This is counterpart of all XMLSearchEngine.get*First methods which are used to search just on level one of the XML tree.
private  java.util.ArrayList getFirst(java.lang.String key, java.util.Hashtable<java.lang.String,java.lang.Object> inData)
          This is copy of the upper get method.
private  java.util.ArrayList getWhere(java.lang.String key, java.lang.String whereKey, java.lang.String whereValue, java.util.Hashtable<java.lang.String,java.lang.Object> inData)
          Returns an ArrayList object of the XML subtrees whose keys first match the key and then in a subtree there must exist another key (whereKey) which value must equeal to the provided value (whereValue) This method is simple equivalent of the SELECT ...
 java.util.ArrayList getXPath(java.lang.String key, java.util.Hashtable<java.lang.String,java.lang.Object> inData)
          Returns an ArrayList object of the XML subtrees whose keys match the provided keyPath (XPath style).
 java.util.ArrayList getXPathFirst(java.lang.String key, java.util.Hashtable<java.lang.String,java.lang.Object> inData)
          This is basically the same implementation as getXPath method but it searches just in depth of level 1 (does not search in depth).
private  boolean hashtableContainsKey(java.lang.String regexKey, java.util.Hashtable<java.lang.String,java.lang.Object> hash)
          The method checks whether there is any key in the Hashtable matching the regexKey regular expression.
private  java.util.ArrayList hashtableGetValue(java.lang.String regexKey, java.util.Hashtable<java.lang.String,java.lang.Object> hash)
          The method gets an ArrayList corresponding to the matches via regular expression.
private  boolean keyHasValue(java.lang.String key, java.lang.String value, java.lang.Object inData)
          Finds the key in the inData structure and checks whether its value matches the provided value.
static void main(java.lang.String[] args)
          Main method - used for testing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

private java.util.Hashtable<java.lang.String,java.lang.Object> data

logger

static org.apache.log4j.Logger logger
Constructor Detail

XMLSearchEngine

public XMLSearchEngine(java.util.Hashtable<java.lang.String,java.lang.Object> data)
Constructor for XMLSearchEngine class

Parameters:
data - The data provided with XMLValidatorAndParser.
See Also:
XMLValidatorAndParser
Method Detail

hashtableContainsKey

private boolean hashtableContainsKey(java.lang.String regexKey,
                                     java.util.Hashtable<java.lang.String,java.lang.Object> hash)
The method checks whether there is any key in the Hashtable matching the regexKey regular expression.

Parameters:
regexKey - the regular expression with which the keys should be compared
hash - the hashtable with keys to compare
Returns:
true if there is at least one match; false otherwise
See Also:
expressions: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum

hashtableGetValue

private java.util.ArrayList hashtableGetValue(java.lang.String regexKey,
                                              java.util.Hashtable<java.lang.String,java.lang.Object> hash)
The method gets an ArrayList corresponding to the matches via regular expression.

Parameters:
regexKey - the regular expression with which the keys should be compared
hash - the hashtable with keys to compare
Returns:
ArrayList with values from the matchin keys; empty ArrayList otherwise
See Also:
expressions: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum

get

private java.util.ArrayList get(java.lang.String key,
                                java.util.Hashtable<java.lang.String,java.lang.Object> inData)
Returns an ArrayList object of the XML subtrees whose keys match the provided key.

The subtrees are Hashtables mixed with ArrayLists. Hashtable is of type XML tag/XML value, where XML value can be another Hashtable or in case of multiple descendants (defined as sequence) an ArrayList.

If no value is found, an empty ArrayList is returned.

Parameters:
key - The name of the XML tag to look for.
Returns:
An ArrayList of values corresponding to the XML tag
See Also:
get(String key, String whereKey, String whereValue)

getFirst

private java.util.ArrayList getFirst(java.lang.String key,
                                     java.util.Hashtable<java.lang.String,java.lang.Object> inData)
This is copy of the upper get method. Differs in definition of additional attribute which is used to monitor depth in which key is searched for. IMPORTANT TODO: additional parameter should be used (instead of hardcoded if-level-greater).

Parameters:
key -
inData -
level -
Returns:

keyHasValue

private boolean keyHasValue(java.lang.String key,
                            java.lang.String value,
                            java.lang.Object inData)
Finds the key in the inData structure and checks whether its value matches the provided value.

Parameters:
key - The name of the key to look for.
value - The value that must match the one found with the key.
Returns:
true if the key is found and its value matches the argument value; false otherwise.

getWhere

private java.util.ArrayList getWhere(java.lang.String key,
                                     java.lang.String whereKey,
                                     java.lang.String whereValue,
                                     java.util.Hashtable<java.lang.String,java.lang.Object> inData)
Returns an ArrayList object of the XML subtrees whose keys first match the key and then in a subtree there must exist another key (whereKey) which value must equeal to the provided value (whereValue)

This method is simple equivalent of the SELECT ... WHERE ... statement in SQL.

The subtrees are Hashtables mixed with ArrayLists. Hashtable is of type XML tag/XML value, where XML value can be another Hashtable or in case of multiple descendants (defined as sequence) an ArrayList.

If no value is found, an empty ArrayList is returned.

Parameters:
key - The name of the XML tag to look for.
whereKey - The name of the XML tag in the subtree to look for.
whereValue - The value that must match the subtree key.
Returns:
An ArrayList of values corresponding to the XML tag
See Also:
get(String key, String whereKey, String whereValue)

getXPath

public java.util.ArrayList getXPath(java.lang.String key,
                                    java.util.Hashtable<java.lang.String,java.lang.Object> inData)
Returns an ArrayList object of the XML subtrees whose keys match the provided keyPath (XPath style).

The subtrees are Hashtables mixed with ArrayLists. Hashtable is of type XML tag/XML value, where XML value can be another Hashtable or in case of multiple descendants (defined as sequence) an ArrayList.

If no value is found, an empty ArrayList is returned.

Parameters:
key - The name of the XML tag to look for.
Returns:
An ArrayList of values corresponding to the XML tag
See Also:
get(String key, String whereKey, String whereValue)

getXPathFirst

public java.util.ArrayList getXPathFirst(java.lang.String key,
                                         java.util.Hashtable<java.lang.String,java.lang.Object> inData)
This is basically the same implementation as getXPath method but it searches just in depth of level 1 (does not search in depth).

This method can be used to search for tags and its context which are nested (as complex types).

Parameters:
key - What label to look for
inData -
Returns:

get

public java.util.ArrayList get(java.lang.String key)
Returns an ArrayList object of the XML subtrees whose keys match the provided key.

The subtrees are Hashtables mixed with ArrayLists. Hashtable is of type XML tag/XML value, where XML value can be another Hashtable or in case of multiple descendants (defined as sequence) an ArrayList.

If no value is found, an empty ArrayList is returned.

Parameters:
key - The name of the XML tag to look for.
Returns:
An ArrayList of values corresponding to the XML tag
See Also:
get(String key, String whereKey, String whereValue)

getFirst

public java.util.ArrayList getFirst(java.lang.String key)
This is counterpart of all XMLSearchEngine.get*First methods which are used to search just on level one of the XML tree.

Parameters:
key -
Returns:

get

public java.util.ArrayList get(java.lang.String key,
                               java.lang.String whereKey,
                               java.lang.String whereValue)
Returns an ArrayList object of the XML subtrees whose keys first match the key and then in a subtree there must exist another key (whereKey) which value must equeal to the provided value (whereValue)

This method is simple equivalent of the SELECT ... WHERE ... statement in SQL.

The subtrees are Hashtables mixed with ArrayLists. Hashtable is of type XML tag/XML value, where XML value can be another Hashtable or in case of multiple descendants (defined as sequence) an ArrayList.

If no value is found, an empty ArrayList is returned.

Parameters:
key - The name of the XML tag to look for.
whereKey - The name of the XML tag in the subtree to look for.
whereValue - The value that must match the subtree key.
Returns:
An ArrayList of values corresponding to the XML tag
See Also:
get(String key)

main

public static void main(java.lang.String[] args)
Main method - used for testing