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