Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle TopLink
11g Release 1 (11.1.1)

E28847-01


org.eclipse.persistence.jpa.internal.jpql
Class WordParser

java.lang.Object
  extended by org.eclipse.persistence.jpa.internal.jpql.WordParser


public final class WordParser
extends java.lang.Object

This "parser" holds onto the string version of the Java Persistence query that is parsed into a parsed tree. It uses a cursor that let the current Expression object to parse its section of the query.

Since:
2.3
Version:
2.3
Author:
Pascal Filion

Field Summary
private  int cursor
          The current position of the cursor within the text.
private  int length
          The total length of the string.
private  java.lang.CharSequence text
          The string representation of the Java Persistence query to parse.

 

Constructor Summary
WordParser(java.lang.CharSequence query)
          Creates a new WordParser.

 

Method Summary
 char character()
          Retrieves the character at the current position of the cursor.
 char character(int position)
          Retrieves the character at the given position.
private  void checkText(java.lang.CharSequence query)
           
 boolean endsWith(int endPosition, java.lang.String suffix)
          Determines whether the query ends with the given suffix and the end position is the end of the range for testing.
 java.lang.String entireWord()
          Retrieves a word starting at the current position.
 java.lang.String entireWord(int position)
          Retrieves a word starting at the given position.
 boolean isArithmeticSymbol(char character)
          Determines whether the given character is an arithmetic symbol, which is one of the following: { '>', '<', '/', '*', '-', '+', '=', '{' }.
 boolean isDelimitor(char character)
          Determines whether the given character is a delimiter.
 boolean isDigit(char character)
          Determines whether the given character is a character that can be used in a number.
 boolean isParsingComplete(char character)
           
 boolean isTail()
          Determines whether the position of the cursor is at the end of the text.
 int length()
          Returns the length of the string value.
 void moveBackward(java.lang.CharSequence word)
          Moves the position of the cursor by the length of the given word.
 void moveBackward(int position)
          Moves backward the position of the cursor by the given amount.
 void moveForward(java.lang.CharSequence word)
          Moves the position of the cursor by the length of the given word.
 void moveForward(int position)
          Moves forward the position of the cursor by the given amount.
 java.lang.String partialWord()
          Retrieves a word before the current position of the cursor, which determines when the parsing stop.
 java.lang.String partialWord(int position)
          Retrieves a word before the specified position, which determines when the parsing stop.
 int partialWordStartPosition(int position)
          Finds the beginning of the word and the given position is within that word.
 int position()
          Returns the current position of the cursor.
 java.lang.String potentialWord()
          Retrieves
 int potentialWordEndPosition()
          Retrieves
 java.lang.String previousWord(int position)
          Retrieves the previous word from the current position.
 void setPosition(int position)
          Manually sets the position of the cursor within the string.
 int skipLeadingWhitespace()
          Removes the whitespace that starts the given text.
 boolean startsWith(char possibleCharacter)
          Determines whether the text starts with the given character.
 boolean startsWith(java.lang.CharSequence prefix)
          Tests whether the query starts with the specified prefix from the current position.
 boolean startsWith(java.lang.CharSequence prefix, int startIndex)
          Tests whether the substring of the query beginning at the specified index starts with the specified prefix.
 boolean startsWithArithmeticOperator()
          Determines whether the character at the current position is one of the arithmetic operators: { '+', '-', '*', '/' },
 java.lang.Boolean startsWithDigit()
          Determines if the text starts with a digit (true), an arithmetic term (false) or anything else (null).
 boolean startsWithIdentifier(java.lang.CharSequence prefix)
           
 boolean startsWithIdentifier(java.lang.CharSequence prefix, int toffset)
           
 boolean startsWithIgnoreCase(char possibleCharacter)
          Determines whether the text starts with the given character.
 boolean startsWithIgnoreCase(java.lang.CharSequence prefix)
          Tests if the string starts with the specified prefix.
 boolean startsWithIgnoreCase(java.lang.CharSequence prefix, int offset)
          Tests if the string starts with the specified prefix.
 java.lang.String substring()
          Returns a substring that is within the current position of the cursor and the end of the text.
 java.lang.String substring(int startIndex)
          Returns a substring that is within the given position and the end of the text.
 java.lang.String substring(int startIndex, int endIndex)
          Returns a substring that is within the given positions.
 java.lang.String toString()
          
 int whitespaceCount()
          Calculates the number of whitespace that are in the query.
 int whitespaceCount(int position)
          Calculates the number of whitespace that are in the query.
 java.lang.String word()
          Retrieves the first word starting at the current position.
 int wordEndPosition()
          Returns the position at which a word ends, the position is determined by the current position of the cursor.
 int wordEndPosition(int position)
          Returns the position at which a word ends.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Field Detail

cursor

private int cursor
The current position of the cursor within the text.

length

private final int length
The total length of the string.

text

private final java.lang.CharSequence text
The string representation of the Java Persistence query to parse.

Constructor Detail

WordParser

public WordParser(java.lang.CharSequence query)
Creates a new WordParser.
Parameters:
text - The string representation of the Java Persistence query to parse

Method Detail

character

public char character()
Retrieves the character at the current position of the cursor.
Returns:
The character retrieved from the string at the cursor position

character

public char character(int position)
Retrieves the character at the given position.
Parameters:
position - The position of the character to return
Returns:
The character retrieved from the string at the given position

checkText

private void checkText(java.lang.CharSequence query)

endsWith

public boolean endsWith(int endPosition,
                        java.lang.String suffix)
Determines whether the query ends with the given suffix and the end position is the end of the range for testing.
Parameters:
endPosition - The position where the check stops
suffix - The suffix is the text that is used to match it with the substring within the text
Returns:
true if the character sequence represented by the argument is a suffix of the query; false otherwise

entireWord

public java.lang.String entireWord()
Retrieves a word starting at the current position. The text before and after the position will be part of the returned value.

For instance, "SELECT AVG(e.age) FROM Employee e":

Returns:
The word in which the cursor is

entireWord

public java.lang.String entireWord(int position)
Retrieves a word starting at the given position. The text before and after the position will be part of the returned value.

For instance, "SELECT AVG(e.age) FROM Employee e":

Parameters:
position - The position where to retrieve the word
Returns:
The word in which the cursor is

isArithmeticSymbol

public boolean isArithmeticSymbol(char character)
Determines whether the given character is an arithmetic symbol, which is one of the following: { '>', '<', '/', '*', '-', '+', '=', '{' }.
Parameters:
character - The character to test if it's a math symbol
Returns:
true if the given character is one of the valid math symbols; false otherwise

isDelimitor

public boolean isDelimitor(char character)
Determines whether the given character is a delimiter. The delimiter are '(', ')' and ','.
Parameters:
character - The character to test
Returns:
true if the given character is a delimiter; false otherwise

isDigit

public boolean isDigit(char character)
Determines whether the given character is a character that can be used in a number. This includes all numeric characters [0, 9] and the period character.
Parameters:
character - The character to test if it's a digit
Returns:
true if the given character is a digit; false otherwise

isParsingComplete

public boolean isParsingComplete(char character)

isTail

public boolean isTail()
Determines whether the position of the cursor is at the end of the text.
Returns:
true if the position of the cursor is at the end of the text; false otherwise

length

public int length()
Returns the length of the string value.
Returns:
The total count of characters

moveBackward

public void moveBackward(java.lang.CharSequence word)
Moves the position of the cursor by the length of the given word.
Parameters:
word - The word used to determine how much to move the position forward

moveBackward

public void moveBackward(int position)
Moves backward the position of the cursor by the given amount.
Parameters:
position - The amount to remove from the current position

moveForward

public void moveForward(java.lang.CharSequence word)
Moves the position of the cursor by the length of the given word.
Parameters:
word - The word used to determine how much to move the position forward

moveForward

public void moveForward(int position)
Moves forward the position of the cursor by the given amount.
Parameters:
position - The amount to add to the current position

partialWord

public java.lang.String partialWord()
Retrieves a word before the current position of the cursor, which determines when the parsing stop.

For instance, "SELECT AVG(e.age) FROM Employee e":

Returns:
The sub-string that is before the position

partialWord

public java.lang.String partialWord(int position)
Retrieves a word before the specified position, which determines when the parsing stop.

For instance, "SELECT AVG(e.age) FROM Employee e":

Parameters:
position - The position of the cursor
Returns:
The sub-string that is before the position

partialWordStartPosition

public int partialWordStartPosition(int position)
Finds the beginning of the word and the given position is within that word.

For instance, "SELECT AVG(e.age) FROM Employee e":

Parameters:
position - The position from which the search ends
Returns:
The position, which is a smaller number or equal, than the given position

position

public int position()
Returns the current position of the cursor.
Returns:
The current position of the cursor

potentialWord

public java.lang.String potentialWord()
Retrieves
Returns:

potentialWordEndPosition

public int potentialWordEndPosition()
Retrieves
Returns:

previousWord

public java.lang.String previousWord(int position)
Retrieves the previous word from the current position. Any character from the position to the first whitespace will be ignore.

For instance, "SELECT AVG(e.age) FROM Employee e":

Parameters:
position - The position to start looking for a word in reverse
Returns:
The previous word that is separated by whitespace with the position

setPosition

public void setPosition(int position)
Manually sets the position of the cursor within the string.
Parameters:
position - The new position of the cursor

skipLeadingWhitespace

public int skipLeadingWhitespace()
Removes the whitespace that starts the given text.
Parameters:
text - The text to have the whitespace removed from the beginning of the string
Returns:
The number of whitespace removed

startsWith

public boolean startsWith(char possibleCharacter)
Determines whether the text starts with the given character. The case of the character is not ignored.
Parameters:
possibleCharacter - The possible character at the current position
Returns:
true if the text starts with the given character at the current position; false otherwise

startsWith

public boolean startsWith(java.lang.CharSequence prefix)
Tests whether the query starts with the specified prefix from the current position.
Parameters:
prefix - The prefix
Returns:
true if the character sequence represented by the argument is a prefix of the text; false otherwise

startsWith

public boolean startsWith(java.lang.CharSequence prefix,
                          int startIndex)
Tests whether the substring of the query beginning at the specified index starts with the specified prefix.
Parameters:
prefix - The prefix
offset - Where to begin looking in the query
Returns:
true if the character sequence represented by the argument is a prefix of the substring of this object starting at index startIndex; false otherwise

startsWithArithmeticOperator

public boolean startsWithArithmeticOperator()
Determines whether the character at the current position is one of the arithmetic operators: { '+', '-', '*', '/' },
Returns:
true if the character at the current position is an arithmetic operator; false otherwise

startsWithDigit

public java.lang.Boolean startsWithDigit()
Determines if the text starts with a digit (true), an arithmetic term (false) or anything else (null).
Returns:
true if the text starts with a digit (we'll assume it is a digit if the text starts with a digit or an arithmetic sign followed by a digit), false if it starts with an arithmetic term (we'll assume it is a digit followed by a non-digit character); otherwise returns null

startsWithIdentifier

public boolean startsWithIdentifier(java.lang.CharSequence prefix)

startsWithIdentifier

public boolean startsWithIdentifier(java.lang.CharSequence prefix,
                                    int toffset)

startsWithIgnoreCase

public boolean startsWithIgnoreCase(char possibleCharacter)
Determines whether the text starts with the given character. The case of the character is ignored.
Parameters:
possibleCharacter - The possible character at the current position
Returns:
true if the text starts with the given character at the current position; false otherwise

startsWithIgnoreCase

public boolean startsWithIgnoreCase(java.lang.CharSequence prefix)
Tests if the string starts with the specified prefix.
Parameters:
prefix - The prefix
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object as determined by the Object.equals(Object) method

startsWithIgnoreCase

public boolean startsWithIgnoreCase(java.lang.CharSequence prefix,
                                    int offset)
Tests if the string starts with the specified prefix.
Parameters:
prefix - The prefix
offset - Where to begin looking in this string
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise

substring

public java.lang.String substring()
Returns a substring that is within the current position of the cursor and the end of the text.
Returns:
The remain of the string starting at the current position

substring

public java.lang.String substring(int startIndex)
Returns a substring that is within the given position and the end of the text.
Parameters:
startIndex - The beginning of the substring, inclusive
Returns:
The remain of the string starting at the given position

substring

public java.lang.String substring(int startIndex,
                                  int endIndex)
Returns a substring that is within the given positions.
Parameters:
startIndex - The beginning of the substring, inclusive
endIndex - The end of the substring, exclusive
Returns:
The remain of the string that is within the given positions

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

whitespaceCount

public int whitespaceCount()
Calculates the number of whitespace that are in the query. The check starts at the current position.
Returns:
The count of consecutive whitespace found from the current position

whitespaceCount

public int whitespaceCount(int position)
Calculates the number of whitespace that are in the query. The check starts at the current position.
Parameters:
position - The position from where the scan starts
Returns:
The count of consecutive whitespace found from the given position

word

public java.lang.String word()
Retrieves the first word starting at the current position.
Returns:
The first word contained in the text, if none could be found, then an empty string is returned

wordEndPosition

public int wordEndPosition()
Returns the position at which a word ends, the position is determined by the current position of the cursor.
Returns:
The position where the current word ends, it ends when a whitespace, a delimitor {',', '(', ')'} or a math symbol is encountered

wordEndPosition

public int wordEndPosition(int position)
Returns the position at which a word ends.
Parameters:
position - The beginning of the search where the word ends
Returns:
The position where the current word ends, it ends when a whitespace, a delimitor {',', '(', ')'} or a math symbol is encountered

Skip navigation links

Copyright © 1998, 2012, Oracle. All Rights Reserved.