Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 shop2020 1
/**
2
 * 
3
 */
4
package in.shop2020.metamodel.definitions;
5
 
17 naveen 6
import in.shop2020.metamodel.util.DBUtils;
7
import in.shop2020.metamodel.util.MM;
8
 
10 shop2020 9
import java.io.Serializable;
10
import java.util.HashMap;
11
import java.util.Map;
12
 
13
/**
14
 * @author naveen
15
 *
16
 */
17
public class DefinitionsContainer implements Serializable {
18
 
19
	/**
20
	 * 
21
	 */
22
	private static final long serialVersionUID = 1L;
23
	private Map<Long, Category> categories;
24
	private Map<Long, SlideDefinition> slideDefinitions;
25
	private Map<Long, FeatureDefinition> featureDefinitions;
26
	private Map<Long, DatatypeDefinition> datatypeDefinitions;
27
	private Map<Long, Unit> units;
28
 
29
	/**
30
	 * 
31
	 */
32
	public DefinitionsContainer() {
17 naveen 33
		// Lazy initialization
10 shop2020 34
	}
35
 
36
	/**
37
	 * 
38
	 * @return Map
39
	 */
40
	public Map<Long, Unit> getUnits() {
17 naveen 41
		System.out.println("getUnits()");
42
 
43
		// De-serialize
44
		if(this.units == null) {
45
			// TODO
46
		}
10 shop2020 47
		return this.units;
48
	}
49
 
50
	/**
51
	 * 
52
	 * @param unitID
53
	 * @return Unit
54
	 */
55
	public Unit getUnit(long unitID) {
17 naveen 56
		System.out.println("getUnit("+ unitID +")");
57
 
58
		// Inititial 
59
		this.getUnits();
60
 
10 shop2020 61
		return this.units.get(new Long(unitID));
62
	}
63
 
64
	/**
17 naveen 65
	 * @return the datatypeDefinitions
10 shop2020 66
	 */
17 naveen 67
	public Map<Long, DatatypeDefinition> getDatatypeDefinitions() {
68
		return datatypeDefinitions;
10 shop2020 69
	}
17 naveen 70
 
10 shop2020 71
	/**
72
	 * @return the categories
17 naveen 73
	 * @throws Exception 
10 shop2020 74
	 */
17 naveen 75
	@SuppressWarnings("unchecked")
76
	public Map<Long, Category> getCategories() throws Exception {
77
		System.out.println("getCategories()");
78
 
79
		// De-serialize
80
		if(this.categories == null) {
81
			String dbFile = MM.DEFINITIONS_DB_PATH + "categories" + ".ser";
82
 
83
			this.categories = (Map<Long, Category>) DBUtils.read(dbFile);
84
		}
85
		return this.categories;
10 shop2020 86
	}
17 naveen 87
 
10 shop2020 88
	/**
17 naveen 89
	 * 
90
	 * @param categoryID
91
	 * @return Category
92
	 * @throws Exception 
10 shop2020 93
	 */
17 naveen 94
	public Category getCategory(long categoryID) throws Exception {
95
		System.out.println("getCategory("+ categoryID +")");
96
 
97
		// Inititial 
98
		if(this.categories == null) {
99
			this.getCategories();
100
		}
101
 
102
		return this.categories.get(new Long(categoryID));
10 shop2020 103
	}
17 naveen 104
 
10 shop2020 105
	/**
106
	 * @return the slideDefinitions
107
	 */
108
	public Map<Long, SlideDefinition> getSlideDefinitions() {
109
		return slideDefinitions;
110
	}
111
 
112
	/**
113
	 * @return the featureDefinitions
114
	 */
115
	public Map<Long, FeatureDefinition> getFeatureDefinitions() {
116
		return featureDefinitions;
117
	}
118
}