001: package net.xoetrope.xml.nanoxml;
002:
003: import java.util.Enumeration;
004: import java.util.Vector;
005:
006: import net.n3.nanoxml.IXMLElement;
007: import net.n3.nanoxml.XMLElement;
008: import net.xoetrope.xml.XmlElement;
009:
010: /**
011: * <p>A customization of the XmlElement to interface with NanoXML</p>
012: * <p>Copyright (c) Xoetrope Ltd., 1998-2003<br>
013: * License: see license.txt
014: * @version $Revision: 1.1 $
015: */
016: public class NanoXmlElement implements XmlElement {
017: protected IXMLElement element;
018:
019: public NanoXmlElement() {
020: element = new XMLElement();
021: }
022:
023: public NanoXmlElement(IXMLElement e) {
024: element = e;
025: }
026:
027: public NanoXmlElement(String name) {
028: element = new XMLElement(name);
029: }
030:
031: public XmlElement elementAt(int i) {
032: return new NanoXmlElement(element.getChildAtIndex(i));
033: }
034:
035: public String getAttribute(String name) {
036: return element.getAttribute(name);
037: }
038:
039: public Vector getChildren() {
040: Vector temp = new Vector();
041: Vector children = element.getChildren();
042: int numChildren = children.size();
043: for (int i = 0; i < numChildren; i++) {
044: temp.addElement(new NanoXmlElement((IXMLElement) children
045: .elementAt(i)));
046: }
047:
048: return temp;
049: }
050:
051: public Vector getChildren(String path) {
052: Vector temp = new Vector();
053: Vector children = element.getChildrenNamed(path);
054: int numChildren = children.size();
055: for (int i = 0; i < numChildren; i++) {
056: temp.addElement(new NanoXmlElement((IXMLElement) children
057: .elementAt(i)));
058: }
059:
060: return temp;
061: }
062:
063: public String getName() {
064: return element.getName();
065: }
066:
067: public void setName(String newName) {
068: element.setName(newName);
069: }
070:
071: public String getContent() {
072: return element.getContent();
073: }
074:
075: public Enumeration enumerateAttributeNames() {
076: return element.enumerateAttributeNames();
077: }
078:
079: public void setAttribute(String name, String value) {
080: element.setAttribute(name, value);
081: }
082:
083: public void addChild(XmlElement child) {
084: if (child instanceof NanoXmlElement)
085: element.addChild((XMLElement) child.getImplementation());
086: }
087:
088: public XmlElement createElement(String name) {
089: IXMLElement ele = element.createElement(name);
090: return new NanoXmlElement(ele);
091: }
092:
093: public XmlElement getFirstChildNamed(String name) {
094: IXMLElement ele = element.getFirstChildNamed(name);
095:
096: return ele == null ? null : new NanoXmlElement(ele);
097: }
098:
099: public String getNamespace() {
100: return element.getNamespace();
101: }
102:
103: public int getAttributeCount() {
104: return element.getAttributeCount();
105: }
106:
107: public String getAttributeNamespace(String name) {
108: return element.getAttributeNamespace(name);
109: }
110:
111: /**
112: * Returns an instance of the implementing NanoXml element (XMLElement)
113: * @return
114: */
115: public Object getImplementation() {
116: return element;
117: }
118:
119: public IXMLElement getElement() {
120: return element;
121: }
122: }
|