001: /* SwingML
002: * Copyright (C) 2002 Robert Morris.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: *
019: * Authors:
020: * Robert Morris <robertj@morris.net>
021: *
022: */
023:
024: package org.swingml.xml.mapper;
025:
026: import java.awt.*;
027:
028: import org.swingml.*;
029: import org.swingml.model.*;
030: import org.swingml.xml.*;
031: import org.w3c.dom.*;
032:
033: /**
034: * @author NumberSix
035: *
036: */
037: public class ActionParamMapper extends MapperUtil implements Mapper {
038:
039: public Object getModelToMap(Node aNode, Object aParent,
040: Container aContainer) {
041: ActionParamModel theModel = new ActionParamModel();
042: if (aParent instanceof ExternalActionModel) {
043: ExternalActionModel theActionModel = (ExternalActionModel) aParent;
044: theActionModel.addParam(theModel);
045: } else if (aParent instanceof ActionParamModel) {
046: ActionParamModel theActionModel = (ActionParamModel) aParent;
047: theActionModel.addChild(theModel);
048: } else if (aParent instanceof ControllerActionModel) {
049: ControllerActionModel theActionModel = (ControllerActionModel) aParent;
050: theActionModel.addParam(theModel);
051:
052: }
053: return theModel;
054: }
055:
056: public void mapModel(Node aNode, Object aParent,
057: Container aContainer) {
058: ActionParamModel theParamModel = (ActionParamModel) this
059: .getModelToMap(aNode, aParent, aContainer);
060: this .mapModelAttributes(aNode, theParamModel, aParent);
061:
062: super .iterate(aNode, theParamModel, aContainer);
063: }
064:
065: public void mapModelAttributes(Node aNode, Object aModel,
066: Object aParent) {
067: Node attributeNode = null;
068: ActionParamModel theParamModel = (ActionParamModel) aModel;
069:
070: attributeNode = super .getAttribute(aNode, Constants.NAME);
071: if (attributeNode != null) {
072: theParamModel.setName(attributeNode.getNodeValue());
073: }
074:
075: attributeNode = super .getAttribute(aNode, Constants.VALUE);
076: if (attributeNode != null) {
077: theParamModel.setValue(attributeNode.getNodeValue());
078: }
079:
080: attributeNode = super .getAttribute(aNode, Constants.ID);
081: if (attributeNode != null) {
082: theParamModel.setId(attributeNode.getNodeValue());
083: }
084:
085: /*
086: * If the ACTION-PARAM element contains a mutli-facted value,
087: * iterate through all of its children in order to fully extract
088: * it from the source.
089: */
090: // NodeList theNodes = aNode.getChildNodes();
091: // if (theNodes.getLength() > 0) {
092: // StringBuffer theValue = new StringBuffer();
093: //
094: // for (int i = 0; i < theNodes.getLength(); i++) {
095: // theValue.append(theNodes.item(i).getNodeValue());
096: // }
097: //
098: // if (theValue.length() > 0) {
099: // theParamModel.setValue(theValue.toString());
100: // }
101: // }
102: }
103: }
|