Exemplo n.º 1
0
 /**
  * Get the test suite specifications from the suite file, apply the options to all, and report any
  * messages to the holder.
  *
  * @param suitePath the String path to the harness suite file
  * @param options the String[] options for the tests - may be null
  * @param holder the IMessageHolder for any messages - may be null
  * @return AjcTest.Suite.Spec test descriptions (non-null but empty if some error)
  */
 public static AjcTest.Suite.Spec getSuiteSpec(
     String suitePath, String[] options, IMessageHolder holder) {
   if (null == suitePath) {
     MessageUtil.fail(holder, "null suitePath");
     return EmptySuite.ME;
   }
   File suiteFile = new File(suitePath);
   if (!suiteFile.canRead() || !suiteFile.isFile()) {
     MessageUtil.fail(holder, "unable to read file " + suitePath);
     return EmptySuite.ME;
   }
   try {
     AjcTest.Suite.Spec tempSpec;
     AbstractRunSpec.RT runtime = new AbstractRunSpec.RT();
     tempSpec = AjcSpecXmlReader.getReader().readAjcSuite(suiteFile);
     tempSpec.setSuiteDirFile(suiteFile.getParentFile());
     if (null == options) {
       options = new String[0];
     }
     runtime.setOptions(options);
     boolean skip = !tempSpec.adoptParentValues(runtime, holder);
     if (skip) {
       tempSpec = EmptySuite.ME;
     }
     return tempSpec;
   } catch (IOException e) {
     MessageUtil.abort(holder, "IOException", e);
     return EmptySuite.ME;
   }
 }
Exemplo n.º 2
0
  private static void testMassMessage() {
    String mediaId = "OS3XEqCEjSgIzp_ggt5yLihCThfcMM2NafRgWj44tRSKjjNGvHDxQbTZ7nIpEhlI";
    System.out.println(MessageUtil.sendMassMessageByGroup(Constants.LICENSE, "1", mediaId));

    List<String> openIds =
        ImmutableList.of("oVDIDt3_SMFnLBBfmQtr67oYT3NI", "oVDIDt_SyuhqP7WF7zliVZrqY2wY");
    System.out.println(MessageUtil.sendMassMessageByUsers(Constants.LICENSE, openIds, mediaId));

    System.out.println(MessageUtil.deleteMassMessage(Constants.LICENSE, 34182));
  }
Exemplo n.º 3
0
  /**
   * Process DB Success message
   *
   * @param aStampContext current context
   * @param payload DB Success message
   */
  public static void processCeCk(WitnessContext aStampContext, byte[] payload) {
    // parse Ce and Ck
    ArrayList<byte[]> ceck = MessageUtil.parseMessage(payload, 2);
    ArrayList<byte[]> ces = MessageUtil.parseMessages(ceck.get(0));
    ArrayList<byte[]> cks = MessageUtil.parseMessages(ceck.get(1));

    // obtain z
    BigInteger z = CryptoUtil.getZ(ces, cks, aStampContext.getPubDSASelf().getParams().getP());
    aStampContext.setRemoteZ(z);
  }
