//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation, Scott Hanselman. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Xrds {
using System;
using System.Xml.XPath;
///
/// The Uri element in an XRDS document.
///
internal class UriElement : XrdsNode, IComparable {
///
/// Initializes a new instance of the class.
///
/// The URI element.
/// The service.
public UriElement(XPathNavigator uriElement, ServiceElement service) :
base(uriElement, service) {
}
///
/// Gets the priority.
///
public int? Priority {
get {
XPathNavigator n = Node.SelectSingleNode("@priority", XmlNamespaceResolver);
return n != null ? n.ValueAsInt : (int?)null;
}
}
///
/// Gets the URI.
///
public Uri Uri {
get {
if (Node.Value != null) {
string value = Node.Value.Trim();
if (value.Length > 0) {
return new Uri(value);
}
}
return null;
}
}
///
/// Gets the parent service.
///
public ServiceElement Service {
get { return (ServiceElement)ParentNode; }
}
#region IComparable Members
///
/// Compares the current object with another object of the same type.
///
/// An object to compare with this object.
///
/// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
/// Value
/// Meaning
/// Less than zero
/// This object is less than the parameter.
/// Zero
/// This object is equal to .
/// Greater than zero
/// This object is greater than .
///
public int CompareTo(UriElement other) {
if (other == null) {
return -1;
}
int compare = this.Service.CompareTo(other.Service);
if (compare != 0) {
return compare;
}
if (this.Priority.HasValue && other.Priority.HasValue) {
return this.Priority.Value.CompareTo(other.Priority.Value);
} else {
if (this.Priority.HasValue) {
return -1;
} else if (other.Priority.HasValue) {
return 1;
} else {
return 0;
}
}
}
#endregion
}
}