01: // Copyright 2007 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.internal.services;
16:
17: import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
18:
19: import java.util.List;
20:
21: import org.apache.tapestry.ioc.AnnotationProvider;
22: import org.apache.tapestry.ioc.internal.util.CollectionFactory;
23: import org.apache.tapestry.services.ValidationConstraintGenerator;
24:
25: public class ValidationConstraintGeneratorImpl implements
26: ValidationConstraintGenerator {
27: private final List<ValidationConstraintGenerator> _configuration;
28:
29: public ValidationConstraintGeneratorImpl(
30: final List<ValidationConstraintGenerator> configuration) {
31: _configuration = configuration;
32: }
33:
34: public List<String> buildConstraints(Class propertyType,
35: AnnotationProvider annotationProvider) {
36: notNull(propertyType, "propertyType");
37: notNull(annotationProvider, "annotationProvider");
38:
39: List<String> result = CollectionFactory.newList();
40:
41: for (ValidationConstraintGenerator g : _configuration) {
42: List<String> constraints = g.buildConstraints(propertyType,
43: annotationProvider);
44:
45: if (constraints != null)
46: result.addAll(constraints);
47: }
48:
49: // TODO: How to handle duplicate or conflicting constraints from different generators?
50:
51: return result;
52: }
53: }
|