Coverage Report - org.apache.camel.component.irc.IrcConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
IrcConsumer
0% 
0% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.component.irc;
 18  
 
 19  
 import org.apache.camel.Processor;
 20  
 import org.apache.camel.impl.DefaultConsumer;
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 import org.schwering.irc.lib.IRCConnection;
 24  
 import org.schwering.irc.lib.IRCEventAdapter;
 25  
 import org.schwering.irc.lib.IRCModeParser;
 26  
 import org.schwering.irc.lib.IRCUser;
 27  
 
 28  0
 public class IrcConsumer extends DefaultConsumer<IrcExchange> {
 29  0
     private static final transient Log LOG = LogFactory.getLog(IrcConsumer.class);
 30  
     
 31  
     private final IrcConfiguration configuration;
 32  
     private final IrcEndpoint endpoint;
 33  
     private final IRCConnection connection;
 34  
     private FilteredIRCEventAdapter listener;
 35  
 
 36  
     public IrcConsumer(IrcEndpoint endpoint, Processor processor, IRCConnection connection) {
 37  0
         super(endpoint, processor);
 38  0
         this.endpoint = endpoint;
 39  0
         this.connection = connection;
 40  0
         configuration = endpoint.getConfiguration();
 41  0
     }
 42  
 
 43  
     @Override
 44  
     protected void doStop() throws Exception {
 45  0
         String target = endpoint.getConfiguration().getTarget();
 46  0
         connection.doPart(target);
 47  0
         connection.removeIRCEventListener(listener);
 48  
 
 49  0
         super.doStop();
 50  0
     }
 51  
 
 52  
     @Override
 53  
     protected void doStart() throws Exception {
 54  0
         super.doStart();
 55  
 
 56  0
         String target = endpoint.getConfiguration().getTarget();
 57  0
         connection.addIRCEventListener(new FilteredIRCEventAdapter(target));
 58  
 
 59  0
         LOG.debug("joining: " + target);
 60  0
         connection.doJoin(target);
 61  0
     }
 62  
 
 63  
     public IRCConnection getConnection() {
 64  0
         return connection;
 65  
     }
 66  
 
 67  
     class FilteredIRCEventAdapter extends IRCEventAdapter {
 68  
         final String target;
 69  
 
 70  0
         public FilteredIRCEventAdapter(String target) {
 71  0
             this.target = target;
 72  0
         }
 73  
 
 74  
         @Override
 75  
         public void onNick(IRCUser user, String newNick) {
 76  0
             if (configuration.isOnNick()) {
 77  0
                 IrcExchange exchange = endpoint.createOnNickExchange(user, newNick);
 78  
                 try {
 79  0
                     getProcessor().process(exchange);
 80  0
                 } catch (Exception e) {
 81  
                     // TODO: what should we do when a processing failure
 82  
                     // occurs??
 83  0
                     e.printStackTrace();
 84  0
                 }
 85  
             }
 86  0
         }
 87  
 
 88  
         @Override
 89  
         public void onQuit(IRCUser user, String msg) {
 90  0
             if (configuration.isOnQuit()) {
 91  0
                 IrcExchange exchange = endpoint.createOnQuitExchange(user, msg);
 92  
                 try {
 93  0
                     getProcessor().process(exchange);
 94  0
                 } catch (Exception e) {
 95  
                     // TODO: what should we do when a processing failure
 96  
                     // occurs??
 97  0
                     e.printStackTrace();
 98  0
                 }
 99  
             }
 100  0
         }
 101  
 
 102  
         @Override
 103  
         public void onJoin(String channel, IRCUser user) {
 104  0
             if (configuration.isOnJoin()) {
 105  0
                 if (channel.equals(configuration.getTarget())) {
 106  0
                     IrcExchange exchange = endpoint.createOnJoinExchange(channel, user);
 107  
                     try {
 108  0
                         getProcessor().process(exchange);
 109  0
                     } catch (Exception e) {
 110  
                         // TODO: what should we do when a processing failure
 111  
                         // occurs??
 112  0
                         e.printStackTrace();
 113  0
                     }
 114  
                 }
 115  
             }
 116  0
         }
 117  
 
 118  
         @Override
 119  
         public void onKick(String channel, IRCUser user, String passiveNick, String msg) {
 120  0
             if (configuration.isOnKick()) {
 121  0
                 if (channel.equals(configuration.getTarget())) {
 122  0
                     IrcExchange exchange = endpoint.createOnKickExchange(channel, user, passiveNick, msg);
 123  
                     try {
 124  0
                         getProcessor().process(exchange);
 125  0
                     } catch (Exception e) {
 126  
                         // TODO: what should we do when a processing failure
 127  
                         // occurs??
 128  0
                         e.printStackTrace();
 129  0
                     }
 130  
                 }
 131  
             }
 132  0
         }
 133  
 
 134  
         @Override
 135  
         public void onMode(String channel, IRCUser user, IRCModeParser modeParser) {
 136  0
             if (configuration.isOnMode()) {
 137  0
                 if (channel.equals(configuration.getTarget())) {
 138  0
                     IrcExchange exchange = endpoint.createOnModeExchange(channel, user, modeParser);
 139  
                     try {
 140  0
                         getProcessor().process(exchange);
 141  0
                     } catch (Exception e) {
 142  
                         // TODO: what should we do when a processing failure
 143  
                         // occurs??
 144  0
                         e.printStackTrace();
 145  0
                     }
 146  
                 }
 147  
             }
 148  0
         }
 149  
 
 150  
         @Override
 151  
         public void onPart(String channel, IRCUser user, String msg) {
 152  0
             if (configuration.isOnPart()) {
 153  0
                 if (channel.equals(configuration.getTarget())) {
 154  0
                     IrcExchange exchange = endpoint.createOnPartExchange(channel, user, msg);
 155  
                     try {
 156  0
                         getProcessor().process(exchange);
 157  0
                     } catch (Exception e) {
 158  
                         // TODO: what should we do when a processing failure
 159  
                         // occurs??
 160  0
                         e.printStackTrace();
 161  0
                     }
 162  
                 }
 163  
             }
 164  0
         }
 165  
 
 166  
         @Override
 167  
         public void onTopic(String channel, IRCUser user, String topic) {
 168  0
             if (configuration.isOnTopic()) {
 169  0
                 if (channel.equals(configuration.getTarget())) {
 170  0
                     IrcExchange exchange = endpoint.createOnTopicExchange(channel, user, topic);
 171  
                     try {
 172  0
                         getProcessor().process(exchange);
 173  0
                     } catch (Exception e) {
 174  
                         // TODO: what should we do when a processing failure
 175  
                         // occurs??
 176  0
                         e.printStackTrace();
 177  0
                     }
 178  
                 }
 179  
             }
 180  0
         }
 181  
 
 182  
         @Override
 183  
         public void onPrivmsg(String target, IRCUser user, String msg) {
 184  0
             if (configuration.isOnPrivmsg()) {
 185  0
                 if (target.equals(configuration.getTarget())) {
 186  0
                     IrcExchange exchange = endpoint.createOnPrivmsgExchange(target, user, msg);
 187  
                     try {
 188  0
                         getProcessor().process(exchange);
 189  0
                     } catch (Exception e) {
 190  
                         // TODO: what should we do when a processing failure
 191  
                         // occurs??
 192  0
                         e.printStackTrace();
 193  0
                     }
 194  
                 }
 195  
             }
 196  0
         }
 197  
     }
 198  
 }