![JAR search and dependency download from the Maven repository](/logo.png)
org.jpos.iso.packager.CTCSubElementPackager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jpos Show documentation
Show all versions of jpos Show documentation
jPOS is an ISO-8583 based financial transaction
library/framework that can be customized and
extended in order to implement financial interchanges.
/*
* jPOS Project [http://jpos.org]
* Copyright (C) 2000-2018 jPOS Software SRL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package org.jpos.iso.packager;
import org.jpos.iso.ISOComponent;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;
import org.jpos.iso.validator.ISOVException;
import org.jpos.util.LogEvent;
import org.jpos.util.Logger;
import java.util.Map;
/**
* Test validatingPackager for subelements in field 48.
*
* Title: jPOS
* Description: Java Framework for Financial Systems
* Copyright: Copyright (c) 2000 jPOS.org. All rights reserved.
* Company: www.jPOS.org
* @author Jose Eduardo Leon
* @version 1.0
*/
public class CTCSubElementPackager extends ISOBaseValidatingPackager {
public CTCSubElementPackager() {
super();
}
public byte[] pack ( ISOComponent c ) throws ISOException {
try {
Map tab = c.getChildren();
StringBuilder sb = new StringBuilder();
for ( int i = 0; i < fld.length; i++ ) {
ISOMsg f = (ISOMsg) tab.get (i);
if ( f != null ) {
sb.append ( ISOUtil.zeropad( f.getKey().toString(), 2 ) + new String( fld[i].pack( f ) ) );
}
}
return sb.toString().getBytes();
}
catch ( Exception ex ) {
throw new ISOException ( this.getRealm() + ":" + ex.getMessage(), ex );
}
}
public int unpack ( ISOComponent m, byte[] b ) throws ISOException {
LogEvent evt = new LogEvent ( this, "unpack" );
int consumed = 0;
for ( int i=0; consumed < b.length ; i++ ) {
ISOComponent c = fld[i].createComponent( i );
consumed += fld[i].unpack ( c, b, consumed );
if ( logger != null ) {
evt.addMessage ("");
if (c.getValue() instanceof ISOMsg)
evt.addMessage (c.getValue());
else
evt.addMessage (" "
+c.getValue().toString()
+ " ");
evt.addMessage (" ");
}
m.set(c);
}
Logger.log (evt);
return consumed;
}
/**
* Always return false
*
**/
protected boolean emitBitMap() {
return false;
}
public ISOComponent validate( ISOComponent c ) throws org.jpos.iso.ISOException {
LogEvent evt = new LogEvent( this, "validate" );
try {
Map tab = c.getChildren();
for ( int i = 0; i < fldVld.length; i++ ) {
ISOMsg f = (ISOMsg) tab.get (i);
if ( f != null )
c.set(fldVld[i].validate( f ));
}
return c;
} catch ( ISOVException ex ) {
if ( !ex.treated() ) {
c.set( ex.getErrComponent() );
ex.setTreated( true );
}
evt.addMessage( ex );
throw ex;
} finally {
Logger.log( evt );
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy