001/* 002 * GeoAPI - Java interfaces for OGC/ISO standards 003 * Copyright © 2008-2024 Open Geospatial Consortium, Inc. 004 * http://www.geoapi.org 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.opengis.test.metadata; 019 020import org.opengis.metadata.citation.CitationDate; 021import org.opengis.metadata.maintenance.MaintenanceInformation; 022import org.opengis.metadata.maintenance.Scope; 023import org.opengis.test.ValidatorContainer; 024 025 026 027/** 028 * Validates objects from the {@code org.opengis.metadata.maintenance} package. 029 * 030 * <p>This class is provided for users wanting to override the validation methods. 031 * When the default behavior is sufficient, the {@link org.opengis.test.Validators} 032 * static methods provide a more convenient way to validate various kinds of objects.</p> 033 * 034 * @author Martin Desruisseaux (Geomatys) 035 * @version 3.1 036 * @since 3.1 037 */ 038public class MaintenanceValidator extends MetadataValidator { 039 /** 040 * Creates a new validator instance. 041 * 042 * @param container the set of validators to use for validating other kinds of objects 043 * (see {@linkplain #container field javadoc}). 044 */ 045 public MaintenanceValidator(final ValidatorContainer container) { 046 super(container, "org.opengis.metadata.maintenance"); 047 } 048 049 /** 050 * Validates the maintenance information. 051 * 052 * @param object the object to validate, or {@code null}. 053 */ 054 public void validate(final MaintenanceInformation object) { 055 if (object == null) { 056 return; 057 } 058 container.validate(toArray(CitationDate.class, object.getMaintenanceDates())); 059 for (Scope scope : toArray(Scope.class, object.getMaintenanceScopes())) { 060 validate(scope); 061 } 062 validate("maintenanceNote", object.getMaintenanceNotes(), ValidatorContainer::validate, false); 063 validate("contact", object.getContacts(), ValidatorContainer::validate, false); 064 } 065 066 /** 067 * Validates the scope. 068 * 069 * @param object the object to validate, or {@code null}. 070 */ 071 public void validate(final Scope object) { 072 if (object == null) { 073 return; 074 } 075 mandatory(object.getLevel(), "Scope: must have a level."); 076 validate("extent", object.getExtents(), ValidatorContainer::validate, false); 077 } 078}