View Javadoc
1   /*
2    * Copyright (c) 1997, 2011, 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   * Refernece 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       *
50       * @param decl
51       *      The {@link BIClass} declaration that has {@link BIClass#getExistingClassRef()}
52       */
53      public CClassRef(Model model, XSComponent source, BIClass decl, CCustomizations customizations) {
54          super(model, source, decl.getLocation(), customizations);
55          fullyQualifiedClassName = decl.getExistingClassRef();
56          assert fullyQualifiedClassName!=null;
57      }
58  
59      /**
60       *
61       * @param decl
62       *      The {@link BIClass} declaration that has {@link BIEnum#ref}
63       */
64      public CClassRef(Model model, XSComponent source, BIEnum decl, CCustomizations customizations) {
65          super(model, source, decl.getLocation(), customizations);
66          fullyQualifiedClassName = decl.ref;
67          assert fullyQualifiedClassName!=null;
68      }
69  
70      public void setAbstract() {
71          // assume that the referenced class is marked as abstract to begin with.
72      }
73  
74      public boolean isAbstract() {
75          // no way to find out for sure
76          return false;
77      }
78  
79      public NType getType() {
80          return this;
81      }
82  
83      /**
84       * Cached for both performance and single identity.
85       */
86      private JClass clazz;
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 }