Package com.sk89q.intake.parametric.handler

Examples of com.sk89q.intake.parametric.handler.InvokeHandler


            boolean invoke = true;

            // preProcess handlers
            List<InvokeHandler> handlers = new ArrayList<InvokeHandler>();
            for (InvokeListener listener : builder.getInvokeListeners()) {
                InvokeHandler handler = listener.createInvokeHandler();
                handlers.add(handler);
                if (!handler.preProcess(object, method, parameters, context, locals)) {
                    invoke = false;
                }
            }

            if (invoke) {
                // Collect parameters
                for (int i = 0; i < parameters.length; i++) {
                    parameter = parameters[i];

                    if (mayConsumeArguments(i, arguments)) {
                        // Parse the user input into a method argument
                        ArgumentStack usedArguments = getScopedContext(parameter, arguments);

                        try {
                            args[i] = parameter.getBinding().bind(parameter, usedArguments, false);
                        } catch (MissingParameterException e) {
                            // Not optional? Then we can't execute this command
                            if (!parameter.isOptional()) {
                                throw e;
                            }

                            args[i] = getDefaultValue(i, arguments);
                        }
                    } else {
                        args[i] = getDefaultValue(i, arguments);
                    }
                }

                // Check for unused arguments
                checkUnconsumed(arguments);

                // preInvoke handlers
                for (InvokeHandler handler : handlers) {
                    if (!handler.preInvoke(object, method, parameters, args, context, locals)) {
                        invoke = false;
                    }
                }
            }

            if (invoke) {
                // Execute!
                method.invoke(object, args);

                // postInvoke handlers
                for (InvokeHandler handler : handlers) {
                    handler.postInvoke(handler, method, parameters, args, context, locals);
                }
            }
        } catch (MissingParameterException e) {
            throw new InvalidUsageException("Too few parameters!", this);
        } catch (UnconsumedParameterException e) {
View Full Code Here

TOP

Related Classes of com.sk89q.intake.parametric.handler.InvokeHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.