public ArrayList getAnswerArray() {
   ArrayList list = new ArrayList();
   Iterator iter = answerSet.iterator();
   while (iter.hasNext()) {
     list.add(iter.next());
   }
   return list;
 }
Esempio n. 2
0
  private static void parseArgs(String args[]) {

    ArrayList cleanedArgs = new ArrayList();

    for (int i = 0; i < args.length; i++) {
      if (args[i].startsWith("--")) {

        // Parse Long Options
        String longopt = args[i].substring(2);

        if (longopt.equals("help")) {
          usage();
        }

      } else if (args[i].startsWith("-")) {

        // Parse Short Options
        String opt = args[i].substring(1);

        if (opt.equals("d")) {
          data = Integer.parseInt(args[++i]);
        } else if (opt.equals("w")) {
          wakeup = true;
        } else if (opt.equals("c")) {
          channel = Integer.parseInt(args[++i]);
        } else if (opt.equals("h")) {
          usage();
        }

      } else {

        // Place into args string
        cleanedArgs.add(args[i]);
      }
    }
  }
 @Override
 public byte[] getBinaryData() {
   final ArrayList<byte[]> binGroups = new ArrayList<byte[]>(this.m_actionGroups.size());
   final ArrayList<byte[]> binRewars = new ArrayList<byte[]>(this.m_rewards.size());
   int presize = 0;
   presize += 4;
   try {
     for (final String var : this.m_varMapping) {
       presize += 4 + var.getBytes("UTF-8").length;
     }
   } catch (Exception e) {
     ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e);
   }
   try {
     presize += 8;
     presize +=
         ((this.m_joinCriterion != null) ? this.m_joinCriterion.getBytes("UTF-8").length : 0);
     presize +=
         ((this.m_rewardEligibilityCriterion != null)
             ? this.m_rewardEligibilityCriterion.getBytes("UTF-8").length
             : 0);
   } catch (Exception e) {
     ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e);
   }
   for (final ActionGroupStorable g : this.m_actionGroups) {
     final byte[] bin = g.serialize();
     presize += bin.length + 4;
     binGroups.add(bin);
   }
   for (final RewardStorable r : this.m_rewards) {
     final byte[] bin = r.serialize();
     presize += bin.length + 4;
     binRewars.add(bin);
   }
   try {
     presize += 4;
     presize += ((this.m_params != null) ? this.m_params.getBytes("UTF-8").length : 0);
   } catch (Exception e) {
     ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e);
   }
   final ByteBuffer bb = ByteBuffer.allocate(31 + presize);
   bb.putInt(this.m_id);
   bb.put(this.m_type);
   bb.put(this.m_userType);
   bb.put((byte) (this.m_autoTrigger ? 1 : 0));
   bb.put((byte) (this.m_isChallenge ? 1 : 0));
   bb.put((byte) (this.m_isChaos ? 1 : 0));
   bb.putShort(this.m_duration);
   bb.putShort(this.m_minUsers);
   bb.putShort(this.m_maxUsers);
   if (this.m_expirationDate != null) {
     bb.putLong(this.m_expirationDate.toLong());
   } else {
     bb.putLong(0L);
   }
   try {
     if (this.m_params != null) {
       final byte[] bytes = this.m_params.getBytes("UTF-8");
       bb.putInt(bytes.length);
       bb.put(bytes);
     } else {
       bb.putInt(0);
     }
   } catch (Exception e2) {
     ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2);
   }
   try {
     bb.putInt(this.m_varMapping.length);
     for (final String var2 : this.m_varMapping) {
       final byte[] bytes2 = var2.getBytes("UTF-8");
       bb.putInt(bytes2.length);
       bb.put(bytes2);
     }
   } catch (Exception e2) {
     ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2);
   }
   try {
     if (this.m_joinCriterion != null) {
       final byte[] bytes = this.m_joinCriterion.getBytes("UTF-8");
       bb.putInt(bytes.length);
       bb.put(bytes);
     } else {
       bb.putInt(0);
     }
     if (this.m_rewardEligibilityCriterion != null) {
       final byte[] bytes = this.m_rewardEligibilityCriterion.getBytes("UTF-8");
       bb.putInt(bytes.length);
       bb.put(bytes);
     } else {
       bb.putInt(0);
     }
   } catch (Exception e2) {
     ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2);
   }
   bb.putInt(binGroups.size());
   for (final byte[] gdata : binGroups) {
     bb.putInt(gdata.length);
     bb.put(gdata);
   }
   bb.putInt(binRewars.size());
   for (final byte[] rdata : binRewars) {
     bb.putInt(rdata.length);
     bb.put(rdata);
   }
   return bb.array();
 }
