public FlatRecordFieldFactory assemble(ConfigurationContext context) {

    if (fieldName.isEmpty()) {
      String message =
          MessageFormatter.getInstance()
              .getMessage(
                  ServingXmlMessages.COMPONENT_ATTRIBUTE_REQUIRED,
                  context.getElement().getTagName(),
                  "name");
      throw new ServingXmlException(message);
    }

    if (digitCount <= 0) {
      String message =
          MessageFormatter.getInstance()
              .getMessage(
                  ServingXmlMessages.COMPONENT_ATTRIBUTE_REQUIRED,
                  context.getElement().getTagName(),
                  "digitCount");
      throw new ServingXmlException(message);
    }

    if (width <= 0) {
      width = PackedDecimal.calculatePackedSize(digitCount);
    }

    FlatFileOptionsFactory flatFileOptionsFactory = assembleFlatFileOptions(context);

    if (label == null) {
      if (fieldLabel != null) {
        SubstitutionExpr subExpr =
            SubstitutionExpr.parseString(context.getQnameContext(), fieldLabel);
        ValueEvaluator valueEvaluator = new SubstitutionExprValueEvaluator(subExpr);
        label = new Label(valueEvaluator);
      } else {
        label = new Label(fieldName.getLocalName());
      }
    }

    FlatRecordFieldFactory fieldTypeFactory =
        new PackedDecimalFieldFactory(
            fieldName,
            label,
            start,
            width,
            digitCount,
            decimalPlaces,
            defaultValue,
            flatFileOptionsFactory);

    return fieldTypeFactory;
  }
Пример #2
0
 public void addToAttributes(ServiceContext context, Flow flow, AttributesImpl attributes) {
   Name name = createName(flow.getRecord());
   String qname = name.toQname(nameContext);
   // System.out.println(getClass().getName()+".addToAttributes");
   try {
     String value = getValue(context, flow);
     attributes.addAttribute(name.getNamespaceUri(), name.getLocalName(), qname, "CDATA", value);
   } catch (ServingXmlException e) {
     if (qname != null) {
       e = e.contextualizeMessage("@" + qname);
     }
     throw e;
   }
 }
  public RecordCombinationFactory assemble(ConfigurationContext context) {
    Environment env = new Environment(parameterDescriptors, context.getQnameContext());

    if (recordTypeName.length() == 0) {
      String message =
          MessageFormatter.getInstance()
              .getMessage(
                  ServingXmlMessages.COMPONENT_ATTRIBUTE_REQUIRED,
                  context.getElement().getTagName(),
                  "recordType");
      throw new ServingXmlException(message);
    }

    NameSubstitutionExpr recordTypeNameExpr =
        NameSubstitutionExpr.parse(context.getQnameContext(), recordTypeName);

    if (dataRecordTypeFactory == null) {
      String message =
          MessageFormatter.getInstance()
              .getMessage(
                  ServingXmlMessages.COMPONENT_ELEMENT_REQUIRED,
                  context.getElement().getTagName(),
                  "sx:flatRecordType");
      throw new ServingXmlException(message);
    }

    if (repeatingGroupFieldName.isEmpty()) {
      String msg =
          MessageFormatter.getInstance()
              .getMessage(
                  ServingXmlMessages.COMPONENT_ATTRIBUTE_REQUIRED,
                  context.getElement().getTagName(),
                  "repeatingGroup");
      throw new ServingXmlException(msg);
    }

    String baseUri = context.getQnameContext().getBase();
    XPathBooleanExpressionFactory startTestFactory;
    if (startTest.length() > 0) {
      startTestFactory =
          new XPathBooleanExpressionFactoryImpl(
              context.getQnameContext(),
              startTest,
              xsltConfiguration.getVersion(),
              baseUri,
              xsltConfiguration.getTransformerFactory());
    } else {
      startTestFactory =
          new SimpleXPathBooleanExpressionFactory(XPathBooleanExpression.ALWAYS_TRUE);
    }
    XPathBooleanExpressionFactory endTestFactory;
    if (endTest.length() > 0) {
      endTestFactory =
          new XPathBooleanExpressionFactoryImpl(
              context.getQnameContext(),
              endTest,
              xsltConfiguration.getVersion(),
              baseUri,
              xsltConfiguration.getTransformerFactory());
    } else {
      endTestFactory = startTestFactory;
    }

    GroupRecognizer groupRecognizer =
        new GroupRecognizerImpl(
            env.getQnameContext().getPrefixMap(), startTestFactory, endTestFactory);

    FlatFileOptionsFactory flatFileOptionsFactory = assembleFlatFileOptions(context);

    RecordCombinationFactory recordCompositionFactory =
        new CombineFlatRecordsFactory(
            recordTypeNameExpr,
            repeatingGroupFieldName,
            groupRecognizer,
            dataRecordTypeFactory,
            flatFileOptionsFactory);
    // if (parameterDescriptors.length > 0) {
    //  recordCompositionFactory = new FlatRecordTypeFactoryPrefilter(recordCompositionFactory,
    //                                                         parameterDescriptors);
    // }
    return recordCompositionFactory;
  }