Package org.apache.accumulo.core.util

Examples of org.apache.accumulo.core.util.BadArgumentException


    }
   
    Node processTerm(int start, int end, Node expr, byte[] expression) {
      if (start != end) {
        if (expr != null)
          throw new BadArgumentException("expression needs | or &", new String(expression, Constants.UTF8), start);
        return new Node(start, end);
      }
      if (expr == null)
        throw new BadArgumentException("empty term", new String(expression, Constants.UTF8), start);
      return expr;
    }
View Full Code Here


        switch (expression[index++]) {
          case '&': {
            expr = processTerm(termStart, index - 1, expr, expression);
            if (result != null) {
              if (!result.type.equals(NodeType.AND))
                throw new BadArgumentException("cannot mix & and |", new String(expression, Constants.UTF8), index - 1);
            } else {
              result = new Node(NodeType.AND);
            }
            result.add(expr);
            expr = null;
            termStart = index;
            termComplete = false;
            break;
          }
          case '|': {
            expr = processTerm(termStart, index - 1, expr, expression);
            if (result != null) {
              if (!result.type.equals(NodeType.OR))
                throw new BadArgumentException("cannot mix | and &", new String(expression, Constants.UTF8), index - 1);
            } else {
              result = new Node(NodeType.OR);
            }
            result.add(expr);
            expr = null;
            termStart = index;
            termComplete = false;
            break;
          }
          case '(': {
            parens++;
            if (termStart != index - 1 || expr != null)
              throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
            expr = parse_(expression);
            termStart = index;
            termComplete = false;
            break;
          }
          case ')': {
            parens--;
            Node child = processTerm(termStart, index - 1, expr, expression);
            if (child == null && result == null)
              throw new BadArgumentException("empty expression not allowed", new String(expression, Constants.UTF8), index);
            if (result == null)
              return child;
            if (result.type == child.type)
              for (Node c : child.children)
                result.add(c);
            else
              result.add(child);
            result.end = index - 1;
            return result;
          }
          case '"': {
            if (termStart != index - 1)
              throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
           
            while (index < expression.length && expression[index] != '"') {
              if (expression[index] == '\\') {
                index++;
                if (expression[index] != '\\' && expression[index] != '"')
                  throw new BadArgumentException("invalid escaping within quotes", new String(expression, Constants.UTF8), index - 1);
              }
              index++;
            }
           
            if (index == expression.length)
              throw new BadArgumentException("unclosed quote", new String(expression, Constants.UTF8), termStart);
           
            if (termStart + 1 == index)
              throw new BadArgumentException("empty term", new String(expression, Constants.UTF8), termStart);
           
            index++;
           
            termComplete = true;
           
            break;
          }
          default: {
            if (termComplete)
              throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
           
            byte c = expression[index - 1];
            if (!Authorizations.isValidAuthChar(c))
              throw new BadArgumentException("bad character (" + c + ")", new String(expression, Constants.UTF8), index - 1);
          }
        }
      }
      Node child = processTerm(termStart, index, expr, expression);
      if (result != null)
        result.add(child);
      else
        result = child;
      if (result.type != NodeType.TERM)
        if (result.children.size() < 2)
          throw new BadArgumentException("missing term", new String(expression, Constants.UTF8), index);
      return result;
    }
