1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
/* * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.xml.bind; /** * As of JAXB 2.0, this class is deprecated and optional. * <p> * The <tt>Validator</tt> class is responsible for controlling the validation * of content trees during runtime. * * <p> * <a name="validationtypes"></a> * <b>Three Forms of Validation</b><br> * <blockquote> * <dl> * <dt><b>Unmarshal-Time Validation</b></dt> * <dd>This form of validation enables a client application to receive * information about validation errors and warnings detected while * unmarshalling XML data into a Java content tree and is completely * orthogonal to the other types of validation. To enable or disable * it, see the javadoc for * {@link Unmarshaller#setValidating(boolean) Unmarshaller.setValidating}. * All JAXB 1.0 Providers are required to support this operation. * </dd> * * <dt><b>On-Demand Validation</b></dt> * <dd> This form of validation enables a client application to receive * information about validation errors and warnings detected in the * Java content tree. At any point, client applications can call * the {@link Validator#validate(Object) Validator.validate} method * on the Java content tree (or any sub-tree of it). All JAXB 1.0 * Providers are required to support this operation. * </dd> * * <dt><b>Fail-Fast Validation</b></dt> * <dd> This form of validation enables a client application to receive * immediate feedback about modifications to the Java content tree * that violate type constraints on Java Properties as defined in * the specification. JAXB Providers are not required support * this type of validation. Of the JAXB Providers that do support * this type of validation, some may require you to decide at schema * compile time whether or not a client application will be allowed * to request fail-fast validation at runtime. * </dd> * </dl> * </blockquote> * * <p> * The <tt>Validator</tt> class is responsible for managing On-Demand Validation. * The <tt>Unmarshaller</tt> class is responsible for managing Unmarshal-Time * Validation during the unmarshal operations. Although there is no formal * method of enabling validation during the marshal operations, the * <tt>Marshaller</tt> may detect errors, which will be reported to the * <tt>ValidationEventHandler</tt> registered on it. * * <p> * <a name="defaulthandler"></a> * <b>Using the Default EventHandler</b><br> * <blockquote> * If the client application does not set an event handler on their * <tt>Validator</tt>, <tt>Unmarshaller</tt>, or <tt>Marshaller</tt> prior to * calling the validate, unmarshal, or marshal methods, then a default event * handler will receive notification of any errors or warnings encountered. * The default event handler will cause the current operation to halt after * encountering the first error or fatal error (but will attempt to continue * after receiving warnings). * </blockquote> * * <p> * <a name="handlingevents"></a> * <b>Handling Validation Events</b><br> * <blockquote> * There are three ways to handle events encountered during the unmarshal, * validate, and marshal operations: * <dl> * <dt>Use the default event handler</dt> * <dd>The default event handler will be used if you do not specify one * via the <tt>setEventHandler</tt> API's on <tt>Validator</tt>, * <tt>Unmarshaller</tt>, or <tt>Marshaller</tt>. * </dd> * * <dt>Implement and register a custom event handler</dt> * <dd>Client applications that require sophisticated event processing * can implement the <tt>ValidationEventHandler</tt> interface and * register it with the <tt>Unmarshaller</tt> and/or * <tt>Validator</tt>. * </dd> * * <dt>Use the {@link javax.xml.bind.util.ValidationEventCollector ValidationEventCollector} * utility</dt> * <dd>For convenience, a specialized event handler is provided that * simply collects any <tt>ValidationEvent</tt> objects created * during the unmarshal, validate, and marshal operations and * returns them to the client application as a * <tt>java.util.Collection</tt>. * </dd> * </dl> * </blockquote> * * <p> * <b>Validation and Well-Formedness</b><br> * <blockquote> * <p> * Validation events are handled differently depending on how the client * application is configured to process them as described in the previous * section. However, there are certain cases where a JAXB Provider indicates * that it is no longer able to reliably detect and report errors. In these * cases, the JAXB Provider will set the severity of the ValidationEvent to * FATAL_ERROR to indicate that the unmarshal, validate, or marshal operations * should be terminated. The default event handler and * <tt>ValidationEventCollector</tt> utility class must terminate processing * after being notified of a fatal error. Client applications that supply their * own <tt>ValidationEventHandler</tt> should also terminate processing after * being notified of a fatal error. If not, unexpected behaviour may occur. * </blockquote> * * <p> * <a name="supportedProps"></a> * <b>Supported Properties</b><br> * <blockquote> * <p> * There currently are not any properties required to be supported by all * JAXB Providers on Validator. However, some providers may support * their own set of provider specific properties. * </blockquote> * * * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Joe Fialli, Sun Microsystems, Inc.</li></ul> * @version $Revision: 1.3 $ $Date: 2005/06/06 15:04:03 $ * @see JAXBContext * @see Unmarshaller * @see ValidationEventHandler * @see ValidationEvent * @see javax.xml.bind.util.ValidationEventCollector * @since JAXB1.0 * @deprecated since JAXB 2.0 */ public interface Validator { /** * Allow an application to register a validation event handler. * <p> * The validation event handler will be called by the JAXB Provider if any * validation errors are encountered during calls to * {@link #validate(Object) validate}. If the client application does not * register a validation event handler before invoking the validate method, * then validation events will be handled by the default event handler which * will terminate the validate operation after the first error or fatal error * is encountered. * <p> * Calling this method with a null parameter will cause the Validator * to revert back to the default default event handler. * * @param handler the validation event handler * @throws JAXBException if an error was encountered while setting the * event handler * @deprecated since JAXB2.0 */ public void setEventHandler( ValidationEventHandler handler ) throws JAXBException; /** * Return the current event handler or the default event handler if one * hasn't been set. * * @return the current ValidationEventHandler or the default event handler * if it hasn't been set * @throws JAXBException if an error was encountered while getting the * current event handler * @deprecated since JAXB2.0 */ public ValidationEventHandler getEventHandler() throws JAXBException; /** * Validate the Java content tree starting at <tt>subrootObj</tt>. * <p> * Client applications can use this method to validate Java content trees * on-demand at runtime. This method can be used to validate any arbitrary * subtree of the Java content tree. Global constraint checking <b>will not * </b> be performed as part of this operation (i.e. ID/IDREF constraints). * * @param subrootObj the obj to begin validation at * @throws JAXBException if any unexpected problem occurs during validation * @throws ValidationException * If the {@link ValidationEventHandler ValidationEventHandler} * returns false from its <tt>handleEvent</tt> method or the * <tt>Validator</tt> is unable to validate the content tree rooted * at <tt>subrootObj</tt> * @throws IllegalArgumentException * If the subrootObj parameter is null * @return true if the subtree rooted at <tt>subrootObj</tt> is valid, false * otherwise * @deprecated since JAXB2.0 */ public boolean validate( Object subrootObj ) throws JAXBException; /** * Validate the Java content tree rooted at <tt>rootObj</tt>. * <p> * Client applications can use this method to validate Java content trees * on-demand at runtime. This method is used to validate an entire Java * content tree. Global constraint checking <b>will</b> be performed as * part of this operation (i.e. ID/IDREF constraints). * * @param rootObj the root obj to begin validation at * @throws JAXBException if any unexpected problem occurs during validation * @throws ValidationException * If the {@link ValidationEventHandler ValidationEventHandler} * returns false from its <tt>handleEvent</tt> method or the * <tt>Validator</tt> is unable to validate the content tree rooted * at <tt>rootObj</tt> * @throws IllegalArgumentException * If the rootObj parameter is null * @return true if the tree rooted at <tt>rootObj</tt> is valid, false * otherwise * @deprecated since JAXB2.0 */ public boolean validateRoot( Object rootObj ) throws JAXBException; /** * Set the particular property in the underlying implementation of * <tt>Validator</tt>. This method can only be used to set one of * the standard JAXB defined properties above or a provider specific * property. Attempting to set an undefined property will result in * a PropertyException being thrown. See <a href="#supportedProps"> * Supported Properties</a>. * * @param name the name of the property to be set. This value can either * be specified using one of the constant fields or a user * supplied string. * @param value the value of the property to be set * * @throws PropertyException when there is an error processing the given * property or value * @throws IllegalArgumentException * If the name parameter is null * @deprecated since JAXB2.0 */ public void setProperty( String name, Object value ) throws PropertyException; /** * Get the particular property in the underlying implementation of * <tt>Validator</tt>. This method can only be used to get one of * the standard JAXB defined properties above or a provider specific * property. Attempting to get an undefined property will result in * a PropertyException being thrown. See <a href="#supportedProps"> * Supported Properties</a>. * * @param name the name of the property to retrieve * @return the value of the requested property * * @throws PropertyException * when there is an error retrieving the given property or value * property name * @throws IllegalArgumentException * If the name parameter is null * @deprecated since JAXB2.0 */ public Object getProperty( String name ) throws PropertyException; }