1 10 package org.jgap.data; 11 12 import java.util.*; 13 14 21 public class DataElement 22 implements IDataElement { 23 24 private final static String CVS_REVISION = "$Revision: 1.5 $"; 25 26 private IDataElementList m_elements; 27 28 private Map m_attributes; 29 30 private String m_tagName; 31 32 public DataElement(final String 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 a_name, final String a_value) 39 throws Exception { 40 m_attributes.put(a_name, a_value); 41 } 42 43 public void appendChild(final IDataElement a_newChild) 44 throws Exception { 45 m_elements.add(a_newChild); 46 } 47 48 public String getTagName() { 49 return m_tagName; 50 } 51 52 public IDataElementList getElementsByTagName(final String 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 getNodeValue() 67 throws Exception { 68 return null; 69 } 70 71 public IDataElementList getChildNodes() { 72 return m_elements; 73 } 74 75 public String getAttribute(final String a_name) { 76 return (String ) m_attributes.get(a_name); 77 } 78 79 public Map getAttributes() { 80 return m_attributes; 81 } 82 } 83 | Popular Tags |