View Full Code Here

    if (cl.hasOption(systemOpt.getOpt()) && permission[0].equalsIgnoreCase("System")) {
      try {
        shellState.getConnector().securityOperations().revokeSystemPermission(user, SystemPermission.valueOf(permission[1]));
        Shell.log.debug("Revoked from " + user + " the " + permission[1] + " permission");
      } catch (IllegalArgumentException e) {
        throw new BadArgumentException("No such system permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
      }
    } else if (permission[0].equalsIgnoreCase("Table")) {
      super.execute(fullCommand, cl, shellState);
    } else if (permission[0].equalsIgnoreCase("Namespace")) {
      if (cl.hasOption(optNamespace.getOpt())) {
        try {
          shellState.getConnector().securityOperations()
              .revokeNamespacePermission(user, cl.getOptionValue(optNamespace.getOpt()), NamespacePermission.valueOf(permission[1]));
        } catch (IllegalArgumentException e) {
          throw new BadArgumentException("No such namespace permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
        }
      } else {
        throw new BadArgumentException("No namespace specified to apply permission to", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
      }
    } else {
      throw new BadArgumentException("Unrecognized permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
    }
    return 0;
  }
View Full Code Here

    }
    if (cl.hasOption(deleteOpt.getOpt())) {
      // delete property from table
      String property = cl.getOptionValue(deleteOpt.getOpt());
      if (property.contains("=")) {
        throw new BadArgumentException("Invalid '=' operator in delete operation.", fullCommand, fullCommand.indexOf('='));
      }
      if (tableName != null) {
        if (!Property.isValidTablePropertyKey(property)) {
          Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
        }
        shellState.getConnector().tableOperations().removeProperty(tableName, property);
        Shell.log.debug("Successfully deleted table configuration option.");
      } else if (namespace != null) {
        if (!Property.isValidTablePropertyKey(property)) {
          Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
        }
        shellState.getConnector().namespaceOperations().removeProperty(namespace, property);
        Shell.log.debug("Successfully deleted namespace configuration option.");
      } else {
        if (!Property.isValidZooPropertyKey(property)) {
          Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
        }
        shellState.getConnector().instanceOperations().removeProperty(property);
        Shell.log.debug("Successfully deleted system configuration option");
      }
    } else if (cl.hasOption(setOpt.getOpt())) {
      // set property on table
      String property = cl.getOptionValue(setOpt.getOpt()), value = null;
      if (!property.contains("=")) {
        throw new BadArgumentException("Missing '=' operator in set operation.", fullCommand, fullCommand.indexOf(property));
      }
      final String pair[] = property.split("=", 2);
      property = pair[0];
      value = pair[1];

      if (tableName != null) {
        if (!Property.isValidTablePropertyKey(property)) {
          throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property));
        }
        if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
          new ColumnVisibility(value); // validate that it is a valid expression
        }
        shellState.getConnector().tableOperations().setProperty(tableName, property, value);
        Shell.log.debug("Successfully set table configuration option.");
      } else if (namespace != null) {
        if (!Property.isValidTablePropertyKey(property)) {
          throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property));
        }
        if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
          new ColumnVisibility(value); // validate that it is a valid expression
        }
        shellState.getConnector().namespaceOperations().setProperty(namespace, property, value);
        Shell.log.debug("Successfully set table configuration option.");
      } else {
        if (!Property.isValidZooPropertyKey(property)) {
          throw new BadArgumentException("Property cannot be modified in zookeeper", fullCommand, fullCommand.indexOf(property));
        }
        shellState.getConnector().instanceOperations().setProperty(property, value);
        Shell.log.debug("Successfully set system configuration option");
      }
    } else {
View Full Code Here

        ++exitCode;
        printException(e);
      }
    } else {
      ++exitCode;
      printException(new BadArgumentException("Unrecognized empty command", command, -1));
    }
    reader.flush();
  }
View Full Code Here

      if (cl.getArgs()[0].equalsIgnoreCase("on")) {
        Shell.setDebugging(true);
      } else if (cl.getArgs()[0].equalsIgnoreCase("off")) {
        Shell.setDebugging(false);
      } else {
        throw new BadArgumentException("Argument must be 'on' or 'off'", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
      }
    } else if (cl.getArgs().length == 0) {
      shellState.getReader().println(Shell.isDebuggingEnabled() ? "on" : "off");
    } else {
      shellState.printException(new IllegalArgumentException("Expected 0 or 1 argument. There were " + cl.getArgs().length + "."));
View Full Code Here

   
    Node parse(byte[] expression) {
      if (expression.length > 0) {
        Node node = parse_(expression);
        if (node == null) {
          throw new BadArgumentException("operator or missing parens", new String(expression, Constants.UTF8), index - 1);
        }
        if (parens != 0) {
          throw new BadArgumentException("parenthesis mis-match", new String(expression, Constants.UTF8), index - 1);
        }
        return node;
      }
      return null;
    }
View Full Code Here

    }
   
    Node processTerm(int start, int end, Node expr, byte[] expression) {
      if (start != end) {
        if (expr != null)
          throw new BadArgumentException("expression needs | or &", new String(expression, Constants.UTF8), start);
        return new Node(start, end);
      }
      if (expr == null)
        throw new BadArgumentException("empty term", new String(expression, Constants.UTF8), start);
      return expr;
    }
