1 /*** DataPointCategoryFactory.java - part of the MirkE (say murky) application for colormetric analysis emphesizing
2 kinetics.
3
4 Created by: Scott Menor on 21 July, 2004.
5 Last modified by: Scott Menor on 2 February, 2005
6
7 Copyright (c) 2004 Arizona State University - Cancer Research Institute. All rights reserved.
8
9 MirkE is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 MirkE is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with MirkE; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
22 */
23
24 package edu.asu.cri.MirkE.dataStructures;
25
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 import edu.asu.cri.MirkE.exceptions.MirkEApplicationException;
31
32 /*** Simple utility class to prevent duplication of Observable objects
33
34 TODO - depreciate / remove this class by using features of Hibernate with a non-unique key (like DataPointCategory.categoryName)
35 */
36 public class DataPointCategoryFactory {
37 private Map dataPointCategoryMap = new HashMap();
38
39 private DataSet dataSet;
40
41 /*** default constructor
42
43 */
44 public DataPointCategoryFactory() {}
45
46 /*** constructor
47
48 @param dataSet
49 */
50 public DataPointCategoryFactory(DataSet dataSet) {
51 setDataSet(dataSet);
52 }
53
54
55 /***
56 @param dataSet
57 */
58 public void setDataSet(DataSet dataSet) {
59 this.dataSet = dataSet;
60 }
61
62 /***
63 @return dataSet
64 */
65 public DataSet getDataSet() {
66 return this.dataSet;
67 }
68
69
70 /***
71 * @param categoryName
72 * @param categoryType
73 * @return <code>DataPointCategory</code>
74 * @throws MirkEApplicationException
75 */
76 public DataPointCategory getDataPointCategory(String categoryName,
77 String categoryType)
78 throws MirkEApplicationException{
79 if (dataSet != null) {
80 try {
81
82 DataPointCategory dataPointCategory = (DataPointCategory)dataPointCategoryMap.get(categoryName + "\t" + categoryType);
83
84 if (dataPointCategory != null) {
85 return dataPointCategory;
86
87 } else {
88
89 List list = dataSet.find("from DataPointCategory as c " +
90 "where c.categoryName='" + categoryName +
91 "' and c.categoryType = '" + categoryType + "'");
92
93 if (list.size() > 0) {
94 dataPointCategory = (DataPointCategory)list.get(0);
95 dataPointCategoryMap.put(categoryName + "\t" + categoryType, dataPointCategory);
96
97 return dataPointCategory;
98
99 }
100
101
102 }
103
104 } catch (Exception exception) {
105 throw new MirkEApplicationException("Exception getdatapointCategory ", exception);
106
107 }
108 }
109
110 DataPointCategory dataPointCategory = new DataPointCategory(categoryName,
111 categoryType);
112
113 dataPointCategoryMap.put(categoryName + "\t" + categoryType, dataPointCategory);
114
115
116
117 return dataPointCategory;
118 }
119
120 /*** ensure that all <code>DataPointCategory</code>(ies) have been saved
121
122 */
123 public void saveDataPointCategories() {
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 }
151 }