limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +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 | |
| 17 | package com.google.inject; |
| 18 | |
| 19 | import com.google.inject.commands.*; |
limpbizkit | 916f548 | 2008-04-16 20:51:14 +0000 | [diff] [blame] | 20 | import com.google.inject.internal.ErrorHandler; |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 21 | |
| 22 | import java.util.Iterator; |
| 23 | import java.util.List; |
| 24 | |
| 25 | /** |
| 26 | * Abstract base class for executing commands to creating an injector. |
| 27 | * |
| 28 | * <p>Extending classes must return {@code true} from any overridden |
| 29 | * {@code visit*()} methods, in order for the command processor to remove the |
| 30 | * handled command. |
| 31 | * |
| 32 | * @author jessewilson@google.com (Jesse Wilson) |
| 33 | */ |
| 34 | abstract class CommandProcessor implements Command.Visitor<Boolean> { |
| 35 | |
limpbizkit | ad94bcb | 2008-04-28 00:22:43 +0000 | [diff] [blame] | 36 | private final ErrorHandler errorHandler; |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 37 | |
limpbizkit | ad94bcb | 2008-04-28 00:22:43 +0000 | [diff] [blame] | 38 | protected CommandProcessor(ErrorHandler errorHandler) { |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 39 | this.errorHandler = errorHandler; |
limpbizkit | ad94bcb | 2008-04-28 00:22:43 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | public void processCommands(List<Command> commands) { |
| 43 | for (Iterator<Command> i = commands.iterator(); i.hasNext(); ) { |
| 44 | Boolean allDone = i.next().acceptVisitor(this); |
| 45 | if (allDone) { |
| 46 | i.remove(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 47 | } |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | protected void addError(Object source, String message, Object... arguments) { |
| 52 | errorHandler.handle(source, message, arguments); |
| 53 | } |
| 54 | |
| 55 | protected void addError(Object source, String message) { |
| 56 | errorHandler.handle(source, message); |
| 57 | } |
| 58 | |
| 59 | public Boolean visitAddMessageError(AddMessageErrorCommand command) { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | public Boolean visitAddError(AddThrowableErrorCommand command) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | public Boolean visitBindInterceptor(BindInterceptorCommand command) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | public Boolean visitBindScope(BindScopeCommand command) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | public Boolean visitRequestStaticInjection(RequestStaticInjectionCommand command) { |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | public Boolean visitBindConstant(BindConstantCommand command) { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | public Boolean visitConvertToTypes(ConvertToTypesCommand command) { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | public <T> Boolean visitBind(BindCommand<T> command) { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | public <T> Boolean visitGetProvider(GetProviderCommand<T> command) { |
| 92 | return false; |
| 93 | } |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 94 | } |