Esempio n. 1
0
 @Resource
 @Autowired
 public void setApplicationMessageTypes(List<KoalaMessageBase> applicationMessages) {
   for (KoalaMessageBase message : applicationMessages) {
     LOG.debug("Adding Message " + message.getKoalaMessageType() + TO_TYPE_MAP);
     applicationTypeMap.put(message.getKoalaMessageType(), message.getClass());
   }
 }
Esempio n. 2
0
  public Object createObject(JSONObject jsonObject, String type) {
    try {
      if (LOG.isDebugEnabled()) LOG.debug(String.format("Creating message from %s", jsonObject));
      if (StringUtils.isEmpty(type)) {
        throw new MessageCreationException(
            String.format("Failed to create message: no message type found in JSON"));
      }

      Class<?> messageClass = applicationTypeMap.get(type);
      LOG.debug("Message class: " + messageClass);
      if (messageClass == null) {
        throw new MessageCreationException(String.format("Unknown message type: %s", type));
      }

      // Constructor<? extends KoalaMessage> constructor =
      // messageClass.getConstructor(JSONObject.class);

      Object res = koalaJsonParser.getObject(jsonObject.toString(), messageClass);
      if (res instanceof KoalaMessageBase)
        ((KoalaMessageBase) res).setKoalaJsonParser(koalaJsonParser);
      return res;
    } catch (IllegalArgumentException e) {
      throw new MessageCreationException(
          String.format(FAILED_TO_CREATE_MESSAGE_WITH_TYPE_S, type), e);
    } catch (SecurityException e) {
      throw new MessageCreationException(
          String.format(FAILED_TO_CREATE_MESSAGE_WITH_TYPE_S, type), e);
    }
  }