📄 ctcsubelementpackager.java
字号:
/* * jPOS Project [http://jpos.org] * Copyright (C) 2000-2008 Alejandro P. Revilla * * 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 <http://www.gnu.org/licenses/>. */package org.jpos.iso.packager;import java.util.Hashtable;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;/** * Test validatingPackager for subelements in field 48. * * <p>Title: jPOS</p> * <p>Description: Java Framework for Financial Systems</p> * <p>Copyright: Copyright (c) 2000 jPOS.org. All rights reserved.</p> * <p>Company: www.jPOS.org</p> * @author Jose Eduardo Leon * @version 1.0 */public class CTCSubElementPackager extends ISOBaseValidatingPackager { public CTCSubElementPackager() { super(); } public byte[] pack ( ISOComponent c ) throws ISOException { try { Hashtable tab = c.getChildren(); StringBuffer sb = new StringBuffer(); for ( int i = 0; i < fld.length; i++ ) { ISOMsg f = (ISOMsg) tab.get ( new Integer( i ) ); if ( f != null ) { sb.append ( ISOUtil.zeropad( ((Integer)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 ("<unpack fld=\"" + i +"\" packager=\"" +fld[i].getClass().getName()+ "\">"); if (c.getValue() instanceof ISOMsg) evt.addMessage (c.getValue()); else evt.addMessage (" <value>" +c.getValue().toString() + "</value>"); evt.addMessage ("</unpack>"); } m.set(c); } Logger.log (evt); return consumed; } /** * Always return false * <br><br> **/ protected boolean emitBitMap() { return false; } public ISOComponent validate( ISOComponent c ) throws org.jpos.iso.ISOException { LogEvent evt = new LogEvent( this, "validate" ); try { Hashtable tab = c.getChildren(); for ( int i = 0; i < fldVld.length; i++ ) { ISOMsg f = (ISOMsg) tab.get ( new Integer( i ) ); if ( f != null ) c.set( (ISOMsg)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 ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -