ActionParamMapper.java :  » XML-UI » SwingML » org » swingml » xml » mapper » Java Open Source

Java Open Source » XML UI » SwingML 
SwingML » org » swingml » xml » mapper » ActionParamMapper.java
/* SwingML
 * Copyright (C) 2002 Robert Morris.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authors:
 *     Robert Morris <robertj@morris.net>
 *
 */

package org.swingml.xml.mapper;

import java.awt.*;

import org.swingml.*;
import org.swingml.model.*;
import org.swingml.xml.*;
import org.w3c.dom.*;


/**
 * @author NumberSix
 *
 */
public class ActionParamMapper extends MapperUtil implements Mapper {

    public Object getModelToMap (Node aNode, Object aParent, Container aContainer) {
        ActionParamModel theModel = new ActionParamModel();
        if (aParent instanceof ExternalActionModel) {
            ExternalActionModel theActionModel = (ExternalActionModel) aParent;
            theActionModel.addParam(theModel);
        } else if (aParent instanceof ActionParamModel) {
            ActionParamModel theActionModel = (ActionParamModel) aParent;
            theActionModel.addChild(theModel);
        } else if (aParent instanceof ControllerActionModel) {
          ControllerActionModel theActionModel = (ControllerActionModel) aParent;
          theActionModel.addParam(theModel);
          
          
        }
        return theModel;
    }

    public void mapModel (Node aNode, Object aParent, Container aContainer) {
        ActionParamModel theParamModel = (ActionParamModel) this.getModelToMap(aNode, aParent, aContainer);
        this.mapModelAttributes(aNode, theParamModel, aParent);

        super.iterate(aNode, theParamModel, aContainer);
    }

    public void mapModelAttributes (Node aNode, Object aModel, Object aParent) {
        Node attributeNode = null;
        ActionParamModel theParamModel = (ActionParamModel) aModel;

        attributeNode = super.getAttribute(aNode, Constants.NAME);
        if (attributeNode != null) {
            theParamModel.setName(attributeNode.getNodeValue());
        }

        attributeNode = super.getAttribute(aNode, Constants.VALUE);
        if (attributeNode != null) {
            theParamModel.setValue(attributeNode.getNodeValue());
        }

        attributeNode = super.getAttribute(aNode, Constants.ID);
        if (attributeNode != null) {
            theParamModel.setId(attributeNode.getNodeValue());
        }

        /*
         * If the ACTION-PARAM element contains a mutli-facted value, 
         * iterate through all of its children in order to fully extract
         * it from the source.
         */
//        NodeList theNodes = aNode.getChildNodes();
//        if (theNodes.getLength() > 0) {
//            StringBuffer theValue = new StringBuffer();
//
//            for (int i = 0; i < theNodes.getLength(); i++) {
//                theValue.append(theNodes.item(i).getNodeValue());
//            }
//
//            if (theValue.length() > 0) {
//                theParamModel.setValue(theValue.toString());
//            }
//        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.