本文整理汇总了Java中org.springframework.shell.event.ParseResult类的典型用法代码示例。如果您正苦于以下问题:Java ParseResult类的具体用法?Java ParseResult怎么用?Java ParseResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParseResult类属于org.springframework.shell.event包,在下文中一共展示了ParseResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGfshExecutionStartegyExecute
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
/**
* tests execute method by executing dummy method command1
*/
@Test
public void testGfshExecutionStartegyExecute() throws Exception {
CommandManager commandManager = CommandManager.getInstance();
assertNotNull("CommandManager should not be null.", commandManager);
commandManager.add(Commands.class.newInstance());
GfshParser parser = new GfshParser(commandManager);
String[] command1Names =
((CliCommand) Commands.class.getMethod(COMMAND1_NAME).getAnnotation(CliCommand.class))
.value();
String input = command1Names[0];
ParseResult parseResult = null;
parseResult = parser.parse(input);
String[] args = new String[] {command1Names[0]};
Gfsh gfsh = Gfsh.getInstance(false, args, new GfshConfig());
GfshExecutionStrategy gfshExecutionStrategy = new GfshExecutionStrategy(gfsh);
Result resultObject = (Result) gfshExecutionStrategy.execute(parseResult);
String str = resultObject.nextLine();
assertTrue(str.trim().equals(COMMAND1_SUCESS));
}
示例2: testGfshExecutionStartegyExecute
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
public void testGfshExecutionStartegyExecute() throws Exception {
CommandManager commandManager = null;
try {
commandManager = CommandManager.getInstance();
assertNotNull("CommandManager should not be null.", commandManager);
commandManager.add(Commands.class.newInstance());
GfshParser parser = new GfshParser(commandManager);
String[] command1Names = ((CliCommand) Commands.class.getMethod(
COMMAND1_NAME).getAnnotation(CliCommand.class)).value();
String input =command1Names[0];
ParseResult parseResult = null;
parseResult = parser.parse(input);
String[] args = new String[] {command1Names[0] };
Gfsh gfsh = Gfsh.getInstance(false, args, new GfshConfig());
GfshExecutionStrategy gfshExecutionStrategy = new GfshExecutionStrategy(gfsh);
Result resultObject = (Result)gfshExecutionStrategy.execute(parseResult);
String str = resultObject.nextLine();
assertTrue(str.trim().equals(COMMAND1_SUCESS));
} catch (Exception e) {
throw e;
}
}
示例3: execute
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
public Object execute(ParseResult parseResult) throws RuntimeException {
Assert.notNull(parseResult, "Parse result required");
logger.info("LensSimpleExecutionStrategy execute method invoked");
synchronized (this) {
Assert.isTrue(isReadyForCommands(), "SimpleExecutionStrategy not yet ready for commands");
Object target = parseResult.getInstance();
if (target instanceof ExecutionProcessor) {
ExecutionProcessor processor = ((ExecutionProcessor) target);
parseResult = processor.beforeInvocation(parseResult);
try {
Object result = invoke(parseResult);
processor.afterReturningInvocation(parseResult, result);
return result;
} catch (Throwable th) {
processor.afterThrowingInvocation(parseResult, th);
return handleThrowable(th);
}
}
else {
return invoke(parseResult);
}
}
}
示例4: execute
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
public Object execute(ParseResult parseResult) throws RuntimeException {
Assert.notNull(parseResult, "Parse result required");
synchronized (mutex) {
Assert.isTrue(isReadyForCommands(), "SimpleExecutionStrategy not yet ready for commands");
Object target = parseResult.getInstance();
if (target instanceof ExecutionProcessor) {
ExecutionProcessor processor = ((ExecutionProcessor) target);
parseResult = processor.beforeInvocation(parseResult);
try {
Object result = invoke(parseResult);
processor.afterReturningInvocation(parseResult, result);
return result;
} catch (Throwable th) {
processor.afterThrowingInvocation(parseResult, th);
return handleThrowable(th);
}
} else {
return invoke(parseResult);
}
}
}
示例5: parseCommand
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
public ParseResult parseCommand(String commentLessLine)
throws CommandProcessingException, IllegalStateException {
if (commentLessLine != null) {
return getParser().parse(commentLessLine);
}
throw new IllegalStateException("Command String should not be null.");
}
示例6: invoke
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
private Object invoke(ParseResult parseResult) {
try {
return ReflectionUtils.invokeMethod(parseResult.getMethod(),
parseResult.getInstance(), parseResult.getArguments());
} catch (Throwable th) {
logger.severe("Command failed " + th);
return handleThrowable(th);
}
}
示例7: beforeInvocation
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
@Override
public ParseResult beforeInvocation(ParseResult invocationContext) {
watch = new StopWatch();
watch.start();
return invocationContext;
}
示例8: invoke
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
private Object invoke(ParseResult parseResult) {
try {
Method method = parseResult.getMethod();
ReflectionUtils.makeAccessible(method);
return ReflectionUtils.invokeMethod(method, parseResult.getInstance(), parseResult.getArguments());
} catch (Throwable th) {
logger.severe("Command failed " + th);
return handleThrowable(th);
}
}
示例9: execCLISteps
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
public static Object execCLISteps(LogWrapper logWrapper, Gfsh shell, ParseResult parseResult) {
CLIStep[] steps = (CLIStep[]) ReflectionUtils.invokeMethod(parseResult.getMethod(),
parseResult.getInstance(), parseResult.getArguments());
if (steps != null) {
boolean endStepReached = false;
int stepNumber = 0;
CLIStep nextStep = steps[stepNumber];
Result lastResult = null;
SectionResultData nextStepArgs = null;
while (!endStepReached) {
try {
Result result = executeStep(logWrapper, shell, nextStep, parseResult, nextStepArgs);
String nextStepString = null;
nextStepString = getNextStep(result);
nextStepArgs = extractArgumentsForNextStep(result);
if (!"END".equals(nextStepString)) {
String step = nextStepString;
boolean stepFound = false;
for (CLIStep s : steps)
if (step.equals(s.getName())) {
nextStep = s;
stepFound = true;
}
if (!stepFound) {
return ResultBuilder.buildResult(ResultBuilder.createErrorResultData()
.addLine("Wrong step name returned by previous step : " + step));
}
} else {
lastResult = result;
endStepReached = true;
}
} catch (CLIStepExecption e) {
endStepReached = true;
lastResult = e.getResult();
}
}
return lastResult;
} else {
Gfsh.println("Command returned null steps");
return ResultBuilder.buildResult(ResultBuilder.createErrorResultData()
.addLine("Multi-step command Return NULL STEP Array"));
}
}
示例10: getParseResult
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
/**
* @return the parseResult
*/
ParseResult getParseResult() {
return parseResult;
}
示例11: setParseResult
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
/**
* @param parseResult the parseResult to set
*/
void setParseResult(ParseResult parseResult) {
this.parseResult = parseResult;
}
示例12: execCLISteps
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
public static Object execCLISteps(LogWrapper logWrapper, Gfsh shell, ParseResult parseResult) {
CLIStep[] steps = (CLIStep[]) ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(),
parseResult.getArguments());
if (steps != null) {
boolean endStepReached = false;
int stepNumber = 0;
CLIStep nextStep = steps[stepNumber];
Result lastResult = null;
SectionResultData nextStepArgs = null;
while (!endStepReached) {
try {
Result result = executeStep(logWrapper, shell, nextStep, parseResult, nextStepArgs);
String nextStepString = null;
nextStepString = getNextStep(result);
nextStepArgs = extractArgumentsForNextStep(result);
if (!"END".equals(nextStepString)) {
String step = nextStepString;
boolean stepFound = false;
for (CLIStep s : steps)
if (step.equals(s.getName())) {
nextStep = s;
stepFound = true;
}
if (!stepFound) {
return ResultBuilder.buildResult(ResultBuilder.createErrorResultData().addLine(
"Wrong step name returned by previous step : " + step));
}
} else {
lastResult = result;
endStepReached = true;
}
} catch (CLIStepExecption e) {
endStepReached = true;
lastResult = e.getResult();
}
}
return lastResult;
} else {
Gfsh.println("Command returned null steps");
return ResultBuilder.buildResult(ResultBuilder.createErrorResultData().addLine(
"Multi-step command Return NULL STEP Array"));
}
}
示例13: executeStep
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
private static Result executeStep(LogWrapper logWrapper,
Gfsh shell,
CLIStep nextStep,
ParseResult parseResult,
SectionResultData nextStepArgs)
{
try {
if (nextStep instanceof CLIRemoteStep) {
if (shell.isConnectedAndReady()) {
if (GfshParseResult.class.isInstance(parseResult)) {
GfshParseResult gfshParseResult = (GfshParseResult) parseResult;
CommandRequest commandRequest = new CommandRequest(gfshParseResult, prepareJSONArgs(shell.getEnv(), nextStepArgs));
commandRequest.setCustomInput(changeStepName(gfshParseResult.getUserInput(), nextStep.getName()));
return ResultBuilder.fromJson((String) shell.getOperationInvoker().processCommand(commandRequest));
} else {
throw new IllegalArgumentException("Command Configuration/Definition error.");
}
} else {
try{throw new Exception();} catch (Exception ex) {ex.printStackTrace();}
throw new IllegalStateException(
"Can't execute a remote command without connection. Use 'connect' first to connect.");
}
} else {
Map<String, String> args = CommandExecutionContext.getShellEnv();
if (args == null) {
args = new HashMap<String, String>();
CommandExecutionContext.setShellEnv(args);
}
if (nextStepArgs != null) {
GfJsonObject argsJSon = nextStepArgs.getSectionGfJsonObject();
Gfsh.getCurrentInstance().setEnvProperty(CLIMultiStepHelper.STEP_ARGS, argsJSon.toString());
}
return nextStep.exec();
}
} catch (CLIStepExecption e) {
logWrapper.severe("CLIStep " + nextStep.getName() + " failed aborting command");
throw e;
}
}
示例14: parseCommand
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
public ParseResult parseCommand(String commentLessLine) throws CommandProcessingException, IllegalStateException {
if (commentLessLine != null) {
return getParser().parse(commentLessLine);
}
throw new IllegalStateException("Command String should not be null.");
}
示例15: TestableGfsh
import org.springframework.shell.event.ParseResult; //导入依赖的package包/类
public TestableGfsh(String name, boolean launchShell, String[] args) throws ClassNotFoundException, IOException {
super(launchShell, args, new TestableGfshConfig(name));
oldParser = super.getParser();
resultLatch = new CountDownLatch(1);
parserHook = new Parser() {
@Override
public ParseResult parse(String buffer) {
Util.debug("In parsing hook .... with input buffer <" + buffer + ">");
ParseResult result = null;
try{
result = oldParser.parse(buffer);
}catch(Exception e){
String reason = e.getMessage() != null ? " Reason: "+e.getMessage() + " Exception: " + String.valueOf(e) : " Exception: " + String.valueOf(e);
addError("Parsing failed...." + reason + " buffer returned by EIS " + eis.getBufferFormdAfterReading(),e);
return null;
}
if(result==null){
addError("Parsing failed....",null);
}else{
Util.log("Parse Result is " + result);
}
return result;
}
// @Override
public int completeAdvanced(String buffer, int cursor, List<Completion> candidates) {
return oldParser.completeAdvanced(buffer, cursor, candidates);
}
@Override
public int complete(String buffer, int cursor, List<String> candidates) {
return oldParser.complete(buffer, cursor, candidates);
}
};
this.name = name;
Util.debug("Using CommandManager configured with commands "+ this.getCommandNames(""));
eis = new EventedInputStream();
output = new ByteArrayOutputStream(1024 * 10);
PrintStream sysout = new PrintStream(output, true);
TestableGfsh.setGfshOutErr(sysout);
// Writer out = new BufferedWriter(new OutputStreamWriter(sysout)); // saj
wrappedOut = new BufferedWriter(new OutputStreamWriter(sysout));
try {
ConsoleReaderWrapper wrapper = new ConsoleReaderWrapper(eis, wrappedOut);
Util.debug("Reader created is " + wrapper);
newConsoleReader = wrapper;
reader = newConsoleReader;
completorAdaptor = new JLineCompletorAdapterWrapper(getParser(), this);
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}