Package org.jboss.as.cli.parsing
Interface ParsingContext
-
public interface ParsingContext- Author:
- Alexey Loubyansky
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidactivateControl(char c)Activates a control character.voidadvanceLocation(int offset)Advances the current location by skipping the specified number of characters.voiddeactivateControl(char c)Indicates that a control character temporarily shouldn't be treated as a control but a usual content one.voidenterState(ParsingState state)Enters the state passed in as the argument which then becomes the current state.ParsingStateCallbackHandlergetCallbackHandler()The callback handler used for current parsing.chargetCharacter()The character at the current location in the input string.CommandFormatExceptiongetError()Returns the exception if there was one during parsing or null if the line was parsed successfully.StringgetInput()The complete string being parsed.intgetLocation()The current location in the input string.ParsingStategetState()The current state.booleanisDeactivated(char c)Checks whether deactivateControl(c) was called for the character and the character is still not active.booleanisEndOfContent()Checks whether the end of the input string has been reached.booleanisLookingFor(char c)Checks whether the character is the one the parser is looking for.booleanisStrict()Indicates whether handlers should complain by throwing exceptions in case of issues or be forgiving where possible and there is a reason to be.ParsingStateleaveState()Leaves the current state and and returns it.voidlookFor(char c)Indicates that the passed in the argument character is expected further the line.booleanmeetIfLookedFor(char c)This is a convenient safe method which checks whether the passed in character is the current look-for one.voidreenterState()Leaves the current state and then enters it again.booleanreplaceSpecialChars()This method is called after a backslash character is met.voidresolveExpression(boolean systemProperty, boolean exceptionIfNotResolved)Replaces system property specified with ${xxx} fomrat or a local variable whose name is prefixed with '$'.voidsetError(CommandFormatException e)Sets the error indicating that there was a problem during parsing.
-
-
-
Method Detail
-
getInput
String getInput()
The complete string being parsed.- Returns:
- the complete string being parsed
-
getState
ParsingState getState()
The current state.- Returns:
- current state
-
enterState
void enterState(ParsingState state) throws CommandFormatException
Enters the state passed in as the argument which then becomes the current state.- Parameters:
state- the state to enter- Throws:
CommandFormatException- in case something went wrong
-
leaveState
ParsingState leaveState() throws CommandFormatException
Leaves the current state and and returns it.- Returns:
- the state that's been left
- Throws:
CommandFormatException- in case something went wrong
-
reenterState
void reenterState() throws CommandFormatExceptionLeaves the current state and then enters it again.- Throws:
CommandFormatException- in case something went wrong
-
getCallbackHandler
ParsingStateCallbackHandler getCallbackHandler()
The callback handler used for current parsing.- Returns:
- the callback handler used for the current parsing
-
getCharacter
char getCharacter()
The character at the current location in the input string.- Returns:
- the character at the current location in the input string
-
getLocation
int getLocation()
The current location in the input string.- Returns:
- the current location in the input string
-
isEndOfContent
boolean isEndOfContent()
Checks whether the end of the input string has been reached.- Returns:
- true if the end of the input stream has been reached
-
advanceLocation
void advanceLocation(int offset) throws IndexOutOfBoundsExceptionAdvances the current location by skipping the specified number of characters.- Parameters:
offset- the number of characters to skip- Throws:
IndexOutOfBoundsException- if the new location exceeds the input string length
-
isStrict
boolean isStrict()
Indicates whether handlers should complain by throwing exceptions in case of issues or be forgiving where possible and there is a reason to be.- Returns:
- true if the parser is in the strict parsing mode, otherwise - false.
-
getError
CommandFormatException getError()
Returns the exception if there was one during parsing or null if the line was parsed successfully.- Returns:
- the exception if there was one during parsing, otherwise null.
-
setError
void setError(CommandFormatException e)
Sets the error indicating that there was a problem during parsing. If the handler chose not to throw the exception and terminate the parsing process immediately, then handling subsequent callbacks may result subsequent errors. This method should set the error only once (the first call) and ignore the subsequent ones.- Parameters:
e- the error
-
resolveExpression
void resolveExpression(boolean systemProperty, boolean exceptionIfNotResolved) throws UnresolvedExpressionExceptionReplaces system property specified with ${xxx} fomrat or a local variable whose name is prefixed with '$'. After the property or the variable has been replaced with its actual value, the parsing continues from the same location but with the value resolved.- Parameters:
exceptionIfNotResolved- whether an exception should be thrown in case the property or the variable couldn't be resolved or should it continue unnoticed- Throws:
CommandFormatExceptionUnresolvedExpressionException
-
replaceSpecialChars
boolean replaceSpecialChars()
This method is called after a backslash character is met. In case the backslash and the following character (if any) are recognized as a special character (e.g. \t, \b, \n, \r, \f), they are replaced with the special character they signify. Otherwise, the method returns w/o any effects on the input sequence.- Returns:
- true if the character was recognized as a special one and was replaced, false otherwise
-
lookFor
void lookFor(char c)
Indicates that the passed in the argument character is expected further the line. This is useful for special characters like brackets, braces, etc. This method can be called multiple times during parsing. Each invocation will push the current look-for character into the look-for character stack. Once the look-for character has been met, the met(char ch) method must be called to pop the met character from the stack.- Parameters:
ch- the character to look for
-
meetIfLookedFor
boolean meetIfLookedFor(char c)
This is a convenient safe method which checks whether the passed in character is the current look-for one. If it is then the parser will consider that it's been met and will pop from the look-for stack and will return true to indicate that. If it's not then the method will simply return false.- Parameters:
c- the character that should be checked and met- Returns:
- if the character was in fact the current look-for one, false otherwise
-
isLookingFor
boolean isLookingFor(char c)
Checks whether the character is the one the parser is looking for.- Parameters:
c- the character to check- Returns:
- true if it's the current look-for character, false otherwise
-
deactivateControl
void deactivateControl(char c)
Indicates that a control character temporarily shouldn't be treated as a control but a usual content one.- Parameters:
c- control character to deactivate
-
activateControl
void activateControl(char c)
Activates a control character. It has effect if the character has previously been deactivated. Invoking this method for an active control character has no effect.- Parameters:
c- control character to activate
-
isDeactivated
boolean isDeactivated(char c)
Checks whether deactivateControl(c) was called for the character and the character is still not active.- Parameters:
c- the character to check- Returns:
- true if the character was deactivated and still is, otherwise - false
-
-