org.basex.core
Class Command

java.lang.Object
  extended by org.basex.core.Proc
      extended by org.basex.core.Command
Direct Known Subclasses:
ACreate, AlterUser, AQuery, Check, Close, Copy, CreateBackup, CreateEvent, CreateUser, DropBackup, DropEvent, DropUser, Execute, Exit, Export, Flush, Get, Grant, Help, Info, InfoDB, InfoIndex, Inspect, Kill, List, Open, Password, RepoDelete, RepoInstall, RepoList, Restore, Set, ShowBackups, ShowEvents, ShowSessions, ShowUsers

public abstract class Command
extends Proc

This class provides the architecture for all internal command implementations. It evaluates queries that are sent by the GUI, the client or the standalone version.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
 java.lang.String[] args
          Command arguments.
protected  Context context
          Database context.
protected  org.xml.sax.InputSource in
          Optional input source.
protected  MainProp mprop
          Main properties.
protected  PrintOutput out
          Output stream.
protected  Performance perf
          Performance measurements.
protected  Prop prop
          Database properties.
 
Fields inherited from class org.basex.core.Proc
listen, updating
 
Constructor Summary
protected Command(Perm p, boolean d, java.lang.String... arg)
          Constructor.
protected Command(Perm p, java.lang.String... arg)
          Constructor for commands requiring no opened database.
 
Method Summary
protected  void build(CmdBuilder cb)
          Builds a string representation from the command.
protected static boolean close(Context ctx, java.lang.String db)
          Closes the specified database if it is currently opened and only pinned once.
protected  boolean databases(StringList db, int a)
          Adds the names of the database that has been addressed by the argument index.
protected  boolean error(java.lang.String msg, java.lang.Object... ext)
          Adds the error message to the message buffer info.
 java.lang.String execute(Context ctx)
          Executes the command and returns the result as string.
 void execute(Context ctx, java.io.OutputStream os)
          Executes the command and prints the result to the specified output stream.
protected
<E extends java.lang.Enum<E>>
E
getOption(java.lang.Class<E> typ)
          Returns the specified command option.
protected static
<E extends java.lang.Enum<E>>
E
getOption(java.lang.String s, java.lang.Class<E> typ)
          Returns the specified command option.
 java.lang.String info()
          Returns command information.
protected  boolean info(java.lang.String str, java.lang.Object... ext)
          Adds information on command execution.
 boolean newData(Context ctx)
          Closes an open data reference and returns true if this command will change the Context.data reference.
 Result result()
          Returns the result set, generated by a query command.
protected abstract  boolean run()
          Executes the command and serializes the result (internal call).
 boolean run(Context ctx)
          Runs the command without permission, data and concurrency checks.
 boolean run(Context ctx, java.io.OutputStream os)
          Runs the command without permission, data and concurrency checks.
 void setInput(org.xml.sax.InputSource is)
          Attaches an input source.
 void setInput(java.io.InputStream is)
          Attaches an input stream.
 boolean stoppable()
          Returns true if this command can be stopped.
 boolean supportsProg()
          Returns true if this command returns a progress value.
 java.lang.String toString()
           
 boolean updated(Context ctx)
          Checks if the command has updated any data.
 boolean updating(Context ctx)
          Checks if the command performs updates/write operations.
 
Methods inherited from class org.basex.core.Proc
abort, checkStop, databases, det, detail, listen, proc, prog, progress, registered, registered, startTimeout, stop, stopTimeout, tit, title
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

args

public final java.lang.String[] args
Command arguments.


perf

protected Performance perf
Performance measurements.


context

protected Context context
Database context.


out

protected PrintOutput out
Output stream.


in

protected org.xml.sax.InputSource in
Optional input source.


prop

protected Prop prop
Database properties.


mprop

protected MainProp mprop
Main properties.

Constructor Detail

Command

protected Command(Perm p,
                  java.lang.String... arg)
Constructor for commands requiring no opened database.

Parameters:
p - required permission
arg - arguments

