Source Code Cross Referenced for JabberMarshaler.java in  » ESB » servicemix » org » apache » servicemix » components » jabber » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » servicemix » org.apache.servicemix.components.jabber 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.servicemix.components.jabber;
018:
019:        import org.apache.servicemix.jbi.jaxp.SourceMarshaler;
020:        import org.jivesoftware.smack.packet.Message;
021:        import org.jivesoftware.smack.packet.Packet;
022:
023:        import javax.jbi.messaging.MessagingException;
024:        import javax.jbi.messaging.NormalizedMessage;
025:        import javax.xml.transform.Source;
026:        import javax.xml.transform.TransformerException;
027:        import java.util.Date;
028:        import java.util.Iterator;
029:
030:        /**
031:         * Marshals Jabber messages into and out of NMS messages
032:         *
033:         * @version $Revision: 429277 $
034:         */
035:        public class JabberMarshaler {
036:            private SourceMarshaler sourceMarshaler;
037:
038:            public JabberMarshaler() {
039:                this (new SourceMarshaler());
040:            }
041:
042:            public JabberMarshaler(SourceMarshaler sourceMarshaler) {
043:                this .sourceMarshaler = sourceMarshaler;
044:            }
045:
046:            /**
047:             * Marshals the Jabber message into an NMS message
048:             *
049:             * @throws MessagingException
050:             */
051:            public void toNMS(NormalizedMessage normalizedMessage, Packet packet)
052:                    throws MessagingException {
053:                addNmsProperties(normalizedMessage, packet);
054:                if (packet instanceof  Message) {
055:                    Message message = (Message) packet;
056:                    Source source = sourceMarshaler.asSource(message.getBody());
057:                    normalizedMessage.setContent(source);
058:                }
059:
060:                // lets add the packet to the NMS
061:                normalizedMessage.setProperty(
062:                        "org.apache.servicemix.jabber.packet", packet);
063:            }
064:
065:            /**
066:             * Marshals from the Jabber message to the normalized message
067:             *
068:             * @param message
069:             * @param normalizedMessage
070:             * @throws TransformerException
071:             */
072:            public void fromNMS(Message message,
073:                    NormalizedMessage normalizedMessage)
074:                    throws TransformerException {
075:                // lets create a text message
076:                String xml = messageAsString(normalizedMessage);
077:                message.setBody(xml);
078:                addJabberProperties(message, normalizedMessage);
079:            }
080:
081:            // Properties
082:            //-------------------------------------------------------------------------
083:            /**
084:             * @deprecated use getSourceMarshaler instead
085:             */
086:            public SourceMarshaler getSourceMarshaller() {
087:                return sourceMarshaler;
088:            }
089:
090:            /**
091:             * @deprecated use setSourceMashaler instead
092:             */
093:            public void setSourceMarshaller(SourceMarshaler sourceMarshaler) {
094:                this .sourceMarshaler = sourceMarshaler;
095:            }
096:
097:            /**
098:             * @return the sourceMarshaler
099:             */
100:            public SourceMarshaler getSourceMarshaler() {
101:                return sourceMarshaler;
102:            }
103:
104:            /**
105:             * @param sourceMarshaler the sourceMarshaler to set
106:             */
107:            public void setSourceMarshaler(SourceMarshaler sourceMarshaler) {
108:                this .sourceMarshaler = sourceMarshaler;
109:            }
110:
111:            // Implementation methods
112:            //-------------------------------------------------------------------------
113:
114:            /**
115:             * Converts the inbound message to a String that can be sent
116:             */
117:            protected String messageAsString(NormalizedMessage normalizedMessage)
118:                    throws TransformerException {
119:                return sourceMarshaler.asString(normalizedMessage.getContent());
120:            }
121:
122:            /**
123:             * Appends properties on the NMS to the JMS Message
124:             */
125:            protected void addJabberProperties(Message message,
126:                    NormalizedMessage normalizedMessage) {
127:                for (Iterator iter = normalizedMessage.getPropertyNames()
128:                        .iterator(); iter.hasNext();) {
129:                    String name = (String) iter.next();
130:                    Object value = normalizedMessage.getProperty(name);
131:                    if (shouldIncludeHeader(normalizedMessage, name, value)) {
132:                        message.setProperty(name, value);
133:                    }
134:                }
135:            }
136:
137:            protected void addNmsProperties(
138:                    NormalizedMessage normalizedMessage, Packet message) {
139:                Iterator iter = message.getPropertyNames();
140:                while (iter.hasNext()) {
141:                    String name = (String) iter.next();
142:                    Object value = message.getProperty(name);
143:                    normalizedMessage.setProperty(name, value);
144:                }
145:            }
146:
147:            /**
148:             * Decides whether or not the given header should be included in the JMS message.
149:             * By default this includes all suitable typed values
150:             */
151:            protected boolean shouldIncludeHeader(
152:                    NormalizedMessage normalizedMessage, String name,
153:                    Object value) {
154:                return value instanceof  String || value instanceof  Number
155:                        || value instanceof  Date;
156:            }
157:
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.