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