001package com.ganteater.ae.util.xml.easyparser;
002
003import java.util.StringTokenizer;
004
005public class NodeMapper extends Node {
006
007        private static final long serialVersionUID = 1L;
008
009        public NodeMapper(String aBaseTagName) {
010        super(aBaseTagName);
011    }
012
013    public void setAttribute(String aPath, String aAttributName, String aValue) {
014
015        StringTokenizer theStringTokenizer = new StringTokenizer(aPath, "/");
016
017        Node theCurrentNode = this;
018        Node[] theResult = null;
019
020        while (theStringTokenizer.hasMoreTokens()) {
021            String theCurrentTagName = theStringTokenizer.nextToken();
022
023            theResult = theCurrentNode.getNodes(theCurrentTagName);
024
025            if (theResult == null || theResult.length == 0 || theResult[0] == null) {
026                Node theNewNode = new Node(theCurrentTagName);
027                theCurrentNode.addInnerTag(theNewNode);
028                theCurrentNode = theNewNode;
029            } else {
030                theCurrentNode = theResult[0];
031            }
032        }
033
034        theCurrentNode.setAttribute(aAttributName, aValue);
035    }
036
037}