src/share/jaxws_classes/com/sun/xml/internal/bind/v2/model/impl/RuntimeModelBuilder.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 450
b0c2840e2513
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

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

mercurial