blob: 99b3d094af379decd0ed3a6d8716778ea8691a20 [file] [log] [blame]
limpbizkit477f9f92008-07-28 07:05:14 +00001/**
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
17package com.google.inject;
18
19import com.google.inject.internal.Errors;
20import com.google.inject.spi.Message;
21import java.util.logging.Level;
22import java.util.logging.Logger;
23
24/**
25 * Handles {@link Binder#addError} commands.
26 *
27 * @author crazybob@google.com (Bob Lee)
28 * @author jessewilson@google.com (Jesse Wilson)
29 */
limpbizkit00ca9f72008-08-02 17:56:17 +000030class MessageProcessor extends AbstractProcessor {
limpbizkit477f9f92008-07-28 07:05:14 +000031
32 private static final Logger logger = Logger.getLogger(Guice.class.getName());
33
limpbizkit00ca9f72008-08-02 17:56:17 +000034 MessageProcessor(Errors errors) {
limpbizkit477f9f92008-07-28 07:05:14 +000035 super(errors);
36 }
37
limpbizkit03b81a62009-03-18 05:34:39 +000038 @Override public Boolean visit(Message message) {
limpbizkit477f9f92008-07-28 07:05:14 +000039 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}