Class Command

    • Field Detail

      • args

        public final String[] args
        Command arguments.
      • openDB

        public final boolean openDB
        Indicates if the command requires an opened database.
      • exception

        public Exception exception
        Exception during command execution.
      • result

        public Value result
        Cached result of a command execution.
      • context

        protected Context context
        Database context.
      • options

        protected MainOptions options
        Convenience access to database options.
      • soptions

        protected StaticOptions soptions
        Convenience access to static options.
      • uri

        protected String uri
        Base URI.
    • Constructor Detail

      • Command

        protected Command​(Perm perm,
                          String... args)
        Constructor for commands requiring no opened database.
        Parameters:
        perm - required permission
        args - arguments
      • Command

        protected Command​(Perm perm,
                          boolean openDB,
                          String... args)
        Constructor.
        Parameters:
        perm - required permission
        openDB - requires an opened database
        args - arguments
    • Method Detail

      • execute

        public final void execute​(Context ctx,
                                  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 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 final void setInput​(InputStream input)
        Attaches an input stream.
        Parameters:
        input - input stream
      • setInput

        public final void setInput​(InputSource input)
        Attaches an input source.
        Parameters:
        input - input source
      • run

        public final boolean run​(Context ctx)
        Runs the command without permission, data and concurrency checks. Should only be called by other database commands.
        Parameters:
        ctx - database context
        Returns:
        result of check
      • info

        public final String info()
        Returns command information.
        Returns:
        info string
      • 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 only required by the GUI.
        Parameters:
        ctx - database context
        Returns:
        result of check
      • supportsProg

        public boolean supportsProg()
        Returns true if this command returns a progress value. This method is only required by the GUI.
        Returns:
        result of check
      • stoppable

        public boolean stoppable()
        Returns true if this command can be stopped. This method is only required by the GUI.
        Returns:
        result of check
      • init

        public final void init​(Context ctx,
                               OutputStream os)
        Initializes the command execution.
        Parameters:
        ctx - database context
        os - output stream
      • run

        public final boolean run​(Context ctx,
                                 OutputStream os)
        Runs the command without permission, data and concurrency checks.
        Parameters:
        ctx - database context
        os - output stream
        Returns:
        result of check
      • toString

        public final String toString​(boolean password)
        Returns a string representation of the command.
        Parameters:
        password - password flag
        Returns:
        result of check
      • baseURI

        public Command baseURI​(String base)
        Sets a base URI.
        Parameters:
        base - base URI
        Returns:
        self reference
      • baseURI

        public String baseURI()
        Returns the base URI.
        Returns:
        base URI
      • run

        protected abstract boolean run()
                                throws IOException
        Executes the command and serializes the result (internal call).
        Returns:
        success of operation
        Throws:
        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​(String msg,
                                      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​(String str,
                                     Object... ext)
        Adds information on command execution.
        Parameters:
        str - information to be added
        ext - extended info
        Returns:
        true
      • getOption

        protected final <E extends Enum<E>> E getOption​(Class<E> typ)
        Returns the specified command option.
        Type Parameters:
        E - token type
        Parameters:
        typ - options enumeration
        Returns:
        option
      • addLocks

        protected final void addLocks​(LockList list,
                                      int index)
        Adds the name of the database that has been addressed by the argument index. No databases will be added if the argument uses glob syntax.
        Parameters:
        list - lock list
        index - argument index
      • getOption

        protected static <E extends Enum<E>> E getOption​(String string,
                                                         Class<E> type)
        Returns the specified command option.
        Type Parameters:
        E - token type
        Parameters:
        string - string to be found
        type - options enumeration
        Returns:
        option, or null if the option is not found
      • close

        protected static boolean close​(Context ctx,
                                       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:
        true if opened database was closed