01: /*
02: * $Id: MemoryBPELProcessDAO.java,v 1.12 2004/12/06 07:53:29 fornp1 Exp $
03: *
04: * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
05: * Berne University of Applied Sciences
06: * School of Engineering and Information Technology
07: * All rights reserved.
08: */
09: package bexee.dao;
10:
11: import java.util.HashMap;
12: import java.util.Map;
13:
14: import bexee.model.process.BPELProcess;
15:
16: /**
17: * This class uses memory rather than persistent storage to store and load
18: * <code>BPELProcess</code> objects.
19: *
20: * @version $Revision: 1.12 $, $Date: 2004/12/06 07:53:29 $
21: * @author Patric Fornasier
22: * @author Pawel Kowalski
23: */
24: public class MemoryBPELProcessDAO implements BPELProcessDAO {
25:
26: protected static Map map;
27:
28: /**
29: * Creates a new <code>MemoryBPELProcessDAO</code> that uses a static
30: * <code>Map</code> to manage the stored <code>BPELProcess</code>
31: * objects.
32: */
33: public MemoryBPELProcessDAO() {
34: if (map == null) {
35: map = new HashMap();
36: }
37: }
38:
39: public void delete(String name) {
40: map.remove(name);
41: }
42:
43: public void deleteAll() {
44: map.clear();
45: }
46:
47: public BPELProcess find(String name) {
48: return (BPELProcess) map.get(name);
49: }
50:
51: public String insert(BPELProcess process) {
52:
53: // generate id and set it on BPEL process
54: String name = process.getName();
55:
56: // store BPEL process and return id
57: map.put(name, process);
58: return name;
59: }
60:
61: public void update(BPELProcess process) throws DAOException {
62:
63: // check if we have that object already
64: String name = process.getName();
65: BPELProcess oldProcess = find(name);
66: if (oldProcess == null) {
67: throw new DAOException("No object with id " + name
68: + " to update");
69: }
70:
71: // replace with new version
72: map.put(name, process);
73:
74: }
75:
76: public String replace(BPELProcess process) throws DAOException {
77:
78: // check if we have that object already
79: String name = process.getName();
80: BPELProcess oldProcess = find(name);
81:
82: if (oldProcess != null) {
83: update(process);
84: } else {
85: name = insert(process);
86: }
87:
88: return name;
89: }
90: }
|