001    package data;
002    
003    /**
004     * Basic implementation of the {@link DataBasketCondition} interface. You can use this
005     * class as a basis for implementing more sophisticated queries.
006     *
007     * @author Steffen Zschaler
008     * @version 2.0 14/06/1999
009     * @since v2.0
010     */
011    public class DataBasketConditionImpl extends Object implements DataBasketCondition {
012    
013        /**
014         * The source condition.
015         *
016         * @serial
017         */
018        protected DataBasketEntrySource m_dbesSource;
019    
020        /**
021         * The destination condition.
022         *
023         * @serial
024         */
025        protected DataBasketEntryDestination m_dbedDest;
026    
027        /**
028         * The main key condition.
029         *
030         * @serial
031         */
032        protected String m_sMainKey;
033    
034        /**
035         * The secondary key condition.
036         *
037         * @serial
038         */
039        protected String m_sSecondaryKey;
040    
041        /**
042         * The value condition.
043         *
044         * @serial
045         */
046        protected Object m_oValue;
047    
048        /**
049         * Create a new DataBasketConditionImpl.
050         *
051         * @param sMainKey the value for {@link #m_sMainKey}.
052         * @param sSecondaryKey the value for {@link #m_sSecondaryKey}.
053         * @param dbesSource the value for {@link #m_dbesSource}.
054         * @param dbedDest the value for {@link #m_dbedDest}.
055         * @param oValue the value for {@link #m_oValue}.
056         */
057        public DataBasketConditionImpl(String sMainKey, String sSecondaryKey, DataBasketEntrySource dbesSource,
058                DataBasketEntryDestination dbedDest, Object oValue) {
059            super();
060    
061            m_sMainKey = sMainKey;
062            m_sSecondaryKey = sSecondaryKey;
063            m_dbesSource = dbesSource;
064            m_dbedDest = dbedDest;
065            m_oValue = oValue;
066        }
067    
068        /**
069         * @return {@link #m_dbesSource}.
070         *
071         * @override Never Instead set the value of {@link #m_dbesSource}.
072         */
073        public DataBasketEntrySource getSource() {
074            return m_dbesSource;
075        }
076    
077        /**
078         * @return {@link #m_dbedDest}.
079         *
080         * @override Never Instead set the value of {@link #m_dbedDest}.
081         */
082        public DataBasketEntryDestination getDestination() {
083            return m_dbedDest;
084        }
085    
086        /**
087         * @return {@link #m_oValue}.
088         *
089         * @override Never Instead set the value of {@link #m_oValue}.
090         */
091        public Object getValue() {
092            return m_oValue;
093        }
094    
095        /**
096         * @return {@link #m_sMainKey}.
097         *
098         * @override Never Instead set the value of {@link #m_sMainKey}.
099         */
100        public String getMainKey() {
101            return m_sMainKey;
102        }
103    
104        /**
105         * @return {@link #m_sSecondaryKey}.
106         *
107         * @override Never Instead set the value of {@link #m_sSecondaryKey}.
108         */
109        public String getSecondaryKey() {
110            return m_sSecondaryKey;
111        }
112    
113        /**
114         * As a default, always returns true.
115         *
116         * @override Sometimes
117         */
118        public boolean match(DataBasketEntry dbe) {
119            return true;
120        }
121    
122        // some static convenience functions and objects
123        /**
124         * A DataBasketCondition matching all items in a DataBasket.
125         */
126        public final static DataBasketCondition ALL_ENTRIES = new DataBasketConditionImpl(null, null, null, null, null);
127        /**
128         * A DataBasketCondition that matches all entries that describe StockItem movements.
129         */
130        public final static DataBasketCondition ALL_STOCK_ITEMS = new DataBasketConditionImpl(STOCK_ITEM_MAIN_KEY, null, null, null, null);
131    
132        /**
133         * A DataBasketCondition that matches all entries that describe CatalogItem movements.
134         */
135        public final static DataBasketCondition ALL_CATALOG_ITEMS = new DataBasketConditionImpl(
136                CATALOG_ITEM_MAIN_KEY, null, null, null, null);
137    
138        /**
139         * A DataBasketCondition that matches all entries that describe StockItems being taken from the
140         * given Stock.
141         */
142        public static final DataBasketCondition allStockItemsWithSource(Stock stSource) {
143            return new DataBasketConditionImpl(STOCK_ITEM_MAIN_KEY, null, stSource, null, null);
144        }
145    
146        /**
147         * A DataBasketCondition that matches all entries that describe StockItems being entered into the
148         * given Stock.
149         */
150        public static final DataBasketCondition allStockItemsWithDest(Stock stDest) {
151            return new DataBasketConditionImpl(STOCK_ITEM_MAIN_KEY, null, null, stDest, null);
152        }
153    
154        /**
155         * A DataBasketCondition that matches all entries that describe CatalogItems being taken from the
156         * given Catalog.
157         */
158        public static final DataBasketCondition allCatalogItemsWithSource(Catalog cSource) {
159            return new DataBasketConditionImpl(CATALOG_ITEM_MAIN_KEY, null, cSource, null, null);
160        }
161    
162        /**
163         * A DataBasketCondition that matches all entries that describe CatalogItems being entered into the
164         * given Catalog.
165         */
166        public static final DataBasketCondition allCatalogItemsWithDest(Catalog cDest) {
167            return new DataBasketConditionImpl(CATALOG_ITEM_MAIN_KEY, null, null, cDest, null);
168        }
169    
170        /**
171         * A DataBasketCondition that matches exactly one given CatalogItem.
172         */
173        public static final DataBasketCondition specificCatalogItem(CatalogItem ci) {
174            return new DataBasketConditionImpl(CATALOG_ITEM_MAIN_KEY, ci.getName(), null, null, ci);
175        }
176    
177        /**
178         * A DataBasketCondition that matches exactly one given StockItem.
179         */
180        public static final DataBasketCondition specificStockItem(StockItem si) {
181            return new DataBasketConditionImpl(STOCK_ITEM_MAIN_KEY, si.getName(), null, null, si);
182        }
183    }