#region Disclaimer / License
// Copyright (C) 2013, Jackie Ng
// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com
//
// Original code from SharpDevelop 3.2.1 licensed under the same terms (LGPL 2.1)
// Copyright 2002-2010 by
//
// AlphaSierraPapa, Christoph Wille
// Vordernberger Strasse 27/8
// A-8700 Leoben
// Austria
//
// email: office@alphasierrapapa.com
// court of jurisdiction: Landesgericht Leoben
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion Disclaimer / License
using System;
using System.Xml;
namespace Maestro.Editors.Generic.XmlEditor.AutoCompletion
{
///
/// An with the namespace prefix.
///
///
/// The namespace prefix active for a namespace is
/// needed when an element is inserted via autocompletion. This
/// class just adds this extra information alongside the
/// .
///
internal class QualifiedName
{
private XmlQualifiedName xmlQualifiedName = XmlQualifiedName.Empty;
private string prefix = String.Empty;
public QualifiedName()
{
}
public QualifiedName(string name, string namespaceUri)
: this(name, namespaceUri, String.Empty)
{
}
public QualifiedName(string name, string namespaceUri, string prefix)
{
xmlQualifiedName = new XmlQualifiedName(name, namespaceUri);
this.prefix = prefix;
}
public static bool operator ==(QualifiedName lhs, QualifiedName rhs)
{
bool equals = false;
if (((object)lhs != null) && ((object)rhs != null))
{
equals = lhs.Equals(rhs);
}
else if (((object)lhs == null) && ((object)rhs == null))
{
equals = true;
}
return equals;
}
public static bool operator !=(QualifiedName lhs, QualifiedName rhs)
{
return !(lhs == rhs);
}
///
/// A qualified name is considered equal if the namespace and
/// name are the same. The prefix is ignored.
///
public override bool Equals(object obj)
{
bool equals = false;
QualifiedName qualifiedName = obj as QualifiedName;
if (qualifiedName != null)
{
equals = xmlQualifiedName.Equals(qualifiedName.xmlQualifiedName);
}
else
{
XmlQualifiedName name = obj as XmlQualifiedName;
if (name != null)
{
equals = xmlQualifiedName.Equals(name);
}
}
return equals;
}
///
/// Returns the hash code for the QualifiedName
///
///
public override int GetHashCode()
{
return xmlQualifiedName.GetHashCode();
}
///
/// Gets the namespace of the qualified name.
///
public string Namespace
{
get { return xmlQualifiedName.Namespace; }
set { xmlQualifiedName = new XmlQualifiedName(xmlQualifiedName.Name, value); }
}
///
/// Gets the name of the element.
///
public string Name
{
get { return xmlQualifiedName.Name; }
set { xmlQualifiedName = new XmlQualifiedName(value, xmlQualifiedName.Namespace); }
}
///
/// Gets the namespace prefix used.
///
public string Prefix
{
get { return prefix; }
set { prefix = value; }
}
///
/// Returns a string that represents the QualifiedName.
///
public override string ToString()
{
if (xmlQualifiedName.Namespace.Length > 0)
{
string prefixToString = String.Empty;
if (!String.IsNullOrEmpty(prefix))
{
prefixToString = prefix + ":";
}
return String.Concat(prefixToString, xmlQualifiedName.Name, " [", xmlQualifiedName.Namespace, "]");
}
else if (!String.IsNullOrEmpty(prefix))
{
return prefix + ":" + xmlQualifiedName.Name;
}
return xmlQualifiedName.Name;
}
}
}