Ejemplo n.º 1
0
  /**
   * Returns a string showing the formal parameters for this method. The returned string is a comma
   * separated list of parameter types, if <code>withNames</code> is true, then the returned string
   * is a comma separated list of type:name.
   *
   * <p>Example: method is "void getX(int a, int b)", <code>withNames</code> is false, returned
   * string is "int,int".
   *
   * <p>Example: method is "void getX(int a, int b)", <code>withNames</code> is true, returned
   * string is "int a,int b".
   *
   * @param withNames should returned string include the formal parameter names
   * @param typeAsSuffix if true and if withNames is true, name and type will be reversed, e.g.
   *     method is "void getX(int a, int b), returned string is "a : int, b : int"
   * @param includeFinal if true, include any "final" modifier, e.g. method is "void getX(int a,
   *     final int b)", returned string is "int, final int", or if withNames is true, "int a, final
   *     int b", and if typeAsSuffix is true, "a : int, b : final int"
   * @return parameters as string, see above
   */
  public String getFormalParams(
      boolean withNames, boolean typeAsSuffix, boolean includeFinal, boolean includeTypeArgs) {

    if (formalParams == null || formalParams.size() == 0) return "";

    StringBuffer sb = new StringBuffer();
    for (Iterator it = formalParams.iterator(); it.hasNext(); ) {
      Parameter param = (Parameter) it.next();
      if (typeAsSuffix) {
        if (includeFinal && param.isFinal()) sb.append("final ");
        sb.append(param.type.type);
        if (includeTypeArgs) sb.append(param.type.typeArgs);
        if (param.isVarArg()) sb.append("...");
        if (withNames) sb.append(" : ").append(param.getName());
      } else {
        if (withNames) sb.append(param.getName()).append(" : ");
        if (includeFinal && param.isFinal()) sb.append("final ");
        sb.append(param.type.type);
        if (includeTypeArgs) sb.append(param.type.typeArgs);
        if (param.isVarArg()) sb.append("...");
      }
      if (it.hasNext()) sb.append(", ");
    }
    return sb.toString();
  }
Ejemplo n.º 2
0
  @Override
  protected void fillVoiceXmlDocument(
      Document document, Element formElement, VoiceXmlDialogueContext dialogueContext)
      throws VoiceXmlDocumentRenderingException {

    List<String> submitNameList = new ArrayList<String>();
    VariableList submitVariableList = mSubmitParameters;
    if (submitVariableList != null) {
      addVariables(formElement, submitVariableList);

      for (Entry<String, String> entry : mSubmitParameters) {
        submitNameList.add(entry.getKey());
      }
    }

    Element subdialogueElement = DomUtils.appendNewElement(formElement, SUBDIALOG_ELEMENT);
    subdialogueElement.setAttribute(NAME_ATTRIBUTE, SUBDIALOGUE_FORM_ITEM_NAME);
    subdialogueElement.setAttribute(SRC_ATTRIBUTE, mUri);

    if (!submitNameList.isEmpty()) {
      subdialogueElement.setAttribute(NAME_LIST_ATTRIBUTE, StringUtils.join(submitNameList, " "));
    }

    for (Parameter parameter : mParameters) {
      Element paramElement = DomUtils.appendNewElement(subdialogueElement, PARAM_ELEMENT);
      paramElement.setAttribute(NAME_ATTRIBUTE, parameter.getName());
      setAttribute(paramElement, VALUE_ATTRIBUTE, parameter.getValue());
      setAttribute(paramElement, EXPR_ATTRIBUTE, parameter.getExpression());
    }

    SubmitMethod submitMethod = mMethod;
    if (submitMethod != null) {
      subdialogueElement.setAttribute(METHOD_ATTRIBUTE, submitMethod.name());
    }

    DocumentFetchConfiguration fetchConfiguration = mFetchConfiguration;
    if (fetchConfiguration != null) {
      applyFetchAudio(subdialogueElement, fetchConfiguration.getFetchAudio());
      applyRessourceFetchConfiguration(subdialogueElement, fetchConfiguration);
    }

    Element filledElement = DomUtils.appendNewElement(subdialogueElement, FILLED_ELEMENT);

    createVarElement(
        filledElement, SUBDIALOGUE_RESULT_VARIABLE_NAME, "dialog." + SUBDIALOGUE_FORM_ITEM_NAME);

    if (mPostDialogueScript != null) {
      createScript(filledElement, mPostDialogueScript);
    }

    createScript(
        filledElement,
        RIVR_SCOPE_OBJECT + ".addValueResult(" + SUBDIALOGUE_RESULT_VARIABLE_NAME + ");");
    createGotoSubmit(filledElement);
  }
 /** Refreshes the functions. */
 protected void refreshFunctions() {
   // put the parameter values into the data properties map
   Map map = getData().getProperties();
   map.clear();
   Iterator it = paramEditor.getObjects().iterator();
   while (it.hasNext()) {
     Parameter p = (Parameter) it.next();
     String name = p.getName();
     double val = p.getValue();
     map.put(name, new Double(val));
   }
   // evaluate the functions
   functionEditor.evaluateAll();
 }
