1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/api/ClassResolver.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,104 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.bind.api; 1.30 + 1.31 +import javax.xml.bind.JAXBContext; 1.32 +import javax.xml.bind.Unmarshaller; 1.33 +import javax.xml.bind.ValidationEventHandler; 1.34 +import javax.xml.bind.annotation.XmlAnyElement; 1.35 + 1.36 +import com.sun.istack.internal.NotNull; 1.37 +import com.sun.istack.internal.Nullable; 1.38 + 1.39 +/** 1.40 + * Dynamically locates classes to represent elements discovered during the unmarshalling. 1.41 + * 1.42 + * <p> 1.43 + * <b>THIS INTERFACE IS SUBJECT TO CHANGE WITHOUT NOTICE.</b> 1.44 + * 1.45 + * <h2>Background</h2> 1.46 + * <p> 1.47 + * {@link JAXBContext#newInstance(Class...)} requires that application informs JAXB 1.48 + * about all the classes that it may see in the instance document. While this allows 1.49 + * JAXB to take time to optimize the unmarshalling, it is sometimes inconvenient 1.50 + * for applications. 1.51 + * 1.52 + * <p> 1.53 + * This is where {@link ClassResolver} comes to resucue. 1.54 + * 1.55 + * <p> 1.56 + * A {@link ClassResolver} instance can be specified on {@link Unmarshaller} via 1.57 + * {@link Unmarshaller#setProperty(String, Object)} as follows: 1.58 + * 1.59 + * <pre> 1.60 + * unmarshaller.setProperty( ClassResolver.class.getName(), new MyClassResolverImpl() ); 1.61 + * </pre> 1.62 + * 1.63 + * <p> 1.64 + * When an {@link Unmarshaller} encounters (i) an unknown root element or (ii) unknown 1.65 + * elements where unmarshaller is trying to unmarshal into {@link XmlAnyElement} with 1.66 + * <tt>lax=true</tt>, unmarshaller calls {@link #resolveElementName(String, String)} 1.67 + * method to see if the application may be able to supply a class that corresponds 1.68 + * to that class. 1.69 + * 1.70 + * <p> 1.71 + * When a {@link Class} is returned, a new {@link JAXBContext} is created with 1.72 + * all the classes known to it so far, plus a new class returned. This operation 1.73 + * may fail (for example because of some conflicting annotations.) This failure 1.74 + * is handled just like {@link Exception}s thrown from 1.75 + * {@link ClassResolver#resolveElementName(String, String)}. 1.76 + * 1.77 + * @author Kohsuke Kawaguchi 1.78 + * @since 2.1 1.79 + */ 1.80 +public abstract class ClassResolver { 1.81 + /** 1.82 + * JAXB calls this method when it sees an unknown element. 1.83 + * 1.84 + * <p> 1.85 + * See the class javadoc for details. 1.86 + * 1.87 + * @param nsUri 1.88 + * Namespace URI of the unknown element. Can be empty but never null. 1.89 + * @param localName 1.90 + * Local name of the unknown element. Never be empty nor null. 1.91 + * 1.92 + * @return 1.93 + * If a non-null class is returned, it will be used to unmarshal this element. 1.94 + * If null is returned, the resolution is assumed to be failed, and 1.95 + * the unmarshaller will behave as if there was no {@link ClassResolver} 1.96 + * to begin with (that is, to report it to {@link ValidationEventHandler}, 1.97 + * then move on.) 1.98 + * 1.99 + * @throws Exception 1.100 + * Throwing any {@link RuntimeException} causes the unmarshaller to stop 1.101 + * immediately. The exception will be propagated up the call stack. 1.102 + * Throwing any other checked {@link Exception} results in the error 1.103 + * reproted to {@link ValidationEventHandler} (just like any other error 1.104 + * during the unmarshalling.) 1.105 + */ 1.106 + public abstract @Nullable Class<?> resolveElementName(@NotNull String nsUri, @NotNull String localName) throws Exception; 1.107 +}