KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > business > inventory > InventoryImpl


1  /*-----------------------------------------------------------------------------
2  * Enhydra Java Application Server
3  * Copyright 1997-1999 Lutris Technologies, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  * This product includes Enhydra software developed by Lutris
17  * Technologies, Inc. and its contributors.
18  * 4. Neither the name of Lutris Technologies nor the names of its contributors
19  * may be used to endorse or promote products derived from this software
20  * without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *-----------------------------------------------------------------------------
34  * $Id: InventoryImpl.java,v 1.1 2004/08/16 09:44:52 slobodan Exp $
35  *-----------------------------------------------------------------------------
36  */

37
38
39
40
41 package golfShop.business.inventory;
42
43 import java.util.Vector JavaDoc;
44 import com.lutris.appserver.server.user.*;
45 import golfShop.data.item.ItemDO;
46 import golfShop.data.item.CategoryDO;
47 import golfShop.spec.inventory.Inventory;
48 // TODO - handle null returns
49
//
50

51 /**
52  * The inventory and/or heirarchy of items for sale.
53  *
54  * @author Scott Pirie
55  * @version $Revision: 1.1 $
56  */

57 public class InventoryImpl implements Inventory{
58     // Instance Variables
59
private boolean isCategoryObj; // Is this a category?
60
private long objectid; // Items object id
61
private String JavaDoc desc; // Human Readable
62
private String JavaDoc ref; // Where
63

64     /*
65      * Constructor
66      */

67     public InventoryImpl(){}
68    
69     public InventoryImpl(boolean IsCategoryObj, long ObjectId, String JavaDoc Desc,
70                      String JavaDoc Ref) {
71         isCategoryObj = IsCategoryObj;
72     objectid = ObjectId;
73     desc = Desc;
74     ref = Ref;
75     }
76
77     /**
78      * Convert name into description. This really should be in the database.
79      */

80     private static String JavaDoc getCatDesc(CategoryDO c) {
81         String JavaDoc desc = c.getName();
82         if (desc.equals("Main Menu")) {
83             desc = "Store Directory";
84         } else if (desc.equals("MensApparel")) {
85             desc = "Men's Apparel";
86         } else if (desc.equals("WomensApparel")) {
87             desc = "Women's Apparel";
88         }
89         return desc;
90     }
91     
92     /* Returns an Inventory list of items and categories for the provided
93      * ojectid
94      */

95     public Vector JavaDoc getItems(long thisid) {
96     Vector JavaDoc retlist = new Vector JavaDoc();
97
98     // Retreive the instance (ie details) of this category.
99
CategoryDO thecategory = CategoryDO.getCategory(thisid);
100
101     // Retreive the subcategories of this category
102
long[] catlist = thecategory.getSubCategories();
103     for ( int count = 0; count < catlist.length ; count++)
104     {
105         CategoryDO c = CategoryDO.getCategory((int)catlist[count]);
106
107         InventoryImpl newinv = new InventoryImpl(true,
108                                              c.getObjectId(),
109                          getCatDesc(c),
110                          c.getName());
111         retlist.addElement(newinv);
112     }
113
114     // Retreive the items for this category
115
long[] itemlist = thecategory.getItems();
116     for ( int count = 0; count < itemlist.length ; count++)
117     {
118         // TODO - fix casting uglyness
119
ItemDO theitem = ItemDO.getItemByObjectId(itemlist[count]);
120
121         InventoryImpl newinv = new InventoryImpl(false,
122                                              theitem.getObjectId(),
123                          theitem.getName(),
124                          theitem.getDescription());
125         retlist.addElement(newinv);
126     }
127
128     return retlist;
129     }
130     public Inventory getParent(long childid)
131     {
132     CategoryDO cc = CategoryDO.getCategory(childid);
133     long pid = cc.getParentId();
134     CategoryDO pc = CategoryDO.getCategory(pid);
135     // Return null if parent is the same as the child ie top of tree
136
if (pc.getObjectId() == cc.getObjectId())
137         return null;
138
139     InventoryImpl pinv = new InventoryImpl(true,
140                                        pc.getObjectId(),
141                                        getCatDesc(pc),
142                                        pc.getName());
143     return pinv;
144     }
145
146     /* Returns an Inventory instance for the specified objectid
147      */

148     public Inventory getInventoryById(long thisid) {
149     // Handle Inventory objects
150
CategoryDO c = CategoryDO.getCategory(thisid);
151     InventoryImpl newinv = new InventoryImpl(true,
152                                          c.getObjectId(),
153                      getCatDesc(c),
154                      c.getName());
155     return newinv;
156     }
157
158     public boolean isCategory() {
159         return isCategoryObj;
160     }
161
162     public long getObjectId() {
163     return objectid;
164     }
165     public String JavaDoc getDesc() {
166     return desc;
167     }
168     public String JavaDoc getRef() {
169     return ref;
170     }
171 }
172
Popular Tags