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.apache.camel.impl.DefaultExchange; 024 import org.schwering.irc.lib.IRCModeParser; 025 import org.schwering.irc.lib.IRCUser; 026 027 /** 028 * Defines the <a href="http://camel.apache.org/irc.html">IRC Endpoint</a> 029 * 030 * @version $Revision: 809097 $ 031 */ 032 public class IrcEndpoint extends DefaultEndpoint { 033 private IrcBinding binding; 034 private IrcConfiguration configuration; 035 private IrcComponent component; 036 037 public IrcEndpoint(String endpointUri, IrcComponent component, IrcConfiguration configuration) { 038 super(endpointUri, component); 039 this.component = component; 040 this.configuration = configuration; 041 } 042 043 public boolean isSingleton() { 044 return true; 045 } 046 047 public Exchange createExchange(ExchangePattern pattern) { 048 DefaultExchange exchange = new DefaultExchange(this, pattern); 049 exchange.setProperty(Exchange.BINDING, getBinding()); 050 return exchange; 051 } 052 053 public Exchange createOnPrivmsgExchange(String target, IRCUser user, String msg) { 054 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 055 exchange.setProperty(Exchange.BINDING, getBinding()); 056 exchange.setIn(new IrcMessage("PRIVMSG", target, user, msg)); 057 return exchange; 058 } 059 060 public Exchange createOnNickExchange(IRCUser user, String newNick) { 061 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 062 exchange.setProperty(Exchange.BINDING, getBinding()); 063 exchange.setIn(new IrcMessage("NICK", user, newNick)); 064 return exchange; 065 } 066 067 public Exchange createOnQuitExchange(IRCUser user, String msg) { 068 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 069 exchange.setProperty(Exchange.BINDING, getBinding()); 070 exchange.setIn(new IrcMessage("QUIT", user, msg)); 071 return exchange; 072 } 073 074 public Exchange createOnJoinExchange(String channel, IRCUser user) { 075 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 076 exchange.setProperty(Exchange.BINDING, getBinding()); 077 exchange.setIn(new IrcMessage("JOIN", channel, user)); 078 return exchange; 079 } 080 081 public Exchange createOnKickExchange(String channel, IRCUser user, String whoWasKickedNick, String msg) { 082 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 083 exchange.setProperty(Exchange.BINDING, getBinding()); 084 exchange.setIn(new IrcMessage("KICK", channel, user, whoWasKickedNick, msg)); 085 return exchange; 086 } 087 088 public Exchange createOnModeExchange(String channel, IRCUser user, IRCModeParser modeParser) { 089 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 090 exchange.setProperty(Exchange.BINDING, getBinding()); 091 exchange.setIn(new IrcMessage("MODE", channel, user, modeParser.getLine())); 092 return exchange; 093 } 094 095 public Exchange createOnPartExchange(String channel, IRCUser user, String msg) { 096 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 097 exchange.setProperty(Exchange.BINDING, getBinding()); 098 exchange.setIn(new IrcMessage("PART", channel, user, msg)); 099 return exchange; 100 } 101 102 public Exchange createOnReplyExchange(int num, String value, String msg) { 103 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 104 exchange.setProperty(Exchange.BINDING, getBinding()); 105 exchange.setIn(new IrcMessage("REPLY", num, value, msg)); 106 return exchange; 107 } 108 109 public Exchange createOnTopicExchange(String channel, IRCUser user, String topic) { 110 DefaultExchange exchange = new DefaultExchange(this, getExchangePattern()); 111 exchange.setProperty(Exchange.BINDING, getBinding()); 112 exchange.setIn(new IrcMessage("TOPIC", channel, user, topic)); 113 return exchange; 114 } 115 116 public IrcProducer createProducer() throws Exception { 117 return new IrcProducer(this, component.getIRCConnection(configuration)); 118 } 119 120 public IrcConsumer createConsumer(Processor processor) throws Exception { 121 return new IrcConsumer(this, processor, component.getIRCConnection(configuration)); 122 } 123 124 public IrcComponent getComponent() { 125 return component; 126 } 127 128 public void setComponent(IrcComponent component) { 129 this.component = component; 130 } 131 132 public IrcBinding getBinding() { 133 if (binding == null) { 134 binding = new IrcBinding(); 135 } 136 return binding; 137 } 138 139 public void setBinding(IrcBinding binding) { 140 this.binding = binding; 141 } 142 143 public IrcConfiguration getConfiguration() { 144 return configuration; 145 } 146 147 public void setConfiguration(IrcConfiguration configuration) { 148 this.configuration = configuration; 149 } 150 } 151