Package dovetaildb.apiservice

Examples of dovetaildb.apiservice.ApiException


   
    @Override
    public ScriptFunction getFunction(String functionName, int numParameters) {
      int lastDot = functionName.lastIndexOf('.');
      if (lastDot == -1)
        throw new ApiException("InvalidFunction", "funtion name must include a fully qualified class name; do not know how to resolve \""+functionName+"\"");
      String className = functionName.substring(0, lastDot);
      functionName = functionName.substring(lastDot+1);
      Object instance = getObject(className);
      Method[] methods = clazz.getMethods();
      if (methods.length != 1) {
        if (methods.length == 0)
          throw new ApiException("InvalidFunction","There is no method named \""+functionName+"\" on "+className);
        else
          throw new ApiException("InvalidFunction","There is more than one method named \""+functionName+"\" on "+className);
      }
      return new NativeScriptFunction(instance, methods[0]);
    }
View Full Code Here


    @Override
    public Object getObject(String className) {
      try {
        clazz = Class.forName(className);
      } catch(ClassNotFoundException e) {
        throw new ApiException("InvalidFunction", "There is no class named \""+className+"\"");
      }
      Constructor constructor = clazz.getConstructors()[0];
      try {
        return constructor.newInstance(new Object[]{globals});
      } catch (IllegalArgumentException e) {
        throw new ApiException("InvalidFunction", e.getMessage());
      } catch (InstantiationException e) {
        throw new ApiException("InvalidFunction", e.getMessage());
      } catch (IllegalAccessException e) {
        throw new ApiException("InvalidFunction", e.getMessage());
      } catch (InvocationTargetException e) {
        throw new ApiException("InvalidFunction", e.getMessage());
      }
    }
View Full Code Here

  }

  public Object evaluateExpression(String code, Map<String, Object> globals) {
    int colonPosition = code.indexOf(':');
    if (colonPosition == -1)
      throw new ApiException("ScriptLanguageNotSpecified", "Please prefix your script expression with a language specifier, like \"js:\"");
    String scriptType = code.substring(0, colonPosition);
    code = code.substring(colonPosition+1);
    ScriptBridge bridge = bridges.get(scriptType);
    if (bridge == null)
      throw new ApiException("UnsupportedScriptLanguage","Unsupported script language: \""+scriptType+"\"");
    return bridge.evaluateExpression(code, globals);
  }
View Full Code Here

      }
      for(Map.Entry<String, Collection<Pair<String, String>>> entry : bucketedFiles.entrySet()) {
        String ext = entry.getKey();
        ScriptBridge bridge = bridges.get(ext);
        if (bridge == null)
          throw new ApiException("UnsupportedScriptLanguage","Unsupported file extension: \""+ext+"\"");
        ScriptEnv env= bridge.makeEnvFromCodeExecution(entry.getValue(), globals);
        envs.put(ext, env);
      }
    }
View Full Code Here

      if (colonPosition != -1) {
        String scriptType = functionName.substring(0, colonPosition);
        functionName = functionName.substring(colonPosition+1);
        ScriptEnv env = envs.get(scriptType);
        if (env == null)
          throw new ApiException("UnsupportedScriptLanguage","Unsupported script language: \""+scriptType+"\" for this function: \""+functionName+"\"");
        return env.getFunction(functionName, numParameters);
      } else { // not prefixed; try to find in each env:
        String lang = null;
        ScriptFunction fn = null;
        for(Map.Entry<String, ScriptEnv> entry: envs.entrySet()) {
          ScriptFunction curFn = entry.getValue().getFunction(functionName, numParameters);
          if (curFn != null) {
            String curLang = entry.getKey();
            if (fn != null) { // multiply defined
              throw new ApiException("MultiplyDefinedObject", "This object (\""+functionName+"\" is defined under multiple scripting languages ("+lang+" and "+curLang+")");
            }
            fn = curFn;
            lang = curLang;
          }
        }
View Full Code Here

    } else {
      bagName = secondElement;
      String actionString = parts[lastPartIndex];
      action = cannonicalActionStrings.get(actionString);
      if (action == null)
        throw new ApiException("UnsupportedAction", "Unsupported action: \""+actionString+"\"");
      if (lastPartIndex == 3) {
        id = parts[2];
      } else if (action.equals("update") && insertOrUpdate) {
        action = "insert";
      }
View Full Code Here

    @Override
    public Object getObject(String objectName) {
      int colonPosition = objectName.indexOf(':');
      if (colonPosition == -1)
        throw new ApiException("UnspecifiedScriptLanguage", "The object \""+objectName+"\" must be prefixed with the script language; like \"js:"+objectName+"\", for instance.");
      String scriptType = objectName.substring(0, colonPosition);
      objectName = objectName.substring(colonPosition+1);
      ScriptEnv env = envs.get(scriptType);
      if (env == null)
        throw new ApiException("UnsupportedScriptLanguage","Unsupported script language: \""+scriptType+"\" for this object: \""+objectName+"\"");
      return env.getObject(objectName);
    }
View Full Code Here

TOP

Related Classes of dovetaildb.apiservice.ApiException

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.