Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.internal.xjc.model; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.Collection; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import javax.activation.MimeType; |
aoqi@0 | 31 | import javax.xml.namespace.QName; |
aoqi@0 | 32 | |
aoqi@0 | 33 | import com.sun.codemodel.internal.JClass; |
aoqi@0 | 34 | import com.sun.codemodel.internal.JExpression; |
aoqi@0 | 35 | import com.sun.tools.internal.xjc.model.nav.NClass; |
aoqi@0 | 36 | import com.sun.tools.internal.xjc.model.nav.NType; |
aoqi@0 | 37 | import com.sun.tools.internal.xjc.outline.Aspect; |
aoqi@0 | 38 | import com.sun.tools.internal.xjc.outline.Outline; |
aoqi@0 | 39 | import com.sun.xml.internal.bind.v2.model.annotation.Locatable; |
aoqi@0 | 40 | import com.sun.xml.internal.bind.v2.model.core.EnumLeafInfo; |
aoqi@0 | 41 | import com.sun.xml.internal.bind.v2.model.core.ID; |
aoqi@0 | 42 | import com.sun.xml.internal.bind.v2.model.core.NonElement; |
aoqi@0 | 43 | import com.sun.xml.internal.bind.v2.model.core.Element; |
aoqi@0 | 44 | import com.sun.xml.internal.bind.v2.runtime.Location; |
aoqi@0 | 45 | import com.sun.xml.internal.xsom.XSComponent; |
aoqi@0 | 46 | import com.sun.xml.internal.xsom.XmlString; |
aoqi@0 | 47 | |
aoqi@0 | 48 | import org.xml.sax.Locator; |
aoqi@0 | 49 | |
aoqi@0 | 50 | /** |
aoqi@0 | 51 | * Transducer that converts a string into an "enumeration class." |
aoqi@0 | 52 | * |
aoqi@0 | 53 | * The structure of the generated class needs to precisely |
aoqi@0 | 54 | * follow the JAXB spec. |
aoqi@0 | 55 | * |
aoqi@0 | 56 | * @author |
aoqi@0 | 57 | * <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a> |
aoqi@0 | 58 | */ |
aoqi@0 | 59 | public final class CEnumLeafInfo implements EnumLeafInfo<NType,NClass>, NClass, CNonElement |
aoqi@0 | 60 | { |
aoqi@0 | 61 | /** |
aoqi@0 | 62 | * The {@link Model} object to which this bean belongs. |
aoqi@0 | 63 | */ |
aoqi@0 | 64 | public final Model model; |
aoqi@0 | 65 | |
aoqi@0 | 66 | /** |
aoqi@0 | 67 | * The parent into which the enum class should be generated. |
aoqi@0 | 68 | */ |
aoqi@0 | 69 | public final CClassInfoParent parent; |
aoqi@0 | 70 | |
aoqi@0 | 71 | /** |
aoqi@0 | 72 | * Short name of the generated type-safe enum. |
aoqi@0 | 73 | */ |
aoqi@0 | 74 | public final String shortName; |
aoqi@0 | 75 | |
aoqi@0 | 76 | private final QName typeName; |
aoqi@0 | 77 | |
aoqi@0 | 78 | private final XSComponent source; |
aoqi@0 | 79 | |
aoqi@0 | 80 | /** |
aoqi@0 | 81 | * Represents the underlying type of this enumeration |
aoqi@0 | 82 | * and its conversion. |
aoqi@0 | 83 | * |
aoqi@0 | 84 | * <p> |
aoqi@0 | 85 | * To parse XML into a constant, we use the base type |
aoqi@0 | 86 | * to do lexical -> value, then use a map to pick up the right one. |
aoqi@0 | 87 | * |
aoqi@0 | 88 | * <p> |
aoqi@0 | 89 | * Hence this also represents the type of the Java value. |
aoqi@0 | 90 | * For example, if this is an enumeration of xs:int, |
aoqi@0 | 91 | * then this field will be Java int. |
aoqi@0 | 92 | */ |
aoqi@0 | 93 | public final CNonElement base; |
aoqi@0 | 94 | |
aoqi@0 | 95 | |
aoqi@0 | 96 | /** |
aoqi@0 | 97 | * List of enum members. |
aoqi@0 | 98 | */ |
aoqi@0 | 99 | public final Collection<CEnumConstant> members; |
aoqi@0 | 100 | |
aoqi@0 | 101 | private final CCustomizations customizations; |
aoqi@0 | 102 | |
aoqi@0 | 103 | /** |
aoqi@0 | 104 | * @see #getLocator() |
aoqi@0 | 105 | */ |
aoqi@0 | 106 | private final Locator sourceLocator; |
aoqi@0 | 107 | |
aoqi@0 | 108 | public String javadoc; |
aoqi@0 | 109 | |
aoqi@0 | 110 | public CEnumLeafInfo(Model model, |
aoqi@0 | 111 | QName typeName, |
aoqi@0 | 112 | CClassInfoParent container, |
aoqi@0 | 113 | String shortName, |
aoqi@0 | 114 | CNonElement base, |
aoqi@0 | 115 | Collection<CEnumConstant> _members, |
aoqi@0 | 116 | XSComponent source, |
aoqi@0 | 117 | CCustomizations customizations, |
aoqi@0 | 118 | Locator _sourceLocator) { |
aoqi@0 | 119 | this.model = model; |
aoqi@0 | 120 | this.parent = container; |
aoqi@0 | 121 | this.shortName = model.allocator.assignClassName(parent,shortName); |
aoqi@0 | 122 | this.base = base; |
aoqi@0 | 123 | this.members = _members; |
aoqi@0 | 124 | this.source = source; |
aoqi@0 | 125 | if(customizations==null) |
aoqi@0 | 126 | customizations = CCustomizations.EMPTY; |
aoqi@0 | 127 | this.customizations = customizations; |
aoqi@0 | 128 | this.sourceLocator = _sourceLocator; |
aoqi@0 | 129 | this.typeName = typeName; |
aoqi@0 | 130 | |
aoqi@0 | 131 | for( CEnumConstant mem : members ) |
aoqi@0 | 132 | mem.setParent(this); |
aoqi@0 | 133 | |
aoqi@0 | 134 | model.add(this); |
aoqi@0 | 135 | |
aoqi@0 | 136 | // TODO: can we take advantage of the fact that enum can be XmlRootElement? |
aoqi@0 | 137 | } |
aoqi@0 | 138 | |
aoqi@0 | 139 | /** |
aoqi@0 | 140 | * Source line information that points to the place |
aoqi@0 | 141 | * where this type-safe enum is defined. |
aoqi@0 | 142 | * Used to report error messages. |
aoqi@0 | 143 | */ |
aoqi@0 | 144 | public Locator getLocator() { |
aoqi@0 | 145 | return sourceLocator; |
aoqi@0 | 146 | } |
aoqi@0 | 147 | |
aoqi@0 | 148 | public QName getTypeName() { |
aoqi@0 | 149 | return typeName; |
aoqi@0 | 150 | } |
aoqi@0 | 151 | |
aoqi@0 | 152 | public NType getType() { |
aoqi@0 | 153 | return this; |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | /** |
aoqi@0 | 157 | * @deprecated |
aoqi@0 | 158 | * why are you calling the method whose return value is known? |
aoqi@0 | 159 | */ |
aoqi@0 | 160 | public boolean canBeReferencedByIDREF() { |
aoqi@0 | 161 | return false; |
aoqi@0 | 162 | } |
aoqi@0 | 163 | |
aoqi@0 | 164 | public boolean isElement() { |
aoqi@0 | 165 | return false; |
aoqi@0 | 166 | } |
aoqi@0 | 167 | |
aoqi@0 | 168 | public QName getElementName() { |
aoqi@0 | 169 | return null; |
aoqi@0 | 170 | } |
aoqi@0 | 171 | |
aoqi@0 | 172 | public Element<NType,NClass> asElement() { |
aoqi@0 | 173 | return null; |
aoqi@0 | 174 | } |
aoqi@0 | 175 | |
aoqi@0 | 176 | public NClass getClazz() { |
aoqi@0 | 177 | return this; |
aoqi@0 | 178 | } |
aoqi@0 | 179 | |
aoqi@0 | 180 | public XSComponent getSchemaComponent() { |
aoqi@0 | 181 | return source; |
aoqi@0 | 182 | } |
aoqi@0 | 183 | |
aoqi@0 | 184 | public JClass toType(Outline o, Aspect aspect) { |
aoqi@0 | 185 | return o.getEnum(this).clazz; |
aoqi@0 | 186 | } |
aoqi@0 | 187 | |
aoqi@0 | 188 | public boolean isAbstract() { |
aoqi@0 | 189 | return false; |
aoqi@0 | 190 | } |
aoqi@0 | 191 | |
aoqi@0 | 192 | public boolean isBoxedType() { |
aoqi@0 | 193 | return false; |
aoqi@0 | 194 | } |
aoqi@0 | 195 | |
aoqi@0 | 196 | public String fullName() { |
aoqi@0 | 197 | return parent.fullName()+'.'+shortName; |
aoqi@0 | 198 | } |
aoqi@0 | 199 | |
aoqi@0 | 200 | public boolean isPrimitive() { |
aoqi@0 | 201 | return false; |
aoqi@0 | 202 | } |
aoqi@0 | 203 | |
aoqi@0 | 204 | public boolean isSimpleType() { |
aoqi@0 | 205 | return true; |
aoqi@0 | 206 | } |
aoqi@0 | 207 | |
aoqi@0 | 208 | |
aoqi@0 | 209 | /** |
aoqi@0 | 210 | * The spec says the value field in the enum class will be generated |
aoqi@0 | 211 | * only under certain circumstances. |
aoqi@0 | 212 | * |
aoqi@0 | 213 | * @return |
aoqi@0 | 214 | * true if the generated enum class should have the value field. |
aoqi@0 | 215 | */ |
aoqi@0 | 216 | public boolean needsValueField() { |
aoqi@0 | 217 | for (CEnumConstant cec : members) { |
aoqi@0 | 218 | if(!cec.getName().equals(cec.getLexicalValue())) |
aoqi@0 | 219 | return true; |
aoqi@0 | 220 | } |
aoqi@0 | 221 | return false; |
aoqi@0 | 222 | } |
aoqi@0 | 223 | |
aoqi@0 | 224 | public JExpression createConstant(Outline outline, XmlString literal) { |
aoqi@0 | 225 | // correctly identifying which constant it maps to is hard, so |
aoqi@0 | 226 | // here I'm cheating |
aoqi@0 | 227 | JClass type = toType(outline,Aspect.EXPOSED); |
aoqi@0 | 228 | for (CEnumConstant mem : members) { |
aoqi@0 | 229 | if(mem.getLexicalValue().equals(literal.value)) |
aoqi@0 | 230 | return type.staticRef(mem.getName()); |
aoqi@0 | 231 | } |
aoqi@0 | 232 | return null; |
aoqi@0 | 233 | } |
aoqi@0 | 234 | |
aoqi@0 | 235 | @Deprecated |
aoqi@0 | 236 | public boolean isCollection() { |
aoqi@0 | 237 | return false; |
aoqi@0 | 238 | } |
aoqi@0 | 239 | |
aoqi@0 | 240 | @Deprecated |
aoqi@0 | 241 | public CAdapter getAdapterUse() { |
aoqi@0 | 242 | return null; |
aoqi@0 | 243 | } |
aoqi@0 | 244 | |
aoqi@0 | 245 | @Deprecated |
aoqi@0 | 246 | public CNonElement getInfo() { |
aoqi@0 | 247 | return this; |
aoqi@0 | 248 | } |
aoqi@0 | 249 | |
aoqi@0 | 250 | public ID idUse() { |
aoqi@0 | 251 | return ID.NONE; |
aoqi@0 | 252 | } |
aoqi@0 | 253 | |
aoqi@0 | 254 | public MimeType getExpectedMimeType() { |
aoqi@0 | 255 | return null; |
aoqi@0 | 256 | } |
aoqi@0 | 257 | |
aoqi@0 | 258 | public Collection<CEnumConstant> getConstants() { |
aoqi@0 | 259 | return members; |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | public NonElement<NType,NClass> getBaseType() { |
aoqi@0 | 263 | return base; |
aoqi@0 | 264 | } |
aoqi@0 | 265 | |
aoqi@0 | 266 | public CCustomizations getCustomizations() { |
aoqi@0 | 267 | return customizations; |
aoqi@0 | 268 | } |
aoqi@0 | 269 | |
aoqi@0 | 270 | public Locatable getUpstream() { |
aoqi@0 | 271 | throw new UnsupportedOperationException(); |
aoqi@0 | 272 | } |
aoqi@0 | 273 | |
aoqi@0 | 274 | public Location getLocation() { |
aoqi@0 | 275 | throw new UnsupportedOperationException(); |
aoqi@0 | 276 | } |
aoqi@0 | 277 | } |