001: /*
002: * Copyright (c) 2007, Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * * Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * * Neither the name of Sun Microsystems, Inc. nor the names of its contributors
015: * may be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028: * THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package partnerservices;
031:
032: import java.rmi.RemoteException;
033: import javax.jms.MapMessage;
034: import javax.xml.soap.SOAPElement;
035: import org.w3c.dom.Node;
036: import org.w3c.dom.NodeList;
037: import partnerservices.callback.ReservationCallbackProviderBean;
038:
039: public class PartnerUtils {
040:
041: public PartnerUtils() {
042: }
043:
044: public static javax.jms.Message createJMSMessageForReservationCallbackProviderDestination(
045: javax.jms.Session session, java.lang.String messsageType,
046: String uniqueID) throws javax.jms.JMSException {
047:
048: MapMessage mapMessage = session.createMapMessage();
049: mapMessage.setString(
050: ReservationCallbackProviderBean.MESSAGE_TYPE,
051: messsageType);
052: mapMessage.setString(ReservationCallbackProviderBean.UNIQUE_ID,
053: uniqueID);
054:
055: return mapMessage;
056: }
057:
058: public static void sendJMSMessageToReservationCallbackProviderDestination(
059: String messageType, String uniqueID) throws RemoteException {
060: javax.jms.Connection conn = null;
061: javax.jms.Session s = null;
062: try {
063: javax.naming.Context c = new javax.naming.InitialContext();
064: javax.jms.ConnectionFactory cf = (javax.jms.ConnectionFactory) c
065: .lookup("java:comp/env/jms/ReservationCallbackProviderDestinationFactory");
066:
067: conn = cf.createConnection();
068: s = conn.createSession(false, s.AUTO_ACKNOWLEDGE);
069: javax.jms.Destination destination = (javax.jms.Destination) c
070: .lookup("java:comp/env/jms/ReservationCallbackProviderDestination");
071: javax.jms.MessageProducer mp = s
072: .createProducer(destination);
073: mp
074: .send(createJMSMessageForReservationCallbackProviderDestination(
075: s, messageType, uniqueID));
076:
077: if (s != null) {
078: s.close();
079: }
080:
081: if (conn != null) {
082: conn.close();
083: }
084:
085: } catch (javax.naming.NamingException ne) {
086: throw new java.rmi.RemoteException("NamingException", ne);
087: } catch (javax.jms.JMSException jmse) {
088: throw new java.rmi.RemoteException("JMSException", jmse);
089: }
090: }
091:
092: public static String getUniqueID(SOAPElement itinerary) {
093: String uniqueID = "";
094:
095: NodeList nodeList = itinerary.getChildNodes();
096: try {
097: for (int index1 = 0; index1 < nodeList.getLength(); index1++) {
098: Node node1 = nodeList.item(index1);
099: if (node1.getNodeName().endsWith("ItineraryRef")) {
100: for (int index2 = 0; index2 < node1.getChildNodes()
101: .getLength(); index2++) {
102: Node node2 = node1.getChildNodes().item(index2);
103: if (node2.getNodeName().endsWith("UniqueID")) {
104: uniqueID = node2.getTextContent();
105: break;
106: }
107: }
108: }
109: }
110: } catch (Exception ex) {
111: }
112: return uniqueID;
113:
114: }
115: }
|