예제 #1
0
  /** List up all the global bindings. */
  private void promoteGlobalBindings() {
    // promote any global bindings in the schema
    XSSchemaSet schemas = Ring.get(XSSchemaSet.class);

    for (XSSchema s : schemas.getSchemas()) {
      BindInfo bi = getBindInfo(s);

      // collect all global customizations
      model.getCustomizations().addAll(bi.toCustomizationList());

      BIGlobalBinding gb = bi.get(BIGlobalBinding.class);
      if (gb == null) continue;

      if (globalBinding == null) {
        globalBinding = gb;
        globalBinding.markAsAcknowledged();
      } else {
        // acknowledge this customization and report an error
        // otherwise the user will see "customization is attached to a wrong place" error,
        // which is incorrect
        gb.markAsAcknowledged();
        getErrorReporter().error(gb.getLocation(), Messages.ERR_MULTIPLE_GLOBAL_BINDINGS);
        getErrorReporter()
            .error(globalBinding.getLocation(), Messages.ERR_MULTIPLE_GLOBAL_BINDINGS_OTHER);
      }
    }

    if (globalBinding == null) {
      // no global customization is present.
      // use the default one
      globalBinding = new BIGlobalBinding();
      BindInfo big = new BindInfo();
      big.addDecl(globalBinding);
      big.setOwner(this, null);
    }

    // code generation mode
    model.strategy = globalBinding.getCodeGenerationStrategy();
    model.rootClass = globalBinding.getSuperClass();
    model.rootInterface = globalBinding.getSuperInterface();

    particleBinder =
        globalBinding.isSimpleMode() ? new ExpressionParticleBinder() : new DefaultParticleBinder();

    // check XJC extensions and realize them
    BISerializable serial = globalBinding.getSerializable();
    if (serial != null) {
      model.serializable = true;
      model.serialVersionUID = serial.uid;
    }

    // obtain the name conversion mode
    if (globalBinding.nameConverter != null) model.setNameConverter(globalBinding.nameConverter);

    // attach global conversions to the appropriate simple types
    globalBinding.dispatchGlobalConversions(schemas);

    globalBinding.errorCheck();
  }
  /** Performs error check */
  public void errorCheck() {
    ErrorReceiver er = Ring.get(ErrorReceiver.class);
    for (QName n : enumBaseTypes) {
      XSSchemaSet xs = Ring.get(XSSchemaSet.class);
      XSSimpleType st = xs.getSimpleType(n.getNamespaceURI(), n.getLocalPart());
      if (st == null) {
        er.error(loc, Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(n));
        continue;
      }

      if (!SimpleTypeBuilder.canBeMappedToTypeSafeEnum(st)) {
        er.error(loc, Messages.ERR_CANNOT_BE_BOUND_TO_SIMPLETYPE.format(n));
        continue;
      }
    }
  }
  /** Moves global BIConversion to the right object. */
  public void dispatchGlobalConversions(XSSchemaSet schema) {
    // also set parent to the global conversions
    for (Map.Entry<QName, BIConversion> e : globalConversions.entrySet()) {

      QName name = e.getKey();
      BIConversion conv = e.getValue();

      XSSimpleType st = schema.getSimpleType(name.getNamespaceURI(), name.getLocalPart());
      if (st == null) {
        Ring.get(ErrorReceiver.class)
            .error(getLocation(), Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(name));
        continue; // abort
      }

      getBuilder().getOrCreateBindInfo(st).addDecl(conv);
    }
  }