Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.bind; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.concurrent.Callable; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import javax.xml.bind.Unmarshaller; |
aoqi@0 | 31 | import javax.xml.bind.ValidationEventHandler; |
aoqi@0 | 32 | import javax.xml.bind.annotation.XmlIDREF; |
aoqi@0 | 33 | |
aoqi@0 | 34 | import org.xml.sax.SAXException; |
aoqi@0 | 35 | |
aoqi@0 | 36 | /** |
aoqi@0 | 37 | * Pluggable ID/IDREF handling layer. |
aoqi@0 | 38 | * |
aoqi@0 | 39 | * <p> |
aoqi@0 | 40 | * <b>THIS INTERFACE IS SUBJECT TO CHANGE WITHOUT NOTICE.</b> |
aoqi@0 | 41 | * |
aoqi@0 | 42 | * <p> |
aoqi@0 | 43 | * This 'interface' can be implemented by applications and specified to |
aoqi@0 | 44 | * {@link Unmarshaller#setProperty(String, Object)} to ovierride the ID/IDREF |
aoqi@0 | 45 | * processing of the JAXB RI like this: |
aoqi@0 | 46 | * |
aoqi@0 | 47 | * <pre> |
aoqi@0 | 48 | * unmarshaller.setProperty(IDResolver.class.getName(),new MyIDResolverImpl()); |
aoqi@0 | 49 | * </pre> |
aoqi@0 | 50 | * |
aoqi@0 | 51 | * <h2>Error Handling</h2> |
aoqi@0 | 52 | * <p> |
aoqi@0 | 53 | * This component runs inside the JAXB RI unmarshaller. Therefore, it needs |
aoqi@0 | 54 | * to coordinate with the JAXB RI unmarshaller when it comes to reporting |
aoqi@0 | 55 | * errors. This makes sure that applications see consistent error handling behaviors. |
aoqi@0 | 56 | * |
aoqi@0 | 57 | * <p> |
aoqi@0 | 58 | * When the {@link #startDocument(ValidationEventHandler)} method is invoked, |
aoqi@0 | 59 | * the unmarshaller passes in a {@link ValidationEventHandler} that can be used |
aoqi@0 | 60 | * by this component to report any errors encountered during the ID/IDREF processing. |
aoqi@0 | 61 | * |
aoqi@0 | 62 | * <p> |
aoqi@0 | 63 | * When an error is detected, the error should be first reported to this |
aoqi@0 | 64 | * {@link ValidationEventHandler}. If the error is fatal or the event handler |
aoqi@0 | 65 | * decided to abort, the implementation should throw a {@link SAXException}. |
aoqi@0 | 66 | * This signals the unmarshaller to abort the processing. |
aoqi@0 | 67 | * |
aoqi@0 | 68 | * @author Kohsuke Kawaguchi |
aoqi@0 | 69 | * @since JAXB 2.0 beta |
aoqi@0 | 70 | */ |
aoqi@0 | 71 | public abstract class IDResolver { |
aoqi@0 | 72 | |
aoqi@0 | 73 | /** |
aoqi@0 | 74 | * Called when the unmarshalling starts. |
aoqi@0 | 75 | * |
aoqi@0 | 76 | * <p> |
aoqi@0 | 77 | * Since one {@link Unmarshaller} may be used multiple times |
aoqi@0 | 78 | * to unmarshal documents, one {@link IDResolver} may be used multiple times, too. |
aoqi@0 | 79 | * |
aoqi@0 | 80 | * @param eventHandler |
aoqi@0 | 81 | * Any errors found during the unmarshalling should be reported to this object. |
aoqi@0 | 82 | */ |
aoqi@0 | 83 | public void startDocument(ValidationEventHandler eventHandler) throws SAXException { |
aoqi@0 | 84 | |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | /** |
aoqi@0 | 88 | * Called after the unmarshalling completes. |
aoqi@0 | 89 | * |
aoqi@0 | 90 | * <p> |
aoqi@0 | 91 | * This is a good opporunity to reset any internal state of this object, |
aoqi@0 | 92 | * so that it doesn't keep references to other objects unnecessarily. |
aoqi@0 | 93 | */ |
aoqi@0 | 94 | public void endDocument() throws SAXException { |
aoqi@0 | 95 | |
aoqi@0 | 96 | } |
aoqi@0 | 97 | |
aoqi@0 | 98 | /** |
aoqi@0 | 99 | * Binds the given object to the specified ID. |
aoqi@0 | 100 | * |
aoqi@0 | 101 | * <p> |
aoqi@0 | 102 | * While a document is being unmarshalled, every time |
aoqi@0 | 103 | * an ID value is found, this method is invoked to |
aoqi@0 | 104 | * remember the association between ID and objects. |
aoqi@0 | 105 | * This association is supposed to be used later to resolve |
aoqi@0 | 106 | * IDREFs. |
aoqi@0 | 107 | * |
aoqi@0 | 108 | * <p> |
aoqi@0 | 109 | * This method is invoked right away as soon as a new ID value is found. |
aoqi@0 | 110 | * |
aoqi@0 | 111 | * @param id |
aoqi@0 | 112 | * The ID value found in the document being unmarshalled. |
aoqi@0 | 113 | * Always non-null. |
aoqi@0 | 114 | * @param obj |
aoqi@0 | 115 | * The object being unmarshalled which is going to own the ID. |
aoqi@0 | 116 | * Always non-null. |
aoqi@0 | 117 | */ |
aoqi@0 | 118 | public abstract void bind( String id, Object obj ) throws SAXException; |
aoqi@0 | 119 | |
aoqi@0 | 120 | /** |
aoqi@0 | 121 | * Obtains the object to be pointed by the IDREF value. |
aoqi@0 | 122 | * |
aoqi@0 | 123 | * <p> |
aoqi@0 | 124 | * While a document is being unmarshalled, every time |
aoqi@0 | 125 | * an IDREF value is found, this method is invoked immediately to |
aoqi@0 | 126 | * obtain the object that the IDREF is pointing to. |
aoqi@0 | 127 | * |
aoqi@0 | 128 | * <p> |
aoqi@0 | 129 | * This method returns a {@link Callable} to support forward-references. |
aoqi@0 | 130 | * When this method returns with a non-null return value, |
aoqi@0 | 131 | * the JAXB RI unmarshaller invokes the {@link Callable#call()} method immediately. |
aoqi@0 | 132 | * If the implementation can find the target object (in which case |
aoqi@0 | 133 | * it was a backward reference), then a non-null object shall be returned, |
aoqi@0 | 134 | * and it is used as the target object. |
aoqi@0 | 135 | * |
aoqi@0 | 136 | * <p> |
aoqi@0 | 137 | * When a forward-reference happens, the <tt>call</tt> method |
aoqi@0 | 138 | * should return null. In this case the JAXB RI unmarshaller invokes |
aoqi@0 | 139 | * the <tt>call</tt> method again after all the documents are fully unmarshalled. |
aoqi@0 | 140 | * If the <tt>call</tt> method still returns null, then the JAXB RI unmarshaller |
aoqi@0 | 141 | * treats it as an error. |
aoqi@0 | 142 | * |
aoqi@0 | 143 | * <p> |
aoqi@0 | 144 | * A {@link Callable} object returned from this method may not throw |
aoqi@0 | 145 | * any exception other than a {@link SAXException} (which means a fatal error.) |
aoqi@0 | 146 | * |
aoqi@0 | 147 | * @param id |
aoqi@0 | 148 | * The IDREF value found in the document being unmarshalled. |
aoqi@0 | 149 | * Always non-null. |
aoqi@0 | 150 | * @param targetType |
aoqi@0 | 151 | * The expected type to which ID resolves to. JAXB infers this |
aoqi@0 | 152 | * information from the signature of the fields that has {@link XmlIDREF}. |
aoqi@0 | 153 | * When a property is a collection, this parameter will be the type |
aoqi@0 | 154 | * of the individual item in the collection. |
aoqi@0 | 155 | * @return |
aoqi@0 | 156 | * null if the implementation is sure that the parameter combination |
aoqi@0 | 157 | * will never yield a valid object. Otherwise non-null. |
aoqi@0 | 158 | */ |
aoqi@0 | 159 | public abstract Callable<?> resolve( String id, Class targetType ) throws SAXException; |
aoqi@0 | 160 | } |