001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.iso; 020 021import org.jpos.iso.packager.XMLPackager; 022 023import java.io.InputStream; 024import java.io.PrintStream; 025import java.util.BitSet; 026 027/** 028 * implements <b>Leaf</b> for Bitmap field 029 * 030 * @author apr@cs.com.uy 031 * @version $Id$ 032 * @see ISOComponent 033 */ 034public class ISOBitMap extends ISOComponent implements Cloneable { 035 protected int fieldNumber; 036 protected BitSet value; 037 038 /** 039 * @param n - the FieldNumber 040 */ 041 public ISOBitMap (int n) { 042 fieldNumber = n; 043 } 044 /** 045 * @param n - fieldNumber 046 * @param v - field value (Bitset) 047 * @see BitSet 048 */ 049 public ISOBitMap (int n, BitSet v) { 050 fieldNumber = n; 051 value = v; 052 } 053 /** 054 * changes this Component field number<br> 055 * Use with care, this method does not change 056 * any reference held by a Composite. 057 * @param fieldNumber new field number 058 */ 059 public void setFieldNumber (int fieldNumber) { 060 this.fieldNumber = fieldNumber; 061 } 062 063 @Override 064 public int getFieldNumber () { 065 return fieldNumber; 066 } 067 068 /** 069 * not available on Leaf - always throw ISOException 070 * @exception ISOException 071 */ 072 public byte[] pack() throws ISOException { 073 throw new ISOException ("Not available on Leaf"); 074 } 075 /** 076 * not available on Leaf - always throw ISOException 077 * @exception ISOException 078 */ 079 public int unpack(byte[] b) throws ISOException { 080 throw new ISOException ("Not available on Leaf"); 081 } 082 /** 083 * not available on Leaf - always throw ISOException 084 * @exception ISOException 085 */ 086 public void unpack(InputStream in) throws ISOException { 087 throw new ISOException ("Not available on Leaf"); 088 } 089 /** 090 * @return Object representing this field number 091 */ 092 public Object getKey() { 093 return fieldNumber; 094 } 095 /** 096 * @return Object representing this field value 097 */ 098 public Object getValue() { 099 return value; 100 } 101 /** 102 * @param obj - Object representing this field value 103 * @exception ISOException 104 */ 105 public void setValue(Object obj) throws ISOException { 106 value = (BitSet) obj; 107 } 108 /** 109 * dump this field to PrintStream. The output is sorta 110 * XML, intended to be easily parsed. 111 * @param p - print stream 112 * @param indent - optional indent string 113 */ 114 public void dump (PrintStream p, String indent) { 115 p.println (indent +"<"+XMLPackager.ISOFIELD_TAG + " " + 116 XMLPackager.ID_ATTR +"=\""+XMLPackager.TYPE_BITMAP+"\" "+ 117 XMLPackager.VALUE_ATTR +"=\"" +value+"\" "+ 118 XMLPackager.TYPE_ATTR +"=\"" + XMLPackager.TYPE_BITMAP+ "\"/>" 119 ); 120 } 121}