public class ParametricBuilder
extends java.lang.Object
defines a command
,
defines a flag
Constructor and Description |
---|
ParametricBuilder()
Create a new builder.
|
Modifier and Type | Method and Description |
---|---|
void |
addBinding(Binding binding,
java.lang.reflect.Type... type)
Add a binding for a given type or classifier (annotation).
|
void |
addInvokeListener(InvokeListener listener)
Attach an invocation listener.
|
Authorizer |
getAuthorizer()
Get the authorizer.
|
CommandCompleter |
getDefaultCompleter()
Get the default command suggestions provider that will be used if
no suggestions are available.
|
void |
registerMethodsAsCommands(Dispatcher dispatcher,
java.lang.Object object)
Build a list of commands from methods specially annotated with
Command
(and other relevant annotations) and register them all with the given
Dispatcher . |
void |
setAuthorizer(Authorizer authorizer)
Set the authorizer.
|
void |
setDefaultCompleter(CommandCompleter defaultCompleter)
Set the default command suggestions provider that will be used if
no suggestions are available.
|
public ParametricBuilder()
This method will install PrimitiveBindings
and
StandardBindings
and default bindings.
public void addBinding(Binding binding, java.lang.reflect.Type... type)
Whenever a method parameter is encountered, a binding must be found for it
so that it can be called later to consume the stack of arguments provided by
the user and return an object that is later passed to
Method.invoke(Object, Object...)
.
Normally, a Type
is used to discern between different bindings, but
if this is not specific enough, an annotation can be defined and used. This
makes it a "classifier" and it will take precedence over the base type. For
example, even if there is a binding that handles String
parameters,
a special @MyArg
annotation can be assigned to a String
parameter, which will cause the ImmutableBiMap.Builder
to consult the Binding
associated with @MyArg
rather than with the binding for
the String
type.
binding
- the bindingtype
- a list of types (if specified) to override the binding's typespublic void addInvokeListener(InvokeListener listener)
Invocation handlers are called in order that their listeners are
registered with a ParametricBuilder
. It is not guaranteed that
a listener may be called, in the case of a CommandException
being
thrown at any time before the appropriate listener or handler is called.
It is possible for a
InvokeHandler.preInvoke(Object, Method, ParameterData[], Object[], CommandContext)
to
be called for a invocation handler, but not the associated
InvokeHandler.postInvoke(Object, Method, ParameterData[], Object[], CommandContext)
.
An example of an invocation listener is one to handle
CommandPermissions
, by first checking to see if permission is available
in a InvokeHandler.preInvoke(Object, Method, ParameterData[], Object[], CommandContext)
call. If permission is not found, then an appropriate CommandException
can be thrown to cease invocation.
listener
- the listenerthe handler
public void registerMethodsAsCommands(Dispatcher dispatcher, java.lang.Object object) throws ParametricException
Command
(and other relevant annotations) and register them all with the given
Dispatcher
.dispatcher
- the dispatcher to register commands withobject
- the object contain the methodsParametricException
- thrown if the commands cannot be registeredpublic Authorizer getAuthorizer()
public void setAuthorizer(Authorizer authorizer)
authorizer
- the authorizerpublic CommandCompleter getDefaultCompleter()
public void setDefaultCompleter(CommandCompleter defaultCompleter)
defaultCompleter
- the default command completer