001: /*-----------------------------------------------------------------------------
002: * Enhydra Java Application Server
003: * Copyright 1997-1999 Lutris Technologies, Inc.
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: * 2. Redistributions in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the distribution.
014: * 3. All advertising materials mentioning features or use of this software
015: * must display the following acknowledgement:
016: * This product includes Enhydra software developed by Lutris
017: * Technologies, Inc. and its contributors.
018: * 4. Neither the name of Lutris Technologies nor the names of its contributors
019: * may be used to endorse or promote products derived from this software
020: * without specific prior written permission.
021: *
022: * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
023: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
024: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
025: * ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
026: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
027: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
028: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
029: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
030: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
031: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
032: * POSSIBILITY OF SUCH DAMAGE.
033: *-----------------------------------------------------------------------------
034: * $Id: InventoryImpl.java,v 1.1 2006-09-11 12:36:58 sinisa Exp $
035: *-----------------------------------------------------------------------------
036: */
037:
038: package golfShop.business.inventory;
039:
040: import java.util.Vector;
041: import com.lutris.appserver.server.user.*;
042: import golfShop.data.item.ItemDO;
043: import golfShop.data.item.CategoryDO;
044: import golfShop.spec.inventory.Inventory;
045:
046: // TODO - handle null returns
047: //
048:
049: /**
050: * The inventory and/or heirarchy of items for sale.
051: *
052: * @author Scott Pirie
053: * @version $Revision: 1.1 $
054: */
055: public class InventoryImpl implements Inventory {
056: // Instance Variables
057: private boolean isCategoryObj; // Is this a category?
058: private long objectid; // Items object id
059: private String desc; // Human Readable
060: private String ref; // Where
061:
062: /*
063: * Constructor
064: */
065: public InventoryImpl() {
066: }
067:
068: public InventoryImpl(boolean IsCategoryObj, long ObjectId,
069: String Desc, String Ref) {
070: isCategoryObj = IsCategoryObj;
071: objectid = ObjectId;
072: desc = Desc;
073: ref = Ref;
074: }
075:
076: /**
077: * Convert name into description. This really should be in the database.
078: */
079: private static String getCatDesc(CategoryDO c) {
080: String desc = c.getName();
081: if (desc.equals("Main Menu")) {
082: desc = "Store Directory";
083: } else if (desc.equals("MensApparel")) {
084: desc = "Men's Apparel";
085: } else if (desc.equals("WomensApparel")) {
086: desc = "Women's Apparel";
087: }
088: return desc;
089: }
090:
091: /* Returns an Inventory list of items and categories for the provided
092: * ojectid
093: */
094: public Vector getItems(long this id) {
095: Vector retlist = new Vector();
096:
097: // Retreive the instance (ie details) of this category.
098: CategoryDO thecategory = CategoryDO.getCategory(this id);
099:
100: // Retreive the subcategories of this category
101: long[] catlist = thecategory.getSubCategories();
102: for (int count = 0; count < catlist.length; count++) {
103: CategoryDO c = CategoryDO.getCategory((int) catlist[count]);
104:
105: InventoryImpl newinv = new InventoryImpl(true, c
106: .getObjectId(), getCatDesc(c), c.getName());
107: retlist.addElement(newinv);
108: }
109:
110: // Retreive the items for this category
111: long[] itemlist = thecategory.getItems();
112: for (int count = 0; count < itemlist.length; count++) {
113: // TODO - fix casting uglyness
114: ItemDO theitem = ItemDO.getItemByObjectId(itemlist[count]);
115:
116: InventoryImpl newinv = new InventoryImpl(false, theitem
117: .getObjectId(), theitem.getName(), theitem
118: .getDescription());
119: retlist.addElement(newinv);
120: }
121:
122: return retlist;
123: }
124:
125: public Inventory getParent(long childid) {
126: CategoryDO cc = CategoryDO.getCategory(childid);
127: long pid = cc.getParentId();
128: CategoryDO pc = CategoryDO.getCategory(pid);
129: // Return null if parent is the same as the child ie top of tree
130: if (pc.getObjectId() == cc.getObjectId())
131: return null;
132:
133: InventoryImpl pinv = new InventoryImpl(true, pc.getObjectId(),
134: getCatDesc(pc), pc.getName());
135: return pinv;
136: }
137:
138: /* Returns an Inventory instance for the specified objectid
139: */
140: public Inventory getInventoryById(long this id) {
141: // Handle Inventory objects
142: CategoryDO c = CategoryDO.getCategory(this id);
143: InventoryImpl newinv = new InventoryImpl(true, c.getObjectId(),
144: getCatDesc(c), c.getName());
145: return newinv;
146: }
147:
148: public boolean isCategory() {
149: return isCategoryObj;
150: }
151:
152: public long getObjectId() {
153: return objectid;
154: }
155:
156: public String getDesc() {
157: return desc;
158: }
159:
160: public String getRef() {
161: return ref;
162: }
163: }
|