Ejemplo n.º 4
0
 /**
  * Loads an object with data from an XMLControl.
  *
  * @param control the control
  * @param obj the object
  * @return the loaded object
  */
 public Object loadObject(XMLControl control, Object obj) {
   // load track data
   XML.getLoader(TTrack.class).loadObject(control, obj);
   ParticleModel p = (ParticleModel) obj;
   p.mass = control.getDouble("mass"); // $NON-NLS-1$
   p.inspectorX = control.getInt("inspector_x"); // $NON-NLS-1$
   p.inspectorY = control.getInt("inspector_y"); // $NON-NLS-1$
   p.inspectorH = control.getInt("inspector_h"); // $NON-NLS-1$
   p.showInspector = control.getBoolean("inspector_visible"); // $NON-NLS-1$
   Parameter[] params = (Parameter[]) control.getObject("user_parameters"); // $NON-NLS-1$
   p.getParamEditor().setParameters(params);
   params = (Parameter[]) control.getObject("initial_values"); // $NON-NLS-1$
   // remove trailing "0" from initial condition parameters
   for (int i = 0; i < params.length; i++) {
     Parameter param = params[i];
     String name = param.getName();
     int n = name.lastIndexOf("0"); // $NON-NLS-1$
     if (n > -1) {
       // replace parameter with new one
       name = name.substring(0, n);
       Parameter newParam = new Parameter(name, param.getExpression());
       newParam.setDescription(param.getDescription());
       newParam.setNameEditable(false);
       params[i] = newParam;
     }
   }
   p.getInitEditor().setParameters(params);
   UserFunction[] functions =
       (UserFunction[]) control.getObject("main_functions"); // $NON-NLS-1$
   p.getFunctionEditor().setMainFunctions(functions);
   functions = (UserFunction[]) control.getObject("support_functions"); // $NON-NLS-1$
   if (functions != null) {
     for (int i = 0; i < functions.length; i++) {
       p.getFunctionEditor().addObject(functions[i], false);
     }
   }
   p.functionPanel.refreshFunctions();
   int n = control.getInt("start_frame"); // $NON-NLS-1$
   if (n != Integer.MIN_VALUE) p.startFrame = n;
   else {
     p.startFrameUndefined = true;
   }
   n = control.getInt("end_frame"); // $NON-NLS-1$
   if (n != Integer.MIN_VALUE) p.endFrame = n;
   return obj;
 }
