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.camel.component.irc;
018    
019    import org.apache.camel.Exchange;
020    import org.apache.camel.ExchangePattern;
021    import org.apache.camel.Processor;
022    import org.apache.camel.impl.DefaultEndpoint;
023    import org.schwering.irc.lib.IRCModeParser;
024    import org.schwering.irc.lib.IRCUser;
025    
026    /**
027     * Defines the <a href="http://camel.apache.org/irc.html">IRC Endpoint</a>
028     *
029     * @version $Revision: 738604 $
030     */
031    public class IrcEndpoint extends DefaultEndpoint {
032        private IrcBinding binding;
033        private IrcConfiguration configuration;
034        private IrcComponent component;
035    
036        public IrcEndpoint(String endpointUri, IrcComponent component, IrcConfiguration configuration) {
037            super(endpointUri, component);
038            this.component = component;
039            this.configuration = configuration;
040        }
041    
042        public boolean isSingleton() {
043            return true;
044        }
045    
046        public Exchange createExchange(ExchangePattern pattern) {
047            return new IrcExchange(this, pattern, getBinding());
048        }
049    
050        public IrcExchange createOnPrivmsgExchange(String target, IRCUser user, String msg) {
051            return new IrcExchange(this, getExchangePattern(), getBinding(), new IrcMessage("PRIVMSG", target, user, msg));
052        }
053    
054        public IrcExchange createOnNickExchange(IRCUser user, String newNick) {
055            return new IrcExchange(this, getExchangePattern(), getBinding(), new IrcMessage("NICK", user, newNick));
056        }
057    
058        public IrcExchange createOnQuitExchange(IRCUser user, String msg) {
059            return new IrcExchange(this, getExchangePattern(), getBinding(), new IrcMessage("QUIT", user, msg));
060        }
061    
062        public IrcExchange createOnJoinExchange(String channel, IRCUser user) {
063            return new IrcExchange(this, getExchangePattern(), getBinding(), new IrcMessage("JOIN", channel, user));
064        }
065    
066        public IrcExchange createOnKickExchange(String channel, IRCUser user, String whoWasKickedNick, String msg) {
067            return new IrcExchange(this, getExchangePattern(), getBinding(), new IrcMessage("KICK", channel, user, whoWasKickedNick, msg));
068        }
069    
070        public IrcExchange createOnModeExchange(String channel, IRCUser user, IRCModeParser modeParser) {
071            return new IrcExchange(this, getExchangePattern(), getBinding(), new IrcMessage("MODE", channel, user, modeParser.getLine()));
072        }
073    
074        public IrcExchange createOnPartExchange(String channel, IRCUser user, String msg) {
075            return new IrcExchange(this, getExchangePattern(), getBinding(), new IrcMessage("PART", channel, user, msg));
076        }
077    
078        public IrcExchange createOnTopicExchange(String channel, IRCUser user, String topic) {
079            return new IrcExchange(this, getExchangePattern(), getBinding(), new IrcMessage("TOPIC", channel, user, topic));
080        }
081    
082        public IrcProducer createProducer() throws Exception {
083            return new IrcProducer(this, component.getIRCConnection(configuration));
084        }
085    
086        public IrcConsumer createConsumer(Processor processor) throws Exception {
087            return new IrcConsumer(this, processor, component.getIRCConnection(configuration));
088        }
089    
090        public IrcComponent getComponent() {
091            return component;
092        }
093    
094        public void setComponent(IrcComponent component) {
095            this.component = component;
096        }
097    
098        public IrcBinding getBinding() {
099            if (binding == null) {
100                binding = new IrcBinding();
101            }
102            return binding;
103        }
104    
105        public void setBinding(IrcBinding binding) {
106            this.binding = binding;
107        }
108    
109        public IrcConfiguration getConfiguration() {
110            return configuration;
111        }
112    
113        public void setConfiguration(IrcConfiguration configuration) {
114            this.configuration = configuration;
115        }
116    }
117