src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/xmlschema/BGMBuilder.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.tools.internal.xjc.reader.xmlschema;
ohair@286 27
ohair@286 28 import java.util.ArrayList;
ohair@286 29 import java.util.HashMap;
ohair@286 30 import java.util.List;
ohair@286 31 import java.util.Map;
ohair@286 32 import java.util.Set;
ohair@286 33
ohair@286 34 import javax.xml.namespace.QName;
ohair@286 35 import javax.xml.transform.Transformer;
ohair@286 36 import javax.xml.transform.TransformerConfigurationException;
ohair@286 37 import javax.xml.transform.TransformerFactory;
ohair@286 38
ohair@286 39 import com.sun.codemodel.internal.JCodeModel;
ohair@286 40 import com.sun.codemodel.internal.fmt.JTextFile;
ohair@286 41 import com.sun.istack.internal.NotNull;
ohair@286 42 import com.sun.istack.internal.Nullable;
ohair@286 43 import com.sun.tools.internal.xjc.ErrorReceiver;
ohair@286 44 import com.sun.tools.internal.xjc.Options;
ohair@286 45 import com.sun.tools.internal.xjc.Plugin;
ohair@286 46 import com.sun.tools.internal.xjc.generator.bean.field.FieldRendererFactory;
ohair@286 47 import com.sun.tools.internal.xjc.model.CClassInfoParent;
ohair@286 48 import com.sun.tools.internal.xjc.model.Model;
ohair@286 49 import com.sun.tools.internal.xjc.reader.ModelChecker;
ohair@286 50 import com.sun.tools.internal.xjc.reader.Ring;
ohair@286 51 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIDeclaration;
ohair@286 52 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIDom;
ohair@286 53 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIGlobalBinding;
ohair@286 54 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BISchemaBinding;
ohair@286 55 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BISerializable;
ohair@286 56 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BindInfo;
ohair@286 57 import com.sun.tools.internal.xjc.util.CodeModelClassFactory;
ohair@286 58 import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
ohair@286 59 import com.sun.xml.internal.bind.api.impl.NameConverter;
alanb@368 60 import com.sun.xml.internal.bind.v2.util.XmlFactory;
ohair@286 61 import com.sun.xml.internal.xsom.XSAnnotation;
ohair@286 62 import com.sun.xml.internal.xsom.XSAttributeUse;
ohair@286 63 import com.sun.xml.internal.xsom.XSComponent;
ohair@286 64 import com.sun.xml.internal.xsom.XSDeclaration;
ohair@286 65 import com.sun.xml.internal.xsom.XSParticle;
ohair@286 66 import com.sun.xml.internal.xsom.XSSchema;
ohair@286 67 import com.sun.xml.internal.xsom.XSSchemaSet;
ohair@286 68 import com.sun.xml.internal.xsom.XSSimpleType;
ohair@286 69 import com.sun.xml.internal.xsom.XSTerm;
ohair@286 70 import com.sun.xml.internal.xsom.XSType;
ohair@286 71 import com.sun.xml.internal.xsom.XSWildcard;
ohair@286 72 import com.sun.xml.internal.xsom.util.XSFinder;
ohair@286 73
ohair@286 74 import org.xml.sax.Locator;
ohair@286 75
ohair@286 76 /**
ohair@286 77 * Root of the XML Schema binder.
ohair@286 78 *
ohair@286 79 * <div><img src="doc-files/binding_chart.png"/></div>
ohair@286 80 *
ohair@286 81 * @author Kohsuke Kawaguchi
ohair@286 82 */
ohair@286 83 public class BGMBuilder extends BindingComponent {
ohair@286 84
ohair@286 85 /**
ohair@286 86 * Entry point.
ohair@286 87 */
ohair@286 88 public static Model build( XSSchemaSet _schemas, JCodeModel codeModel,
ohair@286 89 ErrorReceiver _errorReceiver, Options opts ) {
ohair@286 90 // set up a ring
ohair@286 91 final Ring old = Ring.begin();
ohair@286 92 try {
ohair@286 93 ErrorReceiverFilter ef = new ErrorReceiverFilter(_errorReceiver);
ohair@286 94
ohair@286 95 Ring.add(XSSchemaSet.class,_schemas);
ohair@286 96 Ring.add(codeModel);
ohair@286 97 Model model = new Model(opts, codeModel, null/*set later*/, opts.classNameAllocator, _schemas);
ohair@286 98 Ring.add(model);
ohair@286 99 Ring.add(ErrorReceiver.class,ef);
ohair@286 100 Ring.add(CodeModelClassFactory.class,new CodeModelClassFactory(ef));
ohair@286 101
ohair@286 102 BGMBuilder builder = new BGMBuilder(opts.defaultPackage,opts.defaultPackage2,
ohair@286 103 opts.isExtensionMode(),opts.getFieldRendererFactory(), opts.activePlugins);
ohair@286 104 builder._build();
ohair@286 105
ohair@286 106 if(ef.hadError()) return null;
ohair@286 107 else return model;
ohair@286 108 } finally {
ohair@286 109 Ring.end(old);
ohair@286 110 }
ohair@286 111 }
ohair@286 112
ohair@286 113
ohair@286 114 /**
ohair@286 115 * True if the compiler is running in the extension mode
ohair@286 116 * (as opposed to the strict conformance mode.)
ohair@286 117 */
ohair@286 118 public final boolean inExtensionMode;
ohair@286 119
ohair@286 120 /**
ohair@286 121 * If this is non-null, this package name takes over
ohair@286 122 * all the schema customizations.
ohair@286 123 */
ohair@286 124 public final String defaultPackage1;
ohair@286 125
ohair@286 126 /**
ohair@286 127 * If this is non-null, this package name will be
ohair@286 128 * used when no customization is specified.
ohair@286 129 */
ohair@286 130 public final String defaultPackage2;
ohair@286 131
ohair@286 132 private final BindGreen green = Ring.get(BindGreen.class);
ohair@286 133 private final BindPurple purple = Ring.get(BindPurple.class);
ohair@286 134
ohair@286 135 public final Model model = Ring.get(Model.class);
ohair@286 136
ohair@286 137 public final FieldRendererFactory fieldRendererFactory;
ohair@286 138
ohair@286 139 /**
ohair@286 140 * Lazily computed {@link RefererFinder}.
ohair@286 141 *
ohair@286 142 * @see #getReferer
ohair@286 143 */
ohair@286 144 private RefererFinder refFinder;
ohair@286 145
ohair@286 146 private List<Plugin> activePlugins;
ohair@286 147
ohair@286 148 protected BGMBuilder(String defaultPackage1, String defaultPackage2,
ohair@286 149 boolean _inExtensionMode, FieldRendererFactory fieldRendererFactory,
ohair@286 150 List<Plugin> activePlugins) {
ohair@286 151 this.inExtensionMode = _inExtensionMode;
ohair@286 152 this.defaultPackage1 = defaultPackage1;
ohair@286 153 this.defaultPackage2 = defaultPackage2;
ohair@286 154 this.fieldRendererFactory = fieldRendererFactory;
ohair@286 155 this.activePlugins = activePlugins;
ohair@286 156 promoteGlobalBindings();
ohair@286 157 }
ohair@286 158
ohair@286 159 private void _build() {
ohair@286 160 // do the binding
ohair@286 161 buildContents();
ohair@286 162 getClassSelector().executeTasks();
ohair@286 163
ohair@286 164 // additional error check
ohair@286 165 // Reports unused customizations to the user as errors.
ohair@286 166 Ring.get(UnusedCustomizationChecker.class).run();
ohair@286 167
ohair@286 168 Ring.get(ModelChecker.class).check();
ohair@286 169
ohair@286 170 for( Plugin ma : activePlugins )
ohair@286 171 ma.postProcessModel(model, Ring.get(ErrorReceiver.class));
ohair@286 172
ohair@286 173 }
ohair@286 174
ohair@286 175
ohair@286 176 /** List up all the global bindings. */
ohair@286 177 private void promoteGlobalBindings() {
ohair@286 178 // promote any global bindings in the schema
ohair@286 179 XSSchemaSet schemas = Ring.get(XSSchemaSet.class);
ohair@286 180
ohair@286 181 for( XSSchema s : schemas.getSchemas() ) {
ohair@286 182 BindInfo bi = getBindInfo(s);
ohair@286 183
ohair@286 184 // collect all global customizations
ohair@286 185 model.getCustomizations().addAll(bi.toCustomizationList());
ohair@286 186
ohair@286 187 BIGlobalBinding gb = bi.get(BIGlobalBinding.class);
ohair@286 188 if(gb==null)
ohair@286 189 continue;
ohair@286 190
ohair@286 191 gb.markAsAcknowledged();
ohair@286 192
ohair@286 193 if(globalBinding==null) {
ohair@286 194 globalBinding = gb;
ohair@286 195 } else {
ohair@286 196 if (!globalBinding.isEqual(gb)) { // see Issue 687 - this may happen with syntactically imported documents
ohair@286 197 // acknowledge this customization and report an error
ohair@286 198 // otherwise the user will see "customization is attached to a wrong place" error,
ohair@286 199 // which is incorrect
ohair@286 200 getErrorReporter().error( gb.getLocation(),
ohair@286 201 Messages.ERR_MULTIPLE_GLOBAL_BINDINGS);
ohair@286 202 getErrorReporter().error( globalBinding.getLocation(),
ohair@286 203 Messages.ERR_MULTIPLE_GLOBAL_BINDINGS_OTHER);
ohair@286 204 }
ohair@286 205 }
ohair@286 206 }
ohair@286 207
ohair@286 208 if( globalBinding==null ) {
ohair@286 209 // no global customization is present.
ohair@286 210 // use the default one
ohair@286 211 globalBinding = new BIGlobalBinding();
ohair@286 212 BindInfo big = new BindInfo();
ohair@286 213 big.addDecl(globalBinding);
ohair@286 214 big.setOwner(this,null);
ohair@286 215 }
ohair@286 216
ohair@286 217 // code generation mode
ohair@286 218 model.strategy = globalBinding.getCodeGenerationStrategy();
ohair@286 219 model.rootClass = globalBinding.getSuperClass();
ohair@286 220 model.rootInterface = globalBinding.getSuperInterface();
ohair@286 221
ohair@286 222 particleBinder = globalBinding.isSimpleMode() ? new ExpressionParticleBinder() : new DefaultParticleBinder();
ohair@286 223
ohair@286 224 // check XJC extensions and realize them
ohair@286 225 BISerializable serial = globalBinding.getSerializable();
ohair@286 226 if(serial!=null) {
ohair@286 227 model.serializable = true;
ohair@286 228 model.serialVersionUID = serial.uid;
ohair@286 229 }
ohair@286 230
ohair@286 231 // obtain the name conversion mode
alanb@368 232 if (globalBinding.nameConverter!=null)
ohair@286 233 model.setNameConverter(globalBinding.nameConverter);
ohair@286 234
ohair@286 235 // attach global conversions to the appropriate simple types
ohair@286 236 globalBinding.dispatchGlobalConversions(schemas);
ohair@286 237
ohair@286 238 globalBinding.errorCheck();
ohair@286 239 }
ohair@286 240
ohair@286 241 /**
ohair@286 242 * Global bindings.
ohair@286 243 *
ohair@286 244 * The empty global binding is set as the default, so that
ohair@286 245 * there will be no need to test if the value is null.
ohair@286 246 */
ohair@286 247 private BIGlobalBinding globalBinding;
ohair@286 248
ohair@286 249 /**
ohair@286 250 * Gets the global bindings.
ohair@286 251 */
ohair@286 252 public @NotNull BIGlobalBinding getGlobalBinding() { return globalBinding; }
ohair@286 253
ohair@286 254
ohair@286 255 private ParticleBinder particleBinder;
ohair@286 256
ohair@286 257 /**
ohair@286 258 * Gets the particle binder for this binding.
ohair@286 259 */
ohair@286 260 public @NotNull ParticleBinder getParticleBinder() { return particleBinder; }
ohair@286 261
ohair@286 262
ohair@286 263 /**
ohair@286 264 * Name converter that implements "XML->Java name conversion"
ohair@286 265 * as specified in the spec.
ohair@286 266 *
ohair@286 267 * This object abstracts the detail that we use different name
ohair@286 268 * conversion depending on the customization.
ohair@286 269 *
ohair@286 270 * <p>
ohair@286 271 * This object should be used to perform any name conversion
ohair@286 272 * needs, instead of the JJavaName class in CodeModel.
ohair@286 273 */
ohair@286 274 public NameConverter getNameConverter() { return model.getNameConverter(); }
ohair@286 275
ohair@286 276 /** Fill-in the contents of each classes. */
ohair@286 277 private void buildContents() {
ohair@286 278 ClassSelector cs = getClassSelector();
ohair@286 279 SimpleTypeBuilder stb = Ring.get(SimpleTypeBuilder.class);
ohair@286 280
ohair@286 281 for( XSSchema s : Ring.get(XSSchemaSet.class).getSchemas() ) {
ohair@286 282 BISchemaBinding sb = getBindInfo(s).get(BISchemaBinding.class);
ohair@286 283
ohair@286 284 if(sb!=null && !sb.map) {
ohair@286 285 sb.markAsAcknowledged();
ohair@286 286 continue; // no mapping for this package
ohair@286 287 }
ohair@286 288
ohair@286 289 getClassSelector().pushClassScope( new CClassInfoParent.Package(
ohair@286 290 getClassSelector().getPackage(s.getTargetNamespace())) );
ohair@286 291
ohair@286 292 checkMultipleSchemaBindings(s);
ohair@286 293 processPackageJavadoc(s);
ohair@286 294 populate(s.getAttGroupDecls(),s);
ohair@286 295 populate(s.getAttributeDecls(),s);
ohair@286 296 populate(s.getElementDecls(),s);
ohair@286 297 populate(s.getModelGroupDecls(),s);
ohair@286 298
ohair@286 299 // fill in typeUses
ohair@286 300 for (XSType t : s.getTypes().values()) {
ohair@286 301 stb.refererStack.push(t);
ohair@286 302 model.typeUses().put( getName(t), cs.bindToType(t,s) );
ohair@286 303 stb.refererStack.pop();
ohair@286 304 }
ohair@286 305
ohair@286 306 getClassSelector().popClassScope();
ohair@286 307 }
ohair@286 308 }
ohair@286 309
ohair@286 310 /** Reports an error if there are more than one jaxb:schemaBindings customization. */
ohair@286 311 private void checkMultipleSchemaBindings( XSSchema schema ) {
ohair@286 312 ArrayList<Locator> locations = new ArrayList<Locator>();
ohair@286 313
ohair@286 314 BindInfo bi = getBindInfo(schema);
ohair@286 315 for( BIDeclaration bid : bi ) {
ohair@286 316 if( bid.getName()==BISchemaBinding.NAME )
ohair@286 317 locations.add( bid.getLocation() );
ohair@286 318 }
ohair@286 319 if(locations.size()<=1) return; // OK
ohair@286 320
ohair@286 321 // error
ohair@286 322 getErrorReporter().error( locations.get(0),
ohair@286 323 Messages.ERR_MULTIPLE_SCHEMA_BINDINGS,
ohair@286 324 schema.getTargetNamespace() );
ohair@286 325 for( int i=1; i<locations.size(); i++ )
ohair@286 326 getErrorReporter().error( (Locator)locations.get(i),
ohair@286 327 Messages.ERR_MULTIPLE_SCHEMA_BINDINGS_LOCATION);
ohair@286 328 }
ohair@286 329
ohair@286 330 /**
ohair@286 331 * Calls {@link ClassSelector} for each item in the iterator
ohair@286 332 * to populate class items if there is any.
ohair@286 333 */
ohair@286 334 private void populate( Map<String,? extends XSComponent> col, XSSchema schema ) {
ohair@286 335 ClassSelector cs = getClassSelector();
ohair@286 336 for( XSComponent sc : col.values() )
ohair@286 337 cs.bindToType(sc,schema);
ohair@286 338 }
ohair@286 339
ohair@286 340 /**
ohair@286 341 * Generates <code>package.html</code> if the customization
ohair@286 342 * says so.
ohair@286 343 */
ohair@286 344 private void processPackageJavadoc( XSSchema s ) {
ohair@286 345 // look for the schema-wide customization
ohair@286 346 BISchemaBinding cust = getBindInfo(s).get(BISchemaBinding.class);
ohair@286 347 if(cust==null) return; // not present
ohair@286 348
ohair@286 349 cust.markAsAcknowledged();
ohair@286 350 if( cust.getJavadoc()==null ) return; // no javadoc customization
ohair@286 351
ohair@286 352 // produce a HTML file
ohair@286 353 JTextFile html = new JTextFile("package.html");
ohair@286 354 html.setContents(cust.getJavadoc());
ohair@286 355 getClassSelector().getPackage(s.getTargetNamespace()).addResourceFile(html);
ohair@286 356 }
ohair@286 357
ohair@286 358
ohair@286 359
ohair@286 360
ohair@286 361
ohair@286 362
ohair@286 363 /**
ohair@286 364 * Gets or creates the BindInfo object associated to a schema component.
ohair@286 365 *
ohair@286 366 * @return
ohair@286 367 * Always return a non-null valid BindInfo object.
ohair@286 368 * Even if no declaration was specified, this method creates
ohair@286 369 * a new BindInfo so that new decls can be added.
ohair@286 370 */
ohair@286 371 public BindInfo getOrCreateBindInfo( XSComponent schemaComponent ) {
ohair@286 372
ohair@286 373 BindInfo bi = _getBindInfoReadOnly(schemaComponent);
ohair@286 374 if(bi!=null) return bi;
ohair@286 375
ohair@286 376 // XSOM is read-only, so we cannot add new annotations.
ohair@286 377 // for components that didn't have annotations,
ohair@286 378 // we maintain an external map.
ohair@286 379 bi = new BindInfo();
ohair@286 380 bi.setOwner(this,schemaComponent);
ohair@286 381 externalBindInfos.put(schemaComponent,bi);
ohair@286 382 return bi;
ohair@286 383 }
ohair@286 384
ohair@286 385
ohair@286 386 /**
ohair@286 387 * Used as a constant instance to represent the empty {@link BindInfo}.
ohair@286 388 */
ohair@286 389 private final BindInfo emptyBindInfo = new BindInfo();
ohair@286 390
ohair@286 391 /**
ohair@286 392 * Gets the BindInfo object associated to a schema component.
ohair@286 393 *
ohair@286 394 * @return
ohair@286 395 * always return a valid {@link BindInfo} object. If none
ohair@286 396 * is specified for the given component, a dummy empty BindInfo
ohair@286 397 * will be returned.
ohair@286 398 */
ohair@286 399 public BindInfo getBindInfo( XSComponent schemaComponent ) {
ohair@286 400 BindInfo bi = _getBindInfoReadOnly(schemaComponent);
ohair@286 401 if(bi!=null) return bi;
ohair@286 402 else return emptyBindInfo;
ohair@286 403 }
ohair@286 404
ohair@286 405 /**
ohair@286 406 * Gets the BindInfo object associated to a schema component.
ohair@286 407 *
ohair@286 408 * @return
ohair@286 409 * null if no bind info is associated to this schema component.
ohair@286 410 */
ohair@286 411 private BindInfo _getBindInfoReadOnly( XSComponent schemaComponent ) {
ohair@286 412
ohair@286 413 BindInfo bi = externalBindInfos.get(schemaComponent);
ohair@286 414 if(bi!=null) return bi;
ohair@286 415
ohair@286 416 XSAnnotation annon = schemaComponent.getAnnotation();
ohair@286 417 if(annon!=null) {
ohair@286 418 bi = (BindInfo)annon.getAnnotation();
ohair@286 419 if(bi!=null) {
ohair@286 420 if(bi.getOwner()==null)
ohair@286 421 bi.setOwner(this,schemaComponent);
ohair@286 422 return bi;
ohair@286 423 }
ohair@286 424 }
ohair@286 425
ohair@286 426 return null;
ohair@286 427 }
ohair@286 428
ohair@286 429 /**
ohair@286 430 * A map that stores binding declarations augmented by XJC.
ohair@286 431 */
ohair@286 432 private final Map<XSComponent,BindInfo> externalBindInfos = new HashMap<XSComponent,BindInfo>();
ohair@286 433
ohair@286 434 /**
ohair@286 435 * Gets the {@link BIDom} object that applies to the given particle.
ohair@286 436 */
ohair@286 437 protected final BIDom getLocalDomCustomization( XSParticle p ) {
ohair@286 438 if (p == null) {
ohair@286 439 return null;
ohair@286 440 }
ohair@286 441 BIDom dom = getBindInfo(p).get(BIDom.class);
ohair@286 442 if(dom!=null) return dom;
ohair@286 443
ohair@286 444 // if not, the term might have one.
ohair@286 445 dom = getBindInfo(p.getTerm()).get(BIDom.class);
ohair@286 446 if(dom!=null) return dom;
ohair@286 447
ohair@286 448 XSTerm t = p.getTerm();
ohair@286 449 // type could also have one, in case of the dom customization
ohair@286 450 if(t.isElementDecl())
ohair@286 451 return getBindInfo(t.asElementDecl().getType()).get(BIDom.class);
ohair@286 452 // similarly the model group in a model group definition may have one.
ohair@286 453 if(t.isModelGroupDecl())
ohair@286 454 return getBindInfo(t.asModelGroupDecl().getModelGroup()).get(BIDom.class);
ohair@286 455
ohair@286 456 return null;
ohair@286 457 }
ohair@286 458
ohair@286 459 /**
ohair@286 460 * Returns true if the component should be processed by purple.
ohair@286 461 */
ohair@286 462 private final XSFinder toPurple = new XSFinder() {
ohair@286 463 @Override
ohair@286 464 public Boolean attributeUse(XSAttributeUse use) {
ohair@286 465 // attribute use always maps to a property
ohair@286 466 return true;
ohair@286 467 }
ohair@286 468
ohair@286 469 @Override
ohair@286 470 public Boolean simpleType(XSSimpleType xsSimpleType) {
ohair@286 471 // simple type always maps to a type, hence we should take purple
ohair@286 472 return true;
ohair@286 473 }
ohair@286 474
ohair@286 475 @Override
ohair@286 476 public Boolean wildcard(XSWildcard xsWildcard) {
ohair@286 477 // attribute wildcards always maps to a property.
ohair@286 478 // element wildcards should have been processed with particle binders
ohair@286 479 return true;
ohair@286 480 }
ohair@286 481 };
ohair@286 482 /**
ohair@286 483 * If the component maps to a property, forwards to purple, otherwise to green.
ohair@286 484 *
ohair@286 485 * If the component is mapped to a type, this method needs to return true.
ohair@286 486 * See the chart at the class javadoc.
ohair@286 487 */
ohair@286 488 public void ying( XSComponent sc, @Nullable XSComponent referer ) {
ohair@286 489 if(sc.apply(toPurple)==true || getClassSelector().bindToType(sc,referer)!=null)
ohair@286 490 sc.visit(purple);
ohair@286 491 else
ohair@286 492 sc.visit(green);
ohair@286 493 }
ohair@286 494
ohair@286 495 private Transformer identityTransformer;
ohair@286 496
ohair@286 497 /**
ohair@286 498 * Gets the shared instance of the identity transformer.
ohair@286 499 */
ohair@286 500 public Transformer getIdentityTransformer() {
ohair@286 501 try {
alanb@368 502 if(identityTransformer==null) {
alanb@368 503 TransformerFactory tf = XmlFactory.createTransformerFactory(model.options.disableXmlSecurity);
alanb@368 504 identityTransformer = tf.newTransformer();
alanb@368 505 }
ohair@286 506 return identityTransformer;
ohair@286 507 } catch (TransformerConfigurationException e) {
ohair@286 508 throw new Error(e); // impossible
ohair@286 509 }
ohair@286 510 }
ohair@286 511
ohair@286 512 /**
ohair@286 513 * Find all types that refer to the given complex type.
ohair@286 514 */
ohair@286 515 public Set<XSComponent> getReferer(XSType c) {
ohair@286 516 if(refFinder==null) {
ohair@286 517 refFinder = new RefererFinder();
ohair@286 518 refFinder.schemaSet(Ring.get(XSSchemaSet.class));
ohair@286 519 }
ohair@286 520 return refFinder.getReferer(c);
ohair@286 521 }
ohair@286 522
ohair@286 523 /**
ohair@286 524 * Returns the QName of the declaration.
ohair@286 525 * @return null
ohair@286 526 * if the declaration is anonymous.
ohair@286 527 */
ohair@286 528 public static QName getName(XSDeclaration decl) {
ohair@286 529 String local = decl.getName();
ohair@286 530 if(local==null) return null;
ohair@286 531 return new QName(decl.getTargetNamespace(),local);
ohair@286 532 }
ohair@286 533
ohair@286 534 /**
ohair@286 535 * Derives a name from a schema component.
ohair@286 536 *
ohair@286 537 * This method handles prefix/suffix modification and
ohair@286 538 * XML-to-Java name conversion.
ohair@286 539 *
ohair@286 540 * @param name
ohair@286 541 * The base name. This should be things like element names
ohair@286 542 * or type names.
ohair@286 543 * @param comp
ohair@286 544 * The component from which the base name was taken.
ohair@286 545 * Used to determine how names are modified.
ohair@286 546 */
ohair@286 547 public String deriveName( String name, XSComponent comp ) {
ohair@286 548 XSSchema owner = comp.getOwnerSchema();
ohair@286 549
ohair@286 550 name = getNameConverter().toClassName(name);
ohair@286 551
ohair@286 552 if( owner!=null ) {
ohair@286 553 BISchemaBinding sb = getBindInfo(owner).get(BISchemaBinding.class);
ohair@286 554
ohair@286 555 if(sb!=null) name = sb.mangleClassName(name,comp);
ohair@286 556 }
ohair@286 557
ohair@286 558 return name;
ohair@286 559 }
ohair@286 560
ohair@286 561 public boolean isGenerateMixedExtensions() {
ohair@286 562 if (globalBinding != null) {
ohair@286 563 return globalBinding.isGenerateMixedExtensions();
ohair@286 564 }
ohair@286 565 return false;
ohair@286 566 }
ohair@286 567
ohair@286 568 }

mercurial