1 /*
2 * Copyright [2007] [University Corporation for Advanced Internet Development, 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
17 package org.opensaml.xml.schema.validator;
18
19 import org.opensaml.xml.schema.XSInteger;
20 import org.opensaml.xml.validation.ValidationException;
21 import org.opensaml.xml.validation.Validator;
22
23 /**
24 * Checks {@link org.opensaml.xml.schema.XSInteger} for Schema compliance.
25 *
26 * @param <T> the type to be validated
27 */
28 public class XSIntegerSchemaValidator<T extends XSInteger> implements Validator<T> {
29
30 /** Flag specifying whether empty element content should be allowed. */
31 private boolean allowEmptyContent;
32
33 /**
34 * Constructor.
35 *
36 * @param allowEmptyElementContent flag indicated whether empty content should be allowed
37 */
38 public XSIntegerSchemaValidator(boolean allowEmptyElementContent) {
39 allowEmptyContent = allowEmptyElementContent;
40 }
41
42 /**
43 * Constructor.
44 *
45 * Empty content is not allowed.
46 *
47 */
48 public XSIntegerSchemaValidator() {
49 allowEmptyContent = false;
50 }
51
52 /** {@inheritDoc} */
53 public void validate(T xmlObject) throws ValidationException {
54 validateIntegerContent(xmlObject);
55 }
56
57 /**
58 * Get the flag which determines whether empty content should be allowed.
59 *
60 * @return true if empty content should be allowed, false otherwise
61 */
62 protected boolean isAllowEmptyContent() {
63 return allowEmptyContent;
64 }
65
66 /**
67 * Validates the content of the XSBase64Binary object.
68 *
69 * @param xmlObject the object to evaluate
70 * @throws ValidationException thrown if the content of the Base64Binary object is invalid
71 */
72 protected void validateIntegerContent(T xmlObject) throws ValidationException {
73 if (! isAllowEmptyContent()) {
74 if (xmlObject.getValue() == null) {
75 throw new ValidationException("Integer content may not be empty");
76 }
77 }
78 }
79
80 }