blob: a2ebd8200d403d3cb74037c1e3b20adcffd25ece [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
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 }
limpbizkit3d58d6b2008-03-08 16:11:47 +000095}