01: package org.jasig.portal.layout.alm;
02:
03: import java.util.Iterator;
04: import java.util.Map;
05:
06: import javax.sql.DataSource;
07:
08: public class ALFragmentNodeAttributeService {
09:
10: ALNodeAttributeDao dao;
11:
12: public ALFragmentNodeAttributeService(DataSource ds) {
13: this .dao = new ALNodeAttributeDao(ds);
14: }
15:
16: /**
17: * Returns a Map from String attribute names to String attribute values.
18: * @param fragmentId
19: * @param nodeId
20: * @return
21: */
22: public Map attributesForFragmentNode(int fragmentId, int nodeId) {
23: return this .dao.attributesForFragmentNode(fragmentId, nodeId);
24: }
25:
26: public void storeFragmentNodeAttribute(int fragmentId, int nodeId,
27: String attributeName, String attributeValue) {
28:
29: // TODO: make this sane
30:
31: // does the attribute already exist?
32:
33: Map attributesForNode = attributesForFragmentNode(fragmentId,
34: nodeId);
35:
36: // if so, update it
37: if (attributesForNode.containsKey(attributeName)) {
38: dao.setFragmentNodeAttribute(fragmentId, nodeId,
39: attributeName, attributeValue);
40: } else {
41: // if not, insert it
42: dao.insertFragmentNodeAttribute(fragmentId, nodeId,
43: attributeName, attributeValue);
44: }
45:
46: }
47:
48: public void storeFragmentNodeAttributes(int fragmentId, int nodeId,
49: Map attributeNamesToValues) {
50:
51: for (Iterator iter = attributeNamesToValues.keySet().iterator(); iter
52: .hasNext();) {
53: String attributeName = (String) iter.next();
54: String attributeValue = (String) attributeNamesToValues
55: .get(attributeName);
56:
57: storeFragmentNodeAttribute(fragmentId, nodeId,
58: attributeName, attributeValue);
59: }
60:
61: }
62:
63: }
|