Exemplo n.º 4
0
  /**
   * Endorse the proof
   *
   * @param aStampContext current context
   * @param aProof proof
   * @return endorsed proof
   * @throws NoSuchAlgorithmException
   * @throws BadPaddingException
   * @throws IllegalBlockSizeException
   * @throws NoSuchPaddingException
   * @throws InvalidKeyException
   */
  private static byte[] endorseP(WitnessContext aStampContext, byte aProof[]) {

    // Sign on the proof first
    byte[] sig = {};
    try {
      sig = CryptoUtil.signDSA(aStampContext.getPriDSASelf(), aProof);
    } catch (InvalidKeyException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (SignatureException e) {
      e.printStackTrace();
    }

    // Include own ID in EP
    byte[] wID = aStampContext.getPubDSASelf().getEncoded();

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(wID);
    array.add(aProof);
    array.add(sig);

    byte[] epContent = MessageUtil.compileMessages(array);

    // Encrypt epContent with an AES key first
    SecretKey aesKey = null;
    byte[] epEncrypted = {};
    byte[] keyEncrypted = {};
    try {
      aesKey = CryptoUtil.generateAESKey(128);
      epEncrypted = CryptoUtil.encryptAES(aesKey, epContent);
      keyEncrypted = CryptoUtil.encryptRSA(aStampContext.getPubRSACA(), aesKey.getEncoded());
    } catch (NoSuchAlgorithmException e1) {
      e1.printStackTrace();
    } catch (InvalidKeyException e) {
      e.printStackTrace();
    } catch (NoSuchPaddingException e) {
      e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
      e.printStackTrace();
    } catch (BadPaddingException e) {
      e.printStackTrace();
    }

    ArrayList<byte[]> arrayOut = new ArrayList<byte[]>();
    arrayOut.add(epEncrypted);
    arrayOut.add(keyEncrypted);

    return MessageUtil.compileMessages(arrayOut);
  }
Exemplo n.º 5
0
  /**
   * Create a STPR STPR = T|Comm(L_1, r^1_W)|...|Comm(L_n, r^n_W)
   *
   * @param aStampContext
   * @param location location L_1
   * @param time Preq time T
   * @return STPR
   */
  private static byte[] createSTPR(WitnessContext aStampContext, byte location[], byte time[]) {

    BigInteger rw = aStampContext.getEPRandomW();

    String locString = new String(location);
    Location loc = new Location(locString);
    short levelCount = (short) loc.getLevelCount();

    LinkedList<BigInteger> rws = new LinkedList<BigInteger>();
    try {
      rws = CryptoUtil.getHashChain(rw, levelCount);
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }

    ArrayList<byte[]> locComms = new ArrayList<byte[]>();
    for (int i = 0; i < levelCount; i++) {
      byte[] locComm = {};
      try {
        locComm = CryptoUtil.getCommitment(loc.getLevel(i).getBytes(), rws.get(i)).toByteArray();
      } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }
      locComms.add(locComm);
    }

    return MessageUtil.createMessageFromArray(locComms);
  }
 public static void start(String group) {
   if (timers.containsKey(group)) {
     timers.clear();
     throw new IllegalArgumentException(
         MessageUtil.getMessage("message.timerAlreadyStarted", group));
   }
   timers.put(group, System.currentTimeMillis());
 }
Exemplo n.º 7
0
  /**
   * Create EP message body EP = r_w1|E^(K_ca)(ID_W|P|E^(K_W)(Hash(P)))
   *
   * @param aStampContext current context
   * @return EP message body
   */
  public static byte[] createEP(WitnessContext aStampContext) {
    byte proof[] = createP(aStampContext);
    byte eproof[] = endorseP(aStampContext, proof);
    byte randomW[] = aStampContext.getEPRandomW().toByteArray();

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(eproof);
    array.add(randomW);

    return MessageUtil.compileMessages(array);
  }
  public static void end(String group) {
    Long end = timers.get(group);
    if (end == null) {
      timers.clear();
      throw new IllegalArgumentException(
          MessageUtil.getMessage("message.timerNeverStarted", group));
    }
    timers.remove(group);

    log.info("[" + group + "] Time: " + (System.currentTimeMillis() - end));
  }
Exemplo n.º 9
0
  /**
   * Create DB ready message body
   *
   * @return DB ready message
   */
  public static byte[] createCeCk(ProverContext aStampContext) {

    BigInteger e = aStampContext.getE();
    BigInteger k = aStampContext.getK();
    BigInteger p = aStampContext.getPubDSASelf().getParams().getP();
    BigInteger g = aStampContext.getPubDSASelf().getParams().getG();
    BigInteger h = aStampContext.getH();
    BigInteger v = aStampContext.getV();

    ArrayList<byte[]> ces = CryptoUtil.getBitCommitments(g, p, h, v, e);
    ArrayList<byte[]> cks = CryptoUtil.getBitCommitments(g, p, h, v, k);

    byte[] cesBytes = MessageUtil.createMessageFromArray(ces);
    byte[] cksBytes = MessageUtil.createMessageFromArray(cks);

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(cesBytes);
    array.add(cksBytes);

    return MessageUtil.compileMessages(array);
  }
Exemplo n.º 10
0
  /**
   * ******************************************************************** // Witness operations
   *
   * <p>/** Save preq information in current context for later use
   *
   * @param aStampContext current context
   * @param payload preq message body
   */
  public static void processPreq(WitnessContext aStampContext, byte[] payload) {
    ArrayList<byte[]> array = MessageUtil.parseMessage(payload, 3);

    byte[] commID = array.get(0);
    aStampContext.setRemoteCommittedID(commID);

    byte[] time = array.get(1);
    aStampContext.setRemoteTime(time);

    byte[] location = array.get(2);
    aStampContext.setRemoteLocation(location);
  }
