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