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

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

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 0
373ffda63c9a
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

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.reader.xmlschema.bindinfo;
aoqi@0 27
aoqi@0 28 import java.util.Collections;
aoqi@0 29 import java.util.HashMap;
aoqi@0 30 import java.util.Map;
aoqi@0 31 import java.util.Set;
aoqi@0 32
aoqi@0 33 import javax.xml.bind.annotation.XmlAttribute;
aoqi@0 34 import javax.xml.bind.annotation.XmlElement;
aoqi@0 35 import javax.xml.bind.annotation.XmlEnumValue;
aoqi@0 36 import javax.xml.bind.annotation.XmlRootElement;
aoqi@0 37 import javax.xml.bind.annotation.XmlTransient;
aoqi@0 38 import javax.xml.namespace.QName;
aoqi@0 39
aoqi@0 40 import com.sun.codemodel.internal.ClassType;
aoqi@0 41 import com.sun.codemodel.internal.JClassAlreadyExistsException;
aoqi@0 42 import com.sun.codemodel.internal.JCodeModel;
aoqi@0 43 import com.sun.codemodel.internal.JDefinedClass;
aoqi@0 44 import com.sun.tools.internal.xjc.ErrorReceiver;
aoqi@0 45 import com.sun.tools.internal.xjc.generator.bean.ImplStructureStrategy;
aoqi@0 46 import static com.sun.tools.internal.xjc.generator.bean.ImplStructureStrategy.BEAN_ONLY;
aoqi@0 47 import com.sun.tools.internal.xjc.model.Model;
aoqi@0 48 import com.sun.tools.internal.xjc.reader.Const;
aoqi@0 49 import com.sun.tools.internal.xjc.reader.Ring;
aoqi@0 50 import com.sun.tools.internal.xjc.reader.xmlschema.SimpleTypeBuilder;
aoqi@0 51 import com.sun.tools.internal.xjc.util.ReadOnlyAdapter;
aoqi@0 52 import com.sun.xml.internal.bind.api.impl.NameConverter;
aoqi@0 53 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
aoqi@0 54 import com.sun.xml.internal.xsom.XSDeclaration;
aoqi@0 55 import com.sun.xml.internal.xsom.XSSchemaSet;
aoqi@0 56 import com.sun.xml.internal.xsom.XSSimpleType;
aoqi@0 57
aoqi@0 58 /**
aoqi@0 59 * Global binding customization. The code is highly temporary.
aoqi@0 60 *
aoqi@0 61 * <p>
aoqi@0 62 * One of the information contained in a global customization
aoqi@0 63 * is the default binding for properties. This object contains a
aoqi@0 64 * BIProperty object to keep this information.
aoqi@0 65 *
aoqi@0 66 * @author
aoqi@0 67 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
aoqi@0 68 */
aoqi@0 69 @XmlRootElement(name="globalBindings")
aoqi@0 70 public final class BIGlobalBinding extends AbstractDeclarationImpl {
aoqi@0 71
aoqi@0 72
aoqi@0 73 /**
aoqi@0 74 * Gets the name converter that will govern the XML->Java
aoqi@0 75 * name conversion process for this compilation.
aoqi@0 76 *
aoqi@0 77 * <p>
aoqi@0 78 * The "underscoreBinding" customization will determine
aoqi@0 79 * the exact object returned from this method. The rest of XJC
aoqi@0 80 * should just use the NameConverter interface.
aoqi@0 81 *
aoqi@0 82 * <p>
aoqi@0 83 * Always non-null.
aoqi@0 84 */
aoqi@0 85 @XmlTransient
aoqi@0 86 public NameConverter nameConverter = NameConverter.standard;
aoqi@0 87
aoqi@0 88 // JAXB will use this property to set nameConverter
aoqi@0 89 @XmlAttribute
aoqi@0 90 void setUnderscoreBinding( UnderscoreBinding ub ) {
aoqi@0 91 nameConverter = ub.nc;
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 UnderscoreBinding getUnderscoreBinding() {
aoqi@0 95 throw new IllegalStateException(); // no need for this
aoqi@0 96 }
aoqi@0 97
aoqi@0 98 public JDefinedClass getSuperClass() {
aoqi@0 99 if(superClass==null) return null;
aoqi@0 100 return superClass.getClazz(ClassType.CLASS);
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 public JDefinedClass getSuperInterface() {
aoqi@0 104 if(superInterface==null) return null;
aoqi@0 105 return superInterface.getClazz(ClassType.INTERFACE);
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 public BIProperty getDefaultProperty() {
aoqi@0 109 return defaultProperty;
aoqi@0 110 }
aoqi@0 111
aoqi@0 112 public boolean isJavaNamingConventionEnabled() {
aoqi@0 113 return isJavaNamingConventionEnabled;
aoqi@0 114 }
aoqi@0 115
aoqi@0 116 public BISerializable getSerializable() {
aoqi@0 117 return serializable;
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 public boolean isGenerateElementClass() {
aoqi@0 121 return generateElementClass;
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 public boolean isGenerateMixedExtensions() {
aoqi@0 125 return generateMixedExtensions;
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 public boolean isChoiceContentPropertyEnabled() {
aoqi@0 129 return choiceContentProperty;
aoqi@0 130 }
aoqi@0 131
aoqi@0 132 public int getDefaultEnumMemberSizeCap() {
aoqi@0 133 return defaultEnumMemberSizeCap;
aoqi@0 134 }
aoqi@0 135
aoqi@0 136 public boolean isSimpleMode() {
aoqi@0 137 return simpleMode!=null;
aoqi@0 138 }
aoqi@0 139
aoqi@0 140 public boolean isRestrictionFreshType() {
aoqi@0 141 return treatRestrictionLikeNewType !=null;
aoqi@0 142 }
aoqi@0 143
aoqi@0 144 public EnumMemberMode getEnumMemberMode() {
aoqi@0 145 return generateEnumMemberName;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 public boolean isSimpleTypeSubstitution() {
aoqi@0 149 return simpleTypeSubstitution;
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 public ImplStructureStrategy getCodeGenerationStrategy() {
aoqi@0 153 return codeGenerationStrategy;
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 public LocalScoping getFlattenClasses() {
aoqi@0 157 return flattenClasses;
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 /**
aoqi@0 161 * Performs error check
aoqi@0 162 */
aoqi@0 163 public void errorCheck() {
aoqi@0 164 ErrorReceiver er = Ring.get(ErrorReceiver.class);
aoqi@0 165 for (QName n : enumBaseTypes) {
aoqi@0 166 XSSchemaSet xs = Ring.get(XSSchemaSet.class);
aoqi@0 167 XSSimpleType st = xs.getSimpleType(n.getNamespaceURI(), n.getLocalPart());
aoqi@0 168 if(st==null) {
aoqi@0 169 er.error(loc,Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(n));
aoqi@0 170 continue;
aoqi@0 171 }
aoqi@0 172
aoqi@0 173 if(!SimpleTypeBuilder.canBeMappedToTypeSafeEnum(st)) {
aoqi@0 174 er.error(loc,Messages.ERR_CANNOT_BE_BOUND_TO_SIMPLETYPE.format(n));
aoqi@0 175 continue;
aoqi@0 176 }
aoqi@0 177 }
aoqi@0 178 }
aoqi@0 179
aoqi@0 180 private static enum UnderscoreBinding {
aoqi@0 181 @XmlEnumValue("asWordSeparator")
aoqi@0 182 WORD_SEPARATOR(NameConverter.standard),
aoqi@0 183 @XmlEnumValue("asCharInWord")
aoqi@0 184 CHAR_IN_WORD(NameConverter.jaxrpcCompatible);
aoqi@0 185
aoqi@0 186 final NameConverter nc;
aoqi@0 187
aoqi@0 188 UnderscoreBinding(NameConverter nc) {
aoqi@0 189 this.nc = nc;
aoqi@0 190 }
aoqi@0 191 }
aoqi@0 192
aoqi@0 193 /**
aoqi@0 194 * Returns true if the "isJavaNamingConventionEnabled" option is turned on.
aoqi@0 195 *
aoqi@0 196 * In this mode, the compiler is expected to apply XML-to-Java name
aoqi@0 197 * conversion algorithm even to names given by customizations.
aoqi@0 198 *
aoqi@0 199 * This method is intended to be called by other BIXXX classes.
aoqi@0 200 * The effect of this switch should be hidden inside this package.
aoqi@0 201 * IOW, the reader.xmlschema package shouldn't be aware of this switch.
aoqi@0 202 */
aoqi@0 203 @XmlAttribute(name="enableJavaNamingConventions")
aoqi@0 204 /*package*/ boolean isJavaNamingConventionEnabled = true;
aoqi@0 205
aoqi@0 206 /**
aoqi@0 207 * True to generate classes for every simple type.
aoqi@0 208 */
aoqi@0 209 @XmlAttribute(name="mapSimpleTypeDef")
aoqi@0 210 boolean simpleTypeSubstitution = false;
aoqi@0 211
aoqi@0 212 /**
aoqi@0 213 * Gets the default defaultProperty customization.
aoqi@0 214 */
aoqi@0 215 @XmlTransient
aoqi@0 216 private BIProperty defaultProperty;
aoqi@0 217
aoqi@0 218 /*
aoqi@0 219 Three properties used to construct a default property
aoqi@0 220 */
aoqi@0 221 @XmlAttribute
aoqi@0 222 private boolean fixedAttributeAsConstantProperty = false;
aoqi@0 223 @XmlAttribute
aoqi@0 224 private CollectionTypeAttribute collectionType = new CollectionTypeAttribute();
aoqi@0 225 @XmlAttribute
aoqi@0 226 void setGenerateIsSetMethod(boolean b) {
aoqi@0 227 optionalProperty = b ? OptionalPropertyMode.ISSET : OptionalPropertyMode.WRAPPER;
aoqi@0 228 }
aoqi@0 229
aoqi@0 230
aoqi@0 231 /**
aoqi@0 232 * Returns true if the compiler needs to generate type-safe enum
aoqi@0 233 * member names when enumeration values cannot be used as constant names.
aoqi@0 234 */
aoqi@0 235 @XmlAttribute(name="typesafeEnumMemberName")
aoqi@0 236 EnumMemberMode generateEnumMemberName = EnumMemberMode.SKIP;
aoqi@0 237
aoqi@0 238 /**
aoqi@0 239 * The code generation strategy.
aoqi@0 240 */
aoqi@0 241 @XmlAttribute(name="generateValueClass")
aoqi@0 242 ImplStructureStrategy codeGenerationStrategy = BEAN_ONLY;
aoqi@0 243
aoqi@0 244 /**
aoqi@0 245 * Set of datatype names. For a type-safe enum class
aoqi@0 246 * to be generated, the underlying XML datatype must be derived from
aoqi@0 247 * one of the types in this set.
aoqi@0 248 */
aoqi@0 249 // default value is set in the post-init action
aoqi@0 250 @XmlAttribute(name="typesafeEnumBase")
aoqi@0 251 private Set<QName> enumBaseTypes;
aoqi@0 252
aoqi@0 253 /**
aoqi@0 254 * Returns {@link BISerializable} if the extension is specified,
aoqi@0 255 * or null otherwise.
aoqi@0 256 */
aoqi@0 257 @XmlElement
aoqi@0 258 private BISerializable serializable = null;
aoqi@0 259
aoqi@0 260 /**
aoqi@0 261 * If &lt;xjc:superClass> extension is specified,
aoqi@0 262 * returns the specified root class. Otherwise null.
aoqi@0 263 */
aoqi@0 264 @XmlElement(namespace=Const.XJC_EXTENSION_URI)
aoqi@0 265 ClassNameBean superClass = null;
aoqi@0 266
aoqi@0 267 /**
aoqi@0 268 * If &lt;xjc:superInterface> extension is specified,
aoqi@0 269 * returns the specified root class. Otherwise null.
aoqi@0 270 */
aoqi@0 271 @XmlElement(namespace=Const.XJC_EXTENSION_URI)
aoqi@0 272 ClassNameBean superInterface = null;
aoqi@0 273
aoqi@0 274 /**
aoqi@0 275 * Generate the simpler optimized code, but not necessarily
aoqi@0 276 * conforming to the spec.
aoqi@0 277 */
aoqi@0 278 @XmlElement(name="simple",namespace=Const.XJC_EXTENSION_URI)
aoqi@0 279 String simpleMode = null;
aoqi@0 280
aoqi@0 281 /**
aoqi@0 282 * Handles complex type restriction as if it were a new type.
aoqi@0 283 */
aoqi@0 284 @XmlElement(name="treatRestrictionLikeNewType",namespace=Const.XJC_EXTENSION_URI)
aoqi@0 285 String treatRestrictionLikeNewType = null;
aoqi@0 286
aoqi@0 287 /**
aoqi@0 288 * True to generate a class for elements by default.
aoqi@0 289 */
aoqi@0 290 @XmlAttribute
aoqi@0 291 boolean generateElementClass = false;
aoqi@0 292
aoqi@0 293 @XmlAttribute
aoqi@0 294 boolean generateMixedExtensions = false;
aoqi@0 295
aoqi@0 296 @XmlElement(namespace=Const.XJC_EXTENSION_URI)
aoqi@0 297 Boolean generateElementProperty = null;
aoqi@0 298
aoqi@0 299 @XmlAttribute(name="generateElementProperty") // for JAXB unmarshaller
aoqi@0 300 private void setGenerateElementPropertyStd(boolean value) {
aoqi@0 301 generateElementProperty = value;
aoqi@0 302 }
aoqi@0 303
aoqi@0 304 @XmlAttribute
aoqi@0 305 boolean choiceContentProperty = false;
aoqi@0 306
aoqi@0 307 @XmlAttribute
aoqi@0 308 OptionalPropertyMode optionalProperty = OptionalPropertyMode.WRAPPER;
aoqi@0 309
aoqi@0 310 /**
aoqi@0 311 * Default cap to the number of constants in the enum.
aoqi@0 312 * We won't attempt to produce a type-safe enum by default
aoqi@0 313 * if there are more enumeration facets than specified in this field.
aoqi@0 314 */
aoqi@0 315 @XmlAttribute(name="typesafeEnumMaxMembers")
aoqi@0 316 int defaultEnumMemberSizeCap = 256;
aoqi@0 317
aoqi@0 318 /**
aoqi@0 319 * If true, interfaces/classes that are normally generated as a nested interface/class
aoqi@0 320 * will be generated into the package, allowing the generated classes to be flat.
aoqi@0 321 *
aoqi@0 322 * See <a href="http://monaco.sfbay/detail.jsf?cr=4969415">Bug 4969415</a> for the motivation.
aoqi@0 323 */
aoqi@0 324 @XmlAttribute(name="localScoping")
aoqi@0 325 LocalScoping flattenClasses = LocalScoping.NESTED;
aoqi@0 326
aoqi@0 327 /**
aoqi@0 328 * Globally-defined conversion customizations.
aoqi@0 329 *
aoqi@0 330 * @see #setGlobalConversions
aoqi@0 331 */
aoqi@0 332 @XmlTransient
aoqi@0 333 private final Map<QName,BIConversion> globalConversions = new HashMap<QName, BIConversion>();
aoqi@0 334
aoqi@0 335 // method for JAXB unmarshaller
aoqi@0 336 @XmlElement(name="javaType")
aoqi@0 337 private void setGlobalConversions(GlobalStandardConversion[] convs) {
aoqi@0 338 for (GlobalStandardConversion u : convs) {
aoqi@0 339 globalConversions.put(u.xmlType,u);
aoqi@0 340 }
aoqi@0 341 }
aoqi@0 342
aoqi@0 343 @XmlElement(name="javaType",namespace=Const.XJC_EXTENSION_URI)
aoqi@0 344 private void setGlobalConversions2(GlobalVendorConversion[] convs) {
aoqi@0 345 for (GlobalVendorConversion u : convs) {
aoqi@0 346 globalConversions.put(u.xmlType,u);
aoqi@0 347 }
aoqi@0 348 }
aoqi@0 349
aoqi@0 350 //
aoqi@0 351 // these customizations were valid in 1.0, but in 2.0 we don't
aoqi@0 352 // use them. OTOH, we don't want to issue an error for them,
aoqi@0 353 // so we just define a mapping and ignore the value.
aoqi@0 354 //
aoqi@0 355 @XmlElement(namespace=Const.XJC_EXTENSION_URI)
aoqi@0 356 String noMarshaller = null;
aoqi@0 357 @XmlElement(namespace=Const.XJC_EXTENSION_URI)
aoqi@0 358 String noUnmarshaller = null;
aoqi@0 359 @XmlElement(namespace=Const.XJC_EXTENSION_URI)
aoqi@0 360 String noValidator = null;
aoqi@0 361 @XmlElement(namespace=Const.XJC_EXTENSION_URI)
aoqi@0 362 String noValidatingUnmarshaller = null;
aoqi@0 363 @XmlElement(namespace=Const.XJC_EXTENSION_URI)
aoqi@0 364 TypeSubstitutionElement typeSubstitution = null;
aoqi@0 365
aoqi@0 366 /**
aoqi@0 367 * Another 1.0 compatibility customization (but we accept it
aoqi@0 368 * and treat it as {@link #serializable})
aoqi@0 369 */
aoqi@0 370 @XmlElement(name="serializable",namespace=Const.XJC_EXTENSION_URI)
aoqi@0 371 void setXjcSerializable(BISerializable s) {
aoqi@0 372 this.serializable = s;
aoqi@0 373 }
aoqi@0 374
aoqi@0 375
aoqi@0 376
aoqi@0 377 private static final class TypeSubstitutionElement {
aoqi@0 378 @XmlAttribute
aoqi@0 379 String type;
aoqi@0 380 }
aoqi@0 381
aoqi@0 382 public void onSetOwner() {
aoqi@0 383 super.onSetOwner();
aoqi@0 384 // if one is given by options, use that
aoqi@0 385 NameConverter nc = Ring.get(Model.class).options.getNameConverter();
aoqi@0 386 if(nc!=null)
aoqi@0 387 nameConverter = nc;
aoqi@0 388 }
aoqi@0 389
aoqi@0 390 /**
aoqi@0 391 * Creates a bind info object with the default values
aoqi@0 392 */
aoqi@0 393 public BIGlobalBinding() {
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 public void setParent(BindInfo parent) {
aoqi@0 397 super.setParent(parent);
aoqi@0 398 // fill in the remaining default values
aoqi@0 399 if(enumBaseTypes==null)
aoqi@0 400 enumBaseTypes = Collections.singleton(new QName(WellKnownNamespace.XML_SCHEMA,"string"));
aoqi@0 401
aoqi@0 402 this.defaultProperty = new BIProperty(getLocation(),null,null,null,
aoqi@0 403 collectionType, fixedAttributeAsConstantProperty, optionalProperty, generateElementProperty );
aoqi@0 404 defaultProperty.setParent(parent); // don't forget to initialize the defaultProperty
aoqi@0 405 }
aoqi@0 406
aoqi@0 407 /**
aoqi@0 408 * Moves global BIConversion to the right object.
aoqi@0 409 */
aoqi@0 410 public void dispatchGlobalConversions( XSSchemaSet schema ) {
aoqi@0 411 // also set parent to the global conversions
aoqi@0 412 for( Map.Entry<QName,BIConversion> e : globalConversions.entrySet() ) {
aoqi@0 413
aoqi@0 414 QName name = e.getKey();
aoqi@0 415 BIConversion conv = e.getValue();
aoqi@0 416
aoqi@0 417 XSSimpleType st = schema.getSimpleType(name.getNamespaceURI(),name.getLocalPart());
aoqi@0 418 if(st==null) {
aoqi@0 419 Ring.get(ErrorReceiver.class).error(
aoqi@0 420 getLocation(),
aoqi@0 421 Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(name)
aoqi@0 422 );
aoqi@0 423 continue; // abort
aoqi@0 424 }
aoqi@0 425
aoqi@0 426 getBuilder().getOrCreateBindInfo(st).addDecl(conv);
aoqi@0 427 }
aoqi@0 428 }
aoqi@0 429
aoqi@0 430
aoqi@0 431 /**
aoqi@0 432 * Checks if the given XML Schema built-in type can be mapped to
aoqi@0 433 * a type-safe enum class.
aoqi@0 434 *
aoqi@0 435 * @param typeName
aoqi@0 436 */
aoqi@0 437 public boolean canBeMappedToTypeSafeEnum( QName typeName ) {
aoqi@0 438 return enumBaseTypes.contains(typeName);
aoqi@0 439 }
aoqi@0 440
aoqi@0 441 public boolean canBeMappedToTypeSafeEnum( String nsUri, String localName ) {
aoqi@0 442 return canBeMappedToTypeSafeEnum(new QName(nsUri,localName));
aoqi@0 443 }
aoqi@0 444
aoqi@0 445 public boolean canBeMappedToTypeSafeEnum( XSDeclaration decl ) {
aoqi@0 446 return canBeMappedToTypeSafeEnum( decl.getTargetNamespace(), decl.getName() );
aoqi@0 447 }
aoqi@0 448
aoqi@0 449
aoqi@0 450 public QName getName() { return NAME; }
aoqi@0 451 public static final QName NAME = new QName(
aoqi@0 452 Const.JAXB_NSURI, "globalBindings" );
aoqi@0 453
aoqi@0 454
aoqi@0 455 /**
aoqi@0 456 * Used to unmarshal
aoqi@0 457 * <xmp>
aoqi@0 458 * <[element] name="className" />
aoqi@0 459 * </xmp>
aoqi@0 460 */
aoqi@0 461 static final class ClassNameBean {
aoqi@0 462 @XmlAttribute(required=true)
aoqi@0 463 String name;
aoqi@0 464
aoqi@0 465 /**
aoqi@0 466 * Computed from {@link #name} on demand.
aoqi@0 467 */
aoqi@0 468 @XmlTransient
aoqi@0 469 JDefinedClass clazz;
aoqi@0 470
aoqi@0 471 JDefinedClass getClazz(ClassType t) {
aoqi@0 472 if (clazz != null) return clazz;
aoqi@0 473 try {
aoqi@0 474 JCodeModel codeModel = Ring.get(JCodeModel.class);
aoqi@0 475 clazz = codeModel._class(name, t);
aoqi@0 476 clazz.hide();
aoqi@0 477 return clazz;
aoqi@0 478 } catch (JClassAlreadyExistsException e) {
aoqi@0 479 return e.getExistingClass();
aoqi@0 480 }
aoqi@0 481 }
aoqi@0 482 }
aoqi@0 483
aoqi@0 484 static final class ClassNameAdapter extends ReadOnlyAdapter<ClassNameBean,String> {
aoqi@0 485 public String unmarshal(ClassNameBean bean) throws Exception {
aoqi@0 486 return bean.name;
aoqi@0 487 }
aoqi@0 488 }
aoqi@0 489
aoqi@0 490 /**
aoqi@0 491 * Global &lt;jaxb:javaType>.
aoqi@0 492 */
aoqi@0 493 static final class GlobalStandardConversion extends BIConversion.User {
aoqi@0 494 @XmlAttribute
aoqi@0 495 QName xmlType;
aoqi@0 496
aoqi@0 497 @Override
aoqi@0 498 public boolean equals(Object obj) {
aoqi@0 499 if(obj instanceof GlobalStandardConversion) {
aoqi@0 500 return ((GlobalStandardConversion)obj).xmlType.equals(xmlType);
aoqi@0 501 }
aoqi@0 502
aoqi@0 503 return false;
aoqi@0 504 }
aoqi@0 505
aoqi@0 506 @Override
aoqi@0 507 public int hashCode() {
aoqi@0 508 int hash = 7;
aoqi@0 509 hash = 73 * hash + (this.xmlType != null ? this.xmlType.hashCode() : 0);
aoqi@0 510 return hash;
aoqi@0 511 }
aoqi@0 512 }
aoqi@0 513
aoqi@0 514 /**
aoqi@0 515 * Global &lt;xjc:javaType>.
aoqi@0 516 */
aoqi@0 517 static final class GlobalVendorConversion extends BIConversion.UserAdapter {
aoqi@0 518 @XmlAttribute
aoqi@0 519 QName xmlType;
aoqi@0 520
aoqi@0 521 @Override
aoqi@0 522 public boolean equals(Object obj) {
aoqi@0 523 if(obj instanceof GlobalVendorConversion) {
aoqi@0 524 return ((GlobalVendorConversion)obj).xmlType.equals(xmlType);
aoqi@0 525 }
aoqi@0 526
aoqi@0 527 return false;
aoqi@0 528 }
aoqi@0 529
aoqi@0 530 @Override
aoqi@0 531 public int hashCode() {
aoqi@0 532 int hash = 7;
aoqi@0 533 hash = 73 * hash + (this.xmlType != null ? this.xmlType.hashCode() : 0);
aoqi@0 534 return hash;
aoqi@0 535 }
aoqi@0 536 }
aoqi@0 537
aoqi@0 538 /* don't want to override equals to avoid overriding hashcode for this complex object, too */
aoqi@0 539 public boolean isEqual(BIGlobalBinding b) {
aoqi@0 540 boolean equal =
aoqi@0 541 this.isJavaNamingConventionEnabled == b.isJavaNamingConventionEnabled &&
aoqi@0 542 this.simpleTypeSubstitution == b.simpleTypeSubstitution &&
aoqi@0 543 this.fixedAttributeAsConstantProperty == b.fixedAttributeAsConstantProperty &&
aoqi@0 544 this.generateEnumMemberName == b.generateEnumMemberName &&
aoqi@0 545 this.codeGenerationStrategy == b.codeGenerationStrategy &&
aoqi@0 546 this.serializable == b.serializable &&
aoqi@0 547 this.superClass == b.superClass &&
aoqi@0 548 this.superInterface == b.superInterface &&
aoqi@0 549 this.generateElementClass == b.generateElementClass &&
aoqi@0 550 this.generateMixedExtensions == b.generateMixedExtensions &&
aoqi@0 551 this.generateElementProperty == b.generateElementProperty &&
aoqi@0 552 this.choiceContentProperty == b.choiceContentProperty &&
aoqi@0 553 this.optionalProperty == b.optionalProperty &&
aoqi@0 554 this.defaultEnumMemberSizeCap == b.defaultEnumMemberSizeCap &&
aoqi@0 555 this.flattenClasses == b.flattenClasses;
aoqi@0 556
aoqi@0 557 if (!equal) return false;
aoqi@0 558
aoqi@0 559 return isEqual(this.nameConverter, b.nameConverter) &&
aoqi@0 560 isEqual(this.noMarshaller, b.noMarshaller) &&
aoqi@0 561 isEqual(this.noUnmarshaller, b.noUnmarshaller) &&
aoqi@0 562 isEqual(this.noValidator, b.noValidator) &&
aoqi@0 563 isEqual(this.noValidatingUnmarshaller, b.noValidatingUnmarshaller) &&
aoqi@0 564 isEqual(this.typeSubstitution, b.typeSubstitution) &&
aoqi@0 565 isEqual(this.simpleMode, b.simpleMode) &&
aoqi@0 566 isEqual(this.enumBaseTypes, b.enumBaseTypes) &&
aoqi@0 567 isEqual(this.treatRestrictionLikeNewType, b.treatRestrictionLikeNewType) &&
aoqi@0 568 isEqual(this.globalConversions, b.globalConversions);
aoqi@0 569 }
aoqi@0 570
aoqi@0 571 private boolean isEqual(Object a, Object b) {
aoqi@0 572 if (a != null) {
aoqi@0 573 return a.equals(b);
aoqi@0 574 }
aoqi@0 575 return (b == null);
aoqi@0 576 }
aoqi@0 577 }

mercurial