src/share/jaxws_classes/com/sun/xml/internal/bind/IDResolver.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/IDResolver.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,160 @@
     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;
    1.30 +
    1.31 +import java.util.concurrent.Callable;
    1.32 +
    1.33 +import javax.xml.bind.Unmarshaller;
    1.34 +import javax.xml.bind.ValidationEventHandler;
    1.35 +import javax.xml.bind.annotation.XmlIDREF;
    1.36 +
    1.37 +import org.xml.sax.SAXException;
    1.38 +
    1.39 +/**
    1.40 + * Pluggable ID/IDREF handling layer.
    1.41 + *
    1.42 + * <p>
    1.43 + * <b>THIS INTERFACE IS SUBJECT TO CHANGE WITHOUT NOTICE.</b>
    1.44 + *
    1.45 + * <p>
    1.46 + * This 'interface' can be implemented by applications and specified to
    1.47 + * {@link Unmarshaller#setProperty(String, Object)} to ovierride the ID/IDREF
    1.48 + * processing of the JAXB RI like this:
    1.49 + *
    1.50 + * <pre>
    1.51 + * unmarshaller.setProperty(IDResolver.class.getName(),new MyIDResolverImpl());
    1.52 + * </pre>
    1.53 + *
    1.54 + * <h2>Error Handling</h2>
    1.55 + * <p>
    1.56 + * This component runs inside the JAXB RI unmarshaller. Therefore, it needs
    1.57 + * to coordinate with the JAXB RI unmarshaller when it comes to reporting
    1.58 + * errors. This makes sure that applications see consistent error handling behaviors.
    1.59 + *
    1.60 + * <p>
    1.61 + * When the {@link #startDocument(ValidationEventHandler)} method is invoked,
    1.62 + * the unmarshaller passes in a {@link ValidationEventHandler} that can be used
    1.63 + * by this component to report any errors encountered during the ID/IDREF processing.
    1.64 + *
    1.65 + * <p>
    1.66 + * When an error is detected, the error should be first reported to this
    1.67 + * {@link ValidationEventHandler}. If the error is fatal or the event handler
    1.68 + * decided to abort, the implementation should throw a {@link SAXException}.
    1.69 + * This signals the unmarshaller to abort the processing.
    1.70 + *
    1.71 + * @author Kohsuke Kawaguchi
    1.72 + * @since JAXB 2.0 beta
    1.73 + */
    1.74 +public abstract class IDResolver {
    1.75 +
    1.76 +    /**
    1.77 +     * Called when the unmarshalling starts.
    1.78 +     *
    1.79 +     * <p>
    1.80 +     * Since one {@link Unmarshaller} may be used multiple times
    1.81 +     * to unmarshal documents, one {@link IDResolver} may be used multiple times, too.
    1.82 +     *
    1.83 +     * @param eventHandler
    1.84 +     *      Any errors found during the unmarshalling should be reported to this object.
    1.85 +     */
    1.86 +    public void startDocument(ValidationEventHandler eventHandler) throws SAXException {
    1.87 +
    1.88 +    }
    1.89 +
    1.90 +    /**
    1.91 +     * Called after the unmarshalling completes.
    1.92 +     *
    1.93 +     * <p>
    1.94 +     * This is a good opporunity to reset any internal state of this object,
    1.95 +     * so that it doesn't keep references to other objects unnecessarily.
    1.96 +     */
    1.97 +    public void endDocument() throws SAXException {
    1.98 +
    1.99 +    }
   1.100 +
   1.101 +    /**
   1.102 +     * Binds the given object to the specified ID.
   1.103 +     *
   1.104 +     * <p>
   1.105 +     * While a document is being unmarshalled, every time
   1.106 +     * an ID value is found, this method is invoked to
   1.107 +     * remember the association between ID and objects.
   1.108 +     * This association is supposed to be used later to resolve
   1.109 +     * IDREFs.
   1.110 +     *
   1.111 +     * <p>
   1.112 +     * This method is invoked right away as soon as a new ID value is found.
   1.113 +     *
   1.114 +     * @param id
   1.115 +     *      The ID value found in the document being unmarshalled.
   1.116 +     *      Always non-null.
   1.117 +     * @param obj
   1.118 +     *      The object being unmarshalled which is going to own the ID.
   1.119 +     *      Always non-null.
   1.120 +     */
   1.121 +    public abstract void bind( String id, Object obj ) throws SAXException;
   1.122 +
   1.123 +    /**
   1.124 +     * Obtains the object to be pointed by the IDREF value.
   1.125 +     *
   1.126 +     * <p>
   1.127 +     * While a document is being unmarshalled, every time
   1.128 +     * an IDREF value is found, this method is invoked immediately to
   1.129 +     * obtain the object that the IDREF is pointing to.
   1.130 +     *
   1.131 +     * <p>
   1.132 +     * This method returns a {@link Callable} to support forward-references.
   1.133 +     * When this method returns with a non-null return value,
   1.134 +     * the JAXB RI unmarshaller invokes the {@link Callable#call()} method immediately.
   1.135 +     * If the implementation can find the target object (in which case
   1.136 +     * it was a backward reference), then a non-null object shall be returned,
   1.137 +     * and it is used as the target object.
   1.138 +     *
   1.139 +     * <p>
   1.140 +     * When a forward-reference happens, the <tt>call</tt> method
   1.141 +     * should return null. In this case the JAXB RI unmarshaller invokes
   1.142 +     * the <tt>call</tt> method again after all the documents are fully unmarshalled.
   1.143 +     * If the <tt>call</tt> method still returns null, then the JAXB RI unmarshaller
   1.144 +     * treats it as an error.
   1.145 +     *
   1.146 +     * <p>
   1.147 +     * A {@link Callable} object returned from this method may not throw
   1.148 +     * any exception other than a {@link SAXException} (which means a fatal error.)
   1.149 +     *
   1.150 +     * @param id
   1.151 +     *      The IDREF value found in the document being unmarshalled.
   1.152 +     *      Always non-null.
   1.153 +     * @param targetType
   1.154 +     *      The expected type to which ID resolves to. JAXB infers this
   1.155 +     *      information from the signature of the fields that has {@link XmlIDREF}.
   1.156 +     *      When a property is a collection, this parameter will be the type
   1.157 +     *      of the individual item in the collection.
   1.158 +     * @return
   1.159 +     *      null if the implementation is sure that the parameter combination
   1.160 +     *      will never yield a valid object. Otherwise non-null.
   1.161 +     */
   1.162 +    public abstract Callable<?> resolve( String id, Class targetType ) throws SAXException;
   1.163 +}

mercurial