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