Source Code Cross Referenced for CategoryDO.java in  » J2EE » Enhydra-Demos » golfShop » data » item » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Demos » golfShop.data.item 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server 
003:         * The Initial Developer of the Original Code is Lutris Technologies Inc. 
004:         * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
005:         * Inc. 
006:         * All Rights Reserved. 
007:         *
008:         * The contents of this file are subject to the Enhydra Public License Version
009:         * 1.0 (the "License"); you may not use this file except in compliance with the
010:         * License. You may obtain a copy of the License at
011:         * http://www.enhydra.org/software/license/epl.html 
012:         *
013:         * Software distributed under the License is distributed on an "AS IS" basis,
014:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing rights and limitations under the
016:         * License. 
017:         *
018:         * 
019:         */
020:
021:        package golfShop.data.item;
022:
023:        import java.util.Vector;
024:        import java.util.Enumeration;
025:        import java.lang.Object;
026:
027:        // TODO - convert longs to ulong
028:        // TODO - autogenerate objectID 
029:
030:        /**
031:         * Categorize the items we have for sale.
032:         *
033:         * @author Scott Pirie
034:         * @version $Revision: 1.1 $
035:         */
036:        public class CategoryDO {
037:            /*----------------------------------------------------------------------*/
038:            // Class Data
039:            /*----------------------------------------------------------------------*/
040:            private static CategoryStore storage = null;
041:
042:            /*----------------------------------------------------------------------*/
043:            // Class Methods
044:            /*----------------------------------------------------------------------*/
045:
046:            /* Determine the storage media selected for the category and item
047:             * database.
048:             */
049:
050:            public static void InitializeStorageOption(String opt, String dir) {
051:
052:                try {
053:
054:                    if (opt.equalsIgnoreCase("memory")) {
055:                        storage = new CategoryStoreMemory();
056:                        storage.initializeCategoryStore();
057:                    } else if (opt.equalsIgnoreCase("file")) {
058:                        storage = new CategoryStoreFile();
059:                        storage.initializeCategoryStore(dir);
060:
061:                    } else {
062:                        storage = new CategoryStoreMemory();
063:                        storage.initializeCategoryStore();
064:                    }
065:                } catch (Exception e) {
066:                }
067:
068:            }
069:
070:            /* Constructor.  This is private so non item classes must go
071:             * through the provided interfaces below to add new objects.
072:             */
073:            protected CategoryDO(long objectId, long parentId, String name) {
074:                this .objectId = objectId;
075:                this .parentId = parentId;
076:                this .name = name;
077:                this .subList = new Vector();
078:                this .itemList = new Vector();
079:                this .isDirty = false;
080:
081:                // Update parent with subcategory.
082:                CategoryDO parent = getCategory(parentId);
083:                if (parent != null)
084:                    parent.addSubCategory(objectId);
085:            }
086:
087:            /*
088:             * Find the CategoryDO given the object id.
089:             */
090:            public static CategoryDO getCategory(long objid) {
091:                return (storage.findCategoryInStore(objid));
092:            }
093:
094:            /*----------------------------------------------------------------------*/
095:            // Instance Data
096:            /*----------------------------------------------------------------------*/
097:            private long objectId; // Application index
098:            private long parentId; // Parent category index
099:            private String name; // Human read-able
100:            private Vector subList; // Sub Category List
101:            private Vector itemList; // Items in this Category
102:            private boolean isDirty; // Set if instance has been modified.
103:
104:            /*----------------------------------------------------------------------*/
105:            // Instance Methods
106:            /*----------------------------------------------------------------------*/
107:
108:            public long getObjectId() {
109:                return this .objectId;
110:            }
111:
112:            // This is the key so it shouldn't be changed by anyone.
113:            protected void setObjectId(long newId) {
114:                this .objectId = newId;
115:            }
116:
117:            public long getParentId() {
118:                return this .parentId;
119:            }
120:
121:            public void setParentId(long newId) {
122:                this .parentId = newId;
123:            }
124:
125:            public String getName() {
126:                return this .name;
127:            }
128:
129:            public void setName(String newName) {
130:                this .name = newName;
131:            }
132:
133:            public void addSubCategory(long subObjectId) {
134:                // Verify the id isn't already a sub category
135:                for (Enumeration e = this .subList.elements(); e
136:                        .hasMoreElements();) {
137:                    Long o = (Long) e.nextElement();
138:                    if (o.longValue() == subObjectId)
139:                        return;
140:                }
141:
142:                // Add the sub category
143:                Long newsub = new Long(subObjectId);
144:                this .subList.addElement(newsub);
145:            }
146:
147:            public void removeSubCategory(long subObjectId) {
148:                for (Enumeration e = this .subList.elements(); e
149:                        .hasMoreElements();) {
150:                    Long o = (Long) e.nextElement();
151:                    if (o.longValue() == subObjectId)
152:                        this .subList.removeElement((Object) o);
153:                }
154:            }
155:
156:            /* 
157:             * Return an array of subcategory object ids.
158:             */
159:            public long[] getSubCategories() {
160:                Enumeration e;
161:                int count;
162:
163:                long[] list = new long[this .subList.size()];
164:
165:                for (e = this .subList.elements(), count = 0; e
166:                        .hasMoreElements(); count++) {
167:                    Long o = (Long) e.nextElement();
168:                    list[count] = o.longValue();
169:                }
170:                return list;
171:            }
172:
173:            /* 
174:             * Add an item to this category.
175:             */
176:            public void addItem(long objectId) {
177:                // Verify the id isn't already in the list
178:                for (Enumeration e = this .itemList.elements(); e
179:                        .hasMoreElements();) {
180:                    Long o = (Long) e.nextElement();
181:                    if (o.longValue() == objectId)
182:                        return;
183:                }
184:
185:                // Add the item 
186:                Long newitem = new Long(objectId);
187:                this .itemList.addElement(newitem);
188:            }
189:
190:            public void removeItem(long objectId) {
191:                for (Enumeration e = this .itemList.elements(); e
192:                        .hasMoreElements();) {
193:                    Long o = (Long) e.nextElement();
194:                    if (o.longValue() == objectId)
195:                        this .itemList.removeElement(o);
196:                }
197:            }
198:
199:            /*
200:             * Return an array of Item object ids.
201:             */
202:            public long[] getItems() {
203:                Enumeration e;
204:                int count;
205:
206:                long[] list = new long[this .itemList.size()];
207:
208:                for (e = this .itemList.elements(), count = 0; e
209:                        .hasMoreElements(); count++) {
210:                    Long o = (Long) e.nextElement();
211:                    list[count] = o.longValue();
212:                }
213:                return list;
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.