Methods Summary |
---|
public java.util.Iterator | getParts()Returns the iterator for all the name-parts, for the parsed string.
Guaranteed to return a non null iterator even if there are no elements
in it.
return ( mNameParts.iterator() );
|
private boolean | isDelimiterChar(java.lang.String aString, int position)A method to determine whether character at given position in given
string is Tokens.kDelimiterChar && is acting as a delimiter.
A Tokens.kDelimiterChar is delimiter if and only if it is
not escaped with Tokens.kEscapeChar just before it.
boolean isDelim = false;
//Assert.assertRange(position, -1, aString.length(), "invalid position");
if(aString.charAt(position) == Tokens.kDelimiterChar)
{
if(position == 0 ||
aString.charAt(position - 1) != Tokens.kEscapeChar
)
{
isDelim = true;
}
}
return ( isDelim );
|
private boolean | isNonZeroDigit(char aChar)Returns if given character is a non-zero digit (1..9)
return ( Tokens.kNonZeroDigitsString.indexOf(aChar) != -1 );
|
private boolean | isOnlyDelimiterEscaped(java.lang.String npString)Checks whether all the escape characters escape only delimiters.
Method returns true if and only if
string contains at least one escape character &&
all escape charactrs are always followed by a delimiter character.
Returns false, in all other cases.
boolean onlyDelimiterEscaped = true;
if(npString != null && npString.length() > 0)
{
int index = 0;
int strlength = npString.length();
while(index < strlength)
{
char ch = npString.charAt(index);
if(ch == Tokens.kEscapeChar)
{
int nextIndex = index + 1;
if (nextIndex >= strlength ||
npString.charAt(nextIndex) != Tokens.kDelimiterChar)
{
onlyDelimiterEscaped = false;
break; // no need to continue as at least one occurrance found
}
}
index++;
}
}
else
{
onlyDelimiterEscaped = false;
}
return ( onlyDelimiterEscaped );
|
private boolean | isPermissibleChar(char aChar)There are certain characters that are neither letters nor digits but are
allowed in names and this method determines whether the given character
is such a permissible special character.
boolean isPermissibleChar = false;
if (aChar == Tokens.kSubScriptBeginnerChar ||
aChar == Tokens.kSubScriptEnderChar ||
aChar == Tokens.kDelimiterChar ||
aChar == Tokens.kEscapeChar ||
aChar == Tokens.kWildCardChar)
{
isPermissibleChar = true;
}
return isPermissibleChar;
|
private boolean | isSpecialChar(char aChar)Determines whether the given character is one of Tokens.kSpecialsString.
return ( Tokens.kSpecialsString.indexOf(aChar) != -1 );
|
private boolean | isSubscriptLessStringValid(java.lang.String npString)A method to validate the string that contains no subscript characters,
i.e. a String that contains neither Tokens.kSubscriptBeginnerChar nor
Tokens.kSubscriptEnderChar.
boolean remStringValid = false;
if(npString != null && npString.length() > 0)
{
//boolean noMoreDotsPresent = (npString.indexOf(Tokens.kMoreEscapedDelimitersString) == -1);
//boolean endsWithDelimiter = npString.endsWith(Tokens.kEscapedDelimiterString);
boolean onlyDelimiterEscaped = isOnlyDelimiterEscaped(npString);
boolean containsEscape = npString.indexOf(Tokens.kEscapeChar) != -1;
boolean isEscapeValid = ! containsEscape ||
containsEscape && onlyDelimiterEscaped;
boolean noMoreStars = npString.indexOf(Tokens.kMoreWildCardsString) == -1;
if( isEscapeValid &&
noMoreStars
)
{
remStringValid = true;
}
}
return ( remStringValid );
|
private boolean | isSubscriptOrdered(java.lang.String npString)Simple stack based implementation to test whether the subscripts
are in order. e.g. [], [][], [[]] are all valid orders and ][, [[], []]
are all invalid orders.
Note that if the string passed does not contain
any subscript character i.e. a string without '[' or ']', then this
method returns false.
boolean subscriptOrdered = true;
int index = 0;
Stack charStack = new Stack();
if(isSubscriptPresent(npString))
{
while(index < npString.length())
{
char ch = npString.charAt(index);
if(ch == Tokens.kSubScriptBeginnerChar)
{
charStack.push(new Character(ch));
}
else if(ch == Tokens.kSubScriptEnderChar)
{
if(! charStack.empty())
{
Character poppedChar = (Character)charStack.pop();
if(poppedChar.charValue() != Tokens.kSubScriptBeginnerChar)
{
subscriptOrdered = false;
break;
}
}
else
{
subscriptOrdered = false;
break;
}
}
index++;
}
if(! charStack.empty())
{
subscriptOrdered = false;
}
}
else
{
subscriptOrdered = false;
}
return ( subscriptOrdered );
|
private boolean | isSubscriptPresent(java.lang.String npString)Determines whether any subscript character (Tokens.kSubscriptBeginnerChar)
or (Tokens.kSubscriptEnderChar) is present.
boolean subscriptPresent = false;
if(npString.indexOf(Tokens.kSubScriptBeginnerChar) != -1 ||
npString.indexOf(Tokens.kSubScriptEnderChar) != -1
)
{
subscriptPresent = true;
}
return ( subscriptPresent );
|
private boolean | isSubscriptValid(java.lang.String npString)Checks whether the string present inside []
can be a valid index.
Only non-negative integers are valid with some exceptions. e.g. 32 is a
valid index, but 03 or 004 is not.
In other words this method does following checks:
The subscript characters are ordered in given string
#isSubscriptOrdered(java.lang.String)
The contents of string between first index of Tokens.kSubscriptBeginnerChar and
Tokens.kSubScriptEnderChar evaluates to a permissible integer value.
#isValidIndexString(java.lang.String)
if there is a subscript, it is always at the end of the string, as
abc[5]d is invalid.
boolean subscriptValid = true;
boolean subscriptOrdered = isSubscriptOrdered(npString);
if(subscriptOrdered)
{
int leftPos = npString.indexOf(Tokens.kSubScriptBeginnerChar);
int rightPos = npString.lastIndexOf(Tokens.kSubScriptEnderChar);
String indexString = npString.substring(leftPos + 1, rightPos);
if(! isValidIndexString(indexString))
{
subscriptValid = false;
}
boolean lastCharIsRightSquareBracket =
npString.charAt(npString.length() - 1) == Tokens.kSubScriptEnderChar;
if(! lastCharIsRightSquareBracket)
{
subscriptValid = false;
}
}
else
{
subscriptValid = false;
}
return ( subscriptValid );
|
private boolean | isValidChar(char aChar)Determines whether given character is valid as a single character.
return ( Character.isLetter(aChar) ||
Character.isDigit(aChar) ||
this.isPermissibleChar(aChar)||
this.isSpecialChar(aChar)
);
|
private boolean | isValidIndexString(java.lang.String index)A method to determine whether given string reprensents a valid
index. An index is invalid if either of the following is true
it is negative, OR
it is zero and length of the string is more than 1, OR
it is greater than zero and its first digit is 0
In all other cases the string represents a valid index.
boolean isValidIndex = true;
if (index != null && index.length() > 0)
{
try
{
int intValue = Integer.parseInt(index);
if((intValue == 0 && index.length() != 1) ||
(intValue > 0 && index.charAt(0) == Tokens.kZeroDigitChar) ||
(intValue < 0)
)
{
isValidIndex = false;
}
}
catch(NumberFormatException e)
{
//ExceptionUtil.ignoreException(e);
isValidIndex = false;
}
}
else
{
isValidIndex = false;
}
return ( isValidIndex );
|
private boolean | isWildcardCharValid()Determines whether the wild-card character is per grammar.
A wild-card character is permissible in name, if and only if
it is a name-part which has no other char with it &&
it is the last name-part.
It is valid to have no wildcard character at all.
boolean isWildcardCharValid = true;
String starString = new String(new char[]{Tokens.kWildCardChar});
/*
if Any name-part contains wild-card char, then that name-part
should be the only thing that name-part.
*/
for(int i = 0 ; i < mNameParts.size(); i++)
{
String aPart = (String) mNameParts.elementAt(i);
if(aPart.indexOf(Tokens.kWildCardChar) != -1 &&
! aPart.equals(starString))
{
isWildcardCharValid = false;
break;
}
}
return isWildcardCharValid;
|
public void | parseIt(java.lang.String parseString)Initializes the parsing process.
//ArgChecker.check(parseString != null, "null string to parse");
mString = parseString;
parseStringForNameParts();
parseNameParts();
if(! isWildcardCharValid())
{
String msg = /*localizedStrMgr.getString*/( "admin.common.invalid_wild-card_char_placement" );
throw new MalformedObjectNameException( msg );
}
|
private void | parseNameParts()Method to parse each individual name-part in the name.
Iterator partsIter = getParts();
boolean canReduce = false;
while(partsIter.hasNext())
{
String aNamePartString = (String) partsIter.next();
canReduce = reduceNamePart(aNamePartString);
if(! canReduce)
{
String msg = "invalidname"+mString;// /*localizedStrMgr.getString*/( "admin.common.invalid_name", mString );
throw new MalformedObjectNameException( msg );
}
}
|
private void | parseStringForNameParts()Segregates the string to be parsed into the vector of name-parts.
Each Name-part is delimited by a delimiter character defined in
the Tokens class. This method while segregating the name-parts,
determines whether any scanned single character is valid.
int counter = 0;
int begin = counter;
String nameString = null;
while(counter < mString.length())
{
char parseChar = mString.charAt(counter);
if(isValidChar(parseChar))
{
boolean gotDelimiter = isDelimiterChar(mString, counter);
if(gotDelimiter)
{
nameString = mString.substring(begin, counter);
begin = counter + 1;
mNameParts.addElement(removeEscapes(nameString));
//Debug.println("a name string: " + nameString);
}
}
else
{
String msg = "invalidchar";// localizedStrMgr.getString( "admin.common.invalid_char_encountered", new String( parseChar + "" ) );
throw new MalformedObjectNameException( msg );
}
counter++;
}
nameString = mString.substring(begin);
mNameParts.addElement(removeEscapes(nameString));
//Debug.println("a name string: " + nameString);
|
private boolean | reduceNamePart(java.lang.String npString)The actual method that does parsing and determines whether the
sequence of characters in given string is according
to the grammar.
boolean canReduce = true;
if (isSubscriptPresent(npString))
{
canReduce = isSubscriptValid(npString);
}
if (canReduce)
{
String subscriptLessString = removeSubscript(npString);
canReduce = isSubscriptLessStringValid(subscriptLessString);
}
return ( canReduce );
|
private java.lang.String | removeEscapes(java.lang.String str)
int idx;
while((idx=str.indexOf(Tokens.kEscapeChar))>=0)
if(idx==0)
str = str.substring(1);
else
str = str.substring(0, idx)+str.substring(idx+1);
return str;
|
private java.lang.String | removeSubscript(java.lang.String npString)Returns a string that contains anything in given string upto first
index of Tokens.SubscriptBeginnerChar(that character excluded). If at all
this method gets called, it should be made sure that the subscript
characters are ordered, as this method does not make that check.
String subscriptLessString = null;
final int leftIndex = npString.indexOf(Tokens.kSubScriptBeginnerChar);
if ( npString.length() > 0 )
{
if(leftIndex != -1)
{
subscriptLessString = npString.substring(0, leftIndex);
}
else
{
subscriptLessString = npString;
}
}
return ( subscriptLessString );
|