001 /*
002 * JBoss DNA (http://www.jboss.org/dna)
003 * See the COPYRIGHT.txt file distributed with this work for information
004 * regarding copyright ownership. Some portions may be licensed
005 * to Red Hat, Inc. under one or more contributor license agreements.
006 * See the AUTHORS.txt file in the distribution for a full listing of
007 * individual contributors.
008 *
009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
010 * is licensed to you under the terms of the GNU Lesser General Public License as
011 * published by the Free Software Foundation; either version 2.1 of
012 * the License, or (at your option) any later version.
013 *
014 * JBoss DNA is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017 * Lesser General Public License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this software; if not, write to the Free
021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023 */
024 package org.jboss.dna.graph.property.basic;
025
026 import net.jcip.annotations.Immutable;
027 import org.jboss.dna.graph.property.NamespaceRegistry;
028 import org.jboss.dna.graph.property.NamespaceRegistry.Namespace;
029
030 /**
031 * @author Randall Hauch
032 */
033 @Immutable
034 public class BasicNamespace implements NamespaceRegistry.Namespace {
035 private final String prefix;
036 private final String namespaceUri;
037
038 /**
039 * Create a namespace instance.
040 *
041 * @param prefix the namespace prefix; may not be null (this is not checked)
042 * @param namespaceUri the namespace URI; may not be null (this is not checked)
043 */
044 public BasicNamespace( String prefix,
045 String namespaceUri ) {
046 assert prefix != null;
047 assert namespaceUri != null;
048 this.prefix = prefix;
049 this.namespaceUri = namespaceUri;
050 }
051
052 /**
053 * {@inheritDoc}
054 *
055 * @see org.jboss.dna.graph.property.NamespaceRegistry.Namespace#getNamespaceUri()
056 */
057 public String getNamespaceUri() {
058 return namespaceUri;
059 }
060
061 /**
062 * {@inheritDoc}
063 *
064 * @see org.jboss.dna.graph.property.NamespaceRegistry.Namespace#getPrefix()
065 */
066 public String getPrefix() {
067 return prefix;
068 }
069
070 /**
071 * {@inheritDoc}
072 *
073 * @see java.lang.Object#hashCode()
074 */
075 @Override
076 public int hashCode() {
077 return namespaceUri.hashCode();
078 }
079
080 /**
081 * {@inheritDoc}
082 *
083 * @see java.lang.Comparable#compareTo(java.lang.Object)
084 */
085 public int compareTo( Namespace that ) {
086 if (that == null) return 1;
087 if (this == that) return 0;
088 return this.getNamespaceUri().compareTo(that.getNamespaceUri());
089 }
090
091 /**
092 * {@inheritDoc}
093 *
094 * @see java.lang.Object#equals(java.lang.Object)
095 */
096 @Override
097 public boolean equals( Object obj ) {
098 if (obj == this) return true;
099 if (obj instanceof Namespace) {
100 Namespace that = (Namespace)obj;
101 if (!this.namespaceUri.equals(that.getNamespaceUri())) return false;
102 // if (!this.prefix.equals(that.getPrefix())) return false;
103 return true;
104 }
105 return false;
106 }
107
108 /**
109 * {@inheritDoc}
110 *
111 * @see java.lang.Object#toString()
112 */
113 @Override
114 public String toString() {
115 return prefix + "=" + namespaceUri;
116 }
117 }