01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.ioc.internal;
16:
17: import org.apache.commons.logging.Log;
18: import org.apache.tapestry.ioc.Configuration;
19: import org.apache.tapestry.ioc.def.ContributionDef;
20:
21: /**
22: * Performs some validation before delegating to another Configuration.
23: */
24: public class ValidatingConfigurationWrapper<T> implements
25: Configuration<T> {
26: private final String _serviceId;
27:
28: private final ContributionDef _contributionDef;
29:
30: private final Log _log;
31:
32: private final Configuration<T> _delegate;
33:
34: private final Class _expectedType;
35:
36: // Need a strategy for determing the right order for this mass of parameters!
37:
38: public ValidatingConfigurationWrapper(String serviceId, Log log,
39: Class expectedType, ContributionDef contributionDef,
40: Configuration<T> delegate) {
41: _serviceId = serviceId;
42: _log = log;
43: _expectedType = expectedType;
44: _contributionDef = contributionDef;
45: _delegate = delegate;
46: }
47:
48: public void add(T object) {
49: if (object == null) {
50: _log.warn(IOCMessages.contributionWasNull(_serviceId,
51: _contributionDef));
52: return;
53: }
54:
55: // Sure, we say it is type T ... but is it really?
56:
57: if (!_expectedType.isInstance(object)) {
58: _log.warn(IOCMessages.contributionWrongValueType(
59: _serviceId, _contributionDef, object.getClass(),
60: _expectedType));
61: return;
62: }
63:
64: _delegate.add(object);
65: }
66:
67: }
|