Example #1
0
  /** Entry point. */
  public static Model build(
      XSSchemaSet _schemas, JCodeModel codeModel, ErrorReceiver _errorReceiver, Options opts) {
    // set up a ring
    final Ring old = Ring.begin();
    try {
      ErrorReceiverFilter ef = new ErrorReceiverFilter(_errorReceiver);

      Ring.add(XSSchemaSet.class, _schemas);
      Ring.add(codeModel);
      Model model =
          new Model(opts, codeModel, null /*set later*/, opts.classNameAllocator, _schemas);
      Ring.add(model);
      Ring.add(ErrorReceiver.class, ef);
      Ring.add(CodeModelClassFactory.class, new CodeModelClassFactory(ef));

      BGMBuilder builder =
          new BGMBuilder(
              opts.defaultPackage,
              opts.defaultPackage2,
              opts.isExtensionMode(),
              opts.getFieldRendererFactory());
      builder._build();

      if (ef.hadError()) return null;
      else return model;
    } finally {
      Ring.end(old);
    }
  }
Example #2
0
  /**
   * Gets the realization of this particle, if any.
   *
   * @return null if the "collection" attribute was not specified.
   */
  public final FieldRenderer getRealization() {
    String v = DOMUtil.getAttribute(element, "collection");
    if (v == null) return null;

    v = v.trim();
    if (v.equals("array")) return opts.getFieldRendererFactory().getArray();
    if (v.equals("list"))
      return opts.getFieldRendererFactory().getList(parent.parent.codeModel.ref(ArrayList.class));

    // the correctness of the attribute value must be
    // checked by the validator.
    throw new InternalError("unexpected collection value: " + v);
  }
  /**
   * Verify that the given URI is indeed a valid extension namespace URI, and if so enable it.
   *
   * <p>This method does all the error handling.
   */
  protected final void checkAndEnable(String uri) throws SAXException {
    if (!isRecognizableExtension(uri)) {
      String nearest = EditDistance.findNearest(uri, recognizableExtensions);
      // not the namespace URI we know of
      error(Messages.ERR_UNSUPPORTED_EXTENSION.format(uri, nearest));
    } else if (!isSupportedExtension(uri)) {
      // recognizable but not not supported, meaning
      // the plug-in isn't enabled

      // look for plug-in that handles this URI
      Plugin owner = null;
      for (Plugin p : options.getAllPlugins()) {
        if (p.getCustomizationURIs().contains(uri)) {
          owner = p;
          break;
        }
      }
      if (owner != null)
        // we know the plug-in that supports this namespace, but it's not enabled
        error(Messages.ERR_PLUGIN_NOT_ENABLED.format(owner.getOptionName(), uri));
      else {
        // this shouldn't happen, but be defensive...
        error(Messages.ERR_UNSUPPORTED_EXTENSION.format(uri));
      }
    }

    // as an error recovery enable this namespace URI anyway.
    enabledExtensions.add(uri);
  }
  /** @param handler This error handler will receive detected errors. */
  public AbstractExtensionBindingChecker(
      String schemaLanguage, Options options, ErrorHandler handler) {
    this.schemaLanguage = schemaLanguage;
    this.allowExtensions = options.compatibilityMode != Options.STRICT;
    this.options = options;
    setErrorHandler(handler);

    for (Plugin plugin : options.getAllPlugins())
      recognizableExtensions.addAll(plugin.getCustomizationURIs());
    recognizableExtensions.add(Const.XJC_EXTENSION_URI);
  }