Ejemplo n.º 5
0
  public GeneralizedSemPm(SemPm semPm) {
    this(semPm.getGraph());

    // Write down equations.
    try {
      List<Node> variableNodes = getVariableNodes();

      for (int i = 0; i < variableNodes.size(); i++) {
        Node node = variableNodes.get(i);
        List<Node> parents = getVariableParents(node);

        StringBuilder buf = new StringBuilder();

        for (int j = 0; j < parents.size(); j++) {
          if (!(variableNodes.contains(parents.get(j)))) {
            continue;
          }

          Node parent = parents.get(j);

          Parameter _parameter = semPm.getParameter(parent, node);
          String parameter = _parameter.getName();
          Set<Node> nodes = new HashSet<>();
          nodes.add(node);

          referencedParameters.put(parameter, nodes);

          buf.append(parameter);
          buf.append("*");
          buf.append(parents.get(j).getName());

          setParameterExpression(parameter, "Split(-1.5, -.5, .5, 1.5)");
          setStartsWithParametersTemplate(parameter.substring(0, 1), "Split(-1.5, -.5, .5, 1.5)");
          setStartsWithParametersEstimationInitializaationTemplate(
              parameter.substring(0, 1), "Split(-1.5, -.5, .5, 1.5)");

          if (j < parents.size() - 1) {
            buf.append(" + ");
          }
        }

        if (buf.toString().trim().length() != 0) {
          buf.append(" + ");
        }

        buf.append(errorNodes.get(i));
        setNodeExpression(node, buf.toString());
      }

      for (Node node : variableNodes) {
        Parameter _parameter = semPm.getParameter(node, node);
        String parameter = _parameter.getName();

        String distributionFormula = "N(0," + parameter + ")";
        setNodeExpression(getErrorNode(node), distributionFormula);
        setParameterExpression(parameter, "U(0, 1)");
        setStartsWithParametersTemplate(parameter.substring(0, 1), "U(0, 1)");
        setStartsWithParametersEstimationInitializaationTemplate(
            parameter.substring(0, 1), "U(0, 1)");
      }

      variableNames = new ArrayList<>();
      for (Node _node : variableNodes) variableNames.add(_node.getName());
      for (Node _node : errorNodes) variableNames.add(_node.getName());

    } catch (ParseException e) {
      throw new IllegalStateException("Parse error in constructing initial model.", e);
    }
  }
Ejemplo n.º 6
0
  /**
   * Basic Framework implicitely also processes, i'm not sure if we should require any framework to
   * do that (perhaps we could say, that the render method must process, if that is necessary, and
   * not yet done).
   */
  @Override
  public void render(
      Renderer renderer,
      Parameters blockParameters,
      Parameters frameworkParameters,
      Writer w,
      WindowState windowState)
      throws FrameworkException {
    ServletRequest request = frameworkParameters.get(Parameter.REQUEST);
    if (request == null) {
      throw new IllegalArgumentException("No request object given");
    }

    State state = State.getState(request);
    if (state
        .isRendering()) { // mm:component used during rending of a component, that's fine, but use a
                          // new State.
      state = new State(request);
      log.debug("Alreadying rendering, taking a new state for sub-block-rendering: " + state);
    }

    log.debug("Rendering " + renderer.getBlock() + " " + renderer);
    Object prevHints = request.getAttribute(RenderHints.KEY);
    try {

      request.setAttribute(COMPONENT_CLASS_KEY, getComponentClass());
      request.setAttribute(COMPONENT_CURRENTUSER_KEY, getUserNode(frameworkParameters));

      Renderer actualRenderer = state.startBlock(frameworkParameters, renderer);
      if (!actualRenderer.equals(renderer)) {
        Parameters newBlockParameters = actualRenderer.getBlock().createParameters();
        newBlockParameters.setAllIfDefined(blockParameters);
        blockParameters = newBlockParameters;
      }
      state.setAction(request.getParameter(ACTION.getName()));
      if (state.needsProcess()) {
        log.service("Performing action on " + actualRenderer.getBlock());
        Processor processor = actualRenderer.getBlock().getProcessor();
        state.process(processor);
        log.service("Processing " + actualRenderer.getBlock() + " " + processor);
        setBlockParametersForProcess(state, blockParameters);
        processor.process(blockParameters);
        state.endProcess();
      }

      state.render(actualRenderer);

      setBlockParametersForRender(state, blockParameters);

      RenderHints hints =
          new RenderHints(
              actualRenderer,
              windowState,
              state.getId(),
              getComponentClass(),
              RenderHints.Mode.NORMAL);
      request.setAttribute(RenderHints.KEY, hints);
      actualRenderer.render(blockParameters, w, hints);
      request.setAttribute("org.mmbase.framework.hints", hints);
    } catch (FrameworkException fe) {
      log.debug(fe);
      URI uri = renderer.getUri();
      Renderer error =
          new ErrorRenderer(
              renderer.getType(),
              renderer.getBlock(),
              (uri != null) ? uri.toString() : null,
              500,
              fe);
      RenderHints hints =
          new RenderHints(
              error, windowState, state.getId(), getComponentClass(), RenderHints.Mode.NORMAL);
      error.render(blockParameters, w, hints);
    } finally {
      request.setAttribute(RenderHints.KEY, prevHints);
      state.endBlock();
    }
  }