1 /* 2 * Copyright (c) 1997, 2012, 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; | 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; |