Exemplo n.º 11
0
  /**
   * Create Preq message body Preq = Comm(ID_P, r_P)|T|L_1
   *
   * @param aStampContext current context
   * @param aLocLevel desired location level (0 usually)
   * @return Preq message
   */
  public static byte[] createPreq(ProverContext aStampContext) {
    byte commID[] = aStampContext.getCommittedID();
    byte time[] = ByteBuffer.allocate(8).putLong(ProverContext.getTime()).array();
    /* TODO: check if aLocLevel is valid */
    byte location[] = aStampContext.getLocation().toString().getBytes();

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(commID);
    array.add(time);
    array.add(location);

    return MessageUtil.compileMessages(array);
  }
  protected void sendServiceParcelAcknowledge(String messageID, int index) {
    Message msg = mServiceHandler.obtainMessage(MessageUtil.ID_PARCEL_ACKNOWLEDGMENT);
    msg.replyTo = serviceMessenger;
    msg.arg1 = index;

    try {
      debug("sending IPC parcel acknowledge: " + messageID + ", " + index);
      if (messageID != null) msg.obj = MessageUtil.setParcelableMessage(messageID);
      engineMessenger.send(msg);
    } catch (Exception x) {
      debug("sendIPCEvent " + x.getClass().getSimpleName() + ", " + x.getMessage());
    }
  }
Exemplo n.º 13
0
  /**
   * Create a proof P = Comm(ID_p, r_p)|C_k|C_e|STPR
   *
   * @param aStampContext current context
   * @return proof
   */
  private static byte[] createP(WitnessContext aStampContext) {
    byte commID[] = aStampContext.getRemoteCommittedID();
    byte z[] = aStampContext.getRemoteZ().toByteArray();

    byte location[] = aStampContext.getRemoteLocation();
    byte time[] = aStampContext.getRemoteTime();
    byte stpr[] = createSTPR(aStampContext, location, time);

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(commID);
    array.add(z);
    array.add(stpr);

    return MessageUtil.compileMessages(array);
  }
Exemplo n.º 14
0
  public void addLogEntry() {
    String msgId = null;

    try {
      msgId = getCalloutMediatorMessage().getId();
      logger.info("Mediator message id : " + msgId);
    } catch (MediatorException mexp) {
    }

    if (!reentrant) {
      logImsg = "Instance processed";
    } else {
      logImsg = "Stopped";
    }

    SoaLoggerJmsPojo pojo = new SoaLoggerJmsPojo();

    LogInterfaceTo tempLi = null;
    tempLi =
        msgUtil.getInterfaceName(
            getCalloutMediatorMessage().getComponentDN(),
            msgId,
            logImsg,
            "",
            envProps.getProperty("env_flag"));

    pojo.setInterfaceName(tempLi.getLogInterfaceName());
    pojo.setEnvFlag(tempLi.getEnvironmentFlag());
    pojo.setInterfaceId(tempLi.getLogInterfaceId().toString());
    pojo.setLogLevel(tempLi.getLogEntryList().get(0).getLogLevel());
    pojo.setInterfaceVersion(tempLi.getLogInterfaceVersion());
    pojo.setInstanceId(tempLi.getLogEntryList().get(0).getIntegrationInstanceId());

    // try {
    // tempLi = msgUtil.getInterfaceName(getCalloutMediatorMessage().getComponentDN(),msgId,
    // logImsg, "",envProps.getProperty("env_flag"));
    // Failure counter is removed because of the exceptions regarding backing store
    // this.checkFailedLogEntries(tempLi);
    // 15.06.2011, TKatva, removed because JMS-queue listener parses the message.
    /*
    entry = new LogEntryTo();
    entry.setLogEntryId(tempLi.getLogEntryList().get(0).getLogEntryId());
    entry.setLogDate(tempLi.getLogEntryList().get(0).getLogDate());
    entry.setInstanceVersion(tempLi.getLogEntryList().get(0).getInstanceVersion());
    entry.setLogLevel(tempLi.getLogEntryList().get(0).getLogLevel());
    entry.setIntegrationInstanceId(tempLi.getLogEntryList().get(0).getIntegrationInstanceId());
    entry.setLogMsg(tempLi.getLogEntryList().get(0).getLogMsg());
    //entry.setLogInterface(tempLi.getLogEntryList().get(0).getLogInterface());
    entry.setLogPayload(tempLi.getLogEntryList().get(0).getLogPayload());

    li = soaLogger.addLogInterfaceEntry(tempLi);
    } catch (Exception exp) {
      logger.severe("EXCEPTION : " + exp.toString());
    }*/
    /* Failure counter is removed because of the exceptions regarding backing store
    if (li == null) {
      this.increaseFailedCounter(tempLi);
    } else {
      this.failedCountToZero(tempLi);
    }
    /*
    if (!reentrant) {
      this.checkValues();
    } */
    // Get payload of the message
    Map payload = getCalloutMediatorMessage().getPayload();
    // Try to get the message key
    String key = null;

    Iterator it = payload.keySet().iterator();
    while (it.hasNext()) {
      key = (String) it.next();
    }
    Element payloadElement = (Element) payload.get(key);
    // this.logger.severe("ELEMENT : " + this.xmlToString(payloadElement));
    pojo.setMsgPayload(this.xmlToString(payloadElement));
    jmsClient.sendMessage(pojo);
  }
 @Test
 public void testPrintMessage() {
   Assert.assertEquals(message, messageUtil.printMessage());
 }
