View Javadoc
1   /*
2    * Copyright 2006 Werner Guttmann
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  package org.exolab.castor.xml.validators;
17  
18  import org.exolab.castor.xml.TypeValidator;
19  import org.exolab.castor.xml.ValidationContext;
20  import org.exolab.castor.xml.ValidationException;
21  
22  /**
23   * The IDREFS Validation class.
24   *
25   * @author <a href="mailto:werner DOT guttmann AT gmx DOT net">Werner Guttman</a>
26   * @version $Revision: 0000 $ $Date: $
27   */
28  public class IdRefsValidator implements TypeValidator {
29  
30      /** Our IdRefValidator. */
31      private IdRefValidator _idRefValidator;
32  
33      /**
34       * Creates a new IdRefsValidator with no restrictions.
35       */
36      public IdRefsValidator() {
37          super();
38          _idRefValidator = new IdRefValidator();
39      }
40  
41      /**
42       * Validates the given Object.
43       *
44       * @param object the Object to validate
45       * @param context the ValidationContext
46       * @throws ValidationException if the object fails validation.
47       */
48      public void validate(final Object object, final ValidationContext context)
49                                                      throws ValidationException {
50          if (object == null) {
51               String err = "The object of type IDREFS is null!";
52               throw new ValidationException(err);
53          }
54  
55          Object[] objects = (Object[]) object;
56          for (int i = 0; i < objects.length; i++) {
57              _idRefValidator.validate(objects[i], context);
58          }
59  
60          // validate(value, context);
61      } //-- validate
62  
63  }