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

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/model/impl/TypeInfoImpl.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,165 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.bind.v2.model.impl;
    1.30 +
    1.31 +import javax.xml.bind.annotation.XmlRootElement;
    1.32 +import javax.xml.bind.annotation.XmlSchema;
    1.33 +import javax.xml.bind.annotation.XmlType;
    1.34 +import javax.xml.namespace.QName;
    1.35 +
    1.36 +import com.sun.xml.internal.bind.api.impl.NameConverter;
    1.37 +import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
    1.38 +import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
    1.39 +import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
    1.40 +import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
    1.41 +import com.sun.xml.internal.bind.v2.model.nav.Navigator;
    1.42 +
    1.43 +/**
    1.44 + * Common implementation between {@link ClassInfoImpl} and {@link ElementInfoImpl}.
    1.45 + *
    1.46 + * @author Kohsuke Kawaguchi
    1.47 + */
    1.48 +abstract class TypeInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
    1.49 +        implements TypeInfo<TypeT,ClassDeclT>, Locatable {
    1.50 +
    1.51 +    /**
    1.52 +     * The Java class that caused this Java class to be a part of the JAXB processing.
    1.53 +     *
    1.54 +     * null if it's specified explicitly by the user.
    1.55 +     */
    1.56 +    private final Locatable upstream;
    1.57 +
    1.58 +    /**
    1.59 +     * {@link TypeInfoSet} to which this class belongs.
    1.60 +     */
    1.61 +    protected final TypeInfoSetImpl<TypeT,ClassDeclT,FieldT,MethodT> owner;
    1.62 +
    1.63 +    /**
    1.64 +     * Reference to the {@link ModelBuilder}, only until we link {@link TypeInfo}s all together,
    1.65 +     * because we don't want to keep {@link ModelBuilder} too long.
    1.66 +     */
    1.67 +    protected ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder;
    1.68 +
    1.69 +    protected TypeInfoImpl(
    1.70 +        ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder,
    1.71 +        Locatable upstream) {
    1.72 +
    1.73 +        this.builder = builder;
    1.74 +        this.owner = builder.typeInfoSet;
    1.75 +        this.upstream = upstream;
    1.76 +    }
    1.77 +
    1.78 +    public Locatable getUpstream() {
    1.79 +        return upstream;
    1.80 +    }
    1.81 +
    1.82 +    /*package*/ void link() {
    1.83 +        builder = null;
    1.84 +    }
    1.85 +
    1.86 +    protected final Navigator<TypeT,ClassDeclT,FieldT,MethodT> nav() {
    1.87 +        return owner.nav;
    1.88 +    }
    1.89 +
    1.90 +    protected final AnnotationReader<TypeT,ClassDeclT,FieldT,MethodT> reader() {
    1.91 +        return owner.reader;
    1.92 +    }
    1.93 +
    1.94 +    /**
    1.95 +     * Parses an {@link XmlRootElement} annotation on a class
    1.96 +     * and determine the element name.
    1.97 +     *
    1.98 +     * @return null
    1.99 +     *      if none was found.
   1.100 +     */
   1.101 +    protected final QName parseElementName(ClassDeclT clazz) {
   1.102 +        XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this);
   1.103 +        if(e==null)
   1.104 +            return null;
   1.105 +
   1.106 +        String local = e.name();
   1.107 +        if(local.equals("##default")) {
   1.108 +            // if defaulted...
   1.109 +            local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
   1.110 +        }
   1.111 +        String nsUri = e.namespace();
   1.112 +        if(nsUri.equals("##default")) {
   1.113 +            // if defaulted ...
   1.114 +            XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
   1.115 +            if(xs!=null)
   1.116 +                nsUri = xs.namespace();
   1.117 +            else {
   1.118 +                nsUri = builder.defaultNsUri;
   1.119 +            }
   1.120 +        }
   1.121 +
   1.122 +        return new QName(nsUri.intern(),local.intern());
   1.123 +    }
   1.124 +
   1.125 +    protected final QName parseTypeName(ClassDeclT clazz) {
   1.126 +        return parseTypeName( clazz, reader().getClassAnnotation(XmlType.class,clazz,this) );
   1.127 +    }
   1.128 +
   1.129 +    /**
   1.130 +     * Parses a (potentially-null) {@link XmlType} annotation on a class
   1.131 +     * and determine the actual value.
   1.132 +     *
   1.133 +     * @param clazz
   1.134 +     *      The class on which the XmlType annotation is checked.
   1.135 +     * @param t
   1.136 +     *      The {@link XmlType} annotation on the clazz. This value
   1.137 +     *      is taken as a parameter to improve the performance for the case where
   1.138 +     *      't' is pre-computed.
   1.139 +     */
   1.140 +    protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
   1.141 +        String nsUri="##default";
   1.142 +        String local="##default";
   1.143 +        if(t!=null) {
   1.144 +            nsUri = t.namespace();
   1.145 +            local = t.name();
   1.146 +        }
   1.147 +
   1.148 +        if(local.length()==0)
   1.149 +            return null; // anonymous
   1.150 +
   1.151 +
   1.152 +        if(local.equals("##default"))
   1.153 +            // if defaulted ...
   1.154 +            local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
   1.155 +
   1.156 +        if(nsUri.equals("##default")) {
   1.157 +            // if defaulted ...
   1.158 +            XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
   1.159 +            if(xs!=null)
   1.160 +                nsUri = xs.namespace();
   1.161 +            else {
   1.162 +                nsUri = builder.defaultNsUri;
   1.163 +            }
   1.164 +        }
   1.165 +
   1.166 +        return new QName(nsUri.intern(),local.intern());
   1.167 +    }
   1.168 +}

mercurial