1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/developer/JAXBContextFactory.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,102 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, 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.ws.developer; 1.30 + 1.31 +import com.sun.istack.internal.NotNull; 1.32 +import com.sun.xml.internal.bind.api.JAXBRIContext; 1.33 +import com.sun.xml.internal.bind.api.TypeReference; 1.34 +import com.sun.xml.internal.ws.api.model.SEIModel; 1.35 + 1.36 +import javax.xml.bind.JAXBContext; 1.37 +import javax.xml.bind.JAXBException; 1.38 +import java.util.List; 1.39 + 1.40 +/** 1.41 + * Factory to create {@link JAXBContext}. 1.42 + * 1.43 + * <p> 1.44 + * JAX-WS uses JAXB to perform databinding when you use the service endpoint interface, and normally 1.45 + * the JAX-WS RI drives JAXB and creates a necessary {@link JAXBContext} automatically. 1.46 + * 1.47 + * <p> 1.48 + * This annotation is a JAX-WS RI vendor-specific feature, which lets applications create {@link JAXBRIContext} 1.49 + * (which is the JAXB RI's {@link JAXBContext} implementation.) 1.50 + * Combined with the JAXB RI vendor extensions defined in {@link JAXBRIContext}, appliation can use this to 1.51 + * fine-tune how the databinding happens, such as by adding more classes to the binding context, 1.52 + * by controlling the namespace mappings, and so on. 1.53 + * 1.54 + * <p> 1.55 + * Applications should either use {@link UsesJAXBContextFeature} or {@link UsesJAXBContext} to instruct 1.56 + * the JAX-WS runtime to use a custom factory. 1.57 + * 1.58 + * @author Kohsuke Kawaguchi 1.59 + * @since 2.1.5 1.60 + */ 1.61 +public interface JAXBContextFactory { 1.62 + /** 1.63 + * Called by the JAX-WS runtime to create a {@link JAXBRIContext} for the given SEI. 1.64 + * 1.65 + * @param sei 1.66 + * The {@link SEIModel} object being constructed. This object provides you access to 1.67 + * what SEI is being processed, and therefore useful if you are writing a generic 1.68 + * {@link JAXBContextFactory} that can work with arbitrary SEI classes. 1.69 + * 1.70 + * @param classesToBind 1.71 + * List of classes that needs to be bound by JAXB. This value is computed according to 1.72 + * the JAX-WS spec and given to you. 1.73 + * 1.74 + * The calling JAX-WS runtime expects the returned {@link JAXBRIContext} to be capable of 1.75 + * handling all these classes, but you can add more (which is more common), or remove some 1.76 + * (if you know what you are doing.) 1.77 + * 1.78 + * The callee is free to mutate this list. 1.79 + * 1.80 + * @param typeReferences 1.81 + * List of {@link TypeReference}s, which is also a part of the input to the JAXB RI to control 1.82 + * how the databinding happens. Most likely this will be just a pass-through to the 1.83 + * {@link JAXBRIContext#newInstance} method. 1.84 + * 1.85 + * @return 1.86 + * A non-null valid {@link JAXBRIContext} object. 1.87 + * 1.88 + * @throws JAXBException 1.89 + * If the callee encounters a fatal problem and wants to abort the JAX-WS runtime processing 1.90 + * of the given SEI, throw a {@link JAXBException}. This will cause the port instantiation 1.91 + * to fail (if on client), or the application deployment to fail (if on server.) 1.92 + */ 1.93 + @NotNull JAXBRIContext createJAXBContext(@NotNull SEIModel sei, @NotNull List<Class> classesToBind, @NotNull List<TypeReference> typeReferences) throws JAXBException; 1.94 + 1.95 + /** 1.96 + * The default implementation that creates {@link JAXBRIContext} according to the standard behavior. 1.97 + */ 1.98 + public static final JAXBContextFactory DEFAULT = new JAXBContextFactory() { 1.99 + @NotNull 1.100 + public JAXBRIContext createJAXBContext(@NotNull SEIModel sei, @NotNull List<Class> classesToBind, @NotNull List<TypeReference> typeReferences) throws JAXBException { 1.101 + return JAXBRIContext.newInstance(classesToBind.toArray(new Class[classesToBind.size()]), 1.102 + typeReferences, null, sei.getTargetNamespace(), false, null); 1.103 + } 1.104 + }; 1.105 +}