blob: d92f5074f66b35a120d1768690e4a3a3ff471d39 [file] [log] [blame]
limpbizkit3d58d6b2008-03-08 16:11:47 +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.commands.*;
limpbizkit916f5482008-04-16 20:51:14 +000020import com.google.inject.internal.ErrorHandler;
limpbizkit3d58d6b2008-03-08 16:11:47 +000021
22import java.util.Iterator;
23import 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 */
34abstract class CommandProcessor implements Command.Visitor<Boolean> {
35
limpbizkitad94bcb2008-04-28 00:22:43 +000036 private final ErrorHandler errorHandler;
limpbizkit3d58d6b2008-03-08 16:11:47 +000037
limpbizkitad94bcb2008-04-28 00:22:43 +000038 protected CommandProcessor(ErrorHandler errorHandler) {
limpbizkit3d58d6b2008-03-08 16:11:47 +000039 this.errorHandler = errorHandler;
limpbizkitad94bcb2008-04-28 00:22:43 +000040 }
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();
limpbizkit3d58d6b2008-03-08 16:11:47 +000047 }
limpbizkit3d58d6b2008-03-08 16:11:47 +000048 }
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 }
limpbizkit3d58d6b2008-03-08 16:11:47 +000094}