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