/**
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.apache.axis.message;

// $Id: NameImpl.java,v 1.1.1.1 2004/08/20 18:43:48 tdiesler Exp $

import javax.xml.namespace.QName;
import javax.xml.soap.Name;

/**
 * An implementation of a Name
 * <p/>
 * At this time of writing, the spec does not say anything about null values.
 * We assume emty string for any null value.
 *
 * @author Thomas.Diesler (thomas.diesler@jboss.org)
 * @since 01-June-2004
 */
public class NameImpl implements Name
{

   private QName qname;
   private String prefix;

   public NameImpl(String local)
   {
      this(local, null, null);
   }

   public NameImpl(String local, String prefix)
   {
      this(local, prefix, null);
   }

   public NameImpl(String local, String prefix, String uri)
   {
      qname = new QName(uri, local);
      this.prefix = (prefix == null ? "" : prefix);
   }

   /**
    * Gets the local name part of the XML name that this Name object represents.
    *
    * @return a string giving the local name
    */
   public String getLocalName()
   {
      return qname.getLocalPart();
   }

   /**
    * Returns the prefix that was specified when this Name object was initialized.
    * This prefix is associated with the namespace for the XML name that this Name object represents.
    *
    * @return the prefix as a string
    */
   public String getPrefix()
   {
      return prefix;
   }

   /**
    * Gets the namespace-qualified name of the XML name that this Name object represents.
    *
    * @return the namespace-qualified name as a string
    */
   public String getQualifiedName()
   {
      return prefix + ":" + qname.getLocalPart();
   }

   /**
    * Returns the URI of the namespace for the XML name that this Name object represents.
    *
    * @return the URI as a string
    */
   public String getURI()
   {
      return qname.getNamespaceURI();
   }

   public int hashCode()
   {
      return qname.hashCode();
   }

   public boolean equals(Object obj)
   {
      if (!(obj instanceof Name)) return false;
      if (obj == this) return true;
      Name other = (Name)obj;
      boolean equals = getLocalName().equals(other.getLocalName());
      equals &= getURI().equals(other.getURI());
      equals &= getPrefix().equals(other.getPrefix());
      return equals;
   }

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