/** A User Element */
public class UserElement extends OrganizationElement {

  // Properties
  private Name fullName;

  private Address address;

  private String phoneNumber;

  private EmailAddress emailAddress;

  private Boolean coop;

  private Birthday birthday;

  private Float salary;

  private RGB hairColor;

  private RGB eyeColor;

  // Property default values
  private Name fullName_Default;

  private Address address_Default;

  private String phoneNumber_Default = "555-1111"; // $NON-NLS-1$

  private EmailAddress emailAddress_Default;

  private Boolean coop_Default;

  private Birthday birthday_Default;

  private Float salary_Default;

  private RGB hairColor_Default;

  private RGB eyeColor_Default;

  // Property unique keys
  public static final String P_ID_PHONENUMBER = "User.phonenumber"; // $NON-NLS-1$

  public static final String P_ID_ADDRESS = "User.address"; // $NON-NLS-1$

  public static final String P_ID_FULLNAME = "User.fullname"; // $NON-NLS-1$

  public static final String P_ID_EMAIL = "User.email"; // $NON-NLS-1$

  public static final String P_ID_COOP = "User.coop student"; // $NON-NLS-1$

  public static final String P_ID_BDAY = "User.birthday"; // $NON-NLS-1$

  public static final String P_ID_SALARY = "User.salary"; // $NON-NLS-1$

  public static final String P_ID_HAIRCOLOR = "User.haircolor"; // $NON-NLS-1$

  public static final String P_ID_EYECOLOR = "User.eyecolor"; // $NON-NLS-1$

  // Property display keys
  public static final String P_PHONENUMBER = MessageUtil.getString("phonenumber"); // $NON-NLS-1$

  public static final String P_ADDRESS = MessageUtil.getString("address"); // $NON-NLS-1$

  public static final String P_FULLNAME = MessageUtil.getString("fullname"); // $NON-NLS-1$

  public static final String P_EMAIL = MessageUtil.getString("email"); // $NON-NLS-1$

  public static final String P_COOP = MessageUtil.getString("coop_student"); // $NON-NLS-1$

  public static final String P_BDAY = MessageUtil.getString("birthday"); // $NON-NLS-1$

  public static final String P_SALARY = MessageUtil.getString("salary"); // $NON-NLS-1$

  public static final String P_HAIRCOLOR = MessageUtil.getString("haircolor"); // $NON-NLS-1$

  public static final String P_EYECOLOR = MessageUtil.getString("eyecolor"); // $NON-NLS-1$

  // Help context ids
  private static final String PHONE_NUMBER_CONTEXT =
      "org.eclipse.ui.examples.propertysheet.phone_number_context"; //$NON-NLS-1$

  private static final String ADDRESS_CONTEXT =
      "org.eclipse.ui.examples.propertysheet.address_context"; //$NON-NLS-1$

