diff options
author | cbateman | 2007-02-28 21:26:05 +0000 |
---|---|---|
committer | cbateman | 2007-02-28 21:26:05 +0000 |
commit | 992d40f1e81cc3088f98f5e5a72a13ebcdf21ba7 (patch) | |
tree | 4e5be4db5ec8fa78e2f08f0785d9aadcb709f769 /jsf | |
parent | af6383617c66b602bcb11dd21435ef04d93cbb33 (diff) | |
download | webtools.jsf-992d40f1e81cc3088f98f5e5a72a13ebcdf21ba7.tar.gz webtools.jsf-992d40f1e81cc3088f98f5e5a72a13ebcdf21ba7.tar.xz webtools.jsf-992d40f1e81cc3088f98f5e5a72a13ebcdf21ba7.zip |
Move TagIdentifier to common.
Diffstat (limited to 'jsf')
-rw-r--r-- | jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/provisional/dom/TagIdentifier.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/provisional/dom/TagIdentifier.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/provisional/dom/TagIdentifier.java new file mode 100644 index 000000000..6e7ff43c6 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/provisional/dom/TagIdentifier.java @@ -0,0 +1,104 @@ +package org.eclipse.jst.jsf.common.internal.provisional.dom; + +import javax.xml.namespace.QName; + + +/** + * Creates an abstraction for a tag. A tag is defined as a DOM Element whose + * namespace uri may be defined outside of the DOM, such as in a JSP tag library + * declaration. This allows tags to be abstracted from actual DOM elements, which + * is useful in situations like palette creation drops where the construction information + * is known, but we are not ready to create and add a node to the document yet. + * + * All tag TagIdentifier<i>s</i> should be considered immutable and idempotent. + * TagIdentifier instances may be cached by the factory. + * + * @author cbateman + * + */ +public abstract class TagIdentifier +{ + /** + * @return the uri that uniquely identifies the tag. + * + * i.e. + * + * If the tag is defined by an XML namespace, then that uri string will be returned. + * If the tag is defined by a JSP tag library, then the tag library uri should + * be returned. + */ + public abstract String getUri(); + + /** + * @return the local name of the tag (without namespace prefix) + */ + public abstract String getTagName(); + + /** + * @return true if this tag is a JSP tag + */ + public abstract boolean isJSPTag(); + + public final boolean equals(Object compareTo) + { + if (compareTo instanceof TagIdentifier) + { + return isSameTagType((TagIdentifier) compareTo); + } + return false; + } + + public final int hashCode() + { + int hashCode = getTagName().hashCode(); + + String uri = getUri(); + if (uri != null) + { + hashCode ^= uri.hashCode(); + } + return hashCode; + } + + public final boolean isSameTagType(TagIdentifier tagWrapper) + { + if (tagWrapper == this) + { + return true; + } + + final String uri = tagWrapper.getUri(); + + if (uri == null && getUri() != null) + { + return false; + } + else if (uri.equals(getUri())) + { + final String tagName = tagWrapper.getTagName(); + + if (tagName == null && getTagName() != null) + { + return false; + } + + // uri and tag name must both the same for it to be the same type + // TODO: the ignore case thing is dependent on the type of container document + if (tagName.equalsIgnoreCase((getTagName()))) + { + return true; + } + } + + // fall-through, not same + return false; + } + + /** + * @return the QName equivalent. Returns a new object on every invocation. + */ + public final QName asQName() + { + return new QName(getUri(), getTagName()); + } +} |