Package hermes.xml

Examples of hermes.xml.Property


        XMLMapMessage mapMessage = (XMLMapMessage) message;
        MapMessage mapRval = (MapMessage) rval;

        for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) {
          final Property property = (Property) iter.next();

          if (property.getValue() == null) {
            mapRval.setObject(property.getName(), null);
          } else if (property.getType().equals(String.class.getName())) {
            mapRval.setString(property.getName(), property.getValue());
          } else if (property.getType().equals(Long.class.getName())) {
            mapRval.setLong(property.getName(), Long.parseLong(property.getValue()));
          } else if (property.getType().equals(Double.class.getName())) {
            mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue()));
          } else if (property.getType().equals(Boolean.class.getName())) {
            mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue()));
          } else if (property.getType().equals(Character.class.getName())) {
            mapRval.setChar(property.getName(), property.getValue().charAt(0));
          } else if (property.getType().equals(Short.class.getName())) {
            mapRval.setShort(property.getName(), Short.parseShort(property.getValue()));
          } else if (property.getType().equals(Integer.class.getName())) {
            mapRval.setInt(property.getName(), Integer.parseInt(property.getValue()));
          }
        }
      } else if (message instanceof XMLBytesMessage) {
        rval = hermes.createBytesMessage();

        XMLBytesMessage bytesMessage = (XMLBytesMessage) message;
        BytesMessage bytesRval = (BytesMessage) rval;

        bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes()));
      } else if (message instanceof XMLObjectMessage) {
        rval = hermes.createObjectMessage();

        XMLObjectMessage objectMessage = (XMLObjectMessage) message;
        ObjectMessage objectRval = (ObjectMessage) rval;
        ByteArrayInputStream bistream = new ByteArrayInputStream(base64EncoderTL.get().decode(objectMessage.getObject().getBytes()));

        ObjectInputStream oistream = new ObjectInputStream(bistream);

        objectRval.setObject((Serializable) oistream.readObject());
      }

      //
      // JMS Header properties

      try {
        rval.setJMSDeliveryMode(message.getJMSDeliveryMode());
      } catch (JMSException ex) {
        log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": " + ex.getMessage());
      }

      try {
        rval.setJMSMessageID(message.getJMSMessageID());
      } catch (JMSException ex) {
        log.error("unable to set JMSMessageID: " + ex.getMessage(), ex);
      }

      try {
        if (message.getJMSExpiration() != null) {
          rval.setJMSExpiration(message.getJMSExpiration());
        }
      } catch (JMSException ex) {
        log.error("unable to set JMSExpiration: " + ex.getMessage(), ex);
      }

      try {
        if (message.getJMSPriority() != null) {
          rval.setJMSPriority(message.getJMSPriority());
        }
      } catch (JMSException ex) {
        log.error("unable to set JMSPriority: " + ex.getMessage(), ex);
      }

      try {
        if (message.getJMSTimestamp() != null) {
          rval.setJMSTimestamp(message.getJMSTimestamp());
        }
      } catch (JMSException ex) {
        log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex);
      }

      if (message.getJMSCorrelationID() != null) {
        rval.setJMSCorrelationID(message.getJMSCorrelationID());
      }

      if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) {
        rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(), Domain.getDomain(message.getJMSReplyToDomain())));
      }

      if (message.getJMSType() != null) {
        rval.setJMSType(message.getJMSType());
      }

      if (message.getJMSDestination() != null) {
        if (message.isFromQueue()) {
          rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE));
        } else {
          rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC));
        }
      }

      for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) {
        Property property = (Property) iter.next();

        if (property.getValue() == null) {
          rval.setObjectProperty(property.getName(), null);
        } else if (property.getType().equals(String.class.getName())) {
          rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue()));
        } else if (property.getType().equals(Long.class.getName())) {
          rval.setLongProperty(property.getName(), Long.parseLong(property.getValue()));
        } else if (property.getType().equals(Double.class.getName())) {
          rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue()));
        } else if (property.getType().equals(Boolean.class.getName())) {
          rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue()));
        } else if (property.getType().equals(Short.class.getName())) {
          rval.setShortProperty(property.getName(), Short.parseShort(property.getValue()));
        } else if (property.getType().equals(Integer.class.getName())) {
          rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue()));
        }
      }

      return rval;
    } catch (NamingException e) {
View Full Code Here


        MapMessage mapMessage = (MapMessage) message;

        for (Enumeration iter = mapMessage.getMapNames(); iter.hasMoreElements();) {
          String propertyName = (String) iter.nextElement();
          Object propertyValue = mapMessage.getObject(propertyName);
          Property xmlProperty = factory.createProperty();

          if (propertyValue != null) {
            xmlProperty.setValue(propertyValue.toString());
            xmlProperty.setType(propertyValue.getClass().getName());
          }
          xmlProperty.setName(propertyName);

          mapRval.getBodyProperty().add(xmlProperty);
        }
      } else if (message instanceof BytesMessage) {
        rval = factory.createXMLBytesMessage();

        XMLBytesMessage bytesRval = (XMLBytesMessage) rval;
        BytesMessage bytesMessage = (BytesMessage) message;
        ByteArrayOutputStream bosream = new ByteArrayOutputStream();

        bytesMessage.reset();

        try {
          for (;;) {
            bosream.write(bytesMessage.readByte());
          }
        } catch (MessageEOFException ex) {
          // NOP
        }

        bytesRval.setBytes(new String(base64EncoderTL.get().encode(bosream.toByteArray())));
      } else if (message instanceof ObjectMessage) {
        rval = factory.createXMLObjectMessage();

        XMLObjectMessage objectRval = (XMLObjectMessage) rval;
        ObjectMessage objectMessage = (ObjectMessage) message;

        ByteArrayOutputStream bostream = new ByteArrayOutputStream();
        ObjectOutputStream oostream = new ObjectOutputStream(bostream);

        oostream.writeObject(objectMessage.getObject());
        oostream.flush();
        byte b[] = base64EncoderTL.get().encode(bostream.toByteArray());
        String s = new String(b, "ASCII");
        objectRval.setObject(s);
      }

      if (message.getJMSReplyTo() != null) {
        rval.setJMSReplyTo(JMSUtils.getDestinationName(message.getJMSReplyTo()));
        rval.setJMSReplyToDomain(Domain.getDomain(message.getJMSReplyTo()).getId());
      }

      // try/catch each individually as we sometime find some JMS
      // providers
      // can barf
      try {
        rval.setJMSDeliveryMode(message.getJMSDeliveryMode());
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      }

      try {
        rval.setJMSExpiration(message.getJMSExpiration());
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      }

      try {
        rval.setJMSMessageID(message.getJMSMessageID());
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      }

      try {
        rval.setJMSPriority(message.getJMSPriority());
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      }

      try {
        rval.setJMSRedelivered(message.getJMSRedelivered());
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      } catch (IllegalStateException ex) {
        // http://hermesjms.com/forum/viewtopic.php?f=4&t=346

        log.error(ex.getMessage(), ex);
      }

      try {
        rval.setJMSTimestamp(message.getJMSTimestamp());
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      }

      try {
        rval.setJMSType(message.getJMSType());
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      }

      try {
        rval.setJMSCorrelationID(message.getJMSCorrelationID());
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      }

      try {
        if (message.getJMSDestination() != null) {
          rval.setJMSDestination(JMSUtils.getDestinationName(message.getJMSDestination()));
          rval.setFromQueue(JMSUtils.isQueue(message.getJMSDestination()));
        }
      } catch (JMSException ex) {
        log.error(ex.getMessage(), ex);
      }

      for (final Enumeration iter = message.getPropertyNames(); iter.hasMoreElements();) {
        String propertyName = (String) iter.nextElement();

        if (!propertyName.startsWith("JMS")) {
          Object propertyValue = message.getObjectProperty(propertyName);
          Property property = factory.createProperty();

          property.setName(propertyName);

          if (propertyValue != null) {
            property.setValue(StringEscapeUtils.escapeXml(propertyValue.toString()));
            property.setType(propertyValue.getClass().getName());
          }

          rval.getHeaderProperty().add(property);
        }
      }
View Full Code Here

TOP

Related Classes of hermes.xml.Property

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.