  private static final String FULL_NAME_CONTEXT =
      "org.eclipse.ui.examples.propertysheet.full_name_context"; //$NON-NLS-1$

  private static final String EMAIL_CONTEXT =
      "org.eclipse.ui.examples.propertysheet.email_context"; //$NON-NLS-1$

  private static final String COOP_CONTEXT =
      "org.eclipse.ui.examples.propertysheet.coop_context"; //$NON-NLS-1$

  private static final String BIRTHDAY_CONTEXT =
      "org.eclipse.ui.examples.propertysheet.birthday_context"; //$NON-NLS-1$

  private static final String SALARY_CONTEXT =
      "org.eclipse.ui.examples.propertysheet.salary_context"; //$NON-NLS-1$

  private static final String HAIR_COLOR__CONTEXT =
      "org.eclipse.ui.examples.propertysheet.hair_color_context"; //$NON-NLS-1$

  private static final String EYE_COLOR_CONTEXT =
      "org.eclipse.ui.examples.propertysheet.eye_color_context"; //$NON-NLS-1$

  // Property Category
  public static final String P_CONTACTINFO = MessageUtil.getString("contact"); // $NON-NLS-1$

  public static final String P_PERSONELINFO = MessageUtil.getString("personel"); // $NON-NLS-1$

  public static final String P_PERSONALINFO = MessageUtil.getString("personal"); // $NON-NLS-1$

  // Property Values
  public static final Integer P_VALUE_TRUE = new Integer(0);

  public static final Integer P_VALUE_FALSE = new Integer(1);

  public static final String P_VALUE_TRUE_LABEL = MessageUtil.getString("true"); // $NON-NLS-1$

  public static final String P_VALUE_FALSE_LABEL = MessageUtil.getString("false"); // $NON-NLS-1$

  private static class BooleanLabelProvider extends LabelProvider {
    public String getText(Object element) {
      String[] values = new String[] {P_VALUE_TRUE_LABEL, P_VALUE_FALSE_LABEL};
      return values[((Integer) element).intValue()];
    }
  }

  //
  private static Vector descriptors;

  static {
    descriptors = new Vector();
    PropertyDescriptor propertyDescriptor;

    ///
    propertyDescriptor = new TextPropertyDescriptor(P_ID_PHONENUMBER, P_PHONENUMBER);
    propertyDescriptor.setCategory(P_CONTACTINFO);
    propertyDescriptor.setHelpContextIds(PHONE_NUMBER_CONTEXT);
    descriptors.addElement(propertyDescriptor);

    ///
    propertyDescriptor = new PropertyDescriptor(P_ID_ADDRESS, P_ADDRESS);
    propertyDescriptor.setCategory(P_CONTACTINFO);
    propertyDescriptor.setHelpContextIds(ADDRESS_CONTEXT);
    descriptors.addElement(propertyDescriptor);

    ///
    propertyDescriptor = new TextPropertyDescriptor(P_ID_EMAIL, P_EMAIL);
    propertyDescriptor.setCategory(P_CONTACTINFO);
    propertyDescriptor.setHelpContextIds(EMAIL_CONTEXT);
    propertyDescriptor.setValidator(new EmailAddressValidator());
    descriptors.addElement(propertyDescriptor);

    ///
    propertyDescriptor = new TextPropertyDescriptor(P_ID_FULLNAME, P_FULLNAME);
    propertyDescriptor.setCategory(P_PERSONELINFO);
    propertyDescriptor.setHelpContextIds(FULL_NAME_CONTEXT);
    descriptors.addElement(propertyDescriptor);

    ///
    propertyDescriptor = new PropertyDescriptor(P_ID_BDAY, P_BDAY);
    propertyDescriptor.setCategory(P_PERSONELINFO);
    propertyDescriptor.setHelpContextIds(BIRTHDAY_CONTEXT);
    descriptors.addElement(propertyDescriptor);

    ///
    propertyDescriptor =
        new ComboBoxPropertyDescriptor(
            P_ID_COOP, P_COOP, new String[] {P_VALUE_TRUE_LABEL, P_VALUE_FALSE_LABEL});
    propertyDescriptor.setCategory(P_PERSONELINFO);
    propertyDescriptor.setHelpContextIds(COOP_CONTEXT);
    propertyDescriptor.setLabelProvider(new BooleanLabelProvider());
    descriptors.addElement(propertyDescriptor);

    ///
    propertyDescriptor = new TextPropertyDescriptor(P_ID_SALARY, P_SALARY);
    // add custom validator to propertyDescriptor limiting salary values to be
    // greator than zero
    propertyDescriptor.setHelpContextIds(new Object[] {SALARY_CONTEXT});
    propertyDescriptor.setFilterFlags(new String[] {IPropertySheetEntry.FILTER_ID_EXPERT});
    propertyDescriptor.setValidator(
        new ICellEditorValidator() {
          public String isValid(Object value) {
            if (value == null) return MessageUtil.getString("salary_is_invalid"); // $NON-NLS-1$
            //
            Float trySalary;
            try {
              trySalary = new Float(Float.parseFloat((String) value));
            } catch (NumberFormatException e) {
              return MessageUtil.getString("salary_is_invalid"); // $NON-NLS-1$
            }
            if (trySalary.floatValue() < 0.0)
              return MessageUtil.getString("salary_must_be_greator_than_zero"); // $NON-NLS-1$
            return null;
          }
        });
    propertyDescriptor.setCategory(P_PERSONELINFO);
    descriptors.addElement(propertyDescriptor);

    /// HairColor
    propertyDescriptor = new ColorPropertyDescriptor(P_ID_HAIRCOLOR, P_HAIRCOLOR);
    propertyDescriptor.setCategory(P_PERSONALINFO);
    propertyDescriptor.setHelpContextIds(HAIR_COLOR__CONTEXT);
    descriptors.addElement(propertyDescriptor);

    /// EyeColor
    propertyDescriptor = new ColorPropertyDescriptor(P_ID_EYECOLOR, P_EYECOLOR);
    propertyDescriptor.setCategory(P_PERSONALINFO);
    propertyDescriptor.setHelpContextIds(EYE_COLOR_CONTEXT);
    descriptors.addElement(propertyDescriptor);

    // gets descriptors from parent, warning name-space collision may occur
    Vector parentDescriptors = OrganizationElement.getDescriptors();
    for (int i = 0; i < parentDescriptors.size(); i++) {
      descriptors.addElement(parentDescriptors.elementAt(i));
    }
  }

