001/* 002 * GeoAPI - Java interfaces for OGC/ISO standards 003 * http://www.geoapi.org 004 * 005 * Copyright (C) 2008-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.referencing; 033 034import java.util.Collection; 035 036import org.opengis.referencing.*; 037import org.opengis.referencing.cs.*; 038import org.opengis.referencing.crs.*; 039import org.opengis.referencing.datum.*; 040import org.opengis.referencing.operation.*; 041import org.opengis.parameter.GeneralParameterDescriptor; 042import org.opengis.metadata.Identifier; 043import org.opengis.util.GenericName; 044 045import org.opengis.test.Units; 046import org.opengis.test.Validator; 047import org.opengis.test.ValidatorContainer; 048import static org.opengis.test.Assert.*; 049 050 051/** 052 * Base class for validators of {@link IdentifiedObject} and related objects from the 053 * {@code org.opengis.referencing} package. 054 * 055 * <p>This class is provided for users wanting to override the validation methods. When the default 056 * behavior is sufficient, the {@link org.opengis.test.Validators} static methods provide a more 057 * convenient way to validate various kinds of objects.</p> 058 * 059 * @author Martin Desruisseaux (Geomatys) 060 * @version 3.1 061 * @since 2.2 062 */ 063public abstract class ReferencingValidator extends Validator { 064 /** 065 * Provider of units of measurement (degree, metre, second, <i>etc</i>). 066 * This field is set to the {@linkplain Units#getDefault() default provider} for now 067 * (it may be revisited in a future GeoAPI-conformance version). 068 */ 069 final Units units = Units.getDefault(); 070 071 /** 072 * Creates a new validator instance. 073 * 074 * @param container the set of validators to use for validating other kinds of objects 075 * (see {@linkplain #container field javadoc}). 076 * @param packageName the name of the package containing the classes to be validated. 077 */ 078 protected ReferencingValidator(final ValidatorContainer container, final String packageName) { 079 super(container, packageName); 080 } 081 082 /** 083 * For each interface implemented by the given object, invokes the corresponding 084 * {@code validate(…)} method defined in this package (if any). 085 * 086 * @param object the object to dispatch to {@code validate(…)} methods, or {@code null}. 087 */ 088 public final void dispatchObject(final IdentifiedObject object) { 089 int n = 0; 090 if (object != null) { 091 if (object instanceof CoordinateReferenceSystem) {container.validate((CoordinateReferenceSystem) object); n++;} 092 if (object instanceof CoordinateSystem) {container.validate((CoordinateSystem) object); n++;} 093 if (object instanceof CoordinateSystemAxis) {container.validate((CoordinateSystemAxis) object); n++;} 094 if (object instanceof Datum) {container.validate((Datum) object); n++;} 095 if (object instanceof Ellipsoid) {container.validate((Ellipsoid) object); n++;} 096 if (object instanceof PrimeMeridian) {container.validate((PrimeMeridian) object); n++;} 097 if (object instanceof GeneralParameterDescriptor) {container.validate((GeneralParameterDescriptor) object); n++;} 098 if (object instanceof CoordinateOperation) {container.validate((CoordinateOperation) object); n++;} 099 if (object instanceof OperationMethod) {container.validate((OperationMethod) object); n++;} 100 if (n == 0) { 101 if (object instanceof ReferenceSystem) { 102 validateReferenceSystem((ReferenceSystem) object); 103 } else { 104 validateIdentifiedObject(object); 105 } 106 } 107 } 108 } 109 110 /** 111 * Ensures that the given identifier has a {@linkplain Identifier#getCode() code}. 112 * 113 * @param object the object to validate, or {@code null}. 114 */ 115 public void validate(final Identifier object) { 116 container.validate(object); 117 } 118 119 /** 120 * Performs the validation that are common to all reference systems. This method is 121 * invoked by {@code validate} methods after they have determined the type of their 122 * argument. 123 * 124 * @param object the object to validate (can not be null). 125 */ 126 final void validateReferenceSystem(final ReferenceSystem object) { 127 validateIdentifiedObject(object); 128 container.validate(object.getScope()); 129 container.validate(object.getDomainOfValidity()); 130 } 131 132 /** 133 * Performs the validation that are common to all identified objects. This method is 134 * invoked by {@code validate} methods after they have determined the type of their 135 * argument. 136 * 137 * @param object the object to validate (can not be null). 138 */ 139 final void validateIdentifiedObject(final IdentifiedObject object) { 140 validate(object.getName()); 141 final Collection<? extends Identifier> identifiers = object.getIdentifiers(); 142 if (identifiers != null) { 143 validate(identifiers); 144 for (final Identifier id : identifiers) { 145 assertNotNull("IdentifiedObject: getIdentifiers() can not contain null element.", id); 146 validate(id); 147 } 148 } 149 final Collection<? extends GenericName> alias = object.getAlias(); 150 if (alias != null) { 151 validate(alias); 152 for (final GenericName name : alias) { 153 assertNotNull("IdentifiedObject: getAlias() can not contain null element.", alias); 154 container.validate(name); 155 } 156 } 157 container.validate(object.getRemarks()); 158 } 159}