示例#1
0
  /** Find the input associated with this panel based on the path Input. */
  @SuppressWarnings("unchecked")
  public Input<?> resolveInput(BeautiDoc doc, int iPartition) {
    try {
      //            if (parentPlugins != null && parentPlugins.size() > 0 && _input != null)
      //                System.err.println("sync " + parentPlugins.get(iPartition) + "[?] = " +
      // _input.get());

      List<BEASTInterface> plugins;
      if (bHasPartitionsInput.get() == Partition.none) {
        plugins = new ArrayList<BEASTInterface>();
        plugins.add(doc.mcmc.get());
      } else {
        plugins = doc.getPartitions(bHasPartitionsInput.get().toString());
      }
      parentPlugins = new ArrayList<BEASTInterface>();
      parentInputs = new ArrayList<Input<?>>();

      parentPlugins.add(doc);
      parentInputs.add(doc.mcmc);
      type = doc.mcmc.getType();
      bIsList = false;
      for (int i = 0; i < sPathComponents.length; i++) {
        List<BEASTInterface> oldPlugins = plugins;
        plugins = new ArrayList<BEASTInterface>();
        parentPlugins = new ArrayList<BEASTInterface>();
        parentInputs = new ArrayList<Input<?>>();
        for (BEASTInterface plugin : oldPlugins) {
          Input<?> namedInput = plugin.getInput(sPathComponents[i]);
          type = namedInput.getType();
          if (namedInput.get() instanceof List<?>) {
            bIsList = true;
            List<?> list = (List<?>) namedInput.get();
            if (sConditionalAttribute[i] == null) {
              for (Object o : list) {
                BEASTInterface plugin2 = (BEASTInterface) o;
                plugins.add(plugin2);
                parentPlugins.add(plugin);
                parentInputs.add(namedInput);
              }
              // throw new Exception ("Don't know which element to pick from the list. List
              // component should come with a condition. " + m_sPathComponents[i]);
            } else {
              int nMatches = 0;
              for (int j = 0; j < list.size(); j++) {
                BEASTInterface plugin2 = (BEASTInterface) list.get(j);
                if (matches(plugin2, sConditionalAttribute[i], sConditionalValue[i])) {
                  plugins.add(plugin2);
                  parentPlugins.add(plugin);
                  parentInputs.add(namedInput);
                  nMatches++;
                  break;
                }
              }
              if (nMatches == 0) {
                parentInputs.add(namedInput);
                parentPlugins.add(plugin);
              }
            }
          } else if (namedInput.get() instanceof BEASTInterface) {
            bIsList = false;
            if (sConditionalAttribute[i] == null) {
              plugins.add((BEASTInterface) namedInput.get());
              parentPlugins.add(plugin);
              parentInputs.add(namedInput);
            } else {
              if (matches(plugin, sConditionalAttribute[i], sConditionalValue[i])) {
                //							if ((m_sConditionalAttribute[i].equals("id") &&
                // plugin.getID().equals(m_sConditionalValue[i])) ||
                //							    (m_sConditionalAttribute[i].equals("type") &&
                // plugin.getClass().getName().equals(m_sConditionalValue[i]))) {
                plugins.add(plugin);
                parentPlugins.add(plugin);
                parentInputs.add(namedInput);
              }
            }
          } else {
            throw new Exception("input " + sPathComponents[i] + "  is not a plugin or list");
          }
        }
      }
      if (sTypeInput.get() != null) {
        type = Class.forName(sTypeInput.get());
      }
      // sanity check
      if (!bIsList && (bHasPartitionsInput.get() == Partition.none) && plugins.size() > 1) {
        System.err.println("WARNING: multiple plugins match, but hasPartitions=none");
        // this makes sure that all mathing plugins are available in one go
        bIsList = true;
        // this suppresses syncing
        parentInputs.clear();
      }
      inputs.clear();
      startInputs.clear();
      for (BEASTInterface plugin : plugins) {
        inputs.add(plugin);
        startInputs.add(plugin);
      }

      if (!bIsList) {
        _input = new FlexibleInput<BEASTInterface>();
      } else {
        _input = new FlexibleInput<ArrayList<BEASTInterface>>(new ArrayList<BEASTInterface>());
      }
      _input.setRule(Validate.REQUIRED);
      syncTo(iPartition);
      //            if (parentPlugins != null && parentPlugins.size() > 0)
      //                System.err.println("sync " + parentPlugins.get(iPartition) + "[?] = " +
      // _input.get());

      if (bIsList) {
        checkForDups((List<Object>) _input.get());
      }

      return _input;
    } catch (Exception e) {
      System.err.println(
          "Warning: could not find objects in path " + Arrays.toString(sPathComponents));
    }
    return null;
  } // resolveInputs