⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapentryelementadapter.java

📁 开源框架
💻 JAVA
字号:
/*
 * $Id: MapEntryElementAdapter.java,v 1.6 2006/01/29 18:58:30 geoffm74 Exp $
 * $Source: /cvsroot/domify/domify/src/java/org/infohazard/domify/MapEntryElementAdapter.java,v $
 */

package org.infohazard.domify;

import org.apache.log4j.Category;
import org.w3c.dom.*;
import java.util.*;


/**
 */
public class MapEntryElementAdapter extends TypedElementAdapter
{
	/** Logging category for log4j. */
	protected static Category log = Category.getInstance(MapEntryElementAdapter.class.getName());

	/**
	 */
	protected static final String ATTRNAME_KEY = "key";

	/**
	 */
	protected class MapEntryNamedNodeMapAdapter extends NamedNodeMapUnimplemented
	{
		Node typeAttr = null;
		Node keyAttr = null;

		int attrCount = 0;

		/** */
		public MapEntryNamedNodeMapAdapter()
		{
			if (getWrapped() != null)
			{
				typeAttr = new AttrAdapter(ATTRNAME_TYPE, getWrapped().getClass().getName());
				attrCount++;
			}

			if (mapKey != null)
			{
				keyAttr = new AttrAdapter(ATTRNAME_KEY, mapKey);
				attrCount++;
			}
		}

		/** */
		public Node getNamedItem(String name)
		{
			if (log.isDebugEnabled())
				log.debug("MapEntryNamedNodeMapAdapter.getNamedItem(" + name + ")");

			if (name.equals(ATTRNAME_KEY))
				return keyAttr;
			else if (name.equals(ATTRNAME_TYPE))
				return typeAttr;
			else
				return null;
		}

		/** */
		public Node item(int index)
		{
			if (log.isDebugEnabled())
				log.debug("MapEntryNamedNodeMapAdapter.item(" + index + ")");

			switch (attrCount)
			{
				case 0:
					return null;

				case 1:
					if (index == 0)
						return (typeAttr == null) ? keyAttr : typeAttr;
					else
						return null;

				case 2:
					if (index == 0)
						return keyAttr;
					else if (index == 1)
						return typeAttr;
					else
						return null;

				default:
					throw new IllegalStateException();
			}
		}

		/** */
		public int getLength()
		{
			if (log.isDebugEnabled())
				log.debug("MapEntryNamedNodeMapAdapter.getLength() is " + attrCount);

			return attrCount;
		}

		/** */
		public Node getNamedItemNS(String namespaceURI, String localName)
		{
			log.debug("MapEntryNamedNodeMapAdapter.getNamedItemNS()");

			return null;
		}
	}

	/**
	 */
	protected String mapKey;

	/**
	 * This is lazy-created.
	 */
	protected NamedNodeMap namedNodeMapAdapter = null;

	/**
	 */
	protected MapEntryElementAdapter(Map.Entry me, String name, Node parent, int ordinal, DOMAdapter config)
	{
		super(me.getValue(), name, parent, ordinal, config);

		// Convert everything to string, if possible
		mapKey = me.getKey()==null ? null : me.getKey().toString();

		log.debug("Actually it was a MapEntryElementAdapter");
	}

	/**
	 * Override this in subclass to change available attrs
	 */
	protected NamedNodeMap getNamedNodeMapAdapter()
	{
		if (this.namedNodeMapAdapter == null)
			this.namedNodeMapAdapter = new MapEntryNamedNodeMapAdapter();

		return this.namedNodeMapAdapter;
	}

	/**
	 * Override this in subclass to change available attrs
	 */
	public boolean hasAttribute(String name)
	{
		if (log.isDebugEnabled())
			log.debug("hasAttribute(" + name + ")");

		return (name.equals(ATTRNAME_TYPE) || name.equals(ATTRNAME_KEY));
	}

	/**
	 */
	public NamedNodeMap getAttributes()
	{
		log.debug("getAttributes()");

		return getNamedNodeMapAdapter();
	}

    public String getBaseURI() {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public short compareDocumentPosition(Node other) throws DOMException {
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public String getTextContent() throws DOMException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public void setTextContent(String textContent) throws DOMException {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public boolean isSameNode(Node other) {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public String lookupPrefix(String namespaceURI) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public boolean isDefaultNamespace(String namespaceURI) {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public String lookupNamespaceURI(String prefix) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public boolean isEqualNode(Node arg) {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public Object getFeature(String feature, String version) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public Object setUserData(String key, Object data, UserDataHandler handler) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public Object getUserData(String key) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
	 */
	public String getAttribute(String name)
	{
		if (log.isDebugEnabled())
			log.debug("getAttribute(" + name + ")");

		if (this.hasAttribute(name))
			return ((Attr)getNamedNodeMapAdapter().getNamedItem(name)).getValue();
		else
			return "";
	}

	/**
	 */
	public Attr getAttributeNode(String name)
	{
		if (log.isDebugEnabled())
			log.debug("getAttributeNode(" + name + ")");

		if (this.hasAttribute(name))
			return (Attr)getNamedNodeMapAdapter().getNamedItem(name);
		else
			return null;
	}

	/**
	 * Retrieves an attribute value by local name and namespace URI. HTML-only
	 * DOM implementations do not need to implement this method.
	 * @param namespaceURI The namespace URI of the attribute to retrieve.
	 * @param localName The local name of the attribute to retrieve.
	 * @return The <code>Attr</code> value as a string, or the empty string
	 *   if that attribute does not have a specified or default value.
	 * @since DOM Level 2
	 */
	public String getAttributeNS(String namespaceURI,
								 String localName)
	{
        log.info("UnsupportedOperationException Thrown");
		throw new UnsupportedOperationException();
	}

	/**
	 * Retrieves an <code>Attr</code> node by local name and namespace URI.
	 * HTML-only DOM implementations do not need to implement this method.
	 * @param namespaceURI The namespace URI of the attribute to retrieve.
	 * @param localName The local name of the attribute to retrieve.
	 * @return The <code>Attr</code> node with the specified attribute local
	 *   name and namespace URI or <code>null</code> if there is no such
	 *   attribute.
	 * @since DOM Level 2
	 */
	public Attr getAttributeNodeNS(String namespaceURI,
								   String localName)
	{
        log.info("UnsupportedOperationException Thrown");
		throw new UnsupportedOperationException();
	}

	/**
	 * Returns <code>true</code> when an attribute with a given local name and
	 * namespace URI is specified on this element or has a default value,
	 * <code>false</code> otherwise. HTML-only DOM implementations do not
	 * need to implement this method.
	 * @param namespaceURI The namespace URI of the attribute to look for.
	 * @param localName The local name of the attribute to look for.
	 * @return <code>true</code> if an attribute with the given local name
	 *   and namespace URI is specified or has a default value on this
	 *   element, <code>false</code> otherwise.
	 * @since DOM Level 2
	 */
	public boolean hasAttributeNS(String namespaceURI,
								  String localName)
	{
        log.info("UnsupportedOperationException Thrown");
		throw new UnsupportedOperationException();
	}

    public TypeInfo getSchemaTypeInfo() {
        log.info("UnsupportedOperationException Thrown");
		throw new UnsupportedOperationException();
    }

    public void setIdAttribute(String name, boolean isId) throws DOMException {
        log.info("UnsupportedOperationException Thrown");
		throw new UnsupportedOperationException();
    }

    public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException {
        log.info("UnsupportedOperationException Thrown");
		throw new UnsupportedOperationException();
    }

    public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
        log.info("UnsupportedOperationException Thrown");
		throw new UnsupportedOperationException();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -