Source Code Cross Referenced for MockMessageProducer.java in  » Testing » mockrunner-0.4 » com » mockrunner » mock » jms » 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 » Testing » mockrunner 0.4 » com.mockrunner.mock.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.mock.jms;
002:
003:        import javax.jms.BytesMessage;
004:        import javax.jms.DeliveryMode;
005:        import javax.jms.Destination;
006:        import javax.jms.InvalidDestinationException;
007:        import javax.jms.JMSException;
008:        import javax.jms.Message;
009:        import javax.jms.MessageProducer;
010:        import javax.jms.StreamMessage;
011:
012:        /**
013:         * Mock implementation of JMS <code>MessageProducer</code>.
014:         */
015:        public class MockMessageProducer implements  MessageProducer {
016:            private MockConnection connection;
017:            private MockDestination destination;
018:            private MockSession session;
019:            private boolean closed;
020:            private boolean disableMessageId;
021:            private boolean disableTimestamp;
022:            private int deliveryMode;
023:            private int priority;
024:            private long timeToLive;
025:
026:            public MockMessageProducer(MockConnection connection,
027:                    MockSession session, MockDestination destination) {
028:                this .connection = connection;
029:                this .destination = destination;
030:                this .session = session;
031:                closed = false;
032:                disableMessageId = false;
033:                disableTimestamp = false;
034:                deliveryMode = DeliveryMode.PERSISTENT;
035:                priority = 4;
036:                timeToLive = 0;
037:            }
038:
039:            /**
040:             * Returns if this producer was closed.
041:             * @return <code>true</code> if this sender is closed
042:             */
043:            public boolean isClosed() {
044:                return closed;
045:            }
046:
047:            public void send(Message message) throws JMSException {
048:                send(destination, message, deliveryMode, priority, timeToLive);
049:            }
050:
051:            public void send(Message message, int deliveryMode, int priority,
052:                    long timeToLive) throws JMSException {
053:                send(destination, message, deliveryMode, priority, timeToLive);
054:            }
055:
056:            public void send(Destination destination, Message message)
057:                    throws JMSException {
058:                send(destination, message, deliveryMode, priority, timeToLive);
059:            }
060:
061:            public void send(Destination destination, Message message,
062:                    int deliveryMode, int priority, long timeToLive)
063:                    throws JMSException {
064:                connection.throwJMSException();
065:                if (isClosed()) {
066:                    throw new JMSException("Producer is closed");
067:                }
068:                if (null == destination) {
069:                    throw new InvalidDestinationException(
070:                            "destination must not be null");
071:                }
072:                if ((message instanceof  MockMessage)
073:                        && connection.getConfigurationManager()
074:                                .getDoCloneOnSend()) {
075:                    message = (MockMessage) ((MockMessage) message).clone();
076:                }
077:                if (destination instanceof  MockQueue) {
078:                    setJMSMessageHeaders(message, destination, deliveryMode,
079:                            priority, timeToLive);
080:                    session.addSessionToQueue((MockQueue) destination);
081:                    ((MockQueue) destination).addMessage(message);
082:                } else if (destination instanceof  MockTopic) {
083:                    setJMSMessageHeaders(message, destination, deliveryMode,
084:                            priority, timeToLive);
085:                    session.addSessionToTopic((MockTopic) destination);
086:                    ((MockTopic) destination).addMessage(message);
087:                } else {
088:                    throw new InvalidDestinationException(
089:                            "destination must be an instance of MockQueue or MockTopic");
090:                }
091:            }
092:
093:            public Destination getDestination() throws JMSException {
094:                connection.throwJMSException();
095:                return destination;
096:            }
097:
098:            public void close() throws JMSException {
099:                connection.throwJMSException();
100:                closed = true;
101:            }
102:
103:            public void setDisableMessageID(boolean disableMessageId)
104:                    throws JMSException {
105:                connection.throwJMSException();
106:                this .disableMessageId = disableMessageId;
107:            }
108:
109:            public boolean getDisableMessageID() throws JMSException {
110:                connection.throwJMSException();
111:                return disableMessageId;
112:            }
113:
114:            public void setDisableMessageTimestamp(boolean disableTimestamp)
115:                    throws JMSException {
116:                connection.throwJMSException();
117:                this .disableTimestamp = disableTimestamp;
118:            }
119:
120:            public boolean getDisableMessageTimestamp() throws JMSException {
121:                connection.throwJMSException();
122:                return disableTimestamp;
123:            }
124:
125:            public void setDeliveryMode(int deliveryMode) throws JMSException {
126:                connection.throwJMSException();
127:                this .deliveryMode = deliveryMode;
128:            }
129:
130:            public int getDeliveryMode() throws JMSException {
131:                connection.throwJMSException();
132:                return deliveryMode;
133:            }
134:
135:            public void setPriority(int priority) throws JMSException {
136:                connection.throwJMSException();
137:                this .priority = priority;
138:            }
139:
140:            public int getPriority() throws JMSException {
141:                connection.throwJMSException();
142:                return priority;
143:            }
144:
145:            public void setTimeToLive(long timeToLive) throws JMSException {
146:                connection.throwJMSException();
147:                this .timeToLive = timeToLive;
148:            }
149:
150:            public long getTimeToLive() throws JMSException {
151:                connection.throwJMSException();
152:                return timeToLive;
153:            }
154:
155:            private void setJMSMessageHeaders(Message message,
156:                    Destination destination, int deliveryMode, int priority,
157:                    long timeToLive) throws JMSException {
158:                message.setJMSDeliveryMode(deliveryMode);
159:                message.setJMSPriority(priority);
160:                message.setJMSDestination(destination);
161:                long currentTime = System.currentTimeMillis();
162:                if (!disableTimestamp) {
163:                    message.setJMSTimestamp(currentTime);
164:                }
165:                if (0 == timeToLive) {
166:                    message.setJMSExpiration(0);
167:                } else {
168:                    message.setJMSExpiration(currentTime + timeToLive);
169:                }
170:                if (!disableMessageId) {
171:                    message.setJMSMessageID("ID:"
172:                            + String.valueOf(Math.random()));
173:                }
174:                if (message instanceof  MockMessage) {
175:                    ((MockMessage) message).setReadOnly(true);
176:                    ((MockMessage) message).setReadOnlyProperties(true);
177:                }
178:                if (message instanceof  BytesMessage) {
179:                    ((BytesMessage) message).reset();
180:                }
181:                if (message instanceof  StreamMessage) {
182:                    ((StreamMessage) message).reset();
183:                }
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.