示例#1
0
 /**
  * Returns true if this variable exists in the database, regardless of whether or not it is set.
  * This method exists solely for the code in {@link ConfigVars} to migrate variables from the old
  * system over to this class, and generally shouldn't be used by anything else.
  *
  * @param scope
  * @param name
  * @return
  */
 public static boolean hasDatastoreVar(String scope, String name) {
   scope = normalizeScope(scope);
   ConfigStorage storage = getConfigStorage(scope, false);
   if (storage == null) return false;
   if (storage.getVariable(name) == null) return false;
   return true;
 }
示例#2
0
 /**
  * Registers a new variable.
  *
  * @param scope The scope to register the variable at
  * @param name The name of the variable, complete with folders if desired. The folders must have
  *     been previously registered.
  * @param description The description of the variable
  * @param type The type of the variable
  * @param defaultValue The default value. This is ignored for folders.
  */
 public static void register(
     String scope, String name, String description, VarType type, String defaultValue) {
   scope = normalizeScope(scope);
   ConfigStorage storage = getConfigStorage(scope, true);
   if (type == VarType.folder) {
     registerFolder(scope, name, description);
     return;
   }
   ConfigVariable valueObject = storage.getVariable(name);
   String value;
   if (valueObject == null) value = null;
   else value = valueObject.getValue();
   Variable var = new Variable(extractName(name), description, type, defaultValue, value);
   getScopeFolder(scope).getParent(name).add(var);
 }
示例#3
0
 public static void setText(String scope, String name, String text) {
   scope = normalizeScope(scope);
   Variable var = getScopeFolder(scope).getCheckedVariable(name);
   if (var.type == VarType.bool) {
     if (text.equals("true")) text = "1";
     else if (text.equals("false")) text = "0";
   }
   var.validateConformantValue(text);
   if (!var.fireFilters(scope, name, text)) return;
   if (var.type == VarType.guard) {
     /*
      * We need to iterate over all the secret variables in the same folder and
      * unset them.
      */
     for (Setting setting : var.folder.getSettings()) {
       if ((setting instanceof Variable) && ((Variable) setting).type == VarType.secret) {
         Variable secretVar = (Variable) setting;
         String secretName;
         if (name.contains("/"))
           secretName = name.substring(0, name.lastIndexOf("/")) + "/" + secretVar.name;
         else secretName = secretVar.name;
         setText(scope, secretName, null);
       }
     }
   }
   ConfigStorage storage = getConfigStorage(scope, true);
   ConfigVariable storedVar = storage.getVariable(name);
   if (storedVar == null) {
     storedVar = storage.createVariable();
     storedVar.setName(name);
     storage.getVariables().add(storedVar);
   }
   storedVar.setValue(text);
   var.value = text;
   var.fireListeners(scope, name);
 }