KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > data > DataElement


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.data;
11
12 import java.util.*;
13
14 /**
15  * Element owning a tag name and holding attributes.
16  * Used by the DataTreeBuilder.
17  *
18  * @author Klaus Meffert
19  * @since 2.0
20  */

21 public class DataElement
22     implements IDataElement {
23   /** String containing the CVS revision. Read out via reflection!*/
24   private final static String JavaDoc CVS_REVISION = "$Revision: 1.5 $";
25
26   private IDataElementList m_elements;
27
28   private Map m_attributes;
29
30   private String JavaDoc m_tagName;
31
32   public DataElement(final String JavaDoc a_tagName) {
33     m_elements = new DataElementList();
34     m_attributes = new HashMap();
35     m_tagName = a_tagName;
36   }
37
38   public void setAttribute(final String JavaDoc a_name, final String JavaDoc a_value)
39       throws Exception JavaDoc {
40     m_attributes.put(a_name, a_value);
41   }
42
43   public void appendChild(final IDataElement a_newChild)
44       throws Exception JavaDoc {
45     m_elements.add(a_newChild);
46   }
47
48   public String JavaDoc getTagName() {
49     return m_tagName;
50   }
51
52   public IDataElementList getElementsByTagName(final String JavaDoc a_name) {
53     IDataElementList ret = new DataElementList();
54     for (int i = 0; i < m_elements.getLength(); i++) {
55       if (m_elements.item(i).getTagName().equals(a_name)) {
56         ret.add(m_elements.item(i));
57       }
58     }
59     return ret;
60   }
61
62   public short getNodeType() {
63     return 1;
64   }
65
66   public String JavaDoc getNodeValue()
67       throws Exception JavaDoc {
68     return null;
69   }
70
71   public IDataElementList getChildNodes() {
72     return m_elements;
73   }
74
75   public String JavaDoc getAttribute(final String JavaDoc a_name) {
76     return (String JavaDoc) m_attributes.get(a_name);
77   }
78
79   public Map getAttributes() {
80     return m_attributes;
81   }
82 }
83
Popular Tags