/**
* A simple Element class for storing the element name, attributes
* and children.
*
* $Log: Element.java,v $
* Revision 1.7 1998/09/08 15:54:01 jsaarela
* Distribution release V1.4 - aboutEachPrefix added, namespace management
* improved.
*
* Revision 1.6 1998/08/28 10:03:15 jsaarela
* Distribution release 1.3 on 28-Aug-98.
*
* Revision 1.5 1998/08/12 07:54:55 jsaarela
* Namespace management now corresponds with the W3C Working
* Draft dated 2-Aug-98.
*
* Revision 1.4 1998/07/30 13:39:32 jsaarela
* multiple internal references fixed,
* properties without children fixed.
*
* Revision 1.3 1998/07/27 12:20:54 jsaarela
* 1st distribution version logged in.
*
*
* @author Janne Saarela
*/
package org.w3c.rdf;
import java.util.*;
import java.io.*;
import org.xml.sax.AttributeList;
import org.xml.sax.SAXException;
public class Element
{
private String m_sName = null;
private Hashtable m_attributes = new Hashtable();
private Vector m_children = new Vector();
private String m_sID = null;
private String m_sBagID = null;
private Hashtable m_nodes = new Hashtable ();
private Vector m_vTargets = new Vector ();
private boolean m_bDone = false;
public Element (String sName, AttributeList al) throws SAXException {
m_sName = sName;
if (al != null) {
int iLength = al.getLength ();
if (al == null) {
// System.out.println("[Attributes not available]");
} else {
for (int x = 0; x < iLength; x++) {
String aName = al.getName (x);
String aValue = al.getValue (x);
m_attributes.put (aName, aValue);
}
}
}
}
public String name() {
return m_sName;
}
public void addChild (Element e) {
m_children.addElement (e);
}
public Enumeration children () {
return m_children.elements();
}
public Enumeration attributes () {
return m_attributes.keys();
}
public void addAttribute (String sName, String sValue) {
if (sName == null ||
sValue == null)
return;
m_attributes.put (sName, sValue);
}
public void removeAttribute (String sName) {
m_attributes.remove (sName);
}
public String getAttribute (String sName) {
return (String)m_attributes.get (sName);
}
public String getAttribute (String sNamespace, String sName) {
return (String)m_attributes.get (sNamespace+sName);
}
public void addTarget (Element e) {
m_vTargets.addElement (e);
}
public Enumeration targets () {
return m_vTargets.elements();
}
public Element target () {
if (m_vTargets.size() == 0)
return null;
else
return (Element)m_vTargets.elementAt(0);
}
public void ID (String sID) {
m_sID = sID;
}
public String ID () {
return m_sID;
}
public void bagID (String sBagID) {
m_sBagID = sBagID;
}
public String bagID () {
return m_sBagID;
}
public void linearize (int indent, PrintStream ps) {
for (int x = 0; x < indent; x++) {
ps.print (" ");
}
System.out.println ("Element "+name());
Enumeration e = children();
while (e.hasMoreElements()) {
Element ele = (Element)e.nextElement();
ele.linearize (indent + 2, ps);
}
}
public boolean done () {
return m_bDone;
}
public void done (boolean b) {
m_bDone = b;
}
}
Webmaster