01: package org.swingml.xml.mapper;
02:
03: import java.awt.*;
04:
05: import org.swingml.*;
06: import org.swingml.model.*;
07: import org.swingml.xml.*;
08: import org.w3c.dom.*;
09:
10: /**
11: * Class Description goes here.
12: *
13: * @author <a href="mailto:robertj@morris.net">Robert J. Morris</a>
14: */
15: public class DataStoreMapper extends MapperUtil implements Mapper {
16:
17: /**
18: * @see org.swingml.xml.Mapper#getModelToMap(Node, Object)
19: */
20: public Object getModelToMap(Node aNode, Object aParent,
21: Container aContainer) {
22: DataStoreModel theModel = new DataStoreModel();
23: SwingMLModel theContainer = (SwingMLModel) aParent;
24: theContainer.addChild(theModel);
25: theModel.setParent(theContainer);
26: return theModel;
27: }
28:
29: /**
30: * @see org.swingml.xml.Mapper#mapModel(Node, Object)
31: */
32: public void mapModel(Node aNode, Object aParent,
33: Container aContainer) {
34: DataStoreModel model = (DataStoreModel) this .getModelToMap(
35: aNode, aParent, aContainer);
36: this .mapModelAttributes(aNode, model, aParent);
37: super .iterate(aNode, model, aContainer);
38: }
39:
40: /**
41: * @see org.swingml.xml.Mapper#mapModelAttributes(Node, Object,
42: * Object)
43: */
44: public void mapModelAttributes(Node aNode, Object aModel,
45: Object aParent) {
46: DataStoreModel theDataStoreModel = (DataStoreModel) aModel;
47: super .mapCommonAttributes(theDataStoreModel, aNode);
48: Node theResultNode = null;
49:
50: theResultNode = super .getAttribute(aNode, Constants.NAME);
51: if (theResultNode != null) {
52: theDataStoreModel.setName(theResultNode.getNodeValue());
53: }
54:
55: NodeList nodes = aNode.getChildNodes();
56: StringBuffer value = new StringBuffer();
57: if (nodes.getLength() > 0) {
58: for (int i = 0; i < nodes.getLength(); i++) {
59: value.append(nodes.item(i).getNodeValue());
60: }
61: }
62: theDataStoreModel.setValue(value.toString());
63: }
64: }
|