예제 #1
0
  public static CompiledChainImpl buildChain(
      AutomationService service, Class<?> in, OperationParameters[] operations)
      throws OperationNotFoundException, InvalidChainException {
    if (operations.length == 0) {
      throw new InvalidChainException("Null operation chain.");
    }
    OperationParameters params = operations[0];

    CompiledChainImpl invocation =
        new CompiledChainImpl(service.getOperation(params.id()), params.map());
    CompiledChainImpl last = invocation;
    for (int i = 1; i < operations.length; i++) {
      params = operations[i];
      last = new CompiledChainImpl(last, service.getOperation(params.id()), params.map());
    }
    // find the best matching path in the chain
    if (!invocation.initializePath(in)) {
      throw new InvalidChainException(
          "Cannot find any valid path in operation chain - no method found for operation '"
              + opId
              + "' and for first input type '"
              + in.getName()
              + "'");
    }
    return invocation;
  }
예제 #2
0
 public AutomationInfo(AutomationService service) {
   ops = service.getDocumentation();
   // build a map for easy lookup
   Map<String, OperationDocumentation> map = new HashMap<String, OperationDocumentation>();
   for (OperationDocumentation doc : ops) {
     map.put(doc.id, doc);
   }
   chains = new ArrayList<OperationDocumentation>();
   for (OperationChain chain : service.getOperationChains()) {
     OperationDocumentation doc = new OperationDocumentation(chain.getId());
     doc.description = chain.getDescription();
     doc.category = "Chain";
     doc.label = doc.id;
     doc.params = Collections.emptyList();
     // compute chain signature
     List<OperationParameters> ops = chain.getOperations();
     if (ops.isEmpty()) {
       doc.signature = new String[] {"void", "void"};
     } else if (ops.size() == 1) {
       OperationDocumentation opdoc = map.get(ops.get(0).id());
       doc.signature = opdoc.signature;
     } else {
       ArrayList<String[]> sigs = new ArrayList<String[]>();
       for (OperationParameters o : ops) {
         sigs.add(map.get(o.id()).signature);
       }
       String[] head = sigs.get(0);
       ArrayList<String> rs = new ArrayList<String>();
       for (int i = 0; i < head.length; i += 2) {
         String in = head[i];
         String out = head[i + 1];
         List<String> result = new ArrayList<String>();
         checkPath(out, sigs, 1, result);
         for (String r : result) {
           rs.add(in);
           rs.add(r);
         }
       }
       doc.signature = rs.toArray(new String[rs.size()]);
     }
     chains.add(doc);
   }
 }