package ws.prova;

/*
 * Copyright (C) 2002-2007 <a href="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;

import java.util.List;


/**
 * Class encapsulating NamedNodeMap in XML DOM
 * <p>Title: Prova</p>
 * <p>Description: Class encapsulating NamedNodeMap in XML DOM</p>
 * <p>Copyright: Copyright (C) 2002-2007</p>
 * <p>Company: City University, London, United Kingdom</p>
 *
 * @author Alex Kozlenkov
 * @version 2.0 <25 March 2007>
 */
public class XML_NamedNodeMap {
	private NamedNodeMap nm;

	public XML_NamedNodeMap(NamedNodeMap nm) {
		this.nm = nm;
	}

	public XML_Node getNamedItem(String name) {
		return XML_Node.createNode(nm.getNamedItem(name));
	}

	public XML_Node setNamedItem(XML_Node arg)
			throws DOMException {
		return XML_Node.createNode(nm.setNamedItem(arg.node));
	}

	public XML_Node getNamedItemNS(String namespaceURI,
								   String localName) {
		return XML_Node.createNode(nm.getNamedItemNS(namespaceURI, localName));
	}

	public XML_Node item(int index) {
		return XML_Node.createNode(nm.item(index));
	}

	/**
	 * Non-deterministically enumerate nodes in the NamedNodeMap
	 *
	 * @param r
	 * @param bindings
	 * @return
	 */
	public Boolean nodes(final Object[] r, final List bindings) {
		for (int i = 0; i < nm.getLength(); i++) {
//			Node node = nm.item(i);
			Object[] retobj = new Object[1];
//			retobj[0] = XML_Node.createNode( node );
			retobj[0] = item(i);
			bindings.add(retobj);
		}
		return Boolean.TRUE;
	}

	public String toString() {
		return nm.toString();
	}
}