  /**
   * Constructor. Default visibility only called from GroupElement.createSubGroup() Creates a new
   * UserElement within the passed parent GroupElement, *
   *
   * @param name the name
   * @param parent the parent
   */
  UserElement(String name, GroupElement parent) {
    super(name, parent);
  }

  /** Returns the address */
  private Address getAddress() {
    if (address == null) address = new Address();
    return address;
  }

  /** Returns the birthday */
  private Birthday getBirthday() {
    if (birthday == null) birthday = new Birthday();
    return birthday;
  }

  /* (non-Javadoc)
   * Method declared on IWorkbenchAdapter
   */
  public Object[] getChildren(Object o) {
    return new Object[0];
  }

  /** Returns the coop */
  private Boolean getCoop() {
    if (coop == null) coop = new Boolean(false);
    return coop;
  }

  /** Returns the descriptors */
  static Vector getDescriptors() {
    return descriptors;
  }

  /* (non-Javadoc)
   * Method declared on IPropertySource
   */
  public Object getEditableValue() {
    return this.toString();
  }

  /** Returns the email address */
  EmailAddress getEmailAddress() {
    if (emailAddress == null) emailAddress = new EmailAddress();
    return emailAddress;
  }

  /** Returns the eye color */
  private RGB getEyeColor() {
    if (eyeColor == null) eyeColor = new RGB(60, 60, 60);
    return eyeColor;
  }

  /** Returns the full name */
  private Name getFullName() {
    if (fullName == null) fullName = new Name(getName());
    return fullName;
  }

  /** Returns the hair color */
  private RGB getHairColor() {
    if (hairColor == null) hairColor = new RGB(255, 255, 255);
    return hairColor;
  }

  /** Returns the phone number */
  private String getPhoneNumber() {
    return phoneNumber;
  }

  /* (non-Javadoc)
   * Method declared on IPropertySource
   */
  public IPropertyDescriptor[] getPropertyDescriptors() {
    return (IPropertyDescriptor[])
        getDescriptors().toArray(new IPropertyDescriptor[getDescriptors().size()]);
  }

