Thu, 31 Aug 2017 15:18:52 +0800
merge
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.ws.developer;
28 import com.sun.istack.internal.NotNull;
29 import com.sun.xml.internal.bind.api.JAXBRIContext;
30 import com.sun.xml.internal.bind.api.TypeReference;
31 import com.sun.xml.internal.ws.api.model.SEIModel;
33 import javax.xml.bind.JAXBContext;
34 import javax.xml.bind.JAXBException;
35 import java.util.List;
37 /**
38 * Factory to create {@link JAXBContext}.
39 *
40 * <p>
41 * JAX-WS uses JAXB to perform databinding when you use the service endpoint interface, and normally
42 * the JAX-WS RI drives JAXB and creates a necessary {@link JAXBContext} automatically.
43 *
44 * <p>
45 * This annotation is a JAX-WS RI vendor-specific feature, which lets applications create {@link JAXBRIContext}
46 * (which is the JAXB RI's {@link JAXBContext} implementation.)
47 * Combined with the JAXB RI vendor extensions defined in {@link JAXBRIContext}, appliation can use this to
48 * fine-tune how the databinding happens, such as by adding more classes to the binding context,
49 * by controlling the namespace mappings, and so on.
50 *
51 * <p>
52 * Applications should either use {@link UsesJAXBContextFeature} or {@link UsesJAXBContext} to instruct
53 * the JAX-WS runtime to use a custom factory.
54 *
55 * @author Kohsuke Kawaguchi
56 * @since 2.1.5
57 */
58 public interface JAXBContextFactory {
59 /**
60 * Called by the JAX-WS runtime to create a {@link JAXBRIContext} for the given SEI.
61 *
62 * @param sei
63 * The {@link SEIModel} object being constructed. This object provides you access to
64 * what SEI is being processed, and therefore useful if you are writing a generic
65 * {@link JAXBContextFactory} that can work with arbitrary SEI classes.
66 *
67 * @param classesToBind
68 * List of classes that needs to be bound by JAXB. This value is computed according to
69 * the JAX-WS spec and given to you.
70 *
71 * The calling JAX-WS runtime expects the returned {@link JAXBRIContext} to be capable of
72 * handling all these classes, but you can add more (which is more common), or remove some
73 * (if you know what you are doing.)
74 *
75 * The callee is free to mutate this list.
76 *
77 * @param typeReferences
78 * List of {@link TypeReference}s, which is also a part of the input to the JAXB RI to control
79 * how the databinding happens. Most likely this will be just a pass-through to the
80 * {@link JAXBRIContext#newInstance} method.
81 *
82 * @return
83 * A non-null valid {@link JAXBRIContext} object.
84 *
85 * @throws JAXBException
86 * If the callee encounters a fatal problem and wants to abort the JAX-WS runtime processing
87 * of the given SEI, throw a {@link JAXBException}. This will cause the port instantiation
88 * to fail (if on client), or the application deployment to fail (if on server.)
89 */
90 @NotNull JAXBRIContext createJAXBContext(@NotNull SEIModel sei, @NotNull List<Class> classesToBind, @NotNull List<TypeReference> typeReferences) throws JAXBException;
92 /**
93 * The default implementation that creates {@link JAXBRIContext} according to the standard behavior.
94 */
95 public static final JAXBContextFactory DEFAULT = new JAXBContextFactory() {
96 @NotNull
97 public JAXBRIContext createJAXBContext(@NotNull SEIModel sei, @NotNull List<Class> classesToBind, @NotNull List<TypeReference> typeReferences) throws JAXBException {
98 return JAXBRIContext.newInstance(classesToBind.toArray(new Class[classesToBind.size()]),
99 typeReferences, null, sei.getTargetNamespace(), false, null);
100 }
101 };
102 }