View Full Code Here

        switch (expression[index++]) {
          case '&': {
            expr = processTerm(subtermStart, index - 1, expr, expression);
            if (result != null) {
              if (!result.type.equals(NodeType.AND))
                throw new BadArgumentException("cannot mix & and |", new String(expression, Constants.UTF8), index - 1);
            } else {
              result = new Node(NodeType.AND, wholeTermStart);
            }
            result.add(expr);
            expr = null;
            subtermStart = index;
            subtermComplete = false;
            break;
          }
          case '|': {
            expr = processTerm(subtermStart, index - 1, expr, expression);
            if (result != null) {
              if (!result.type.equals(NodeType.OR))
                throw new BadArgumentException("cannot mix | and &", new String(expression, Constants.UTF8), index - 1);
            } else {
              result = new Node(NodeType.OR, wholeTermStart);
            }
            result.add(expr);
            expr = null;
            subtermStart = index;
            subtermComplete = false;
            break;
          }
          case '(': {
            parens++;
            if (subtermStart != index - 1 || expr != null)
              throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
            expr = parse_(expression);
            subtermStart = index;
            subtermComplete = false;
            break;
          }
          case ')': {
            parens--;
            Node child = processTerm(subtermStart, index - 1, expr, expression);
            if (child == null && result == null)
              throw new BadArgumentException("empty expression not allowed", new String(expression, Constants.UTF8), index);
            if (result == null)
              return child;
            if (result.type == child.type)
              for (Node c : child.children)
                result.add(c);
            else
              result.add(child);
            result.end = index - 1;
            return result;
          }
          case '"': {
            if (subtermStart != index - 1)
              throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
           
            while (index < expression.length && expression[index] != '"') {
              if (expression[index] == '\\') {
                index++;
                if (expression[index] != '\\' && expression[index] != '"')
                  throw new BadArgumentException("invalid escaping within quotes", new String(expression, Constants.UTF8), index - 1);
              }
              index++;
            }
           
            if (index == expression.length)
              throw new BadArgumentException("unclosed quote", new String(expression, Constants.UTF8), subtermStart);
           
            if (subtermStart + 1 == index)
              throw new BadArgumentException("empty term", new String(expression, Constants.UTF8), subtermStart);
            index++;
           
            subtermComplete = true;
           
            break;
          }
          default: {
            if (subtermComplete)
              throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
           
            byte c = expression[index - 1];
            if (!Authorizations.isValidAuthChar(c))
              throw new BadArgumentException("bad character (" + c + ")", new String(expression, Constants.UTF8), index - 1);
          }
        }
      }
      Node child = processTerm(subtermStart, index, expr, expression);
      if (result != null) {
        result.add(child);
        result.end = index;
      } else
        result = child;
      if (result.type != NodeType.TERM)
        if (result.children.size() < 2)
          throw new BadArgumentException("missing term", new String(expression, Constants.UTF8), index);
      return result;
    }
View Full Code Here

    if (cl.hasOption(systemOpt.getOpt()) && permission[0].equalsIgnoreCase("System")) {
      try {
        shellState.getConnector().securityOperations().grantSystemPermission(user, SystemPermission.valueOf(permission[1]));
        Shell.log.debug("Granted " + user + " the " + permission[1] + " permission");
      } catch (IllegalArgumentException e) {
        throw new BadArgumentException("No such system permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
      }
    } else if (permission[0].equalsIgnoreCase("Table")) {
      super.execute(fullCommand, cl, shellState);
    } else if (permission[0].equalsIgnoreCase("Namespace")) {
      if (cl.hasOption(optNamespace.getOpt())) {
        try {
          shellState.getConnector().securityOperations()
              .grantNamespacePermission(user, cl.getOptionValue(optNamespace.getOpt()), NamespacePermission.valueOf(permission[1]));
        } catch (IllegalArgumentException e) {
          throw new BadArgumentException("No such namespace permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
        }
      } else {
        throw new BadArgumentException("No namespace specified to apply permission to", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
      }
    } else {
      throw new BadArgumentException("Unrecognized permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
    }
    return 0;
  }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.util.BadArgumentException

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.