01: /*
02: * Copyright 2006 Dan Shellman
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.iscreen.impl;
17:
18: import java.util.ArrayList;
19: import java.util.Collections;
20: import java.util.Iterator;
21: import java.util.List;
22: import java.util.Locale;
23:
24: /**
25: * This is a "default" implementation of the ValidationService interface
26: * that can be configured to act as a full implementation of the service.
27: *
28: * @author Shellman, Dan
29: */
30: public class DefaultValidationService extends BaseValidationService {
31: protected List validatorWrappers = new ArrayList();
32: protected Iterator currentIterator;
33:
34: /**
35: * Constructor requiring a unique id and default locale
36: *
37: * @param uniqueId The unique id of the validation service.
38: * @param locale The default locale
39: */
40: public DefaultValidationService(String uniqueId, Locale locale) {
41: super (uniqueId, locale);
42: } //end DefaultValidationService()
43:
44: /**
45: * Adds a validator wrapper, which is used to call the contained
46: * validator. The ordering of the calls to this method are retained, so
47: * that when the wrappers are iterated through, they are done in order
48: * of when this method is called.
49: *
50: * @param wrapper The wrapper to add to this validation service.
51: */
52: public void addValidatorWrapper(ValidatorWrapper wrapper) {
53: validatorWrappers.add(wrapper);
54: } //end addValidatorWrapper()
55:
56: /**
57: * Retrieves all of the validator wrappers this service is configured with.
58: *
59: * @return Returns the list of wrappers this service is configured with.
60: */
61: public List getAllWrappers() {
62: return Collections.unmodifiableList(validatorWrappers);
63: } //end getAllWrappers()
64:
65: // ***
66: // Protected methods
67: // ***
68:
69: protected ValidatorWrapper getNextValidator() {
70: if (currentIterator != null && currentIterator.hasNext()) {
71: return (ValidatorWrapper) currentIterator.next();
72: }
73:
74: return null;
75: } //end getNextValidator()
76:
77: protected void resetValidatorIteration() {
78: currentIterator = validatorWrappers.iterator();
79: } //end resetValidatorIteration()
80: } //end DefaultValidationService
|