01: /*
02: * SwingML
03: * Copyright (C) 2002 Robert J. Morris.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the
17: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18: * Boston, MA 02111-1307, USA.
19: *
20: * Authors:
21: * <a href="mailto:robertj@morris.net">Robert J. Morris</a>
22: *
23: * Oct 9, 2002 6:51:53 PM
24: */
25: package org.swingml.xml.mapper;
26:
27: import java.awt.*;
28:
29: import org.swingml.*;
30: import org.swingml.model.*;
31: import org.swingml.xml.*;
32: import org.w3c.dom.*;
33:
34: /**
35: *
36: * Maps the values supplied in the DEBUG tag to a new
37: * JDebugModel instance
38: *
39: * @see org.swingml.model.JDebugModel
40: */
41: public class JDebugMapper extends MapperUtil implements Mapper {
42:
43: /**
44: * @see org.swingml.xml.Mapper#getModelToMap(Node, Object)
45: */
46: public Object getModelToMap(Node aNode, Object aParent,
47: Container aContainer) {
48: SwingMLModel theContainer = (SwingMLModel) aParent;
49: JDebugModel theModel = new JDebugModel();
50: theContainer.addChild(theModel);
51: theModel.setParent(theContainer);
52: return theModel;
53: }
54:
55: /**
56: * @see org.swingml.xml.Mapper#mapModel(Node, Object)
57: */
58: public void mapModel(Node aNode, Object aParent,
59: Container aContainer) {
60: JDebugModel theModel = (JDebugModel) this .getModelToMap(aNode,
61: aParent, aContainer);
62: this .mapModelAttributes(aNode, theModel, aParent);
63: super .iterate(aNode, theModel, aContainer);
64: }
65:
66: /**
67: * @see org.swingml.xml.Mapper#mapModelAttributes(Node, Object, Object)
68: */
69: public void mapModelAttributes(Node aNode, Object aModel,
70: Object aParent) {
71: JDebugModel theDebugModel = (JDebugModel) aModel;
72: Node theResultNode = null;
73: Node theFirstChild = null;
74: NodeList theNodes = aNode.getChildNodes();
75: if (theNodes != null && theNodes.getLength() > 0) {
76: for (int i = 0; i < theNodes.getLength(); i++) {
77: theResultNode = theNodes.item(i);
78: if (theResultNode.getNodeName().equalsIgnoreCase(
79: Constants.TEXT)) {
80: // Make sure that something is actually there before
81: // referencing the object.
82: theFirstChild = theResultNode.getFirstChild();
83: if (theFirstChild != null) {
84: theDebugModel.setText(theFirstChild
85: .getNodeValue());
86: }
87: }
88: }
89: }
90: }
91: }
|