Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
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 | import java.util.Collections; |
aoqi@0 | 30 | import java.util.HashSet; |
aoqi@0 | 31 | import java.util.List; |
aoqi@0 | 32 | import java.util.Set; |
aoqi@0 | 33 | |
aoqi@0 | 34 | import javax.xml.bind.JAXBElement; |
aoqi@0 | 35 | import javax.xml.bind.annotation.XmlElement; |
aoqi@0 | 36 | import javax.xml.namespace.QName; |
aoqi@0 | 37 | |
aoqi@0 | 38 | import com.sun.codemodel.internal.JPackage; |
aoqi@0 | 39 | import com.sun.codemodel.internal.JType; |
aoqi@0 | 40 | import com.sun.istack.internal.Nullable; |
aoqi@0 | 41 | import static com.sun.tools.internal.xjc.model.CElementPropertyInfo.CollectionMode.NOT_REPEATED; |
aoqi@0 | 42 | import static com.sun.tools.internal.xjc.model.CElementPropertyInfo.CollectionMode.REPEATED_VALUE; |
aoqi@0 | 43 | import com.sun.tools.internal.xjc.model.nav.NClass; |
aoqi@0 | 44 | import com.sun.tools.internal.xjc.model.nav.NType; |
aoqi@0 | 45 | import com.sun.tools.internal.xjc.model.nav.NavigatorImpl; |
aoqi@0 | 46 | import com.sun.tools.internal.xjc.outline.Aspect; |
aoqi@0 | 47 | import com.sun.tools.internal.xjc.outline.Outline; |
aoqi@0 | 48 | import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIInlineBinaryData; |
aoqi@0 | 49 | import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIFactoryMethod; |
aoqi@0 | 50 | import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder; |
aoqi@0 | 51 | import com.sun.tools.internal.xjc.reader.Ring; |
aoqi@0 | 52 | import com.sun.xml.internal.bind.v2.model.core.ElementInfo; |
aoqi@0 | 53 | import com.sun.xml.internal.xsom.XSElementDecl; |
aoqi@0 | 54 | import com.sun.xml.internal.xsom.XmlString; |
aoqi@0 | 55 | |
aoqi@0 | 56 | import org.xml.sax.Locator; |
aoqi@0 | 57 | |
aoqi@0 | 58 | /** |
aoqi@0 | 59 | * {@link ElementInfo} implementation for the compile-time model. |
aoqi@0 | 60 | * |
aoqi@0 | 61 | * <p> |
aoqi@0 | 62 | * As an NType, it represents the Java representation of this element |
aoqi@0 | 63 | * (either JAXBElement<T> or Foo). |
aoqi@0 | 64 | * |
aoqi@0 | 65 | * @author Kohsuke Kawaguchi |
aoqi@0 | 66 | */ |
aoqi@0 | 67 | public final class CElementInfo extends AbstractCElement |
aoqi@0 | 68 | implements ElementInfo<NType,NClass>, NType, CClassInfoParent { |
aoqi@0 | 69 | |
aoqi@0 | 70 | private final QName tagName; |
aoqi@0 | 71 | |
aoqi@0 | 72 | /** |
aoqi@0 | 73 | * Represents {@code JAXBElement<ContentType>}. |
aoqi@0 | 74 | */ |
aoqi@0 | 75 | private NType type; |
aoqi@0 | 76 | |
aoqi@0 | 77 | /** |
aoqi@0 | 78 | * If this element produces its own class, the short name of that class. |
aoqi@0 | 79 | * Otherwise null. |
aoqi@0 | 80 | */ |
aoqi@0 | 81 | private String className; |
aoqi@0 | 82 | |
aoqi@0 | 83 | /** |
aoqi@0 | 84 | * If this element is global, the element info is considered to be |
aoqi@0 | 85 | * package-level, and this points to the package in which this element |
aoqi@0 | 86 | * lives in. |
aoqi@0 | 87 | * |
aoqi@0 | 88 | * <p> |
aoqi@0 | 89 | * For local elements, this points to the parent {@link CClassInfo}. |
aoqi@0 | 90 | */ |
aoqi@0 | 91 | public final CClassInfoParent parent; |
aoqi@0 | 92 | |
aoqi@0 | 93 | private CElementInfo substitutionHead; |
aoqi@0 | 94 | |
aoqi@0 | 95 | /** |
aoqi@0 | 96 | * Lazily computed. |
aoqi@0 | 97 | */ |
aoqi@0 | 98 | private Set<CElementInfo> substitutionMembers; |
aoqi@0 | 99 | |
aoqi@0 | 100 | /** |
aoqi@0 | 101 | * {@link Model} that owns this object. |
aoqi@0 | 102 | */ |
aoqi@0 | 103 | private final Model model; |
aoqi@0 | 104 | |
aoqi@0 | 105 | private CElementPropertyInfo property; |
aoqi@0 | 106 | |
aoqi@0 | 107 | /** |
aoqi@0 | 108 | * Custom {@link #getSqueezedName() squeezed name}, if any. |
aoqi@0 | 109 | */ |
aoqi@0 | 110 | private /*almost final*/ @Nullable String squeezedName; |
aoqi@0 | 111 | |
aoqi@0 | 112 | /** |
aoqi@0 | 113 | * Creates an element in the given parent. |
aoqi@0 | 114 | * |
aoqi@0 | 115 | * <p> |
aoqi@0 | 116 | * When using this construction, {@link #initContentType(TypeUse, XSElementDecl, XmlString)} |
aoqi@0 | 117 | * must not be invoked. |
aoqi@0 | 118 | */ |
aoqi@0 | 119 | public CElementInfo(Model model,QName tagName, CClassInfoParent parent, TypeUse contentType, XmlString defaultValue, XSElementDecl source, CCustomizations customizations, Locator location ) { |
aoqi@0 | 120 | super(model,source,location,customizations); |
aoqi@0 | 121 | this.tagName = tagName; |
aoqi@0 | 122 | this.model = model; |
aoqi@0 | 123 | this.parent = parent; |
aoqi@0 | 124 | if(contentType!=null) |
aoqi@0 | 125 | initContentType(contentType, source, defaultValue); |
aoqi@0 | 126 | |
aoqi@0 | 127 | model.add(this); |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | /** |
aoqi@0 | 131 | * Creates an element with a class in the given parent. |
aoqi@0 | 132 | * |
aoqi@0 | 133 | * <p> |
aoqi@0 | 134 | * When using this construction, the caller must use |
aoqi@0 | 135 | * {@link #initContentType(TypeUse, XSElementDecl, XmlString)} to fill in the content type |
aoqi@0 | 136 | * later. |
aoqi@0 | 137 | * |
aoqi@0 | 138 | * This is to avoid a circular model construction dependency between buidling a type |
aoqi@0 | 139 | * inside an element and element itself. To build a content type, you need to have |
aoqi@0 | 140 | * {@link CElementInfo} for a parent, so we can't take it as a constructor parameter. |
aoqi@0 | 141 | */ |
aoqi@0 | 142 | public CElementInfo(Model model,QName tagName, CClassInfoParent parent, String className, CCustomizations customizations, Locator location ) { |
aoqi@0 | 143 | this(model,tagName,parent,null,null,null,customizations,location); |
aoqi@0 | 144 | this.className = className; |
aoqi@0 | 145 | } |
aoqi@0 | 146 | |
aoqi@0 | 147 | public void initContentType(TypeUse contentType, @Nullable XSElementDecl source, XmlString defaultValue) { |
aoqi@0 | 148 | assert this.property==null; // must not be called twice |
aoqi@0 | 149 | |
aoqi@0 | 150 | this.property = new CElementPropertyInfo("Value", |
aoqi@0 | 151 | contentType.isCollection()?REPEATED_VALUE:NOT_REPEATED, |
aoqi@0 | 152 | contentType.idUse(), |
aoqi@0 | 153 | contentType.getExpectedMimeType(), |
aoqi@0 | 154 | source,null,getLocator(),true); |
aoqi@0 | 155 | this.property.setAdapter(contentType.getAdapterUse()); |
aoqi@0 | 156 | BIInlineBinaryData.handle(source,property); |
aoqi@0 | 157 | property.getTypes().add(new CTypeRef(contentType.getInfo(),tagName,CTypeRef.getSimpleTypeName(source), true,defaultValue)); |
aoqi@0 | 158 | this.type = NavigatorImpl.createParameterizedType( |
aoqi@0 | 159 | NavigatorImpl.theInstance.ref(JAXBElement.class), |
aoqi@0 | 160 | getContentInMemoryType() ); |
aoqi@0 | 161 | |
aoqi@0 | 162 | BIFactoryMethod factoryMethod = Ring.get(BGMBuilder.class).getBindInfo(source).get(BIFactoryMethod.class); |
aoqi@0 | 163 | if(factoryMethod!=null) { |
aoqi@0 | 164 | factoryMethod.markAsAcknowledged(); |
aoqi@0 | 165 | this.squeezedName = factoryMethod.name; |
aoqi@0 | 166 | } |
aoqi@0 | 167 | |
aoqi@0 | 168 | } |
aoqi@0 | 169 | |
aoqi@0 | 170 | public final String getDefaultValue() { |
aoqi@0 | 171 | return getProperty().getTypes().get(0).getDefaultValue(); |
aoqi@0 | 172 | } |
aoqi@0 | 173 | |
aoqi@0 | 174 | public final JPackage _package() { |
aoqi@0 | 175 | return parent.getOwnerPackage(); |
aoqi@0 | 176 | } |
aoqi@0 | 177 | |
aoqi@0 | 178 | public CNonElement getContentType() { |
aoqi@0 | 179 | return getProperty().ref().get(0); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | public NType getContentInMemoryType() { |
aoqi@0 | 183 | if(getProperty().getAdapter()==null) { |
aoqi@0 | 184 | NType itemType = getContentType().getType(); |
aoqi@0 | 185 | if(!property.isCollection()) |
aoqi@0 | 186 | return itemType; |
aoqi@0 | 187 | |
aoqi@0 | 188 | return NavigatorImpl.createParameterizedType(List.class,itemType); |
aoqi@0 | 189 | } else { |
aoqi@0 | 190 | return getProperty().getAdapter().customType; |
aoqi@0 | 191 | } |
aoqi@0 | 192 | } |
aoqi@0 | 193 | |
aoqi@0 | 194 | public CElementPropertyInfo getProperty() { |
aoqi@0 | 195 | return property; |
aoqi@0 | 196 | } |
aoqi@0 | 197 | |
aoqi@0 | 198 | public CClassInfo getScope() { |
aoqi@0 | 199 | if(parent instanceof CClassInfo) |
aoqi@0 | 200 | return (CClassInfo)parent; |
aoqi@0 | 201 | return null; |
aoqi@0 | 202 | } |
aoqi@0 | 203 | |
aoqi@0 | 204 | /** |
aoqi@0 | 205 | * @deprecated why are you calling a method that returns this? |
aoqi@0 | 206 | */ |
aoqi@0 | 207 | public NType getType() { |
aoqi@0 | 208 | return this; |
aoqi@0 | 209 | } |
aoqi@0 | 210 | |
aoqi@0 | 211 | public QName getElementName() { |
aoqi@0 | 212 | return tagName; |
aoqi@0 | 213 | } |
aoqi@0 | 214 | |
aoqi@0 | 215 | public JType toType(Outline o, Aspect aspect) { |
aoqi@0 | 216 | if(className==null) |
aoqi@0 | 217 | return type.toType(o,aspect); |
aoqi@0 | 218 | else |
aoqi@0 | 219 | return o.getElement(this).implClass; |
aoqi@0 | 220 | } |
aoqi@0 | 221 | |
aoqi@0 | 222 | /** |
aoqi@0 | 223 | * Returns the "squeezed name" of this element. |
aoqi@0 | 224 | * |
aoqi@0 | 225 | * @see CClassInfo#getSqueezedName() |
aoqi@0 | 226 | */ |
aoqi@0 | 227 | @XmlElement |
aoqi@0 | 228 | public String getSqueezedName() { |
aoqi@0 | 229 | if(squeezedName!=null) return squeezedName; |
aoqi@0 | 230 | |
aoqi@0 | 231 | StringBuilder b = new StringBuilder(); |
aoqi@0 | 232 | CClassInfo s = getScope(); |
aoqi@0 | 233 | if(s!=null) |
aoqi@0 | 234 | b.append(s.getSqueezedName()); |
aoqi@0 | 235 | if(className!=null) |
aoqi@0 | 236 | b.append(className); |
aoqi@0 | 237 | else |
aoqi@0 | 238 | b.append( model.getNameConverter().toClassName(tagName.getLocalPart())); |
aoqi@0 | 239 | return b.toString(); |
aoqi@0 | 240 | } |
aoqi@0 | 241 | |
aoqi@0 | 242 | public CElementInfo getSubstitutionHead() { |
aoqi@0 | 243 | return substitutionHead; |
aoqi@0 | 244 | } |
aoqi@0 | 245 | |
aoqi@0 | 246 | public Collection<CElementInfo> getSubstitutionMembers() { |
aoqi@0 | 247 | if(substitutionMembers==null) |
aoqi@0 | 248 | return Collections.emptyList(); |
aoqi@0 | 249 | else |
aoqi@0 | 250 | return substitutionMembers; |
aoqi@0 | 251 | } |
aoqi@0 | 252 | |
aoqi@0 | 253 | public void setSubstitutionHead(CElementInfo substitutionHead) { |
aoqi@0 | 254 | // don't set it twice |
aoqi@0 | 255 | assert this.substitutionHead==null; |
aoqi@0 | 256 | assert substitutionHead!=null; |
aoqi@0 | 257 | this.substitutionHead = substitutionHead; |
aoqi@0 | 258 | |
aoqi@0 | 259 | if(substitutionHead.substitutionMembers==null) |
aoqi@0 | 260 | substitutionHead.substitutionMembers = new HashSet<CElementInfo>(); |
aoqi@0 | 261 | substitutionHead.substitutionMembers.add(this); |
aoqi@0 | 262 | } |
aoqi@0 | 263 | |
aoqi@0 | 264 | public boolean isBoxedType() { |
aoqi@0 | 265 | return false; |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
aoqi@0 | 268 | public String fullName() { |
aoqi@0 | 269 | if(className==null) |
aoqi@0 | 270 | return type.fullName(); |
aoqi@0 | 271 | else { |
aoqi@0 | 272 | String r = parent.fullName(); |
aoqi@0 | 273 | if(r.length()==0) return className; |
aoqi@0 | 274 | else return r+'.'+className; |
aoqi@0 | 275 | } |
aoqi@0 | 276 | } |
aoqi@0 | 277 | |
aoqi@0 | 278 | public <T> T accept(Visitor<T> visitor) { |
aoqi@0 | 279 | return visitor.onElement(this); |
aoqi@0 | 280 | } |
aoqi@0 | 281 | |
aoqi@0 | 282 | public JPackage getOwnerPackage() { |
aoqi@0 | 283 | return parent.getOwnerPackage(); |
aoqi@0 | 284 | } |
aoqi@0 | 285 | |
aoqi@0 | 286 | public String shortName() { |
aoqi@0 | 287 | return className; |
aoqi@0 | 288 | } |
aoqi@0 | 289 | |
aoqi@0 | 290 | /** |
aoqi@0 | 291 | * True if this element has its own class |
aoqi@0 | 292 | * (as opposed to be represented as an instance of {@link JAXBElement}. |
aoqi@0 | 293 | */ |
aoqi@0 | 294 | public boolean hasClass() { |
aoqi@0 | 295 | return className!=null; |
aoqi@0 | 296 | } |
aoqi@0 | 297 | } |