1 /* 2 * Copyright (c) 1997, 2014, 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 */ 25 26 package com.sun.tools.internal.xjc.model; 27 28 import javax.xml.namespace.QName; 29 30 import com.sun.codemodel.internal.JClass; 31 import com.sun.tools.internal.xjc.model.nav.NClass; 32 import com.sun.tools.internal.xjc.model.nav.NType; 33 import com.sun.tools.internal.xjc.outline.Aspect; 34 import com.sun.tools.internal.xjc.outline.Outline; 35 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIClass; 36 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIEnum; 37 import com.sun.xml.internal.xsom.XSComponent; 38 39 /** 40 * Reference to an existing class. 41 * 42 * @author Kohsuke Kawaguchi 43 */ 44 public final class CClassRef extends AbstractCElement implements NClass, CClass { 45 46 private final String fullyQualifiedClassName; 47 48 /** 49 * Cached for both performance and single identity. 50 */ 51 private JClass clazz; 52 53 /** 54 * 55 * @param decl 56 * The {@link BIClass} declaration that has {@link BIClass#getExistingClassRef()} 57 */ 58 public CClassRef(Model model, XSComponent source, BIClass decl, CCustomizations customizations) { 59 super(model, source, decl.getLocation(), customizations); 60 fullyQualifiedClassName = decl.getExistingClassRef(); 61 assert fullyQualifiedClassName!=null; 62 } 63 64 /** 65 * 66 * @param decl 67 * The {@link BIClass} declaration that has {@link BIEnum#ref} 68 */ 69 public CClassRef(Model model, XSComponent source, BIEnum decl, CCustomizations customizations) { 70 super(model, source, decl.getLocation(), customizations); 71 fullyQualifiedClassName = decl.ref; 72 assert fullyQualifiedClassName!=null; 73 } 74 75 public void setAbstract() { 76 // assume that the referenced class is marked as abstract to begin with. 77 } 78 79 public boolean isAbstract() { 80 // no way to find out for sure 81 return false; 82 } 83 84 public NType getType() { 85 return this; 86 } 87 88 public JClass toType(Outline o, Aspect aspect) { 89 if(clazz==null) 90 clazz = o.getCodeModel().ref(fullyQualifiedClassName); 91 return clazz; 92 } 93 94 public String fullName() { 95 return fullyQualifiedClassName; 96 } 97 98 public QName getTypeName() { 99 return null; 100 } 101 102 /** 103 * Guaranteed to return this. 104 */ 105 @Deprecated 106 public CNonElement getInfo() { 107 return this; 108 } 109 110 // are these going to bite us? 111 // we can compute some of them, but not all. 112 113 public CElement getSubstitutionHead() { 114 return null; 115 } 116 117 public CClassInfo getScope() { 118 return null; 119 } 120 121 public QName getElementName() { 122 return null; 123 } 124 125 public boolean isBoxedType() { 126 return false; 127 } 128 129 public boolean isSimpleType() { 130 return false; 131 } 132 133 134 }