package techcon03;
import com.basis.util.common.Template; import java.util.Arrays; import java.util.HashMap; import java.util.Calendar; import java.util.Comparator; import java.util.Iterator;
/** * * @author David Wallwork */ public class BBjAuctionImpl extends com.basis.bbj.webservice.BBjWSImpl implements BBjAuction { private static Sorter m_sorter;
public String logon(String p_name) throws java.rmi.RemoteException { byte bytes[] = invokeBBjReturnBytes("auction_logon.bbj", "auction " + p_name, null, 30); return new String(bytes); }
public boolean bidOnItem(String p_loginID, int p_itemID, double p_amount) throws java.rmi.RemoteException { String command = p_loginID + " " + Integer.toString(p_itemID) + " " + Double.toString(p_amount);
byte ret[] = invokeBBjReturnBytes("auction_bidOnItem.bbj", command, null, 30); return Boolean.valueOf(new String(ret).trim()).booleanValue(); }
public double getBalanceDue(String p_loginID) throws java.rmi.RemoteException { byte amount[] = invokeBBjReturnBytes("auction_getBalanceDue.bbj", p_loginID, null, 30); return Double.parseDouble(new String(amount)); }
/* * return array of itemName, currentHighBid, highBidder */ public AuctionItem[] listActiveItems(String p_loginID) throws java.rmi.RemoteException { HashMap map = invokeBBjReturnMap("auction_getItems.bbj", p_loginID, null, 30); return convertToAuctionItems(map); }
public AuctionItem[] listWonItems(String p_loginID) throws java.rmi.RemoteException { HashMap map = invokeBBjReturnMap("auction_getWonItems.bbj", p_loginID, null, 30); return convertToAuctionItems(map); }
private AuctionItem[] convertToAuctionItems(HashMap p_map) { int size = p_map.size(); AuctionItem ret[] = new AuctionItem[size];
String key; String value;
Iterator next = p_map.keySet().iterator();
while(next.hasNext()) for(int q=0;q<size;++q) { key = (String)next.next(); value = (String)p_map.get(key); ret[q] = AuctionItem.fromByteString(value); } Arrays.sort(ret,getSorter()); return ret; }
private Sorter getSorter() { if(m_sorter == null) m_sorter = new Sorter(); return m_sorter; }
private class Sorter implements Comparator { public int compare(Object obj1, Object obj2) { AuctionItem item1 = (AuctionItem)obj1; AuctionItem item2 = (AuctionItem)obj2; return item1.getItemID() - item2.getItemID(); }
public boolean equals(Object obj) { return this==obj; } } }
|