/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.jms;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueReceiver;
import javax.jms.Topic;
import javax.jms.TopicSubscriber;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class JMSConsumer implements MessageConsumer, QueueReceiver, TopicSubscriber {
    private JMSSession session = null;
    private JMSDestination destination = null;
    private String msgSelector = null;
    private boolean noLocal;

    /**
     * P2P receiver is durable
     * Durable Topic subscriber is durable
     */
    private boolean durable = false;
    // only a durable TopicSubscriber has a name
    private String name = "";

    public JMSConsumer(JMSSession session, Destination destination, String msgSelector, boolean noLocal) {
        this.session = session;
        this.destination = (JMSDestination) destination;
        this.msgSelector = msgSelector;
        this.noLocal = noLocal;
        if(!this.destination.isTopic()) {
            durable = true;
        }
    }

    public String getMessageSelector() throws JMSException {
        throw new JMSException("not support now!");
    }

    public MessageListener getMessageListener() throws JMSException {
        throw new JMSException("not support now!");
    }

    public void setMessageListener(MessageListener listener) throws JMSException {
        throw new JMSException("not support now!");
    }

    public Message receive() throws JMSException {
        throw new JMSException("not support now!");
    }

    public Message receive(long timeout) throws JMSException {
        throw new JMSException("not support now!");
    }

    public Message receiveNoWait() throws JMSException {
        throw new JMSException("not support now!");
    }

    public void close() throws JMSException {
        throw new JMSException("not support now!");
    }

    public Queue getQueue() throws JMSException {
        throw new JMSException("not support now!");
    }

    public Topic getTopic() throws JMSException {
        throw new JMSException("not support now!");
    }

    public boolean getNoLocal() throws JMSException {
        throw new JMSException("not support now!");
    }

    public String getName() {
        return name;
    }

    /**
     * only a durable TopicSubscriber has a name
     *
     * @param name
     */
    public void setName(String name) {
        if(destination.isTopic()) {
            this.name = name;
        }
        durable = true;
    }

    public static void main(String[] args) {

    }
}