Command

protected Command(Perm p,
                  boolean d,
                  java.lang.String... arg)
Constructor.

Parameters:
p - required permission
d - requires opened database
arg - arguments
Method Detail

execute

public final void execute(Context ctx,
                          java.io.OutputStream os)
                   throws BaseXException
Executes the command and prints the result to the specified output stream. If an exception occurs, a BaseXException is thrown.

Parameters:
ctx - database context
os - output stream reference
Throws:
BaseXException - command exception

execute

public final java.lang.String execute(Context ctx)
                               throws BaseXException
Executes the command and returns the result as string. If an exception occurs, a BaseXException is thrown.

Parameters:
ctx - database context
Returns:
string result
Throws:
BaseXException - command exception

setInput

public void setInput(java.io.InputStream is)
Attaches an input stream.

Parameters:
is - input stream

setInput

public void setInput(org.xml.sax.InputSource is)
Attaches an input source.

Parameters:
is - input source

run

public final boolean run(Context ctx)
Runs the command without permission, data and concurrency checks. Should be called with care, and only by other database commands.

Parameters:
ctx - database context
Returns:
result of check

info

public final java.lang.String info()
Returns command information.

Returns:
info string

result

public Result result()
Returns the result set, generated by a query command. Will only yield results if Prop.CACHEQUERY is set, and can only be called once.

Returns:
result set

updating

public boolean updating(Context ctx)
Checks if the command performs updates/write operations.

Parameters:
ctx - database context
Returns:
result of check

updated

public boolean updated(Context ctx)
Checks if the command has updated any data.

Parameters:
ctx - database context
Returns:
result of check

newData

public boolean newData(Context ctx)
Closes an open data reference and returns true if this command will change the Context.data reference. This method is required by the progress dialog in the frontend.

Parameters:
ctx - database context
Returns:
result of check

supportsProg

public boolean supportsProg()
Returns true if this command returns a progress value. This method is required by the progress dialog in the frontend.

Returns:
result of check

stoppable

public boolean stoppable()
Returns true if this command can be stopped. This method is required by the progress dialog in the frontend.

Returns:
result of check

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

run

protected abstract boolean run()
                        throws java.io.IOException
Executes the command and serializes the result (internal call).

Returns:
success of operation
Throws:
java.io.IOException - I/O exception

build

protected void build(CmdBuilder cb)
Builds a string representation from the command. This string must be correctly built, as commands are sent to the server as strings.

Parameters:
cb - command builder

error

protected final boolean error(java.lang.String msg,
                              java.lang.Object... ext)
Adds the error message to the message buffer info.

Parameters:
msg - error message
ext - error extension
Returns:
false

info

protected final boolean info(java.lang.String str,
                             java.lang.Object... ext)
Adds information on command execution.

Parameters:
str - information to be added
ext - extended info
Returns:
true

getOption

protected final <E extends java.lang.Enum<E>> E getOption(java.lang.Class<E> typ)
Returns the specified command option.

Type Parameters:
E - token type
Parameters:
typ - options enumeration
Returns:
option

databases

protected final boolean databases(StringList db,
                                  int a)
Adds the names of the database that has been addressed by the argument index. No databases will be added if the argument uses glob syntax.

Parameters:
db - databases
a - argument index
Returns:
false if database cannot be determined due to glob syntax

getOption

protected static <E extends java.lang.Enum<E>> E getOption(java.lang.String s,
                                                           java.lang.Class<E> typ)
Returns the specified command option.

Type Parameters:
E - token type
Parameters:
s - string to be found
typ - options enumeration
Returns:
option

close

protected static boolean close(Context ctx,
                               java.lang.String db)
Closes the specified database if it is currently opened and only pinned once.

Parameters:
ctx - database context
db - database to be closed
Returns:
closed flag

run

public boolean run(Context ctx,
                   java.io.OutputStream os)
Runs the command without permission, data and concurrency checks.

Parameters:
ctx - database context
os - output stream
Returns:
result of check