Logo Search packages:      
Sourcecode: henplus version File versions  Download package

int henplus::commands::properties::AbstractPropertyCommand::execute ( SQLSession  currentSession,
String  cmd,
String  param 
) [inline, inherited]

execute the command given.

Implements henplus::Command.

Definition at line 60 of file AbstractPropertyCommand.java.

References henplus::view::TableRenderer::addRow(), henplus::view::TableRenderer::closeTable(), henplus::Command::EXEC_FAILED, henplus::property::PropertyHolder::getDefaultValue(), henplus::PropertyRegistry::getPropertyMap(), henplus::commands::properties::AbstractPropertyCommand::getRegistry(), henplus::property::PropertyHolder::getShortDescription(), henplus::property::PropertyHolder::getValue(), henplus::view::ColumnMetaData::resetWidth(), henplus::PropertyRegistry::setProperty(), henplus::property::PropertyHolder::setValue(), henplus::Command::SUCCESS, and henplus::Command::SYNTAX_ERROR.

                                                                             {
      StringTokenizer st = new StringTokenizer(param);
      int argc = st.countTokens();
      
        if (cmd.startsWith("re")) { // 'reset-property'
            if (argc == 1) {
                String name = st.nextToken();
                PropertyHolder holder;
                holder = (PropertyHolder) (getRegistry()
                                           .getPropertyMap().get(name));
                if (holder == null) {
                    return EXEC_FAILED;
                }
                String defaultValue = holder.getDefaultValue();
                try {
                    holder.setValue(defaultValue);
                }
                catch (Exception e) {
                    HenPlus.msg().println("setting to default '" 
                                       + defaultValue + "' failed.");
                    return EXEC_FAILED;
                }
                return SUCCESS;
            }
            return SYNTAX_ERROR;
        }
        else {
        /*
         * no args. show available properties
         */
        if (argc == 0) {
            PROP_META[0].resetWidth();
            PROP_META[1].resetWidth();
            TableRenderer table = new TableRenderer(PROP_META, HenPlus.out());
            Iterator propIt = (getRegistry()
                               .getPropertyMap()
                               .entrySet().iterator());
            while (propIt.hasNext()) {
                Map.Entry entry = (Map.Entry) propIt.next();
                Column[] row = new Column[3];
                PropertyHolder holder = (PropertyHolder) entry.getValue();
                row[0] = new Column((String) entry.getKey());
                row[1] = new Column(holder.getValue());
                row[2] = new Column(holder.getShortDescription());
                table.addRow(row);
            }
            table.closeTable();
            return SUCCESS;
        }

        /*
         * one arg: show help
         */
        else if (argc == 1) {
            String name = st.nextToken();
            PropertyHolder holder;
            holder = (PropertyHolder) (getRegistry()
                                       .getPropertyMap().get(name));
            if (holder == null) {
                return EXEC_FAILED;
            }
            printDescription(name, holder);
            return SUCCESS;
        }

        /*
         * more than one arg
         */
        else if (argc >= 2) {
            String varname = (String) st.nextElement();
            int pos = 0;
            int paramLength = param.length();
            // skip whitespace after 'set'
            while (pos < paramLength
                   && Character.isWhitespace(param.charAt(pos))) {
                ++pos;
            }
            // skip non-whitespace after 'set  ': variable name
            while (pos < paramLength
                   && !Character.isWhitespace(param.charAt(pos))) {
                ++pos;
            }
            // skip whitespace before vlue..
            while (pos < paramLength
                   && Character.isWhitespace(param.charAt(pos))) {
                ++pos;
            }
            String value = param.substring(pos);
            if (value.startsWith("\"") && value.endsWith("\"")) {
                value = value.substring(1, value.length()-1);
            }
            else if (value.startsWith("\'") && value.endsWith("\'")) {
                value = value.substring(1, value.length()-1);
            }

            try {
                getRegistry().setProperty(varname, value);
            }
            catch (Exception e) {
                HenPlus.msg().println(e.getMessage());
                return EXEC_FAILED;
            }
            return SUCCESS;
        }
        }
      return SUCCESS;
    }


Generated by  Doxygen 1.6.0   Back to index