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 | |
| 36 | private ErrorHandler errorHandler; |
| 37 | |
| 38 | public void processCommands(List<Command> commands, ErrorHandler errorHandler) { |
| 39 | this.errorHandler = errorHandler; |
| 40 | try { |
| 41 | for (Iterator<Command> i = commands.iterator(); i.hasNext(); ) { |
| 42 | Boolean allDone = i.next().acceptVisitor(this); |
| 43 | if (allDone) { |
| 44 | i.remove(); |
| 45 | } |
| 46 | } |
| 47 | } finally { |
| 48 | this.errorHandler = null; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | protected void addError(Object source, String message, Object... arguments) { |
| 53 | errorHandler.handle(source, message, arguments); |
| 54 | } |
| 55 | |
| 56 | protected void addError(Object source, String message) { |
| 57 | errorHandler.handle(source, message); |
| 58 | } |
| 59 | |
| 60 | public Boolean visitAddMessageError(AddMessageErrorCommand command) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | public Boolean visitAddError(AddThrowableErrorCommand command) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | public Boolean visitBindInterceptor(BindInterceptorCommand command) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | public Boolean visitBindScope(BindScopeCommand command) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | public Boolean visitRequestStaticInjection(RequestStaticInjectionCommand command) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | public Boolean visitBindConstant(BindConstantCommand command) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | public Boolean visitConvertToTypes(ConvertToTypesCommand command) { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | public <T> Boolean visitBind(BindCommand<T> command) { |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | public <T> Boolean visitGetProvider(GetProviderCommand<T> command) { |
| 93 | return false; |
| 94 | } |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 95 | } |