Source Code Cross Referenced for MockProducer.java in  » Testing » MockEJB » org » mockejb » 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 » MockEJB » org.mockejb.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.mockejb.jms;
002:
003:        import javax.jms.*;
004:
005:        /**
006:         * Sends message to destination.
007:         *  
008:         * @author Dimitar Gospodinov
009:         */
010:        class MockProducer implements  MessageProducer {
011:
012:            private MockDestination destination;
013:            private int deliveryMode = DeliveryMode.PERSISTENT;
014:            private int priority = 4;
015:            private long timeToLive = 0;
016:            private static int messageId = 1;
017:
018:            /**
019:             * Creates producer for the specified destination.
020:             * @param destination
021:             */
022:            MockProducer(MockDestination destination) {
023:                this .destination = destination;
024:            }
025:
026:            /**
027:             * Sends message.
028:             * @param msg
029:             */
030:            public void send(Message msg) throws JMSException {
031:                send(msg, getDeliveryMode(), getPriority(), getTimeToLive());
032:            }
033:
034:            /**
035:             * Sends message with specified delivery mode, priority and time to live.
036:             * @param msg
037:             * @param deliveryMode
038:             * @param priority
039:             * @param timeToLive
040:             */
041:            public void send(Message msg, int deliveryMode, int priority,
042:                    long timeToLive) throws JMSException {
043:
044:                checkDestination(false);
045:                MockProducer.sendMessage((MockDestination) getDestination(),
046:                        msg, deliveryMode, priority, timeToLive);
047:            }
048:
049:            /**
050:             * Generates unique number used to create message Id.
051:             * @return message Id
052:             */
053:            protected static synchronized int getMessageId() {
054:                return messageId++;
055:            }
056:
057:            /**
058:             * Sends <code>msg</code> to <code>destination</code> using specified
059:             * delivery mode, priority and time to live.
060:             * @param destination
061:             * @param msg
062:             * @param deliveryMode
063:             * @param priority
064:             * @param timeToLive
065:             * @throws JMSException
066:             */
067:            protected static void sendMessage(MockDestination destination,
068:                    Message msg, int deliveryMode, int priority, long timeToLive)
069:                    throws JMSException {
070:
071:                msg.setJMSMessageID("ID:MockMessage "
072:                        + MockProducer.getMessageId());
073:                msg.setJMSDestination(destination);
074:                msg.setJMSDeliveryMode(deliveryMode);
075:                msg.setJMSPriority(priority);
076:                msg.setJMSTimestamp(System.currentTimeMillis());
077:                if (timeToLive == 0) {
078:                    msg.setJMSExpiration(0);
079:                } else {
080:                    msg.setJMSExpiration(msg.getJMSTimestamp() + timeToLive);
081:                }
082:                destination.addMessage(msg);
083:            }
084:
085:            /**
086:             * Sends message to destination.
087:             */
088:            public void send(Destination destination, Message msg)
089:                    throws JMSException {
090:                send(destination, msg, getDeliveryMode(), getPriority(),
091:                        getTimeToLive());
092:            }
093:
094:            /**
095:             * Sends message to destination, with specified delivery mode,
096:             * priority and time to live.
097:             */
098:            public void send(Destination destination, Message msg,
099:                    int deliveryMode, int priority, long timeToLive)
100:                    throws JMSException {
101:
102:                checkDestination(true);
103:                if (destination instanceof  MockDestination) {
104:                    MockProducer.sendMessage((MockDestination) destination,
105:                            msg, deliveryMode, priority, timeToLive);
106:                }
107:                throw new InvalidDestinationException(
108:                        "Invalid destination specified!");
109:            }
110:
111:            /**
112:             * Returns destination for this producer.
113:             */
114:            public Destination getDestination() throws JMSException {
115:                return destination;
116:            }
117:
118:            /**
119:             * Does nothing.
120:             * @see javax.jms.MessageProducer#close()
121:             */
122:            public void close() throws JMSException {
123:                // Does nothing.
124:            }
125:
126:            /**
127:             * Does nothing.
128:             * @see javax.jms.MessageProducer#setDisableMessageID(boolean)
129:             */
130:            public void setDisableMessageID(boolean arg0) throws JMSException {
131:                // Does nothing.
132:            }
133:
134:            /**
135:             * Always returns <code>false</code>
136:             * @see javax.jms.MessageProducer#getDisableMessageID()
137:             */
138:            public boolean getDisableMessageID() throws JMSException {
139:                return false;
140:            }
141:
142:            /**
143:             * Does nothing.
144:             * @see javax.jms.MessageProducer#setDisableMessageTimestamp(boolean)
145:             */
146:            public void setDisableMessageTimestamp(boolean arg0)
147:                    throws JMSException {
148:                // Does nothing.
149:            }
150:
151:            /**
152:             * Always returns <code>false</code>
153:             * @see javax.jms.MessageProducer#getDisableMessageTimestamp()
154:             */
155:            public boolean getDisableMessageTimestamp() throws JMSException {
156:                return false;
157:            }
158:
159:            /**
160:             * @see javax.jms.MessageProducer#setDeliveryMode(int)
161:             */
162:            public void setDeliveryMode(int deliveryMode) throws JMSException {
163:                this .deliveryMode = deliveryMode;
164:            }
165:
166:            /**
167:             * @see javax.jms.MessageProducer#getDeliveryMode()
168:             */
169:            public int getDeliveryMode() throws JMSException {
170:                return deliveryMode;
171:            }
172:
173:            /**
174:             * @see javax.jms.MessageProducer#setPriority(int)
175:             */
176:            public void setPriority(int priority) throws JMSException {
177:                this .priority = priority;
178:            }
179:
180:            /**
181:             * @see javax.jms.MessageProducer#getPriority()
182:             */
183:            public int getPriority() throws JMSException {
184:                return priority;
185:            }
186:
187:            /**
188:             * @see javax.jms.MessageProducer#setTimeToLive(long)
189:             */
190:            public void setTimeToLive(long timeToLive) throws JMSException {
191:                this .timeToLive = timeToLive;
192:            }
193:
194:            /**
195:             * @see javax.jms.MessageProducer#getTimeToLive()
196:             */
197:            public long getTimeToLive() throws JMSException {
198:                return timeToLive;
199:            }
200:
201:            /**
202:             * Checks if there is or there is not destination specified for this producer.
203:             * Method is used in cases when <code>UnsupportedOperationException</code>
204:             * should be raised by a <code>MessageProducer</code> (for example
205:             * calling <code>send(Message)</code> when the producer has been created
206:             * without specifying a destination). 
207:             * @param unidentifiedDestinationCheck
208:             * @throws UnsupportedOperationException if unsupported operation is attempted
209:             */
210:            protected void checkDestination(boolean unidentifiedDestinationCheck) {
211:                if (unidentifiedDestinationCheck) {
212:                    if (destination != null) {
213:                        throw new UnsupportedOperationException();
214:                    }
215:                } else {
216:                    if (destination == null) {
217:                        throw new UnsupportedOperationException();
218:                    }
219:                }
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.