limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2008 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame^] | 17 | package com.google.inject.internal; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 18 | |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame^] | 19 | import com.google.inject.Guice; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 20 | import com.google.inject.spi.Message; |
| 21 | import java.util.logging.Level; |
| 22 | import java.util.logging.Logger; |
| 23 | |
| 24 | /** |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame^] | 25 | * Handles {@code Binder.addError} commands. |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 26 | * |
| 27 | * @author crazybob@google.com (Bob Lee) |
| 28 | * @author jessewilson@google.com (Jesse Wilson) |
| 29 | */ |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame^] | 30 | final class MessageProcessor extends AbstractProcessor { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 31 | |
| 32 | private static final Logger logger = Logger.getLogger(Guice.class.getName()); |
| 33 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 34 | MessageProcessor(Errors errors) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 35 | super(errors); |
| 36 | } |
| 37 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 38 | @Override public Boolean visit(Message message) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 39 | if (message.getCause() != null) { |
| 40 | String rootMessage = getRootMessage(message.getCause()); |
| 41 | logger.log(Level.INFO, |
| 42 | "An exception was caught and reported. Message: " + rootMessage, |
| 43 | message.getCause()); |
| 44 | } |
| 45 | |
| 46 | errors.addMessage(message); |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | public static String getRootMessage(Throwable t) { |
| 51 | Throwable cause = t.getCause(); |
| 52 | return cause == null ? t.toString() : getRootMessage(cause); |
| 53 | } |
| 54 | } |