Esempio n. 4
0
  public static AppointmentItem importFromSOAP(Element GetAppointmentResponse)
      throws HarnessException {

    if (GetAppointmentResponse == null) throw new HarnessException("Element cannot be null");

    AppointmentItem appt = null;

    try {

      // Make sure we only have the GetMsgResponse part
      Element getAppointmentResponse =
          ZimbraAccount.SoapClient.selectNode(
              GetAppointmentResponse, "//mail:GetAppointmentResponse");
      if (getAppointmentResponse == null)
        throw new HarnessException("Element does not contain GetAppointmentResponse");

      Element m = ZimbraAccount.SoapClient.selectNode(getAppointmentResponse, "//mail:appt");
      if (m == null) throw new HarnessException("Element does not contain an appt element");

      // Create the object
      appt = new AppointmentItem();

      if (m != null) {

        // Appointment id
        appt.dApptID = m.getAttribute("id");
      }

      String parentFolder = m.getAttribute("l");
      if (parentFolder != null) {

        // Parent folder
        appt.dFolder = parentFolder;
      }

      Element sElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:s");
      if (sElement != null) {

        // Start time
        appt.dStartTime = new ZDate(sElement);
      }

      Element eElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:e");
      if (eElement != null) {

        // End time
        appt.dEndTime = new ZDate(eElement);
      }

      Element compElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:comp");
      if (compElement != null) {

        // Subject
        appt.dSubject = compElement.getAttribute("name");

        // Location
        appt.dLocation = compElement.getAttribute("loc");

        // Display
        appt.dDisplay = compElement.getAttribute("fb");
      }

      Element oElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:or");
      if (oElement != null) {

        // Organizer
        appt.dOrganizer = oElement.getAttribute("a");
      }
      Element mpElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:mp");
      if (mpElement != null) {

        // Get multipart
        appt.dMultipart = mpElement;
      }
      // Parse the required attendees
      ArrayList<String> attendees = new ArrayList<String>();
      Element[] requiredElements =
          ZimbraAccount.SoapClient.selectNodes(m, "//mail:at[@role='REQ']");
      for (Element e : requiredElements) {
        attendees.add(e.getAttribute("a"));
      }
      if (attendees.size() > 0) {
        appt.dAttendees = AppointmentItem.StringListToCommaSeparated(attendees);
      }

      // Parse the optional attendees
      ArrayList<String> optionals = new ArrayList<String>();
      Element[] optionalElements =
          ZimbraAccount.SoapClient.selectNodes(m, "//mail:at[@role='OPT']");
      for (Element e : optionalElements) {
        optionals.add(e.getAttribute("a"));
      }
      if (optionals.size() > 0) {
        appt.dOptionals = AppointmentItem.StringListToCommaSeparated(optionals);
      }

      if (appt.dLocation == "") {

        Element equipElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:at[@cutype='RES']");
        if (equipElement != null) {

          // Equipment
          appt.dEquipment = equipElement.getAttribute("a");
        }

      } else if (appt.dLocation != null) {

        Element equipElement =
            ZimbraAccount.SoapClient.selectNode(m, "//mail:at[@cutype='RES'][2]");
        if (equipElement != null) {

          // Equipment
          appt.dEquipment = equipElement.getAttribute("a");
        }
      }

      Element descElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:fr");
      if (descElement != null) {

        // Body
        appt.dContent = descElement.getTextTrim();
      }

      return (appt);

    } catch (Exception e) {
      throw new HarnessException(
          "Could not parse GetMsgResponse: " + GetAppointmentResponse.prettyPrint(), e);
    } finally {
      if (appt != null) logger.info(appt.prettyPrint());
    }
  }