src/share/jaxws_classes/com/sun/tools/internal/xjc/model/CTypeRef.java

Thu, 24 May 2018 16:44:14 +0800

author
aoqi
date
Thu, 24 May 2018 16:44:14 +0800
changeset 1288
f4ace6971570
parent 1100
391a42f11d6e
parent 637
9c07ef4934dd
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 1997, 2016, 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.tools.internal.xjc.model;
    28 import javax.xml.XMLConstants;
    29 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
    30 import javax.xml.namespace.QName;
    32 import com.sun.tools.internal.xjc.model.nav.NClass;
    33 import com.sun.tools.internal.xjc.model.nav.NType;
    34 import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder;
    35 import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
    36 import com.sun.xml.internal.bind.v2.model.core.TypeRef;
    37 import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil;
    38 import com.sun.xml.internal.xsom.XSType;
    39 import com.sun.xml.internal.xsom.XmlString;
    40 import com.sun.xml.internal.xsom.XSElementDecl;
    41 import com.sun.istack.internal.Nullable;
    43 /**
    44  * {@link TypeRef} for XJC.
    45  *
    46  * TODO: do we need the source schema component support here?
    47  *
    48  * @author Kohsuke Kawaguchi
    49  */
    50 public final class CTypeRef implements TypeRef<NType,NClass> {
    51     /**
    52      * In-memory type.
    53      *
    54      * This is the type used when
    55      */
    56     @XmlJavaTypeAdapter(RuntimeUtil.ToStringAdapter.class)
    57     private final CNonElement type;
    59     private final QName elementName;
    61     /**
    62      * XML Schema type name of {@link #type}, if available.
    63      */
    64     /*package*/ final @Nullable QName typeName;
    66     private final boolean nillable;
    67     public final XmlString defaultValue;
    69     public CTypeRef(CNonElement type, XSElementDecl decl) {
    70         this(type, BGMBuilder.getName(decl),getSimpleTypeName(decl), decl.isNillable(), decl.getDefaultValue() );
    72     }
    74     public QName getTypeName() {
    75         return typeName;
    76     }
    78     public static QName getSimpleTypeName(XSElementDecl decl) {
    79         if(decl==null || !decl.getType().isSimpleType())
    80             return null; // null if not simple type
    81         return resolveSimpleTypeName(decl.getType());
    82     }
    84     /**
    85      * Recursively search for type name.
    86      *
    87      * This is needed to find correct type for refs like:
    88      *
    89      *<xs:simpleType name="parent">
    90      *  <xs:restriction base="xs:date"/>
    91      *</xs:simpleType>
    92      *<xs:simpleType name="child">
    93      *  <xs:restriction base="parent"/>
    94      *</xs:simpleType>
    95      *
    96      *<xs:element name="testField" type="child"/>
    97      *
    98      * @param declType given type
    99      * @return simpleTypeName or null
   100      */
   101     private static QName resolveSimpleTypeName(XSType declType) {
   102         QName name = BGMBuilder.getName(declType);
   103         QName result = null;
   104         if (name != null && !XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(name.getNamespaceURI())) {
   105             result = resolveSimpleTypeName(declType.getBaseType());
   106         } else {
   107             if ( !"anySimpleType".equals(declType.getName()) ) {
   108                 result = name;
   109             }
   110         }
   111         return result;
   112     }
   114     public CTypeRef(CNonElement type, QName elementName, QName typeName, boolean nillable, XmlString defaultValue) {
   115         assert type!=null;
   116         assert elementName!=null;
   118         this.type = type;
   119         this.elementName = elementName;
   120         this.typeName = typeName;
   121         this.nillable = nillable;
   122         this.defaultValue = defaultValue;
   123     }
   125     public CNonElement getTarget() {
   126         return type;
   127     }
   129     public QName getTagName() {
   130         return elementName;
   131     }
   133     public boolean isNillable() {
   134         return nillable;
   135     }
   137     /**
   138      * Inside XJC, use {@link #defaultValue} that has context information.
   139      * This method is to override the one defined in the runtime model.
   140      *
   141      * @see #defaultValue
   142      */
   143     public String getDefaultValue() {
   144         if(defaultValue!=null)
   145             return defaultValue.value;
   146         else
   147             return null;
   148     }
   150     public boolean isLeaf() {
   151         // TODO: implement this method later
   152         throw new UnsupportedOperationException();
   153     }
   155     public PropertyInfo<NType, NClass> getSource() {
   156         // TODO: implement this method later
   157         throw new UnsupportedOperationException();
   158     }
   159 }

mercurial