001/* 002 * GeoAPI - Java interfaces for OGC/ISO standards 003 * http://www.geoapi.org 004 * 005 * Copyright (C) 2012-2019 Open Geospatial Consortium, Inc. 006 * All Rights Reserved. http://www.opengeospatial.org/ogc/legal 007 * 008 * Permission to use, copy, and modify this software and its documentation, with 009 * or without modification, for any purpose and without fee or royalty is hereby 010 * granted, provided that you include the following on ALL copies of the software 011 * and documentation or portions thereof, including modifications, that you make: 012 * 013 * 1. The full text of this NOTICE in a location viewable to users of the 014 * redistributed or derivative work. 015 * 2. Notice of any changes or modifications to the OGC files, including the 016 * date changes were made. 017 * 018 * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE 019 * NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 020 * TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT 021 * THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY 022 * PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. 023 * 024 * COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR 025 * CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION. 026 * 027 * The name and trademarks of copyright holders may NOT be used in advertising or 028 * publicity pertaining to the software without specific, written prior permission. 029 * Title to copyright in this software and any associated documentation will at all 030 * times remain with copyright holders. 031 */ 032package org.opengis.test.metadata; 033 034import java.util.Date; 035import java.util.Collection; 036import org.opengis.metadata.*; 037import org.opengis.metadata.citation.*; 038import org.opengis.metadata.identification.*; 039import org.opengis.test.ValidatorContainer; 040 041 042/** 043 * Validates {@link Metadata} and related objects from the {@code org.opengis.metadata} package. 044 * This validator is named {@code MetadataBaseValidator} for consistency with the {@code "mdb"} 045 * namespace in XML schema. {@link Metadata} is usually the root of the metadata tree. 046 * 047 * <p>This class is provided for users wanting to override the validation methods. When the default 048 * behavior is sufficient, the {@link org.opengis.test.Validators} static methods provide a more 049 * convenient way to validate various kinds of objects.</p> 050 * 051 * @author Martin Desruisseaux (Geomatys) 052 * @version 3.1 053 * @since 3.1 054 */ 055public class MetadataBaseValidator extends MetadataValidator { 056 /** 057 * Creates a new validator instance. 058 * 059 * @param container the set of validators to use for validating other kinds of objects 060 * (see {@linkplain #container field javadoc}). 061 */ 062 public MetadataBaseValidator(final ValidatorContainer container) { 063 super(container, "org.opengis.metadata"); 064 } 065 066 /** 067 * Validates the given metadata. 068 * 069 * @param object the object to validate, or {@code null}. 070 */ 071 public void validate(final Metadata object) { 072 if (object == null) { 073 return; 074 } 075 validate(object.getMetadataIdentifier()); 076 container.validate(object.getParentMetadata()); 077 for (final MetadataScope scope : toArray(MetadataScope.class, object.getMetadataScopes())) { 078 mandatory("Metadata: shall have a scope code.", scope.getResourceScope()); 079 } 080 for (final Responsibility e : toArray(Responsibility.class, object.getContacts())) { 081 container.validate(e); 082 } 083 084 final CitationDate[] dates = toArray(CitationDate.class, object.getDateInfo()); 085 container.validate(dates); 086 Date creationDate = null; 087 for (final CitationDate date : dates) { 088 if (DateType.CREATION.equals(date.getDateType())) { 089 creationDate = date.getDate(); 090 if (creationDate != null) break; 091 } 092 } 093 mandatory("Metadata: shall have a creation date.", creationDate); 094 095 for (final Citation e : toArray(Citation.class, object.getMetadataStandards())) { 096 container.validate(e); 097 } 098 for (final Citation e : toArray(Citation.class, object.getMetadataProfiles())) { 099 container.validate(e); 100 } 101 for (final Citation e : toArray(Citation.class, object.getAlternativeMetadataReferences())) { 102 container.validate(e); 103 } 104 for (final OnlineResource e : toArray(OnlineResource.class, object.getMetadataLinkages())) { 105 container.validate(e); 106 } 107 validate(object.getSpatialRepresentationInfo()); 108 validate(object.getReferenceSystemInfo()); 109 validate(object.getMetadataExtensionInfo()); 110 111 final Collection<? extends Identification> identifications = object.getIdentificationInfo(); 112 mandatory("Metadata: shall have an identification information.", 113 (identifications != null && identifications.isEmpty()) ? null : identifications); 114 validate(identifications); 115 116 validate(object.getContentInfo()); 117 validate(object.getDataQualityInfo()); 118 validate(object.getPortrayalCatalogueInfo()); 119 validate(object.getMetadataConstraints()); 120 validate(object.getApplicationSchemaInfo()); 121 validate(object.getAcquisitionInformation()); 122 validate(object.getResourceLineages()); 123 } 124 125 /** 126 * Validates the given identifier. 127 * 128 * @param object the identifier to validate, or {@code null}. 129 */ 130 public void validate(final Identifier object) { 131 if (object == null) { 132 return; 133 } 134 mandatory("Identifier: shall have a code.", object.getCode()); 135 final Citation citation = object.getAuthority(); 136 if (citation != this) { // Avoid never ending loop (TODO: find a better way). 137 container.validate(citation); 138 } 139 } 140}