Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset fdbe50121f48
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.Collections; |
aoqi@0 | 29 | import java.util.HashMap; |
aoqi@0 | 30 | import java.util.HashSet; |
aoqi@0 | 31 | import java.util.Iterator; |
aoqi@0 | 32 | import java.util.LinkedHashMap; |
aoqi@0 | 33 | import java.util.Map; |
aoqi@0 | 34 | import java.util.Set; |
aoqi@0 | 35 | |
aoqi@0 | 36 | import javax.xml.bind.annotation.XmlAttribute; |
aoqi@0 | 37 | import javax.xml.bind.annotation.XmlNsForm; |
aoqi@0 | 38 | import javax.xml.bind.annotation.XmlTransient; |
aoqi@0 | 39 | import javax.xml.namespace.QName; |
aoqi@0 | 40 | import javax.xml.transform.Result; |
aoqi@0 | 41 | |
aoqi@0 | 42 | import com.sun.codemodel.internal.JClass; |
aoqi@0 | 43 | import com.sun.codemodel.internal.JCodeModel; |
aoqi@0 | 44 | import com.sun.codemodel.internal.JPackage; |
aoqi@0 | 45 | import com.sun.tools.internal.xjc.ErrorReceiver; |
aoqi@0 | 46 | import com.sun.tools.internal.xjc.Options; |
aoqi@0 | 47 | import com.sun.tools.internal.xjc.Plugin; |
aoqi@0 | 48 | import com.sun.tools.internal.xjc.api.ClassNameAllocator; |
aoqi@0 | 49 | import com.sun.tools.internal.xjc.generator.bean.BeanGenerator; |
aoqi@0 | 50 | import com.sun.tools.internal.xjc.generator.bean.ImplStructureStrategy; |
aoqi@0 | 51 | import com.sun.tools.internal.xjc.model.nav.NClass; |
aoqi@0 | 52 | import com.sun.tools.internal.xjc.model.nav.NType; |
aoqi@0 | 53 | import com.sun.tools.internal.xjc.model.nav.NavigatorImpl; |
aoqi@0 | 54 | import com.sun.tools.internal.xjc.outline.Outline; |
aoqi@0 | 55 | import com.sun.tools.internal.xjc.reader.xmlschema.Messages; |
aoqi@0 | 56 | import com.sun.tools.internal.xjc.util.ErrorReceiverFilter; |
aoqi@0 | 57 | import com.sun.xml.internal.bind.api.impl.NameConverter; |
aoqi@0 | 58 | import com.sun.xml.internal.bind.v2.model.core.Ref; |
aoqi@0 | 59 | import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet; |
aoqi@0 | 60 | import com.sun.xml.internal.bind.v2.model.nav.Navigator; |
aoqi@0 | 61 | import com.sun.xml.internal.bind.v2.util.FlattenIterator; |
aoqi@0 | 62 | import com.sun.xml.internal.xsom.XSComponent; |
aoqi@0 | 63 | import com.sun.xml.internal.xsom.XSSchemaSet; |
aoqi@0 | 64 | |
aoqi@0 | 65 | import org.xml.sax.Locator; |
aoqi@0 | 66 | import org.xml.sax.SAXException; |
aoqi@0 | 67 | import org.xml.sax.helpers.LocatorImpl; |
aoqi@0 | 68 | |
aoqi@0 | 69 | /** |
aoqi@0 | 70 | * Root of the object model that represents the code that needs to be generated. |
aoqi@0 | 71 | * |
aoqi@0 | 72 | * <p> |
aoqi@0 | 73 | * A {@link Model} is a schema language neutral representation of the |
aoqi@0 | 74 | * result of a schema parsing. The back-end then works against this model |
aoqi@0 | 75 | * to turn this into a series of Java source code. |
aoqi@0 | 76 | * |
aoqi@0 | 77 | * @author Kohsuke Kawaguchi |
aoqi@0 | 78 | */ |
aoqi@0 | 79 | public final class Model implements TypeInfoSet<NType,NClass,Void,Void>, CCustomizable { |
aoqi@0 | 80 | |
aoqi@0 | 81 | /** |
aoqi@0 | 82 | * Generated beans. |
aoqi@0 | 83 | */ |
aoqi@0 | 84 | private final Map<NClass,CClassInfo> beans = new LinkedHashMap<NClass,CClassInfo>(); |
aoqi@0 | 85 | |
aoqi@0 | 86 | /** |
aoqi@0 | 87 | * Generated enums. |
aoqi@0 | 88 | */ |
aoqi@0 | 89 | private final Map<NClass,CEnumLeafInfo> enums = new LinkedHashMap<NClass,CEnumLeafInfo>(); |
aoqi@0 | 90 | |
aoqi@0 | 91 | /** |
aoqi@0 | 92 | * The element mappings. |
aoqi@0 | 93 | */ |
aoqi@0 | 94 | private final Map<NClass/*scope*/,Map<QName,CElementInfo>> elementMappings = |
aoqi@0 | 95 | new HashMap<NClass,Map<QName,CElementInfo>>(); |
aoqi@0 | 96 | |
aoqi@0 | 97 | private final Iterable<? extends CElementInfo> allElements = |
aoqi@0 | 98 | new Iterable<CElementInfo>() { |
aoqi@0 | 99 | public Iterator<CElementInfo> iterator() { |
aoqi@0 | 100 | return new FlattenIterator<CElementInfo>(elementMappings.values()); |
aoqi@0 | 101 | } |
aoqi@0 | 102 | }; |
aoqi@0 | 103 | |
aoqi@0 | 104 | /** |
aoqi@0 | 105 | * {@link TypeUse}s for all named types. |
aoqi@0 | 106 | * <p> |
aoqi@0 | 107 | * I really don't want to promote the notion of a 'type' in any place except in the XML Schema code, |
aoqi@0 | 108 | * but this needs to be exposed for JAX-RPC. A reference to a named XML type will be converted into |
aoqi@0 | 109 | * a reference to a Java type with annotations. |
aoqi@0 | 110 | */ |
aoqi@0 | 111 | private final Map<QName,TypeUse> typeUses = new LinkedHashMap<QName, TypeUse>(); |
aoqi@0 | 112 | |
aoqi@0 | 113 | /** |
aoqi@0 | 114 | * {@link NameConverter} to be used. |
aoqi@0 | 115 | */ |
aoqi@0 | 116 | private NameConverter nameConverter; |
aoqi@0 | 117 | |
aoqi@0 | 118 | /** |
aoqi@0 | 119 | * Single linked list that connects all {@link CCustomizations} that belong to this model. |
aoqi@0 | 120 | * |
aoqi@0 | 121 | * @see CCustomizations#next |
aoqi@0 | 122 | */ |
aoqi@0 | 123 | /*package*/ CCustomizations customizations; |
aoqi@0 | 124 | |
aoqi@0 | 125 | /** |
aoqi@0 | 126 | * This field controls the generation of package level annotations for s2j |
aoqi@0 | 127 | */ |
aoqi@0 | 128 | private boolean packageLevelAnnotations = true; |
aoqi@0 | 129 | |
aoqi@0 | 130 | /** |
aoqi@0 | 131 | * If this model was built from XML Schema, this field |
aoqi@0 | 132 | * stores the root object of the parse schema model. |
aoqi@0 | 133 | * Otherwise null. |
aoqi@0 | 134 | * |
aoqi@0 | 135 | * @sine 2.1.1 |
aoqi@0 | 136 | */ |
aoqi@0 | 137 | public final XSSchemaSet schemaComponent; |
aoqi@0 | 138 | |
aoqi@0 | 139 | private CCustomizations gloablCustomizations = new CCustomizations(); |
aoqi@0 | 140 | |
aoqi@0 | 141 | /** |
aoqi@0 | 142 | * @param nc |
aoqi@0 | 143 | * Usually this should be set in the constructor, but we do allow this parameter |
aoqi@0 | 144 | * to be initially null, and then set later. |
aoqi@0 | 145 | * @param schemaComponent |
aoqi@0 | 146 | * The source schema model, if this is built from XSD. |
aoqi@0 | 147 | */ |
aoqi@0 | 148 | public Model( Options opts, JCodeModel cm, NameConverter nc, ClassNameAllocator allocator, XSSchemaSet schemaComponent ) { |
aoqi@0 | 149 | this.options = opts; |
aoqi@0 | 150 | this.codeModel = cm; |
aoqi@0 | 151 | this.nameConverter = nc; |
aoqi@0 | 152 | this.defaultSymbolSpace = new SymbolSpace(codeModel); |
aoqi@0 | 153 | defaultSymbolSpace.setType(codeModel.ref(Object.class)); |
aoqi@0 | 154 | |
aoqi@0 | 155 | elementMappings.put(null,new HashMap<QName,CElementInfo>()); |
aoqi@0 | 156 | |
aoqi@0 | 157 | if(opts.automaticNameConflictResolution) |
aoqi@0 | 158 | allocator = new AutoClassNameAllocator(allocator); |
aoqi@0 | 159 | this.allocator = new ClassNameAllocatorWrapper(allocator); |
aoqi@0 | 160 | this.schemaComponent = schemaComponent; |
aoqi@0 | 161 | this.gloablCustomizations.setParent(this,this); |
aoqi@0 | 162 | } |
aoqi@0 | 163 | |
aoqi@0 | 164 | public void setNameConverter(NameConverter nameConverter) { |
aoqi@0 | 165 | assert this.nameConverter==null; |
aoqi@0 | 166 | assert nameConverter!=null; |
aoqi@0 | 167 | this.nameConverter = nameConverter; |
aoqi@0 | 168 | } |
aoqi@0 | 169 | |
aoqi@0 | 170 | /** |
aoqi@0 | 171 | * Gets the name converter that shall be used to parse XML names into Java names. |
aoqi@0 | 172 | */ |
aoqi@0 | 173 | public final NameConverter getNameConverter() { |
aoqi@0 | 174 | return nameConverter; |
aoqi@0 | 175 | } |
aoqi@0 | 176 | |
aoqi@0 | 177 | public boolean isPackageLevelAnnotations() { |
aoqi@0 | 178 | return packageLevelAnnotations; |
aoqi@0 | 179 | } |
aoqi@0 | 180 | |
aoqi@0 | 181 | public void setPackageLevelAnnotations(boolean packageLevelAnnotations) { |
aoqi@0 | 182 | this.packageLevelAnnotations = packageLevelAnnotations; |
aoqi@0 | 183 | } |
aoqi@0 | 184 | |
aoqi@0 | 185 | /** |
aoqi@0 | 186 | * This model uses this code model exclusively. |
aoqi@0 | 187 | */ |
aoqi@0 | 188 | @XmlTransient |
aoqi@0 | 189 | public final JCodeModel codeModel; |
aoqi@0 | 190 | |
aoqi@0 | 191 | /** |
aoqi@0 | 192 | * Command-line options used for building this model. |
aoqi@0 | 193 | */ |
aoqi@0 | 194 | public final Options options; |
aoqi@0 | 195 | |
aoqi@0 | 196 | /** |
aoqi@0 | 197 | * True to generate serializable classes. |
aoqi@0 | 198 | */ |
aoqi@0 | 199 | @XmlAttribute |
aoqi@0 | 200 | public boolean serializable; |
aoqi@0 | 201 | |
aoqi@0 | 202 | /** |
aoqi@0 | 203 | * serial version UID to be generated. |
aoqi@0 | 204 | * |
aoqi@0 | 205 | * null if not to generate serialVersionUID field. |
aoqi@0 | 206 | */ |
aoqi@0 | 207 | @XmlAttribute |
aoqi@0 | 208 | public Long serialVersionUID; |
aoqi@0 | 209 | |
aoqi@0 | 210 | /** |
aoqi@0 | 211 | * If non-null, all the generated classes should eventually derive from this class. |
aoqi@0 | 212 | */ |
aoqi@0 | 213 | @XmlTransient |
aoqi@0 | 214 | public JClass rootClass; |
aoqi@0 | 215 | |
aoqi@0 | 216 | /** |
aoqi@0 | 217 | * If non-null, all the generated interfaces should eventually derive from this interface. |
aoqi@0 | 218 | */ |
aoqi@0 | 219 | @XmlTransient |
aoqi@0 | 220 | public JClass rootInterface; |
aoqi@0 | 221 | |
aoqi@0 | 222 | /** |
aoqi@0 | 223 | * Specifies the code generation strategy. |
aoqi@0 | 224 | * Must not be null. |
aoqi@0 | 225 | */ |
aoqi@0 | 226 | public ImplStructureStrategy strategy = ImplStructureStrategy.BEAN_ONLY; |
aoqi@0 | 227 | |
aoqi@0 | 228 | /** |
aoqi@0 | 229 | * This allocator has the final say on deciding the class name. |
aoqi@0 | 230 | * Must not be null. |
aoqi@0 | 231 | * |
aoqi@0 | 232 | * <p> |
aoqi@0 | 233 | * Model classes are responsible for using the allocator. |
aoqi@0 | 234 | * This allocator interaction should be transparent to the user/builder |
aoqi@0 | 235 | * of the model. |
aoqi@0 | 236 | */ |
aoqi@0 | 237 | /*package*/ final ClassNameAllocatorWrapper allocator; |
aoqi@0 | 238 | |
aoqi@0 | 239 | /** |
aoqi@0 | 240 | * Default ID/IDREF symbol space. Any ID/IDREF without explicit |
aoqi@0 | 241 | * reference to a symbol space is assumed to use this default |
aoqi@0 | 242 | * symbol space. |
aoqi@0 | 243 | */ |
aoqi@0 | 244 | @XmlTransient |
aoqi@0 | 245 | public final SymbolSpace defaultSymbolSpace; |
aoqi@0 | 246 | |
aoqi@0 | 247 | /** All the defined {@link SymbolSpace}s keyed by their name. */ |
aoqi@0 | 248 | private final Map<String,SymbolSpace> symbolSpaces = new HashMap<String,SymbolSpace>(); |
aoqi@0 | 249 | |
aoqi@0 | 250 | public SymbolSpace getSymbolSpace( String name ) { |
aoqi@0 | 251 | SymbolSpace ss = symbolSpaces.get(name); |
aoqi@0 | 252 | if(ss==null) |
aoqi@0 | 253 | symbolSpaces.put(name,ss=new SymbolSpace(codeModel)); |
aoqi@0 | 254 | return ss; |
aoqi@0 | 255 | } |
aoqi@0 | 256 | |
aoqi@0 | 257 | /** |
aoqi@0 | 258 | * Fully-generate the source code into the given model. |
aoqi@0 | 259 | * |
aoqi@0 | 260 | * @return |
aoqi@0 | 261 | * null if there was any errors. Otherwise it returns a valid |
aoqi@0 | 262 | * {@link Outline} object, which captures how the model objects |
aoqi@0 | 263 | * are mapped to the generated source code. |
aoqi@0 | 264 | * <p> |
aoqi@0 | 265 | * Add-ons can use those information to further augment the generated |
aoqi@0 | 266 | * source code. |
aoqi@0 | 267 | */ |
aoqi@0 | 268 | public Outline generateCode(Options opt,ErrorReceiver receiver) { |
aoqi@0 | 269 | ErrorReceiverFilter ehf = new ErrorReceiverFilter(receiver); |
aoqi@0 | 270 | |
aoqi@0 | 271 | // run extensions // moved to BGMBuilder._build() - issue with hyperjaxb3 |
aoqi@0 | 272 | // for( Plugin ma : opt.activePlugins ) |
aoqi@0 | 273 | // ma.postProcessModel(this,ehf); |
aoqi@0 | 274 | |
aoqi@0 | 275 | Outline o = BeanGenerator.generate(this, ehf); |
aoqi@0 | 276 | |
aoqi@0 | 277 | try {// run extensions |
aoqi@0 | 278 | for( Plugin ma : opt.activePlugins ) |
aoqi@0 | 279 | ma.run(o,opt,ehf); |
aoqi@0 | 280 | } catch (SAXException e) { |
aoqi@0 | 281 | // fatal error. error should have been reported |
aoqi@0 | 282 | return null; |
aoqi@0 | 283 | } |
aoqi@0 | 284 | |
aoqi@0 | 285 | // check for unused plug-in customizations. |
aoqi@0 | 286 | // these can be only checked after the plug-ins run, so it's here. |
aoqi@0 | 287 | // the JAXB bindings are checked by XMLSchema's builder. |
aoqi@0 | 288 | Set<CCustomizations> check = new HashSet<CCustomizations>(); |
aoqi@0 | 289 | for( CCustomizations c=customizations; c!=null; c=c.next ) { |
aoqi@0 | 290 | if(!check.add(c)) { |
aoqi@0 | 291 | throw new AssertionError(); // detect a loop |
aoqi@0 | 292 | } |
aoqi@0 | 293 | for (CPluginCustomization p : c) { |
aoqi@0 | 294 | if(!p.isAcknowledged()) { |
aoqi@0 | 295 | ehf.error( |
aoqi@0 | 296 | p.locator, |
aoqi@0 | 297 | Messages.format( |
aoqi@0 | 298 | Messages.ERR_UNACKNOWLEDGED_CUSTOMIZATION, |
aoqi@0 | 299 | p.element.getNodeName() |
aoqi@0 | 300 | )); |
aoqi@0 | 301 | ehf.error( |
aoqi@0 | 302 | c.getOwner().getLocator(), |
aoqi@0 | 303 | Messages.format( |
aoqi@0 | 304 | Messages.ERR_UNACKNOWLEDGED_CUSTOMIZATION_LOCATION)); |
aoqi@0 | 305 | } |
aoqi@0 | 306 | } |
aoqi@0 | 307 | } |
aoqi@0 | 308 | |
aoqi@0 | 309 | if(ehf.hadError()) |
aoqi@0 | 310 | o = null; |
aoqi@0 | 311 | return o; |
aoqi@0 | 312 | } |
aoqi@0 | 313 | |
aoqi@0 | 314 | /** |
aoqi@0 | 315 | * Represents the "top-level binding". |
aoqi@0 | 316 | * |
aoqi@0 | 317 | * <p> |
aoqi@0 | 318 | * This is used to support the use of a schema inside WSDL. |
aoqi@0 | 319 | * For XML Schema, the top-level binding is a map from |
aoqi@0 | 320 | * global element declarations to its representation class. |
aoqi@0 | 321 | * |
aoqi@0 | 322 | * <p> |
aoqi@0 | 323 | * For other schema languages, it should follow the appendicies in |
aoqi@0 | 324 | * WSDL (but in practice no one would use WSDL with a schema language |
aoqi@0 | 325 | * other than XML Schema, so it doesn't really matter.) |
aoqi@0 | 326 | * |
aoqi@0 | 327 | * <p> |
aoqi@0 | 328 | * This needs to be filled by the front-end. |
aoqi@0 | 329 | */ |
aoqi@0 | 330 | public final Map<QName,CClassInfo> createTopLevelBindings() { |
aoqi@0 | 331 | Map<QName,CClassInfo> r = new HashMap<QName,CClassInfo>(); |
aoqi@0 | 332 | for( CClassInfo b : beans().values() ) { |
aoqi@0 | 333 | if(b.isElement()) |
aoqi@0 | 334 | r.put(b.getElementName(),b); |
aoqi@0 | 335 | } |
aoqi@0 | 336 | return r; |
aoqi@0 | 337 | } |
aoqi@0 | 338 | |
aoqi@0 | 339 | public Navigator<NType,NClass,Void,Void> getNavigator() { |
aoqi@0 | 340 | return NavigatorImpl.theInstance; |
aoqi@0 | 341 | } |
aoqi@0 | 342 | |
aoqi@0 | 343 | public CNonElement getTypeInfo(NType type) { |
aoqi@0 | 344 | CBuiltinLeafInfo leaf = CBuiltinLeafInfo.LEAVES.get(type); |
aoqi@0 | 345 | if(leaf!=null) return leaf; |
aoqi@0 | 346 | |
aoqi@0 | 347 | return getClassInfo(getNavigator().asDecl(type)); |
aoqi@0 | 348 | } |
aoqi@0 | 349 | |
aoqi@0 | 350 | public CBuiltinLeafInfo getAnyTypeInfo() { |
aoqi@0 | 351 | return CBuiltinLeafInfo.ANYTYPE; |
aoqi@0 | 352 | } |
aoqi@0 | 353 | |
aoqi@0 | 354 | public CNonElement getTypeInfo(Ref<NType,NClass> ref) { |
aoqi@0 | 355 | // TODO: handle XmlValueList |
aoqi@0 | 356 | assert !ref.valueList; |
aoqi@0 | 357 | return getTypeInfo(ref.type); |
aoqi@0 | 358 | } |
aoqi@0 | 359 | |
aoqi@0 | 360 | public Map<NClass,CClassInfo> beans() { |
aoqi@0 | 361 | return beans; |
aoqi@0 | 362 | } |
aoqi@0 | 363 | |
aoqi@0 | 364 | public Map<NClass,CEnumLeafInfo> enums() { |
aoqi@0 | 365 | return enums; |
aoqi@0 | 366 | } |
aoqi@0 | 367 | |
aoqi@0 | 368 | public Map<QName,TypeUse> typeUses() { |
aoqi@0 | 369 | return typeUses; |
aoqi@0 | 370 | } |
aoqi@0 | 371 | |
aoqi@0 | 372 | /** |
aoqi@0 | 373 | * No array mapping generation for XJC. |
aoqi@0 | 374 | */ |
aoqi@0 | 375 | public Map<NType, ? extends CArrayInfo> arrays() { |
aoqi@0 | 376 | return Collections.emptyMap(); |
aoqi@0 | 377 | } |
aoqi@0 | 378 | |
aoqi@0 | 379 | public Map<NType, ? extends CBuiltinLeafInfo> builtins() { |
aoqi@0 | 380 | return CBuiltinLeafInfo.LEAVES; |
aoqi@0 | 381 | } |
aoqi@0 | 382 | |
aoqi@0 | 383 | public CClassInfo getClassInfo(NClass t) { |
aoqi@0 | 384 | return beans.get(t); |
aoqi@0 | 385 | } |
aoqi@0 | 386 | |
aoqi@0 | 387 | public CElementInfo getElementInfo(NClass scope,QName name) { |
aoqi@0 | 388 | Map<QName,CElementInfo> m = elementMappings.get(scope); |
aoqi@0 | 389 | if(m!=null) { |
aoqi@0 | 390 | CElementInfo r = m.get(name); |
aoqi@0 | 391 | if(r!=null) return r; |
aoqi@0 | 392 | } |
aoqi@0 | 393 | return elementMappings.get(null).get(name); |
aoqi@0 | 394 | } |
aoqi@0 | 395 | |
aoqi@0 | 396 | public Map<QName,CElementInfo> getElementMappings(NClass scope) { |
aoqi@0 | 397 | return elementMappings.get(scope); |
aoqi@0 | 398 | } |
aoqi@0 | 399 | |
aoqi@0 | 400 | public Iterable<? extends CElementInfo> getAllElements() { |
aoqi@0 | 401 | return allElements; |
aoqi@0 | 402 | } |
aoqi@0 | 403 | |
aoqi@0 | 404 | /** |
aoqi@0 | 405 | * @deprecated |
aoqi@0 | 406 | * Always return null. Perhaps you are interested in {@link #schemaComponent}? |
aoqi@0 | 407 | */ |
aoqi@0 | 408 | public XSComponent getSchemaComponent() { |
aoqi@0 | 409 | return null; |
aoqi@0 | 410 | } |
aoqi@0 | 411 | |
aoqi@0 | 412 | /** |
aoqi@0 | 413 | * @deprecated |
aoqi@0 | 414 | * No line number available for the "root" component. |
aoqi@0 | 415 | */ |
aoqi@0 | 416 | public Locator getLocator() { |
aoqi@0 | 417 | LocatorImpl r = new LocatorImpl(); |
aoqi@0 | 418 | r.setLineNumber(-1); |
aoqi@0 | 419 | r.setColumnNumber(-1); |
aoqi@0 | 420 | return r; |
aoqi@0 | 421 | } |
aoqi@0 | 422 | |
aoqi@0 | 423 | /** |
aoqi@0 | 424 | * Gets the global customizations. |
aoqi@0 | 425 | */ |
aoqi@0 | 426 | public CCustomizations getCustomizations() { |
aoqi@0 | 427 | return gloablCustomizations; |
aoqi@0 | 428 | } |
aoqi@0 | 429 | |
aoqi@0 | 430 | /** |
aoqi@0 | 431 | * Not implemented in the compile-time model. |
aoqi@0 | 432 | */ |
aoqi@0 | 433 | public Map<String, String> getXmlNs(String namespaceUri) { |
aoqi@0 | 434 | return Collections.emptyMap(); |
aoqi@0 | 435 | } |
aoqi@0 | 436 | |
aoqi@0 | 437 | public Map<String, String> getSchemaLocations() { |
aoqi@0 | 438 | return Collections.emptyMap(); |
aoqi@0 | 439 | } |
aoqi@0 | 440 | |
aoqi@0 | 441 | public XmlNsForm getElementFormDefault(String nsUri) { |
aoqi@0 | 442 | throw new UnsupportedOperationException(); |
aoqi@0 | 443 | } |
aoqi@0 | 444 | |
aoqi@0 | 445 | public XmlNsForm getAttributeFormDefault(String nsUri) { |
aoqi@0 | 446 | throw new UnsupportedOperationException(); |
aoqi@0 | 447 | } |
aoqi@0 | 448 | |
aoqi@0 | 449 | public void dump(Result out) { |
aoqi@0 | 450 | // TODO |
aoqi@0 | 451 | throw new UnsupportedOperationException(); |
aoqi@0 | 452 | } |
aoqi@0 | 453 | |
aoqi@0 | 454 | /*package*/ void add( CEnumLeafInfo e ) { |
aoqi@0 | 455 | enums.put( e.getClazz(), e ); |
aoqi@0 | 456 | } |
aoqi@0 | 457 | |
aoqi@0 | 458 | /*package*/ void add( CClassInfo ci ) { |
aoqi@0 | 459 | beans.put( ci.getClazz(), ci ); |
aoqi@0 | 460 | } |
aoqi@0 | 461 | |
aoqi@0 | 462 | /*package*/ void add( CElementInfo ei ) { |
aoqi@0 | 463 | NClass clazz = null; |
aoqi@0 | 464 | if(ei.getScope()!=null) |
aoqi@0 | 465 | clazz = ei.getScope().getClazz(); |
aoqi@0 | 466 | |
aoqi@0 | 467 | Map<QName,CElementInfo> m = elementMappings.get(clazz); |
aoqi@0 | 468 | if(m==null) |
aoqi@0 | 469 | elementMappings.put(clazz,m=new HashMap<QName,CElementInfo>()); |
aoqi@0 | 470 | m.put(ei.getElementName(),ei); |
aoqi@0 | 471 | } |
aoqi@0 | 472 | |
aoqi@0 | 473 | |
aoqi@0 | 474 | private final Map<JPackage,CClassInfoParent.Package> cache = new HashMap<JPackage,CClassInfoParent.Package>(); |
aoqi@0 | 475 | |
aoqi@0 | 476 | public CClassInfoParent.Package getPackage(JPackage pkg) { |
aoqi@0 | 477 | CClassInfoParent.Package r = cache.get(pkg); |
aoqi@0 | 478 | if(r==null) |
aoqi@0 | 479 | cache.put(pkg,r=new CClassInfoParent.Package(pkg)); |
aoqi@0 | 480 | return r; |
aoqi@0 | 481 | } |
aoqi@0 | 482 | |
aoqi@0 | 483 | /*package*/ static final Locator EMPTY_LOCATOR; |
aoqi@0 | 484 | |
aoqi@0 | 485 | static { |
aoqi@0 | 486 | LocatorImpl l = new LocatorImpl(); |
aoqi@0 | 487 | l.setColumnNumber(-1); |
aoqi@0 | 488 | l.setLineNumber(-1); |
aoqi@0 | 489 | EMPTY_LOCATOR = l; |
aoqi@0 | 490 | } |
aoqi@0 | 491 | } |