src/share/jaxws_classes/javax/xml/bind/Validator.java

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 397
b99d7e355d4b
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

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

mercurial