content: /*
   * CDDL HEADER START
   *
   * The contents of this file are subject to the terms of the Common Development
   * and Distribution License (the "License").
   * You may not use this file except in compliance with the License.
   *
   * You can obtain a copy of the license at
   * src/com/vodafone360/people/VODAFONE.LICENSE.txt or
   * http://github.com/360/360-Engine-for-Android
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   * When distributing Covered Code, include this CDDL HEADER in each file and
   * include the License file at src/com/vodafone360/people/VODAFONE.LICENSE.txt.
   * If applicable, add the following below this CDDL HEADER, with the fields
   * enclosed by brackets "[]" replaced with your own identifying information:
   * Portions Copyright [yyyy] [name of copyright owner]
   *
   * CDDL HEADER END
   *
   * Copyright 2010 Vodafone Sales & Services Ltd.  All rights reserved.
   * Use is subject to license terms.
   */
  
  package com.vodafone360.people.service.io.rpg;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  
  /**
   * Class representing the contents of RPG push message This will consist of:
   * user-id, message type and message payload
   */
  public class RpgPushMessage {
  
      /** Definition for Push Message 'type' field. */
      private static final String PUSH_MSG_TYPE = "type";
  
      /** Definition for Push Message 'payload' field. */
      private static final String PUSH_PAYLOAD = "payload";
  
      /** Type of Push message. */
      public PushMessageTypes mType = null;
  
      /** Hashtable containing decoded message payload if present. */
      public Hashtable<String, Object> mHash = null;
  
      /**
       * Create RPG push message from hash-table generated by Hessian decoder
       * 
       * @param hash Hash-table containing Push Message data
       * @return RPG push message populated from hash-table
       */
      @SuppressWarnings("unchecked")
      public static RpgPushMessage createFromHashtable(Hashtable<String, Object> hash) {
          RpgPushMessage push = new RpgPushMessage();
          Enumeration<String> e = hash.keys();
          while (e.hasMoreElements()) {
              String key = e.nextElement();
              Object value = hash.get(key);
  
              if (key.compareTo(PUSH_MSG_TYPE) == 0) {
                  push.mType = findTag((String)value);
              } else if ((key.compareTo(PUSH_PAYLOAD) == 0) && (value instanceof Hashtable)) {
                  push.mHash = (Hashtable<String, Object>)value;
              }
          }
  
          return push;
      }
  
      /**
       * Find push message type
       * 
       * @param tag String containing message type identifier
       * @return tag for message type if found, null otherwise.
       */
      private static PushMessageTypes findTag(String tag) {
          for (PushMessageTypes tags : PushMessageTypes.values()) {
              if (tag.compareTo(tags.tag()) == 0) {
                  return tags;
              }
          }
          return null;
      }
  }
  