2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jshopcore.model.basket;
19 import java.io.IOException;
20 import java.io.Serializable;
21 import java.lang.reflect.InvocationTargetException;
22 import java.sql.SQLException;
23 import java.text.MessageFormat;
25 import org.mxchange.jshopcore.BaseShopCore;
26 import org.mxchange.jshopcore.model.item.AddableBasketItem;
29 * A general basket class
31 * @author Roland Haeder
32 * @param <T> Any instance that implements AddableBasketItem
34 public class BaseBasket<T extends AddableBasketItem> extends BaseShopCore implements Basket<T>, Serializable {
38 private static final long serialVersionUID = 784396762230845717L;
41 * Protected constructor with session instance
43 * @throws java.sql.SQLException If an SQL error occurs
45 protected BaseBasket () throws SQLException {
47 this.getLogger().trace("CALLED!"); //NOI18N
51 public void init () throws SQLException {
53 this.getLogger().trace("CALLED!"); //NOI18N
55 // Is the bundle initialized?
56 if (!BaseShopCore.isBundledInitialized()) {
57 // Temporary initialize default bundle
58 // TODO The enum Gender uses this
64 @SuppressWarnings ("unchecked")
65 public void addItem (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
67 this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
69 // item must not be null
72 throw new NullPointerException("item is null"); //NOI18N
73 } else if (this.isAdded(item)) {
75 throw new IllegalArgumentException("item has already been added. Did you miss to call isAdded()?"); //NOI18N
78 // Add item to database
79 // TODO: ((BasketFrontend) this.getFrontend()).addItem(item, this.getSessionId());
82 this.getLogger().trace("EXIT!"); //NOI18N
86 public boolean isEmpty () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
87 // Deligate call to frontend
88 // TODO: return ((BasketFrontend) this.getFrontend()).isEmpty();
89 throw new UnsupportedOperationException("Not yet implmeneted.");
93 @SuppressWarnings("unchecked")
94 public Map<Long, T> getAll () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
96 this.getLogger().trace("CALLED!"); //NOI18N
99 // TODO: Map<Long, T> map = ((BasketFrontend) this.getFrontend()).getAll();
100 Map<Long, T> map = null;
103 this.getLogger().trace("map=" + map); //NOI18N
110 public AddableBasketItem getLast () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
111 // Deligate to frontend
112 // TODO: return ((BasketFrontend) this.getFrontend()).getLast();
113 throw new UnsupportedOperationException("Not yet implmeneted.");
117 public int getLastNumRows () {
118 // Deligate to frontend
119 // TODO: return this.getFrontend().getLastNumRows();
120 throw new UnsupportedOperationException("Not yet implmeneted.");
124 public boolean isAdded (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
126 this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
128 // item must not be null
131 throw new NullPointerException("item is null"); //NOI18N
135 // TODO: boolean isAdded = ((BasketFrontend) this.getFrontend()).isAdded(item, this.getSessionId());
136 boolean isAdded = true;
139 this.getLogger().trace(MessageFormat.format("isAdded={0} - EXIT!", isAdded)); //NOI18N