예제 #1
0
  /** Creation of a input descriptor based on a supplied Configuration instance. */
  public InputDescriptor(Configuration conf) {
    if (conf == null) throw new RuntimeException("Null configuration.");
    try {
      tag = conf.getAttribute("tag", "");
      required = conf.getAttributeAsBoolean("required", false);
      implied = conf.getAttributeAsBoolean("implied", false);
      type = ORB.init().create_interface_tc(conf.getAttribute("type", ""), "");

      Configuration[] children = conf.getChildren();
      if (children.length > 0) {
        criteria = DPML.buildCriteriaElement(children[0]);
      }
    } catch (Exception e) {
      throw new RuntimeException("Failed to configure a input usage decriptor.", e);
    }
  }
    public void process(XPathContext context) throws XPathException {
      String effMessage = message.evaluateAsString(context);
      int effOrientation = 0;
      if (orientation != null) {
        String s = orientation.evaluateAsString(context);
        try {
          effOrientation = Integer.parseInt(s);
          effOrientation = BarcodeDimension.normalizeOrientation(effOrientation);
        } catch (NumberFormatException nfe) {
          throw new ValidationException(nfe);
        } catch (IllegalArgumentException iae) {
          throw new ValidationException(iae);
        }
      }

      try {
        SequenceReceiver out = context.getReceiver();

        // Acquire BarcodeGenerator
        final BarcodeGenerator gen = BarcodeUtil.getInstance().createBarcodeGenerator(cfg);

        // Setup Canvas
        final SVGCanvasProvider svg;
        if (cfg.getAttributeAsBoolean("useNamespace", true)) {
          svg = new SVGCanvasProvider(cfg.getAttribute("prefix", "svg"), effOrientation);
        } else {
          svg = new SVGCanvasProvider(false, effOrientation);
        }
        // Generate barcode
        gen.generateBarcode(svg, effMessage);

        DocumentWrapper wrapper =
            new DocumentWrapper(
                svg.getDOM(), SVGCanvasProvider.SVG_NAMESPACE, context.getConfiguration());
        out.append(wrapper, this.getLocationId(), 1);

      } catch (ConfigurationException ce) {
        throw new DynamicError("(Barcode4J) " + ce.getMessage());
      } catch (BarcodeException be) {
        throw new DynamicError("(Barcode4J) " + be.getMessage());
      }
    }