1 /*
2 * Copyright 2008 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.XSDateTime;
20 import org.opensaml.xml.validation.ValidationException;
21 import org.opensaml.xml.validation.Validator;
22
23 /**
24 * Checks {@link org.opensaml.xml.schema.XSDateTime} for Schema compliance.
25 *
26 * @param <T> the type to be validated
27 */
28 public class XSDateTimeSchemaValidator<T extends XSDateTime> implements Validator<T> {
29 /** Flag specifying whether empty element content should be allowed. */
30 private boolean allowEmptyContent;
31
32 /**
33 * Constructor.
34 *
35 * @param allowEmptyContent flag indicated whether empty content should be allowed
36 */
37 public XSDateTimeSchemaValidator(boolean allowEmptyContent) {
38 this.allowEmptyContent = allowEmptyContent;
39 }
40
41 /** Constructor. */
42 public XSDateTimeSchemaValidator(){
43 allowEmptyContent = false;
44 }
45
46 /**
47 * Get the flag which determines whether empty content should be allowed.
48 *
49 * @return true if empty content should be allowed, false otherwise
50 */
51 protected boolean isAllowEmptyContent() {
52 return allowEmptyContent;
53 }
54
55 /** {@inheritDoc} */
56 public void validate(T xmlObject) throws ValidationException {
57 validateDateTimeContent(xmlObject);
58 }
59
60 /**
61 * Validates the content of the XSDateTime object.
62 *
63 * @param xmlObject the object to evaluate
64 * @throws ValidationException thrown if the content of the object is invalid
65 */
66 protected void validateDateTimeContent(T xmlObject) throws ValidationException{
67 if(!allowEmptyContent && xmlObject.getValue() == null){
68 throw new ValidationException("dateTime content may not be empty");
69 }
70 }
71
72 }