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 /** The ISO field number. */ 036 protected int fieldNumber; 037 /** The BitSet representing the bitmap. */ 038 protected BitSet value; 039 040 /** 041 * Constructs a bitmap with the given field number. 042 * @param n - the FieldNumber 043 */ 044 public ISOBitMap (int n) { 045 fieldNumber = n; 046 } 047 /** 048 * Constructs a bitmap. 049 * @param n - fieldNumber 050 * @param v - field value (Bitset) 051 * @see BitSet 052 */ 053 public ISOBitMap (int n, BitSet v) { 054 fieldNumber = n; 055 value = v; 056 } 057 /** 058 * changes this Component field number<br> 059 * Use with care, this method does not change 060 * any reference held by a Composite. 061 * @param fieldNumber new field number 062 */ 063 public void setFieldNumber (int fieldNumber) { 064 this.fieldNumber = fieldNumber; 065 } 066 067 @Override 068 public int getFieldNumber () { 069 return fieldNumber; 070 } 071 072 /** 073 * not available on Leaf - always throw ISOException 074 * @exception ISOException on ISO processing error 075 */ 076 public byte[] pack() throws ISOException { 077 throw new ISOException ("Not available on Leaf"); 078 } 079 /** 080 * not available on Leaf - always throw ISOException 081 * @exception ISOException on ISO processing error 082 */ 083 public int unpack(byte[] b) throws ISOException { 084 throw new ISOException ("Not available on Leaf"); 085 } 086 /** 087 * not available on Leaf - always throw ISOException 088 * @exception ISOException on ISO processing error 089 */ 090 public void unpack(InputStream in) throws ISOException { 091 throw new ISOException ("Not available on Leaf"); 092 } 093 /** 094 * @return Object representing this field number 095 */ 096 public Object getKey() { 097 return fieldNumber; 098 } 099 /** 100 * @return Object representing this field value 101 */ 102 public Object getValue() { 103 return value; 104 } 105 /** 106 * @param obj - Object representing this field value 107 * @exception ISOException on ISO processing error 108 */ 109 public void setValue(Object obj) throws ISOException { 110 value = (BitSet) obj; 111 } 112 /** 113 * dump this field to PrintStream. The output is sorta 114 * XML, intended to be easily parsed. 115 * @param p - print stream 116 * @param indent - optional indent string 117 */ 118 public void dump (PrintStream p, String indent) { 119 p.println (indent +"<"+XMLPackager.ISOFIELD_TAG + " " + 120 XMLPackager.ID_ATTR +"=\""+XMLPackager.TYPE_BITMAP+"\" "+ 121 XMLPackager.VALUE_ATTR +"=\"" +value+"\" "+ 122 XMLPackager.TYPE_ATTR +"=\"" + XMLPackager.TYPE_BITMAP+ "\"/>" 123 ); 124 } 125}