Formatter exit

Overview

The Formatter exit enables you to read/write values from/to raw data and can be used directly in the database. Instead of interfaces and argument maps, the formatter is proposed as types of a Java class with well defined arguments.

You define the exit in the Formatter field in the Designer when you create a property on an Object Type or an Element Type.

In the InterPlay runtime, you use the formatter exit to:

  • Import and transform raw data into InterPlay data.
  • Export and transform data from InterPlay format to external format.

Implementation

Class annotation

The com.axway.ais.formatter.Formatter interface is a marker interface used in Designer to get the formatter beans that will be proposed when creating a property. It uses the @FormatterType class annotation.

/**

* Class annotations used for {@link Formatter} implementations

* to indicate the formatter bean name and the data types for which the formatter can be

Custom formatter classes must be annotated with the @FormatterType annotation in order to specify the bean name and the data types for which the formatters can be used.

@FormatterType(value="numericFormatter", dataTypes={"DECIMAL", "INTEGER"})

public class CustomNumericFormatter implements Formatter

{

//parse and format methods

{

Method annotation

Formatter implementations include 2 public methods that contain the transformation algorithm from raw data into InterPlay data and vice-versa. These methods are annotated using the @FormatterParameter annotation that supports two attributes:

  • Type - the type of methods : FORMAT or PARSE.
  • Properties - a list of parameter names that are used in the transformation algorithms.
    The parameters are pre-evaluated in the reader/writers before invoking the method.

/**

* Indicates the purpose of the annotated method

* and the arguments needed to be pre-evaluated and passed to the method

*

* @since 2.0

Arguments:

Argument Contents

type

Type of method:

  • Format: Invoked at export time, it defines transformations from internal representation into external (raw) representation.
  • Parse: Invoked at import time, it defines transformations from external representation into internal (raw) representation.
properties

List of parameters that are used in the transformation algorithms.

The list of parameters can include:

  • Predefined parameters
  • Values of other properties such as "LINE_NUMBER", "AMOUNT"
  • Values of parent properties such as "../CURRENCY_CODE", "../BATCH_NAME"

Predefined parameters:

Predefined parameters Type Description
value Object

Value to format / parse

At import it is always the value from the file as String.

decimalSeparator String Decimal separator according to the language of the import/export
dataType String Type of the property
length int, Integer Length of the property
fractionDigits int, Integer Fraction digits used for decimal types
totalDigits int, Integer Total digits used for decimal types
defaultValue Object Default value set on the property
minInclusive Object Min inclusive value
maxInclusive Object Max inclusive value
inherits String Path of the property it inherits from the parent (in case of inherited properties)
format String Format of the property
mandatory boolean, Boolean Mandatory flag on the property
criterion boolean, Boolean Criterion flag on the property
audit boolean, Boolean Audit flag on the property

The exit returns the transformed value or null if the transformation fails.

If you want the exit formatter bean identifier to be displayed in the property data formatter combo box of the Object Type, according to the business property type, you must implement the Formatter interface and use the FormatterType class annotation.

Predefined formatters

Interface Data type Description

accountingIntDateFormatter

Date

Transforms a date property in the AccountingIntegrator format into the InterPlay format.

asciiSignedDataFormatter Integer, Long, Decimal Transforms an AccountingIntegrator signed number into InterPlay data type (integer, long or decimal) using the AccountingIntegrator ASCII encoding, and vice-versa.
booleanFormatters String Changes the boolean values used in the external format ("Yes"/"No") to the InterPlay format (Y/N), and vice-versa.
decimalFormatter Decimal

Transforms decimals in the AccountingIntegrator format into InterPlay format:

  • It adds the decimal separator (in the correct position) when formatting into InterPlay data.
  • It removes the decimal separator (and adds trailing zeros when necessary) when formatting from InterPlay data.
ebcdicSignedDataFormatter Integer, Long, Decimal Transforms the AccountingIntegrator signed data type into correct InterPlay data type using the EBCDIC algorithm, and vice-versa.
packedDataFormatter Decimal, Integer, Long Transforms an AccountingIntegrator packed data format into an InterPlay string representation of the appropriate type, and vice-versa.

Error management

The developer decides the signature of the methods and parameters that are required in the format/parse algorithm.

Errors are logged when:

  • There is no method annotated with TYPE.PARSE or TYPE.FORMAT in the custom formatter class.
  • A parameter cannot be pre-evaluated (is not found between the predefined or dynamic parameters) and null is used as default value for that parameter.
  • The pre-evaluated parameter type is not the same or cannot be cast to the type from the method signature and invocation is skipped.

Samples

Boolean formatter

In this sample, boolean values in external format ("Yes/No", "True/False", "Oui/Non") are transformed into InterPlay format (Y/N) and vice-versa.

/*

* Copyright (c) 2012 by Axway Software

* All brand or product names are trademarks or registered trademarks

* of their respective holders.

* This document and the software described in this document are the property

* of Axway Software and are protected as Axway Software trade secrets.

* No part of this work may be reproduced or disseminated in any form or

* by any means, without the prior written permission of Axway Software.

*/

package com.axway.ais.formatter.predefined;

import com.axway.ais.formatter.Formatter;

Currency code formatter

In this sample, the decimal separator of the AMOUNT property defined on DOC/LINE is:

  • Inserted into the correct position according to the CURRENCY_CODE.
  • Removed.

/*

* Copyright (c) 2012 by Axway Software

* All brand or product names are trademarks or registered trademarks

* of their respective holders.

* This document and the software described in this document are the property

* of Axway Software and are protected as Axway Software trade secrets.

* No part of this work may be reproduced or disseminated in any form or

* by any means, without the prior written permission of Axway Software.

*/

package com.axway.ais.formatter.predefined;

import java.math.BigDecimal;

import com.axway.ais.formatter.Formatter;

Related Links