예제 #1
0
파일: GrabSell.java 프로젝트: erikh/swath
  public boolean initScript() throws Exception {
    if (!atPrompt(Swath.COMMAND_PROMPT)) return false;

    m_planet = new Parameter("Grab from planet");
    m_planet.setType(Parameter.INTEGER);
    m_type = new Parameter("Type of product to grab and sell");
    m_type.setType(Parameter.CHOICE);
    m_type.addChoice(Swath.FUEL_ORE, "Fuel Ore");
    m_type.addChoice(Swath.ORGANICS, "Organics");
    m_type.addChoice(Swath.EQUIPMENT, "Equipment");
    m_type.setCurrentChoice(Swath.FUEL_ORE);

    registerParam(m_planet);
    registerParam(m_type);

    return true;
  }
예제 #2
0
  public void initialize() {
    this.sourceType = ExtensionManager.getInstance().getType(this.sourceTypeName);
    if (this.sourceType == null)
      throw new RuntimeException("Unknown source type '" + this.sourceType + "'");

    this.resultType = ExtensionManager.getInstance().getType(this.resultTypeName);
    if (this.resultType == null)
      throw new RuntimeException("Unknown result type '" + this.resultType + "'");

    for (Parameter par : this.parameter) {
      par.setType(ExtensionManager.getInstance().getType(par.getTypeName()));

      if (par.getType() == null)
        throw new RuntimeException("Unknown parameter type '" + this.resultType + "'");
    }
  }
예제 #3
0
  private static void parseConfiguration(String stringUrl, Product product) {
    try {
      URL url = new URL(stringUrl);
      URLConnection connection = url.openConnection();
      int fileLength = connection.getContentLength();

      if (fileLength == -1) {
        System.out.println("Invalide URL or file.");
        return;
      }

      CommandClass currentCC = null;
      Parameter currentParameter = null;
      Association currentAssociation = null;

      XMLInputFactory inputFactory = XMLInputFactory.newInstance();
      InputStream input = connection.getInputStream();
      final XMLEventReader eventReader = inputFactory.createXMLEventReader(input);

      while (eventReader.hasNext()) {
        XMLEvent event = eventReader.nextEvent();
        if (event.isStartElement()) {
          StartElement startElt = event.asStartElement();
          if (startElt.getName().getLocalPart().equals("CommandClass")) {
            CommandClass cc = product.view().createCommandClass();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();

              if (attrName.equals("id")) {
                cc.setId(Integer.parseInt(next.getValue(), 16));
              }
            }
            product.addCommandClasses(cc);
            currentCC = cc;

          } else if (startElt.getName().getLocalPart().equals("Value")) {

            Parameter param = product.view().createParameter();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();
              if (!next.getValue().equals("")) {
                if (attrName.equals("type")) {
                  param.setType(ParameterType.valueOf(next.getValue().toUpperCase()));
                } else if (attrName.equals("genre")) {
                  param.setGenre(next.getValue());
                } else if (attrName.equals("instance")) {
                  param.setInstance(Integer.valueOf(next.getValue()));
                } else if (attrName.equals("index")) {
                  param.setIndex(Integer.valueOf(next.getValue()));
                } else if (attrName.equals("label")) {
                  param.setLabel(next.getValue());
                } else if (attrName.equals("value")) {
                  param.setValue(next.getValue());
                } else if (attrName.equals("min")) {

                  param.setMin(Integer.valueOf(next.getValue()));
                } else if (attrName.equals("max")) {

                  param.setMax(Integer.valueOf(next.getValue()));
                } else if (attrName.equals("size")) {
                  param.setSize(Integer.valueOf(next.getValue()));
                }
              }
            }
            currentCC.addParameters(param);
            currentParameter = param;

          } else if (startElt.getName().getLocalPart().equals("Help")) {
            // help

          } else if (startElt.getName().getLocalPart().equals("Item")) {
            ParameterItem item = product.view().createParameterItem();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();
              if (attrName.equals("label")) {
                item.setLabel(next.getValue());
              } else if (attrName.equals("value")) {
                item.setValue(Integer.valueOf(next.getValue()));
              }
            }
            currentParameter.addItems(item);
          } else if (startElt.getName().getLocalPart().equals("Associations")) {
            Association assoc = product.view().createAssociation();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();
              if (attrName.equals("num_groups")) {
                assoc.setNumGroups(Integer.valueOf(next.getValue()));
              }
            }
            currentCC.addAssociations(assoc);
            currentAssociation = assoc;
          } else if (startElt.getName().getLocalPart().equals("Group")) {
            AssociationGroup group = product.view().createAssociationGroup();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();
              if (attrName.equals("label")) {
                group.setLabel(next.getValue());
              } else if (attrName.equals("index")) {
                group.setIndex(Integer.valueOf(next.getValue()));
              } else if (attrName.equals("max_associations")) {
                group.setMaxAssociations(Integer.valueOf(next.getValue()));
              } else if (attrName.equals("auto")) {
                group.setAuto(Boolean.valueOf(next.getValue()));
              }
              currentAssociation.addGroups(group);
            }
          }
        }
      }

    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (XMLStreamException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #4
0
  public boolean initScript() throws Exception {
    // Initialisation of the script is done in this method.
    // All parameters should be created and registered here.
    // If something goes wrong, return false.

    // Check that we are at the correct prompt
    if (!atPrompt(Swath.COMMAND_PROMPT)) return false;

    // Create the parameter 'startSector' and set the value to
    // the current sector.
    // The type will be set to INTEGER by setInteger().

    startSector = new Parameter("What sector do you want to start at?");
    startSector.setInteger(Swath.main.currSector());

    // Create the parameter 'cycles' and set the value to
    // to zero.
    // The type will be set to INTEGER by setInteger().
    cycles = new Parameter("How many cycles (0 = until done)");
    cycles.setInteger(0);

    // If we want to set voids during ether probe or not.
    // setting voids will result in longer warp paths.
    // but you will also possible lock out certain parts of
    // the universe so voids is good on a first run.
    // then do a second run without setting any voids.
    // to get the rest of the universe.
    toggleVoid = new Parameter("Set voids ?");
    toggleVoid.setType(Parameter.BOOLEAN);
    toggleVoid.setBoolean(true);

    oneWarps = new Parameter("One Warps ?");
    oneWarps.setType(Parameter.BOOLEAN);
    oneWarps.setBoolean(true);

    twoWarps = new Parameter("Two Warps ?");
    twoWarps.setType(Parameter.BOOLEAN);
    twoWarps.setBoolean(true);

    threeWarps = new Parameter("Three Warps ?");
    threeWarps.setType(Parameter.BOOLEAN);
    threeWarps.setBoolean(false);

    fourWarps = new Parameter("Four Warps ?");
    fourWarps.setType(Parameter.BOOLEAN);
    fourWarps.setBoolean(false);

    fiveWarps = new Parameter("Five Warps ?");
    fiveWarps.setType(Parameter.BOOLEAN);
    fiveWarps.setBoolean(false);

    sixWarps = new Parameter("Six Warps ?");
    sixWarps.setType(Parameter.BOOLEAN);
    sixWarps.setBoolean(true);

    // Resgister the parameters the the user picked
    // so we can use them from inside the script.
    registerParam(startSector);
    registerParam(cycles);
    registerParam(toggleVoid);
    registerParam(oneWarps);
    registerParam(twoWarps);
    registerParam(threeWarps);
    registerParam(fourWarps);
    registerParam(fiveWarps);
    registerParam(sixWarps);

    // Some other initialisation could be done here
    // ...

    return true;
  }