Package client.ws.milanas.controller

Source Code of client.ws.milanas.controller.Controller

/*
* File: Controller.java
* Created on 8 / desembre / 2007, 16:02
*
* Copyright (C) 2008 M.Àngels Cerveró Abelló
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package client.ws.milanas.controller;

import client.ws.milanas.cart.CartWrapper;
import client.ws.milanas.helpers.beans.Cart;
import client.ws.milanas.helpers.beans.CartItem;
import client.ws.milanas.helpers.beans.Item;
import client.ws.milanas.searcher.ItemSearcher;
import java.util.ArrayList;

/**
*
* @author milana
*/
public class Controller
{
    private ItemSearcher is;
    private CartWrapper cw;
   
    /**
     * Creates a new instance of Controller. This means inicializing the
     * ItemSearcher and the CartWrapper objects
     */
    public Controller(ItemSearcher is, CartWrapper cw)
    {
        this.is = is;
        this.cw = cw;       
    }
   
    /**
     * Creates the connections needed by ItemSearcher and CartWrapper in order to
     * have access to the web service.
     */
    public void createConnections()
    {
        is.createConnection();
        cw.createConnection();
    }
   
    /**
     * Closes the web service connections in ItemSearcher and CartWrapper.
     */
    public void closeConnections()
    {
        is.closeConnection();
        cw.closeConnection();
    }
   
    /**
     * Searches books using the ItemSearcher.
     * The search is made using especific words (author and title) or abstract
     * ones (keywords). In addition, a condition and a sort method can be defined.
     * This method returns an ArrayList with all the items found.
     */
    public ArrayList<Item> searchBooks(String author, String title, String keywords, String condition, String sort)
    {
        try
        {
            return is.searchBooks(author, title, keywords, condition, sort);
        }
        catch(Exception e){}
        return new ArrayList<Item>();
    }
   
    /**
     * Searches music (CDs) using the ItemSearcher.
     * The search is made using especific words (artist and title) or abstract
     * ones (keywords). In addition, a condition and a sort method can be defined.
     * This method returns an ArrayList with all the items found.
     */
    public ArrayList<Item> searchMusic(String artist, String title, String keywords, String condition, String sort)
    {
        try
        {
            return is.searchMusic(artist, title, keywords, condition, sort);
        }
        catch(Exception e){}
        return new ArrayList<Item>();
    }
   
    /**
     * Searches an especific book using the ItemSearcher.
     * The search is made using the book identifier.
     * Returns the book found.
     */
    public Item lookupBook(String asin)
    {
        try
        {
            return is.lookupBook(asin);
        }
        catch(Exception e){}
        return new Item();
    }
   
    /**
     * Searches an especific music using the ItemSearcher.
     * The search is made using the book identifier.
     * Returns the music found.
     */
    public Item lookupMusic(String asin)
    {
        try
        {
            return is.lookupMusic(asin);
        }
        catch(Exception e){}
        return new Item();
    }
   
    /**
     * Adds "quantity" units of an item into the cart.
     * This item is identified by the parameter "offerId".
     * Returns true or false depending on whether the item has been added
     * correctly or not.
     */
    public boolean addItemToCart(String offerId, int quantity)
    {
        try
        {
            return cw.addItem(offerId, quantity);
        }
        catch(Exception e){}
        return false;
    }
   
    /**
     * Returns the state of the cart.
     */
    public Cart getCart()
    {
        return cw.getCart();
    }
   
    /**
     * Empties the cart.
     */
    public void emtpyCart()
    {
        try
        {
            cw.resetCart();
        }
        catch(Exception e){}
    }
   
    /**
     * Modifies the items in the cart.
     */
    public void modifyCartItems(ArrayList<CartItem> items)
    {
        try
        {
            cw.modifyItems(items);
        }
        catch(Exception e){}
    }
   
}
TOP

Related Classes of client.ws.milanas.controller.Controller

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.