325N/A/*
325N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.bind.v2.model.impl;
325N/A
325N/Aimport javax.xml.bind.annotation.XmlRootElement;
325N/Aimport javax.xml.bind.annotation.XmlSchema;
325N/Aimport javax.xml.bind.annotation.XmlType;
325N/Aimport javax.xml.namespace.QName;
325N/A
325N/Aimport com.sun.xml.internal.bind.api.impl.NameConverter;
325N/Aimport com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
325N/Aimport com.sun.xml.internal.bind.v2.model.annotation.Locatable;
325N/Aimport com.sun.xml.internal.bind.v2.model.core.TypeInfo;
325N/Aimport com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
325N/Aimport com.sun.xml.internal.bind.v2.model.nav.Navigator;
325N/A
325N/A/**
325N/A * Common implementation between {@link ClassInfoImpl} and {@link ElementInfoImpl}.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/Aabstract class TypeInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
325N/A implements TypeInfo<TypeT,ClassDeclT>, Locatable {
325N/A
325N/A /**
325N/A * The Java class that caused this Java class to be a part of the JAXB processing.
325N/A *
325N/A * null if it's specified explicitly by the user.
325N/A */
325N/A private final Locatable upstream;
325N/A
325N/A /**
325N/A * {@link TypeInfoSet} to which this class belongs.
325N/A */
325N/A protected final TypeInfoSetImpl<TypeT,ClassDeclT,FieldT,MethodT> owner;
325N/A
325N/A /**
325N/A * Reference to the {@link ModelBuilder}, only until we link {@link TypeInfo}s all together,
325N/A * because we don't want to keep {@link ModelBuilder} too long.
325N/A */
325N/A protected ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder;
325N/A
325N/A protected TypeInfoImpl(
325N/A ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder,
325N/A Locatable upstream) {
325N/A
325N/A this.builder = builder;
325N/A this.owner = builder.typeInfoSet;
325N/A this.upstream = upstream;
325N/A }
325N/A
325N/A public Locatable getUpstream() {
325N/A return upstream;
325N/A }
325N/A
325N/A /*package*/ void link() {
325N/A builder = null;
325N/A }
325N/A
325N/A protected final Navigator<TypeT,ClassDeclT,FieldT,MethodT> nav() {
325N/A return owner.nav;
325N/A }
325N/A
325N/A protected final AnnotationReader<TypeT,ClassDeclT,FieldT,MethodT> reader() {
325N/A return owner.reader;
325N/A }
325N/A
325N/A /**
325N/A * Parses an {@link XmlRootElement} annotation on a class
325N/A * and determine the element name.
325N/A *
325N/A * @return null
325N/A * if none was found.
325N/A */
325N/A protected final QName parseElementName(ClassDeclT clazz) {
325N/A XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this);
325N/A if(e==null)
325N/A return null;
325N/A
325N/A String local = e.name();
325N/A if(local.equals("##default")) {
325N/A // if defaulted...
325N/A local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
325N/A }
325N/A String nsUri = e.namespace();
325N/A if(nsUri.equals("##default")) {
325N/A // if defaulted ...
325N/A XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
325N/A if(xs!=null)
325N/A nsUri = xs.namespace();
325N/A else {
325N/A nsUri = builder.defaultNsUri;
325N/A }
325N/A }
325N/A
325N/A return new QName(nsUri.intern(),local.intern());
325N/A }
325N/A
325N/A protected final QName parseTypeName(ClassDeclT clazz) {
325N/A return parseTypeName( clazz, reader().getClassAnnotation(XmlType.class,clazz,this) );
325N/A }
325N/A
325N/A /**
325N/A * Parses a (potentially-null) {@link XmlType} annotation on a class
325N/A * and determine the actual value.
325N/A *
325N/A * @param clazz
325N/A * The class on which the XmlType annotation is checked.
325N/A * @param t
325N/A * The {@link XmlType} annotation on the clazz. This value
325N/A * is taken as a parameter to improve the performance for the case where
325N/A * 't' is pre-computed.
325N/A */
325N/A protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
325N/A String nsUri="##default";
325N/A String local="##default";
325N/A if(t!=null) {
325N/A nsUri = t.namespace();
325N/A local = t.name();
325N/A }
325N/A
325N/A if(local.length()==0)
325N/A return null; // anonymous
325N/A
325N/A
325N/A if(local.equals("##default"))
325N/A // if defaulted ...
325N/A local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
325N/A
325N/A if(nsUri.equals("##default")) {
325N/A // if defaulted ...
325N/A XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
325N/A if(xs!=null)
325N/A nsUri = xs.namespace();
325N/A else {
325N/A nsUri = builder.defaultNsUri;
325N/A }
325N/A }
325N/A
325N/A return new QName(nsUri.intern(),local.intern());
325N/A }
325N/A}