aoqi@0: /* aefimov@1100: * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.internal.xjc.model; aoqi@0: aoqi@0: import javax.xml.XMLConstants; aoqi@0: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; aoqi@0: import javax.xml.namespace.QName; aoqi@0: aoqi@0: import com.sun.tools.internal.xjc.model.nav.NClass; aoqi@0: import com.sun.tools.internal.xjc.model.nav.NType; aoqi@0: import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder; aoqi@0: import com.sun.xml.internal.bind.v2.model.core.PropertyInfo; aoqi@0: import com.sun.xml.internal.bind.v2.model.core.TypeRef; aoqi@0: import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil; aoqi@0: import com.sun.xml.internal.xsom.XSType; aoqi@0: import com.sun.xml.internal.xsom.XmlString; aoqi@0: import com.sun.xml.internal.xsom.XSElementDecl; aoqi@0: import com.sun.istack.internal.Nullable; aoqi@0: aoqi@0: /** aoqi@0: * {@link TypeRef} for XJC. aoqi@0: * aoqi@0: * TODO: do we need the source schema component support here? aoqi@0: * aoqi@0: * @author Kohsuke Kawaguchi aoqi@0: */ aoqi@0: public final class CTypeRef implements TypeRef { aoqi@0: /** aoqi@0: * In-memory type. aoqi@0: * aoqi@0: * This is the type used when aoqi@0: */ aoqi@0: @XmlJavaTypeAdapter(RuntimeUtil.ToStringAdapter.class) aoqi@0: private final CNonElement type; aoqi@0: aoqi@0: private final QName elementName; aoqi@0: aoqi@0: /** aoqi@0: * XML Schema type name of {@link #type}, if available. aoqi@0: */ aoqi@0: /*package*/ final @Nullable QName typeName; aoqi@0: aoqi@0: private final boolean nillable; aoqi@0: public final XmlString defaultValue; aoqi@0: aoqi@0: public CTypeRef(CNonElement type, XSElementDecl decl) { aoqi@0: this(type, BGMBuilder.getName(decl),getSimpleTypeName(decl), decl.isNillable(), decl.getDefaultValue() ); aoqi@0: aoqi@0: } aoqi@0: aoqi@0: public QName getTypeName() { aoqi@0: return typeName; aoqi@0: } aoqi@0: aoqi@0: public static QName getSimpleTypeName(XSElementDecl decl) { aoqi@0: if(decl==null || !decl.getType().isSimpleType()) aoqi@0: return null; // null if not simple type aoqi@0: return resolveSimpleTypeName(decl.getType()); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Recursively search for type name. aoqi@0: * aoqi@0: * This is needed to find correct type for refs like: aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * @param declType given type aoqi@0: * @return simpleTypeName or null aoqi@0: */ aoqi@0: private static QName resolveSimpleTypeName(XSType declType) { aoqi@0: QName name = BGMBuilder.getName(declType); aefimov@1100: QName result = null; aefimov@1100: if (name != null && !XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(name.getNamespaceURI())) { aefimov@1100: result = resolveSimpleTypeName(declType.getBaseType()); aefimov@1100: } else { aefimov@1100: if ( !"anySimpleType".equals(declType.getName()) ) { aefimov@1100: result = name; aefimov@1100: } aefimov@1100: } aefimov@1100: return result; aoqi@0: } aoqi@0: aoqi@0: public CTypeRef(CNonElement type, QName elementName, QName typeName, boolean nillable, XmlString defaultValue) { aoqi@0: assert type!=null; aoqi@0: assert elementName!=null; aoqi@0: aoqi@0: this.type = type; aoqi@0: this.elementName = elementName; aoqi@0: this.typeName = typeName; aoqi@0: this.nillable = nillable; aoqi@0: this.defaultValue = defaultValue; aoqi@0: } aoqi@0: aoqi@0: public CNonElement getTarget() { aoqi@0: return type; aoqi@0: } aoqi@0: aoqi@0: public QName getTagName() { aoqi@0: return elementName; aoqi@0: } aoqi@0: aoqi@0: public boolean isNillable() { aoqi@0: return nillable; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Inside XJC, use {@link #defaultValue} that has context information. aoqi@0: * This method is to override the one defined in the runtime model. aoqi@0: * aoqi@0: * @see #defaultValue aoqi@0: */ aoqi@0: public String getDefaultValue() { aoqi@0: if(defaultValue!=null) aoqi@0: return defaultValue.value; aoqi@0: else aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public boolean isLeaf() { aoqi@0: // TODO: implement this method later aoqi@0: throw new UnsupportedOperationException(); aoqi@0: } aoqi@0: aoqi@0: public PropertyInfo getSource() { aoqi@0: // TODO: implement this method later aoqi@0: throw new UnsupportedOperationException(); aoqi@0: } aoqi@0: }