Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
1 /*
2 * Copyright (c) 1997, 2011, 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.bind.v2.model.impl;
28 import java.lang.reflect.Field;
29 import java.lang.reflect.Method;
30 import java.lang.reflect.Type;
31 import java.util.Map;
33 import javax.activation.MimeType;
35 import com.sun.xml.internal.bind.WhiteSpaceProcessor;
36 import com.sun.xml.internal.bind.api.AccessorException;
37 import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
38 import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader;
39 import com.sun.xml.internal.bind.v2.model.core.ID;
40 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
41 import com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator;
42 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
43 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElementRef;
44 import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
45 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet;
46 import com.sun.xml.internal.bind.v2.runtime.FilterTransducer;
47 import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
48 import com.sun.xml.internal.bind.v2.runtime.InlineBinaryTransducer;
49 import com.sun.xml.internal.bind.v2.runtime.MimeTypedTransducer;
50 import com.sun.xml.internal.bind.v2.runtime.SchemaTypeTransducer;
51 import com.sun.xml.internal.bind.v2.runtime.Transducer;
52 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
53 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
54 import com.sun.istack.internal.Nullable;
56 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
57 import javax.xml.namespace.QName;
58 import org.xml.sax.SAXException;
60 /**
61 * {@link ModelBuilder} that works at the run-time by using
62 * the {@code java.lang.reflect} package.
63 *
64 * <p>
65 * This extends {@link ModelBuilder} by providing more functionalities such
66 * as accessing the fields and classes.
67 *
68 * @author Kohsuke Kawaguchi (kk@kohsuke.org)
69 */
70 public class RuntimeModelBuilder extends ModelBuilder<Type,Class,Field,Method> {
71 /**
72 * The {@link JAXBContextImpl} for which the model is built.
73 * Null when created for reflection.
74 */
75 public final @Nullable JAXBContextImpl context;
77 public RuntimeModelBuilder(JAXBContextImpl context, RuntimeAnnotationReader annotationReader, Map<Class, Class> subclassReplacements, String defaultNamespaceRemap) {
78 super(annotationReader, Navigator.REFLECTION, subclassReplacements, defaultNamespaceRemap);
79 this.context = context;
80 }
82 @Override
83 public RuntimeNonElement getClassInfo( Class clazz, Locatable upstream ) {
84 return (RuntimeNonElement)super.getClassInfo(clazz,upstream);
85 }
87 @Override
88 public RuntimeNonElement getClassInfo( Class clazz, boolean searchForSuperClass, Locatable upstream ) {
89 return (RuntimeNonElement)super.getClassInfo(clazz,searchForSuperClass,upstream);
90 }
92 @Override
93 protected RuntimeEnumLeafInfoImpl createEnumLeafInfo(Class clazz, Locatable upstream) {
94 return new RuntimeEnumLeafInfoImpl(this,upstream,clazz);
95 }
97 @Override
98 protected RuntimeClassInfoImpl createClassInfo( Class clazz, Locatable upstream ) {
99 return new RuntimeClassInfoImpl(this,upstream,clazz);
100 }
102 @Override
103 public RuntimeElementInfoImpl createElementInfo(RegistryInfoImpl<Type,Class,Field,Method> registryInfo, Method method) throws IllegalAnnotationException {
104 return new RuntimeElementInfoImpl(this,registryInfo, method);
105 }
107 @Override
108 public RuntimeArrayInfoImpl createArrayInfo(Locatable upstream, Type arrayType) {
109 return new RuntimeArrayInfoImpl(this, upstream, (Class)arrayType);
110 }
112 public ReflectionNavigator getNavigator() {
113 return (ReflectionNavigator)nav;
114 }
116 @Override
117 protected RuntimeTypeInfoSetImpl createTypeInfoSet() {
118 return new RuntimeTypeInfoSetImpl(reader);
119 }
121 @Override
122 public RuntimeTypeInfoSet link() {
123 return (RuntimeTypeInfoSet)super.link();
124 }
126 /**
127 * Creates a {@link Transducer} given a reference.
128 *
129 * Used to implement {@link RuntimeNonElementRef#getTransducer()}.
130 * Shouldn't be called from anywhere else.
131 *
132 * TODO: this is not the proper place for this class to be in.
133 */
134 public static Transducer createTransducer(RuntimeNonElementRef ref) {
135 Transducer t = ref.getTarget().getTransducer();
136 RuntimePropertyInfo src = ref.getSource();
137 ID id = src.id();
139 if(id==ID.IDREF)
140 return RuntimeBuiltinLeafInfoImpl.STRING;
142 if(id==ID.ID)
143 t = new IDTransducerImpl(t);
145 MimeType emt = src.getExpectedMimeType();
146 if(emt!=null)
147 t = new MimeTypedTransducer(t,emt);
149 if(src.inlineBinaryData())
150 t = new InlineBinaryTransducer(t);
152 if(src.getSchemaType()!=null) {
153 if (src.getSchemaType().equals(createXSSimpleType())) {
154 return RuntimeBuiltinLeafInfoImpl.STRING;
155 }
156 t = new SchemaTypeTransducer(t,src.getSchemaType());
157 }
159 return t;
160 }
162 private static QName createXSSimpleType() {
163 return new QName(WellKnownNamespace.XML_SCHEMA,"anySimpleType");
164 }
166 /**
167 * Transducer implementation for ID.
168 *
169 * This transducer wraps another {@link Transducer} and adds
170 * handling for ID.
171 */
172 private static final class IDTransducerImpl<ValueT> extends FilterTransducer<ValueT> {
173 public IDTransducerImpl(Transducer<ValueT> core) {
174 super(core);
175 }
177 @Override
178 public ValueT parse(CharSequence lexical) throws AccessorException, SAXException {
179 String value = WhiteSpaceProcessor.trim(lexical).toString();
180 UnmarshallingContext.getInstance().addToIdTable(value);
181 return core.parse(value);
182 }
183 }
184 }