  /**
   * The <code>Userment</code> implementation of this <code>IPropertySource</code> method returns
   * the following properties
   *
   * <p>1) P_ADDRESS returns Address (IPropertySource), the address of this user 2) P_FULLNAME
   * returns Name (IPropertySource), the full name of this user 3) P_PHONENUMBER returns String, the
   * phone number of this user 4) P_EMAIL returns EmailAddress (IPropertySource), the email address
   * of this user 5) P_COOP returns Boolean, whether the individual is a coop student or not 6)
   * P_BDAY returns Birthday 7) P_SALARY return java.lang.Float 8) P_HAIRCOLOR, expects RGB 9)
   * P_EYECOLOR, expects RGB
   */
  public Object getPropertyValue(Object propKey) {
    if (propKey.equals(P_ID_ADDRESS)) return getAddress();
    if (propKey.equals(P_ID_FULLNAME)) return getFullName();
    if (propKey.equals(P_ID_PHONENUMBER)) return getPhoneNumber();
    if (propKey.equals(P_ID_EMAIL)) return getEmailAddress();
    if (propKey.equals(P_ID_COOP))
      return getCoop().equals(Boolean.TRUE) ? P_VALUE_TRUE : P_VALUE_FALSE;
    if (propKey.equals(P_ID_BDAY)) return getBirthday();
    if (propKey.equals(P_ID_SALARY)) return getSalary().toString();
    if (propKey.equals(P_ID_HAIRCOLOR)) return getHairColor();
    if (propKey.equals(P_ID_EYECOLOR)) return getEyeColor();
    return super.getPropertyValue(propKey);
  }

  /** Returns the salary */
  private Float getSalary() {
    if (salary == null) salary = new Float(0);
    return salary;
  }

  /* (non-Javadoc)
   * Method declared on IPropertySource
   */
  public boolean isPropertySet(Object property) {
    if (property.equals(P_ID_ADDRESS)) return getAddress() != address_Default;
    if (property.equals(P_ID_FULLNAME)) return getFullName() != fullName_Default;
    if (property.equals(P_ID_PHONENUMBER)) return getPhoneNumber() != phoneNumber_Default;
    if (property.equals(P_ID_EMAIL)) return getEmailAddress() != emailAddress_Default;
    if (property.equals(P_ID_COOP)) return getCoop() != coop_Default;
    if (property.equals(P_ID_BDAY)) return getBirthday() != birthday_Default;
    if (property.equals(P_ID_SALARY)) return getSalary() != salary_Default;
    if (property.equals(P_ID_HAIRCOLOR)) return getHairColor() != hairColor_Default;
    if (property.equals(P_ID_EYECOLOR)) return getEyeColor() != eyeColor_Default;
    return false;
  }

  /* (non-Javadoc)
   * Method declared on OrganizationElement
   */
  public boolean isUser() {
    return true;
  }

  /* (non-Javadoc)
   * Method declared on IPropertySource
   */
  public void resetPropertyValue(Object property) {
    if (property.equals(P_ID_ADDRESS)) {
      setAddress(address_Default);
      return;
    }
    if (property.equals(P_ID_FULLNAME)) {
      setFullName(fullName_Default);
      return;
    }
    if (property.equals(P_ID_PHONENUMBER)) {
      setPhoneNumber(phoneNumber_Default);
      return;
    }
    if (property.equals(P_ID_EMAIL)) {
      setEmailAddress(emailAddress_Default);
      return;
    }
    if (property.equals(P_ID_COOP)) {
      setCoop(coop_Default);
    }
    if (property.equals(P_ID_BDAY)) {
      setBirthday(birthday_Default);
      return;
    }
    if (property.equals(P_ID_SALARY)) {
      setSalary(salary_Default);
      return;
    }
    if (property.equals(P_ID_HAIRCOLOR)) {
      setHairColor(hairColor_Default);
      return;
    }
    if (property.equals(P_ID_EYECOLOR)) {
      setEyeColor(eyeColor_Default);
      return;
    }
    super.resetPropertyValue(property);
  }

  /** Sets the address */
  public void setAddress(Address newAddress) {
    address = newAddress;
  }

  /** Sets the birthday */
  public void setBirthday(Birthday newBirthday) {
    birthday = new Birthday();
  }

