Exemple #1
0
  private void installParameters(boolean isStatic, String className) throws TypeException {
    Type type;
    // add a binding for the helper so we can call builtin static methods
    type = typeGroup.create(helperClass.getName());
    Binding ruleBinding = bindings.lookup("$$");
    if (ruleBinding != null) {
      ruleBinding.setType(type);
    } else {
      bindings.append(new Binding(this, "$$", type));
    }

    if (!isStatic) {
      Binding recipientBinding = bindings.lookup("$0");
      if (recipientBinding != null) {
        type = typeGroup.create(className);
        if (type.isUndefined()) {
          throw new TypeException(
              "Rule.installParameters : Rule " + name + " unable to load class " + className);
        }
        recipientBinding.setType(type);
      }
    }

    String returnTypeName = Type.parseMethodReturnType(triggerDescriptor);

    returnType = typeGroup.create(returnTypeName);

    Iterator<Binding> iterator = bindings.iterator();

    while (iterator.hasNext()) {
      Binding binding = iterator.next();
      // these bindings are typed via the descriptor installed during trigger injection
      // note that the return type has to be done this way because it may represent the
      // trigger method return type or the invoke method return type
      if (binding.isParam() || binding.isLocalVar() || binding.isReturn()) {
        String typeName = binding.getDescriptor();
        String[] typeAndArrayBounds = typeName.split("\\[");
        Type baseType = typeGroup.create(typeAndArrayBounds[0]);
        Type fullType = baseType;
        if (baseType.isUndefined()) {
          throw new TypeException(
              "Rule.installParameters : Rule " + name + " unable to load class " + baseType);
        }
        for (int i = 1; i < typeAndArrayBounds.length; i++) {
          fullType = typeGroup.createArray(fullType);
        }
        binding.setType(fullType);
      } else if (binding.isThrowable()) {
        // TODO -- enable a more precise specification of the throwable type
        // we need to be able to obtain the type descriptor for the throw operation
        binding.setType(typeGroup.ensureType(Throwable.class));
      } else if (binding.isParamCount()) {
        binding.setType(Type.I);
      } else if (binding.isParamArray() || binding.isInvokeParamArray()) {
        binding.setType(Type.OBJECT.arrayType());
      } else if (binding.isTriggerClass() || binding.isTriggerMethod()) {
        binding.setType(Type.STRING);
      }
    }
  }