KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > binding > axis2 > SOAPHelper


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: SOAPHelper.java 154 25 sept. 06 wjoseph $
20  * -------------------------------------------------------------------------
21  */

22
23 package org.objectweb.petals.binding.axis2;
24
25 import java.util.Set JavaDoc;
26
27 import javax.jbi.messaging.MessagingException;
28 import javax.jbi.messaging.NormalizedMessage;
29 import javax.xml.namespace.QName JavaDoc;
30
31 import org.apache.axiom.attachments.Attachments;
32 import org.apache.axis2.AxisFault;
33 import org.apache.axis2.context.MessageContext;
34 import org.apache.axis2.description.AxisService;
35
36 /**
37  * SOAP helper
38  *
39  * @author Christophe HAMERLING - eBMWebSourcing
40  *
41  */

42 public class SOAPHelper {
43
44     /**
45      *
46      */

47     private SOAPHelper() {
48     }
49
50     /**
51      * Transform an axis service name into a qname. (check if the
52      * targetnamespace is part of the name of the service or as a real
53      * targetnamespace
54      *
55      * @param service
56      * can be null
57      * @return
58      */

59     public static QName JavaDoc getServiceName(AxisService service) {
60
61         QName JavaDoc name = null;
62
63         if (service != null) {
64             if (service.getName().startsWith("{")) {
65                 name = new QName JavaDoc(service.getName());
66             } else {
67                 name = new QName JavaDoc(service.getTargetNamespace(), service
68                     .getName());
69             }
70         }
71         return name;
72     }
73
74     /**
75      * Add the attachements from the incoming soap request to the Normalized
76      * message
77      *
78      * @param messageContext
79      * @param nm
80      */

81     public static void copyAttachmentsFromSOAPToJBI(
82         MessageContext messageContext, NormalizedMessage nm)
83         throws MessagingException {
84
85         if (nm != null && messageContext != null) {
86             Attachments attachments = messageContext.getAttachmentMap();
87             if (attachments != null) {
88                 String JavaDoc[] ids = attachments.getAllContentIDs();
89                 for (String JavaDoc id : ids) {
90                     nm.addAttachment(id, attachments.getDataHandler(id));
91                 }
92             }
93         }
94     }
95
96     /**
97      * Add the normalized message attachments to the Axis message context.
98      *
99      * @param nm
100      * @param messageContext
101      *
102      * @throws AxisFault
103      */

104     public static void copyAttachmentsFromJBIToSOAP(NormalizedMessage nm,
105         MessageContext messageContext) {
106         if (nm != null && messageContext != null) {
107             Set JavaDoc attachmentNames = nm.getAttachmentNames();
108             for (Object JavaDoc id : attachmentNames) {
109                 String JavaDoc name = (String JavaDoc) id;
110                 messageContext.addAttachment(name, nm.getAttachment(name));
111             }
112         }
113     }
114
115 }
116
Popular Tags