  /** Sets the coop */
  public void setCoop(Boolean newCoop) {
    coop = newCoop;
  }

  /** Sets the email address */
  public void setEmailAddress(EmailAddress newEmailAddress) {
    emailAddress = newEmailAddress;
  }

  /** Sets eye color */
  public void setEyeColor(RGB newEyeColor) {
    eyeColor = newEyeColor;
  }

  /** Sets full name */
  public void setFullName(Name newFullName) {
    fullName = newFullName;
  }

  /** Sets hair color */
  public void setHairColor(RGB newHairColor) {
    hairColor = newHairColor;
  }

  /** Sets phone number */
  public void setPhoneNumber(String newPhoneNumber) {
    phoneNumber = newPhoneNumber;
  }

  /**
   * The <code>OrganizationElement</code> implementation of this <code>IPropertySource</code> method
   * defines the following Setable properties
   *
   * <p>1) P_ADDRESS, expects Address 2) P_FULLNAME, expects Name 3) P_PHONENUMBER, expects String
   * 4) P_EMAIL, expects EmailAddress. 5) P_BOOLEAN, expects Boolean, whether the individual is a
   * coop student or not 6) P_BDAY, expects Birthday 7) P_SALARY, expects java.lang.Float 8)
   * P_HAIRCOLOR, expects RGB 9) P_EYECOLOR, expects RGB
   */
  public void setPropertyValue(Object propKey, Object val) {
    // need to convert from String to domain objects
    if (propKey.equals(P_ID_ADDRESS)) {
      // setAddress((Address)val);
      return;
    }
    if (propKey.equals(P_ID_FULLNAME)) {
      setFullName(new Name((String) val));
      return;
    }
    if (propKey.equals(P_ID_PHONENUMBER)) {
      setPhoneNumber((String) val);
      return;
    }
    if (propKey.equals(P_ID_EMAIL)) {
      setEmailAddress(new EmailAddress((String) val));
      return;
    }
    if (propKey.equals(P_ID_COOP)) {
      setCoop(((Integer) val).equals(P_VALUE_TRUE) ? Boolean.TRUE : Boolean.FALSE);
    }
    if (propKey.equals(P_ID_BDAY)) {
      // setBirthday((Birthday)val);
      return;
    }
    if (propKey.equals(P_ID_SALARY)) {
      try {
        setSalary(new Float(Float.parseFloat((String) val)));
      } catch (NumberFormatException e) {
        setSalary(salary_Default);
      }
      return;
    }
    if (propKey.equals(P_ID_HAIRCOLOR)) {
      setHairColor((RGB) val);
      return;
    }
    if (propKey.equals(P_ID_EYECOLOR)) {
      setEyeColor((RGB) val);
      return;
    }
    super.setPropertyValue(propKey, val);
  }

  /** Sets the salary */
  void setSalary(Float newSalary) {
    salary = newSalary;
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.model.IWorkbenchAdapter#getForeground(java.lang.Object)
   */
  public RGB getForeground(Object element) {
    return null;
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.model.IWorkbenchAdapter#getBackground(java.lang.Object)
   */
  public RGB getBackground(Object element) {
    return null;
  }
}
Exemplo n.º 17
0
 private static void doSendMsg(CustomMessage msg) {
   msg.setToUser("oVDIDt3_SMFnLBBfmQtr67oYT3NI");
   MessageUtil.sendCustomMessage(Constants.LICENSE, msg);
 }
Exemplo n.º 18
0
 /**
  * 添加前台提示
  *
  * @param id
  * @param info
  */
 protected void addMessage(String id, String info) {
   FacesMessage message = new FacesMessage();
   message.setSeverity(FacesMessage.SEVERITY_INFO);
   MessageUtil.addMessage(id, message, FacesContext.getCurrentInstance(), info);
 }
Exemplo n.º 19
0
 @Test
 public void testSalutationMessage() {
   System.out.println("Inside testSalutationMessage()");
   message = "Hi!" + "Robert";
   assertEquals(message, messageUtil.salutationMessage());
 }
Exemplo n.º 20
0
 public String toStringInternal() {
   return MessageUtil.build(this, null, this.t);
 }
Exemplo n.º 21
0
 @Test(expected = ArithmeticException.class)
 public void testPrintMessage() {
   System.out.println("Inside testPrintMessage()");
   messageUtil.printMessage();
 }