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

Fri, 22 Nov 2013 21:11:19 +0100

author
mkos
date
Fri, 22 Nov 2013 21:11:19 +0100
changeset 450
b0c2840e2513
parent 0
373ffda63c9a
permissions
-rw-r--r--

8010935: Better XML handling
8027378: Two closed/javax/xml/8005432 fails with jdk7u51b04
8028382: Two javax/xml/8005433 tests still fail after the fix JDK-8028147
Summary: base fix + fixes for test regressions; fix also reviewed by Maxim Soloviev, Alexander Fomin
Reviewed-by: mchung, mgrebac, mullan

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 javax.xml.bind.annotation.XmlRootElement;
aoqi@0 29 import javax.xml.bind.annotation.XmlSchema;
aoqi@0 30 import javax.xml.bind.annotation.XmlType;
aoqi@0 31 import javax.xml.namespace.QName;
aoqi@0 32
aoqi@0 33 import com.sun.xml.internal.bind.api.impl.NameConverter;
aoqi@0 34 import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
aoqi@0 35 import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
aoqi@0 36 import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
aoqi@0 37 import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
aoqi@0 38 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
aoqi@0 39
aoqi@0 40 /**
aoqi@0 41 * Common implementation between {@link ClassInfoImpl} and {@link ElementInfoImpl}.
aoqi@0 42 *
aoqi@0 43 * @author Kohsuke Kawaguchi
aoqi@0 44 */
aoqi@0 45 abstract class TypeInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
aoqi@0 46 implements TypeInfo<TypeT,ClassDeclT>, Locatable {
aoqi@0 47
aoqi@0 48 /**
aoqi@0 49 * The Java class that caused this Java class to be a part of the JAXB processing.
aoqi@0 50 *
aoqi@0 51 * null if it's specified explicitly by the user.
aoqi@0 52 */
aoqi@0 53 private final Locatable upstream;
aoqi@0 54
aoqi@0 55 /**
aoqi@0 56 * {@link TypeInfoSet} to which this class belongs.
aoqi@0 57 */
aoqi@0 58 protected final TypeInfoSetImpl<TypeT,ClassDeclT,FieldT,MethodT> owner;
aoqi@0 59
aoqi@0 60 /**
aoqi@0 61 * Reference to the {@link ModelBuilder}, only until we link {@link TypeInfo}s all together,
aoqi@0 62 * because we don't want to keep {@link ModelBuilder} too long.
aoqi@0 63 */
aoqi@0 64 protected ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder;
aoqi@0 65
aoqi@0 66 protected TypeInfoImpl(
aoqi@0 67 ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder,
aoqi@0 68 Locatable upstream) {
aoqi@0 69
aoqi@0 70 this.builder = builder;
aoqi@0 71 this.owner = builder.typeInfoSet;
aoqi@0 72 this.upstream = upstream;
aoqi@0 73 }
aoqi@0 74
aoqi@0 75 public Locatable getUpstream() {
aoqi@0 76 return upstream;
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 /*package*/ void link() {
aoqi@0 80 builder = null;
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 protected final Navigator<TypeT,ClassDeclT,FieldT,MethodT> nav() {
aoqi@0 84 return owner.nav;
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 protected final AnnotationReader<TypeT,ClassDeclT,FieldT,MethodT> reader() {
aoqi@0 88 return owner.reader;
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 /**
aoqi@0 92 * Parses an {@link XmlRootElement} annotation on a class
aoqi@0 93 * and determine the element name.
aoqi@0 94 *
aoqi@0 95 * @return null
aoqi@0 96 * if none was found.
aoqi@0 97 */
aoqi@0 98 protected final QName parseElementName(ClassDeclT clazz) {
aoqi@0 99 XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this);
aoqi@0 100 if(e==null)
aoqi@0 101 return null;
aoqi@0 102
aoqi@0 103 String local = e.name();
aoqi@0 104 if(local.equals("##default")) {
aoqi@0 105 // if defaulted...
aoqi@0 106 local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
aoqi@0 107 }
aoqi@0 108 String nsUri = e.namespace();
aoqi@0 109 if(nsUri.equals("##default")) {
aoqi@0 110 // if defaulted ...
aoqi@0 111 XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
aoqi@0 112 if(xs!=null)
aoqi@0 113 nsUri = xs.namespace();
aoqi@0 114 else {
aoqi@0 115 nsUri = builder.defaultNsUri;
aoqi@0 116 }
aoqi@0 117 }
aoqi@0 118
aoqi@0 119 return new QName(nsUri.intern(),local.intern());
aoqi@0 120 }
aoqi@0 121
aoqi@0 122 protected final QName parseTypeName(ClassDeclT clazz) {
aoqi@0 123 return parseTypeName( clazz, reader().getClassAnnotation(XmlType.class,clazz,this) );
aoqi@0 124 }
aoqi@0 125
aoqi@0 126 /**
aoqi@0 127 * Parses a (potentially-null) {@link XmlType} annotation on a class
aoqi@0 128 * and determine the actual value.
aoqi@0 129 *
aoqi@0 130 * @param clazz
aoqi@0 131 * The class on which the XmlType annotation is checked.
aoqi@0 132 * @param t
aoqi@0 133 * The {@link XmlType} annotation on the clazz. This value
aoqi@0 134 * is taken as a parameter to improve the performance for the case where
aoqi@0 135 * 't' is pre-computed.
aoqi@0 136 */
aoqi@0 137 protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
aoqi@0 138 String nsUri="##default";
aoqi@0 139 String local="##default";
aoqi@0 140 if(t!=null) {
aoqi@0 141 nsUri = t.namespace();
aoqi@0 142 local = t.name();
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 if(local.length()==0)
aoqi@0 146 return null; // anonymous
aoqi@0 147
aoqi@0 148
aoqi@0 149 if(local.equals("##default"))
aoqi@0 150 // if defaulted ...
aoqi@0 151 local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
aoqi@0 152
aoqi@0 153 if(nsUri.equals("##default")) {
aoqi@0 154 // if defaulted ...
aoqi@0 155 XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
aoqi@0 156 if(xs!=null)
aoqi@0 157 nsUri = xs.namespace();
aoqi@0 158 else {
aoqi@0 159 nsUri = builder.defaultNsUri;
aoqi@0 160 }
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 return new QName(nsUri.intern(),local.intern());
aoqi@0 164 }
aoqi@0 165 }

mercurial