Wed, 28 Mar 2012 02:50:50 -0700
7079902: Refine CORBA data models
Reviewed-by: coffeys
duke@1 | 1 | /* |
ohair@158 | 2 | * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@158 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@158 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@158 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@158 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@158 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | /* |
duke@1 | 27 | * Licensed Materials - Property of IBM |
duke@1 | 28 | * RMI-IIOP v1.0 |
duke@1 | 29 | * Copyright IBM Corp. 1998 1999 All Rights Reserved |
duke@1 | 30 | * |
duke@1 | 31 | */ |
duke@1 | 32 | |
duke@1 | 33 | package sun.rmi.rmic.iiop; |
duke@1 | 34 | |
duke@1 | 35 | import sun.tools.java.ClassNotFound; |
duke@1 | 36 | import sun.tools.java.CompilerError; |
duke@1 | 37 | import sun.tools.java.Identifier; |
duke@1 | 38 | import sun.tools.java.ClassDefinition; |
duke@1 | 39 | |
duke@1 | 40 | /** |
duke@1 | 41 | * SpecialClassType represents any one of the following types: |
duke@1 | 42 | * <pre> |
duke@1 | 43 | * java.lang.Object |
duke@1 | 44 | * java.lang.String |
duke@1 | 45 | * </pre> |
duke@1 | 46 | * all of which are treated as special cases. |
duke@1 | 47 | * <p> |
duke@1 | 48 | * The static forSpecial(...) method must be used to obtain an instance, and |
duke@1 | 49 | * will return null if the type is non-conforming. |
duke@1 | 50 | * |
duke@1 | 51 | * @author Bryan Atsatt |
duke@1 | 52 | */ |
duke@1 | 53 | public class SpecialClassType extends ClassType { |
duke@1 | 54 | |
duke@1 | 55 | //_____________________________________________________________________ |
duke@1 | 56 | // Public Interfaces |
duke@1 | 57 | //_____________________________________________________________________ |
duke@1 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * Create a SpecialClassType object for the given class. |
duke@1 | 61 | * |
duke@1 | 62 | * If the class is not a properly formed or if some other error occurs, the |
duke@1 | 63 | * return value will be null, and errors will have been reported to the |
duke@1 | 64 | * supplied BatchEnvironment. |
duke@1 | 65 | */ |
duke@1 | 66 | public static SpecialClassType forSpecial (ClassDefinition theClass, |
duke@1 | 67 | ContextStack stack) { |
duke@1 | 68 | if (stack.anyErrors()) return null; |
duke@1 | 69 | |
duke@1 | 70 | sun.tools.java.Type type = theClass.getType(); |
duke@1 | 71 | |
duke@1 | 72 | // Do we already have it? |
duke@1 | 73 | |
duke@1 | 74 | String typeKey = type.toString() + stack.getContextCodeString(); |
duke@1 | 75 | |
duke@1 | 76 | Type existing = getType(typeKey,stack); |
duke@1 | 77 | |
duke@1 | 78 | if (existing != null) { |
duke@1 | 79 | |
duke@1 | 80 | if (!(existing instanceof SpecialClassType)) return null; // False hit. |
duke@1 | 81 | |
duke@1 | 82 | // Yep, so return it... |
duke@1 | 83 | |
duke@1 | 84 | return (SpecialClassType) existing; |
duke@1 | 85 | } |
duke@1 | 86 | |
duke@1 | 87 | // Is it a special type? |
duke@1 | 88 | |
duke@1 | 89 | int typeCode = getTypeCode(type,theClass,stack); |
duke@1 | 90 | |
duke@1 | 91 | if (typeCode != TYPE_NONE) { |
duke@1 | 92 | |
duke@1 | 93 | // Yes... |
duke@1 | 94 | |
duke@1 | 95 | SpecialClassType result = new SpecialClassType(stack,typeCode,theClass); |
duke@1 | 96 | putType(typeKey,result,stack); |
duke@1 | 97 | stack.push(result); |
duke@1 | 98 | stack.pop(true); |
duke@1 | 99 | return result; |
duke@1 | 100 | |
duke@1 | 101 | } else { |
duke@1 | 102 | |
duke@1 | 103 | return null; |
duke@1 | 104 | } |
duke@1 | 105 | } |
duke@1 | 106 | |
duke@1 | 107 | /** |
duke@1 | 108 | * Return a string describing this type. |
duke@1 | 109 | */ |
duke@1 | 110 | public String getTypeDescription () { |
duke@1 | 111 | return "Special class"; |
duke@1 | 112 | } |
duke@1 | 113 | |
duke@1 | 114 | //_____________________________________________________________________ |
duke@1 | 115 | // Subclass/Internal Interfaces |
duke@1 | 116 | //_____________________________________________________________________ |
duke@1 | 117 | |
duke@1 | 118 | /** |
duke@1 | 119 | * Create an SpecialClassType instance for the given class. |
duke@1 | 120 | */ |
duke@1 | 121 | private SpecialClassType(ContextStack stack, int typeCode, |
duke@1 | 122 | ClassDefinition theClass) { |
duke@1 | 123 | super(stack,typeCode | TM_SPECIAL_CLASS | TM_CLASS | TM_COMPOUND, theClass); |
duke@1 | 124 | Identifier id = theClass.getName(); |
duke@1 | 125 | String idlName = null; |
duke@1 | 126 | String[] idlModuleName = null; |
duke@1 | 127 | boolean constant = stack.size() > 0 && stack.getContext().isConstant(); |
duke@1 | 128 | |
duke@1 | 129 | // Set names... |
duke@1 | 130 | |
duke@1 | 131 | switch (typeCode) { |
duke@1 | 132 | case TYPE_STRING: { |
duke@1 | 133 | idlName = IDLNames.getTypeName(typeCode,constant); |
duke@1 | 134 | if (!constant) { |
duke@1 | 135 | idlModuleName = IDL_CORBA_MODULE; |
duke@1 | 136 | } |
duke@1 | 137 | break; |
duke@1 | 138 | } |
duke@1 | 139 | |
duke@1 | 140 | case TYPE_ANY: { |
duke@1 | 141 | idlName = IDL_JAVA_LANG_OBJECT; |
duke@1 | 142 | idlModuleName = IDL_JAVA_LANG_MODULE; |
duke@1 | 143 | break; |
duke@1 | 144 | } |
duke@1 | 145 | } |
duke@1 | 146 | |
duke@1 | 147 | setNames(id,idlModuleName,idlName); |
duke@1 | 148 | |
duke@1 | 149 | // Init parents... |
duke@1 | 150 | |
duke@1 | 151 | if (!initParents(stack)) { |
duke@1 | 152 | |
duke@1 | 153 | // Should not be possible! |
duke@1 | 154 | |
duke@1 | 155 | throw new CompilerError("SpecialClassType found invalid parent."); |
duke@1 | 156 | } |
duke@1 | 157 | |
duke@1 | 158 | // Initialize CompoundType... |
duke@1 | 159 | |
duke@1 | 160 | initialize(null,null,null,stack,false); |
duke@1 | 161 | } |
duke@1 | 162 | |
duke@1 | 163 | private static int getTypeCode(sun.tools.java.Type type, ClassDefinition theClass, ContextStack stack) { |
duke@1 | 164 | if (type.isType(TC_CLASS)) { |
duke@1 | 165 | Identifier id = type.getClassName(); |
duke@1 | 166 | if (id == idJavaLangString) return TYPE_STRING; |
duke@1 | 167 | if (id == idJavaLangObject) return TYPE_ANY; |
duke@1 | 168 | } |
duke@1 | 169 | return TYPE_NONE; |
duke@1 | 170 | } |
duke@1 | 171 | } |