gt:             childConfig.addChild( barcodeTextAttribute );
context: package xorg.webservice.app.utils.matrixcode.barcode.generator.factory;
  
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.krysalis.barcode4j.BarcodeException;
  import org.krysalis.barcode4j.BarcodeUtil;
  import org.krysalis.barcode4j.ChecksumMode;
  import org.krysalis.barcode4j.HumanReadablePlacement;
  import org.krysalis.barcode4j.impl.AbstractBarcodeBean;
  import org.krysalis.barcode4j.impl.ConfigurableBarcodeGenerator;
  import org.krysalis.barcode4j.impl.codabar.CodabarBean;
  import org.krysalis.barcode4j.impl.code128.Code128Bean;
  import org.krysalis.barcode4j.impl.code128.EAN128Bean;
  import org.krysalis.barcode4j.impl.code39.Code39Bean;
  import org.krysalis.barcode4j.impl.datamatrix.DataMatrixBean;
  import org.krysalis.barcode4j.impl.fourstate.RoyalMailCBCBean;
  import org.krysalis.barcode4j.impl.fourstate.USPSIntelligentMailBean;
  import org.krysalis.barcode4j.impl.int2of5.Interleaved2Of5Bean;
  import org.krysalis.barcode4j.impl.pdf417.PDF417Bean;
  import org.krysalis.barcode4j.impl.postnet.POSTNETBean;
  import org.krysalis.barcode4j.impl.upcean.EAN13Bean;
  import org.krysalis.barcode4j.impl.upcean.EAN8Bean;
  import org.krysalis.barcode4j.impl.upcean.UPCABean;
  import org.krysalis.barcode4j.impl.upcean.UPCEBean;
  import xorg.webservice.app.utils.matrixcode.barcode.enums.BarcodeType;
  import xorg.webservice.app.utils.matrixcode.barcode.enums.Checksum;
  import xorg.webservice.app.utils.matrixcode.barcode.enums.TextPlacement;
  
  
  /**
   * Created by lonely on 18.08.16.
   * @version: 1.0beta
   */
  public class BarcodeBeanFactory {
  
      public static AbstractBarcodeBean code128( TextPlacement placement ) {
  
          Code128Bean bean = new Code128Bean( );
          bean.setMsgPosition( getPlacement( placement ) );
          bean.setFontSize( 5 );
          return bean;
      }
  
      public static AbstractBarcodeBean codabar( Checksum checksum, TextPlacement placement ) {
  
          CodabarBean bean = new CodabarBean( );
          bean.setMsgPosition( getPlacement( placement ) );
          bean.setChecksumMode( getChecksum( checksum ) );
          return bean;
      }
  
      public static AbstractBarcodeBean code39( Checksum checksum, boolean displayChecksum,
                                                TextPlacement placement ) {
  
          Code39Bean bean = new Code39Bean( );
          bean.setChecksumMode( getChecksum( checksum ) );
          bean.setDisplayChecksum( displayChecksum );
          bean.setMsgPosition( getPlacement( placement ) );
          return bean;
      }
  
      public static AbstractBarcodeBean ean128( Checksum checksum, TextPlacement placement ) {
  
          EAN128Bean result = new EAN128Bean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setMsgPosition( getPlacement( placement ) );
          result.setFontSize( 5 );
          return result;
      }
  
      public static AbstractBarcodeBean datamatrix( TextPlacement placement ) {
  
          DataMatrixBean result = new DataMatrixBean( );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean interleaved2of5( Checksum checksum,
                                                         boolean displayChecksum, TextPlacement placement ) {
  
          Interleaved2Of5Bean result = new Interleaved2Of5Bean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean pdf417( TextPlacement placement ) {
  
          PDF417Bean result = new PDF417Bean( );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean postnet( Checksum checksum,
                                                 boolean displayChecksum, TextPlacement placement ) {
  
          POSTNETBean result = new POSTNETBean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setDisplayChecksum( displayChecksum );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean ean13( Checksum checksum, TextPlacement placement ) {
  
          EAN13Bean result = new EAN13Bean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean ean8( Checksum checksum, TextPlacement placement ) {
  
          EAN8Bean result = new EAN8Bean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean upcA( Checksum checksum, TextPlacement placement ) {
  
          UPCABean result = new UPCABean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean upcE( Checksum checksum, TextPlacement placement ) {
  
          UPCEBean result = new UPCEBean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean royalMailCBC( Checksum checksum, TextPlacement placement ) {
  
          RoyalMailCBCBean result = new RoyalMailCBCBean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      public static AbstractBarcodeBean USPSIntelligentMail( Checksum checksum, TextPlacement placement ) {
  
          USPSIntelligentMailBean result = new USPSIntelligentMailBean( );
          result.setChecksumMode( getChecksum( checksum ) );
          result.setMsgPosition( getPlacement( placement ) );
          return result;
      }
  
      private static HumanReadablePlacement getPlacement( TextPlacement placement ) {
  
          if ( placement == null ) {
              return HumanReadablePlacement.HRP_NONE;
          }
          switch ( placement ) {
              case TOP:
                  return HumanReadablePlacement.HRP_TOP;
              case BOTTOM:
                  return HumanReadablePlacement.HRP_BOTTOM;
              default:
                  return HumanReadablePlacement.HRP_NONE;
          }
      }
  
      private static ChecksumMode getChecksum( Checksum checksum ) {
  
          if ( checksum == null ) {
              return ChecksumMode.CP_AUTO;
          }
          switch ( checksum ) {
              case ADD:
                  return ChecksumMode.CP_ADD;
              case IGNORE:
                  return ChecksumMode.CP_IGNORE;
              case CHECK:
                  return ChecksumMode.CP_CHECK;
              default:
                  return ChecksumMode.CP_AUTO;
          }
      }
  
  
      static class Generator {
  
          private static final BarcodeUtil barcodeUtil = BarcodeUtil.getInstance( );
  
          public static AbstractBarcodeBean getBarcodeBean( BarcodeType type ) {
  
              try {
                  ConfigurableBarcodeGenerator gen = ( ConfigurableBarcodeGenerator ) barcodeUtil.createBarcodeGenerator( configureBarcode( type.toString( ) ) );
                  return gen.getBean( );
              } catch ( BarcodeException | ConfigurationException e ) {
                  e.printStackTrace( );
              }
              return null;
          }
  
          private static Configuration configureBarcode( String type ) {
  
              DefaultConfiguration parentConfig = new DefaultConfiguration( "barcode" );
              DefaultConfiguration childConfig = new DefaultConfiguration( type );
              parentConfig.addChild( childConfig );
  
              DefaultConfiguration barcodeTextAttribute = new DefaultConfiguration( "human-readable" );
              DefaultConfiguration PlacementPosition = new DefaultConfiguration( "placement" );
              PlacementPosition.setValue( "bottom" );
              barcodeTextAttribute.addChild( PlacementPosition );
  
  