Source Code Cross Referenced for MemoryTaskoptions.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » scheduler » taskoptionmanagers » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.scheduler.taskoptionmanagers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: MemoryTaskoptions.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.scheduler.taskoptionmanagers;
009:
010:        import com.uwyn.rife.pcj.map.IntKeyOpenHashMap;
011:        import com.uwyn.rife.scheduler.Scheduler;
012:        import com.uwyn.rife.scheduler.Taskoption;
013:        import com.uwyn.rife.scheduler.TaskoptionManager;
014:        import com.uwyn.rife.scheduler.exceptions.TaskManagerException;
015:        import com.uwyn.rife.scheduler.exceptions.TaskoptionManagerException;
016:        import com.uwyn.rife.scheduler.taskoptionmanagers.exceptions.AddTaskoptionErrorException;
017:        import com.uwyn.rife.scheduler.taskoptionmanagers.exceptions.DuplicateTaskoptionException;
018:        import com.uwyn.rife.scheduler.taskoptionmanagers.exceptions.InexistentTaskIdException;
019:        import com.uwyn.rife.scheduler.taskoptionmanagers.exceptions.UpdateTaskoptionErrorException;
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:
023:        public class MemoryTaskoptions implements  TaskoptionManager {
024:            private Scheduler mScheduler = null;
025:            private IntKeyOpenHashMap<ArrayList<Taskoption>> mTaskoptionsMapping = null;
026:
027:            public MemoryTaskoptions() {
028:                mTaskoptionsMapping = new IntKeyOpenHashMap<ArrayList<Taskoption>>();
029:            }
030:
031:            public void setScheduler(Scheduler scheduler) {
032:                mScheduler = scheduler;
033:            }
034:
035:            public Scheduler getScheduler() {
036:                return mScheduler;
037:            }
038:
039:            public boolean addTaskoption(Taskoption taskoption)
040:                    throws TaskoptionManagerException {
041:                if (null == taskoption)
042:                    throw new IllegalArgumentException(
043:                            "taskoption can't be null.");
044:                if (taskoption.getTaskId() < 0)
045:                    throw new IllegalArgumentException(
046:                            "the task id is required.");
047:
048:                synchronized (this ) {
049:                    Taskoption cloned_taskoption = null;
050:                    try {
051:                        cloned_taskoption = taskoption.clone();
052:                    } catch (CloneNotSupportedException e) {
053:                        throw new AddTaskoptionErrorException(
054:                                cloned_taskoption, e);
055:                    }
056:
057:                    // check if the task id exists
058:                    try {
059:                        if (null == getScheduler().getTaskManager().getTask(
060:                                cloned_taskoption.getTaskId())) {
061:                            throw new InexistentTaskIdException(
062:                                    cloned_taskoption.getTaskId());
063:                        }
064:                    } catch (TaskManagerException e) {
065:                        throw new AddTaskoptionErrorException(
066:                                cloned_taskoption, e);
067:                    }
068:
069:                    // get the taskoptions list for the same task id
070:                    int task_id = cloned_taskoption.getTaskId();
071:                    ArrayList<Taskoption> taskoptions = mTaskoptionsMapping
072:                            .get(task_id);
073:                    if (null == taskoptions) {
074:                        // no list exists, create one
075:                        taskoptions = new ArrayList<Taskoption>();
076:                        mTaskoptionsMapping.put(cloned_taskoption.getTaskId(),
077:                                taskoptions);
078:                    } else {
079:                        // list exists, check if the same taskoption isn't already present
080:                        // and throw an exception if that is the case
081:                        for (Taskoption taskoption_to_check : taskoptions) {
082:                            if (taskoption_to_check.getName().equals(
083:                                    cloned_taskoption.getName())) {
084:                                throw new DuplicateTaskoptionException(
085:                                        cloned_taskoption.getTaskId(),
086:                                        cloned_taskoption.getName());
087:                            }
088:                        }
089:                    }
090:
091:                    taskoptions.add(cloned_taskoption);
092:
093:                    return true;
094:                }
095:            }
096:
097:            public boolean updateTaskoption(Taskoption taskoption)
098:                    throws TaskoptionManagerException {
099:                if (null == taskoption)
100:                    throw new IllegalArgumentException(
101:                            "taskoption can't be null.");
102:                if (taskoption.getTaskId() < 0)
103:                    throw new IllegalArgumentException(
104:                            "the task id is required.");
105:
106:                synchronized (this ) {
107:                    Taskoption cloned_taskoption = null;
108:                    try {
109:                        cloned_taskoption = taskoption.clone();
110:                    } catch (CloneNotSupportedException e) {
111:                        throw new AddTaskoptionErrorException(
112:                                cloned_taskoption, e);
113:                    }
114:
115:                    // check if the task id exists
116:                    try {
117:                        if (null == getScheduler().getTaskManager().getTask(
118:                                cloned_taskoption.getTaskId())) {
119:                            throw new InexistentTaskIdException(
120:                                    cloned_taskoption.getTaskId());
121:                        }
122:                    } catch (TaskManagerException e) {
123:                        throw new UpdateTaskoptionErrorException(
124:                                cloned_taskoption, e);
125:                    }
126:
127:                    // get the taskoptions for the same task id
128:                    int task_id = cloned_taskoption.getTaskId();
129:                    ArrayList<Taskoption> taskoptions = mTaskoptionsMapping
130:                            .get(task_id);
131:                    if (null == taskoptions) {
132:                        return false;
133:                    }
134:                    // obtain the taskoption with same name
135:                    Taskoption taskoption_to_remove = null;
136:                    for (Taskoption taskoption_to_check : taskoptions) {
137:                        if (taskoption_to_check.getName().equals(
138:                                cloned_taskoption.getName())) {
139:                            taskoption_to_remove = taskoption_to_check;
140:                            break;
141:                        }
142:                    }
143:
144:                    // no match was found
145:                    if (null == taskoption_to_remove) {
146:                        return false;
147:                    }
148:
149:                    // remove the old taskoption and store the new one
150:                    taskoptions.remove(taskoption_to_remove);
151:                    taskoptions.add(cloned_taskoption);
152:
153:                    return true;
154:                }
155:            }
156:
157:            public Taskoption getTaskoption(int taskid, String name)
158:                    throws TaskoptionManagerException {
159:                if (taskid < 0)
160:                    throw new IllegalArgumentException(
161:                            "taskid can't be negative.");
162:                if (null == name)
163:                    throw new IllegalArgumentException("name can't be null.");
164:                if (0 == name.length())
165:                    throw new IllegalArgumentException("name can't be empty.");
166:
167:                synchronized (this ) {
168:                    // get the taskoptions for the same task id
169:                    ArrayList<Taskoption> taskoptions = mTaskoptionsMapping
170:                            .get(taskid);
171:                    if (null == taskoptions) {
172:                        return null;
173:                    }
174:                    // obtain the taskoption with same name
175:                    for (Taskoption taskoption : taskoptions) {
176:                        if (taskoption.getName().equals(name)) {
177:                            return taskoption;
178:                        }
179:                    }
180:                }
181:
182:                return null;
183:            }
184:
185:            public Collection<Taskoption> getTaskoptions(int taskid)
186:                    throws TaskoptionManagerException {
187:                if (taskid < 0)
188:                    throw new IllegalArgumentException(
189:                            "taskid can't be negative.");
190:
191:                return mTaskoptionsMapping.get(taskid);
192:            }
193:
194:            public boolean removeTaskoption(Taskoption taskoption)
195:                    throws TaskoptionManagerException {
196:                if (null == taskoption)
197:                    throw new IllegalArgumentException(
198:                            "taskoption can't be null.");
199:
200:                return removeTaskoption(taskoption.getTaskId(), taskoption
201:                        .getName());
202:            }
203:
204:            public boolean removeTaskoption(int taskid, String name)
205:                    throws TaskoptionManagerException {
206:                if (taskid < 0)
207:                    throw new IllegalArgumentException(
208:                            "taskid can't be negative.");
209:                if (null == name)
210:                    throw new IllegalArgumentException("name can't be null.");
211:                if (0 == name.length())
212:                    throw new IllegalArgumentException("name can't be empty.");
213:
214:                synchronized (this ) {
215:                    // get the taskoptions for the same task id
216:                    ArrayList<Taskoption> taskoptions = mTaskoptionsMapping
217:                            .get(taskid);
218:                    if (null == taskoptions) {
219:                        return false;
220:                    }
221:                    // obtain the taskoption with same name
222:                    Taskoption taskoption_to_remove = null;
223:                    for (Taskoption taskoption : taskoptions) {
224:                        if (taskoption.getName().equals(name)) {
225:                            taskoption_to_remove = taskoption;
226:                            break;
227:                        }
228:                    }
229:
230:                    if (null == taskoption_to_remove) {
231:                        return false;
232:                    }
233:
234:                    taskoptions.remove(taskoption_to_remove);
235:                }
236:
237:                return true;
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.