KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > web > QueueBrowseQuery


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.web;
19
20 import org.springframework.beans.factory.DisposableBean;
21
22 import javax.jms.JMSException JavaDoc;
23 import javax.jms.Queue JavaDoc;
24 import javax.jms.QueueBrowser JavaDoc;
25 import javax.jms.Session JavaDoc;
26
27 /**
28  *
29  * @version $Revision: 504235 $
30  */

31 public class QueueBrowseQuery extends DestinationFacade implements DisposableBean {
32     private SessionPool sessionPool;
33     private String JavaDoc selector;
34     private Session JavaDoc session;
35     private Queue JavaDoc queue;
36     private QueueBrowser JavaDoc browser;
37
38     public QueueBrowseQuery(BrokerFacade brokerFacade, SessionPool sessionPool) throws JMSException JavaDoc {
39         super(brokerFacade);
40         this.sessionPool = sessionPool;
41         this.session = sessionPool.borrowSession();
42         setJMSDestinationType("query");
43     }
44
45     public void destroy() throws Exception JavaDoc {
46         if (browser != null) {
47             browser.close();
48         }
49         sessionPool.returnSession(session);
50         session = null;
51     }
52
53     public QueueBrowser JavaDoc getBrowser() throws JMSException JavaDoc {
54         if (browser == null) {
55             browser = createBrowser();
56         }
57         return browser;
58     }
59
60     public void setBrowser(QueueBrowser JavaDoc browser) {
61         this.browser = browser;
62     }
63
64     public Queue JavaDoc getQueue() throws JMSException JavaDoc {
65         if (queue == null) {
66             queue = session.createQueue(getValidDestination());
67         }
68         return queue;
69     }
70
71     public void setQueue(Queue JavaDoc queue) {
72         this.queue = queue;
73     }
74
75     public String JavaDoc getSelector() {
76         return selector;
77     }
78
79     public void setSelector(String JavaDoc selector) {
80         this.selector = selector;
81     }
82
83     public Session JavaDoc getSession() {
84         return session;
85     }
86
87     public boolean isQueue() {
88         return true;
89     }
90
91     protected QueueBrowser JavaDoc createBrowser() throws JMSException JavaDoc {
92         return getSession().createBrowser(getQueue(), getSelector());
93     }
94
95     
96 }
97
Popular Tags