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.activemq.web;
018    
019    import javax.jms.JMSException;
020    import javax.jms.Queue;
021    import javax.jms.QueueBrowser;
022    import javax.jms.Session;
023    
024    import org.springframework.beans.factory.DisposableBean;
025    
026    /**
027     * 
028     * 
029     */
030    public class QueueBrowseQuery extends DestinationFacade implements DisposableBean {
031        private SessionPool sessionPool;
032        private String selector;
033        private Session session;
034        private Queue queue;
035        private QueueBrowser browser;
036    
037        public QueueBrowseQuery(BrokerFacade brokerFacade, SessionPool sessionPool) throws JMSException {
038            super(brokerFacade);
039            this.sessionPool = sessionPool;
040            this.session = sessionPool.borrowSession();
041            setJMSDestinationType("query");
042        }
043    
044        public void destroy() throws Exception {
045            if (browser != null) {
046                browser.close();
047            }
048            sessionPool.returnSession(session);
049            session = null;
050        }
051    
052        public QueueBrowser getBrowser() throws JMSException {
053            if (browser == null) {
054                browser = createBrowser();
055            }
056            return browser;
057        }
058    
059        public void setBrowser(QueueBrowser browser) {
060            this.browser = browser;
061        }
062    
063        public Queue getQueue() throws JMSException {
064            if (queue == null) {
065                queue = session.createQueue(getValidDestination());
066            }
067            return queue;
068        }
069    
070        public void setQueue(Queue queue) {
071            this.queue = queue;
072        }
073    
074        public String getSelector() {
075            return selector;
076        }
077    
078        public void setSelector(String selector) {
079            this.selector = selector;
080        }
081    
082        public Session getSession() {
083            return session;
084        }
085    
086        public boolean isQueue() {
087            return true;
088        }
089    
090        protected QueueBrowser createBrowser() throws JMSException {
091            return getSession().createBrowser(getQueue(), getSelector());
092        }
093    
094        
095    }