001 package data.ooimpl; 002 003 import log.*; 004 005 import data.*; 006 007 /** 008 * DataBasketEntry that represents an operation with StockItems. The details as 009 * to how the individual fields are used depend on the subclasses. 010 * 011 * @author Steffen Zschaler 012 * @version 2.0 19/08/1999 013 * @since v2.0 014 */ 015 public abstract class StockItemDBEntry extends DataBasketEntryImpl<Object> { 016 017 /** 018 * Create a new StockItemDBEntry. 019 * 020 * @param sKey the key of the affected item(s). 021 * @param stiSource the source Stock. 022 * @param stiDest the destination Stock. 023 * @param oValue the value of the DataBasketEntry. 024 */ 025 public StockItemDBEntry(String sKey, StockImpl stiSource, StockImpl stiDest, Object oValue) { 026 super(STOCK_ITEM_MAIN_KEY, sKey, stiSource, stiDest, oValue); 027 } 028 029 /** 030 * Count the items affected by this DataBasketEntry. 031 * 032 * @override Sometimes The default implementation returns 1. 033 */ 034 public int count() { 035 return 1; 036 } 037 038 /** 039 * A LogEntry that describes an operation on one or more StockItem(s). 040 * 041 * @author Steffen Zschaler 042 * @version 2.0 19/08/1999 043 * @since v2.0 044 */ 045 public static class StockItemDBELogEntry extends LogEntry { 046 047 /** 048 * ID for serialization. 049 */ 050 private static final long serialVersionUID = -1085281113728062387L; 051 052 /** 053 * The key of the affected item. 054 * 055 * @serial 056 */ 057 private String m_sKey; 058 059 /** 060 * The source Stock's name, if any. 061 * 062 * @serial 063 */ 064 private String m_sSourceName; 065 066 /** 067 * The destination Stock's name, if any. 068 * 069 * @serial 070 */ 071 private String m_sDestName; 072 073 /** 074 * Create a new StockItemDBELogEntry. 075 * 076 * @param sidbe the DataBasketEntry to be described. 077 */ 078 public StockItemDBELogEntry(StockItemDBEntry sidbe) { 079 super(); 080 081 m_sKey = sidbe.getSecondaryKey(); 082 m_sSourceName = ((sidbe.getSource() != null) ? (((Nameable)sidbe.getSource()).getName()) : (null)); 083 m_sDestName = ((sidbe.getDestination() != null) ? (((Nameable)sidbe.getDestination()).getName()) : (null)); 084 } 085 086 /** 087 * Get the affected item's key. 088 * 089 * @override Never 090 */ 091 public String getKey() { 092 return m_sKey; 093 } 094 095 /** 096 * Get the source Stock's name. 097 * 098 * @override Never 099 */ 100 public String getSource() { 101 return m_sSourceName; 102 } 103 104 /** 105 * Get the destination Stock's name. 106 * 107 * @override Never 108 */ 109 public String getDestination() { 110 return m_sDestName; 111 } 112 113 /** 114 * Get a String representation of the LogEntry. 115 * 116 * @override Sometimes 117 */ 118 public String toString() { 119 return "StockItem transfer: \"" + getKey() + "\" was transferred" + ((getSource() != null) ? 120 (" from Stock \"" + getSource() + "\"") : ("")) + ((getDestination() != null) ? 121 (" to Stock \"" + getDestination() + "\"") : ("")) + " on " + getLogDate() + "."; 122 } 123 } 124 125 /** 126 * Get a LogEntry describing this DataBasketEntry. 127 * 128 * @override Never 129 */ 130 public LogEntry getLogData() { 131 return new StockItemDBELogEntry(this); 132 } 133 }