[runtime] Switch getenv to use heap memory
[mono.git] / mcs / class / System.Web / System.Web.UI / DataSourceSelectArguments.cs
1 //
2 // System.Web.UI.DataSourceSelectArguments.cs
3 //
4 // Author:
5 //   Sanjay Gupta <gsanjay@novell.com>
6 //
7 // (C) 2004-2010 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32
33 namespace System.Web.UI
34 {
35         public sealed class DataSourceSelectArguments
36         {
37                 string sortExpression;
38                 int startingRowIndex;
39                 int maxRows;
40                 bool getTotalRowCount;
41                 int totalRowCount = -1;
42                 DataSourceCapabilities dsc = DataSourceCapabilities.None;
43
44                 // MSDN: Gets a DataSourceSelectArguments object with the sort expression set to Empty. 
45                 public static DataSourceSelectArguments Empty {
46                         get {
47                                 return new DataSourceSelectArguments ();
48                         }
49                 }
50
51                 public DataSourceSelectArguments ()
52                 {
53                 }
54
55                 public DataSourceSelectArguments (string sortExpression)
56                 {
57                         this.sortExpression = sortExpression;
58                 }
59
60                 public DataSourceSelectArguments (int startingRowIndex, int maxRows)
61                 {
62                         this.startingRowIndex = startingRowIndex;
63                         this.maxRows = maxRows;
64                 }
65
66                 public DataSourceSelectArguments (string sortExpression, int startingRowIndex, int maxRows)
67                 {
68                         this.sortExpression = sortExpression; 
69                         this.startingRowIndex = startingRowIndex;
70                         this.maxRows = maxRows;
71                 }
72
73                 public void AddSupportedCapabilities (DataSourceCapabilities srcCapabilities)
74                 {
75                         this.dsc = this.dsc | srcCapabilities;
76                 }
77
78                 // MSDN: The DataSourceSelectArguments class overrides the Object.Equals method to test 
79                 // equality using the various properties of the objects. If the MaximumRows, 
80                 // RetrieveTotalRowCount, SortExpression, StartRowIndex, and TotalRowCount properties 
81                 // are all equal in value, the Equals(Object) method returns true.
82                 public override bool Equals (object obj)
83                 {
84                         DataSourceSelectArguments args = obj as DataSourceSelectArguments;
85                         if (args == null)
86                                 return false;
87
88                         return (this.SortExpression == args.SortExpression &&
89                                 this.StartRowIndex == args.StartRowIndex &&
90                                 this.MaximumRows == args.MaximumRows &&
91                                 this.RetrieveTotalRowCount == args.RetrieveTotalRowCount &&
92                                 this.TotalRowCount == args.TotalRowCount);
93                 }
94
95                 public override int GetHashCode ()
96                 {
97                         int hash = SortExpression != null ? SortExpression.GetHashCode() : 0;
98                         return hash ^ StartRowIndex ^ MaximumRows ^ RetrieveTotalRowCount.GetHashCode() ^ TotalRowCount;
99                 }
100
101                 // The RaiseUnsupportedCapabilitiesError method is used by data-bound controls 
102                 // to compare additional requested capabilities represented by the properties 
103                 // of the DataSourceSelectArguments class, such as the ability to sort or page 
104                 // through a result set, with the capabilities supported by the data source view. 
105                 // The view calls its own RaiseUnsupportedCapabilityError method for each possible 
106                 // capability defined in the DataSourceCapabilities enumeration. 
107                 public void RaiseUnsupportedCapabilitiesError (DataSourceView view)
108                 {
109                         DataSourceCapabilities requestedCaps = RequestedCapabilities;
110                         DataSourceCapabilities notSupportedCaps = (requestedCaps ^ dsc) & requestedCaps;
111                         if (notSupportedCaps == DataSourceCapabilities.None)
112                                 return;
113
114                         if ((notSupportedCaps & DataSourceCapabilities.RetrieveTotalRowCount) > 0)
115                                 notSupportedCaps = DataSourceCapabilities.RetrieveTotalRowCount;
116                         else if ((notSupportedCaps & DataSourceCapabilities.Page) > 0)
117                                 notSupportedCaps = DataSourceCapabilities.Page;
118
119                         view.RaiseUnsupportedCapabilityError (notSupportedCaps);
120                 }
121
122                 DataSourceCapabilities RequestedCapabilities {
123                         get {
124                                 DataSourceCapabilities caps = DataSourceCapabilities.None;
125                                 if (!String.IsNullOrEmpty (SortExpression))
126                                         caps |= DataSourceCapabilities.Sort;
127                                 if (RetrieveTotalRowCount)
128                                         caps |= DataSourceCapabilities.RetrieveTotalRowCount;
129                                 if (StartRowIndex > 0 || MaximumRows > 0)
130                                         caps |= DataSourceCapabilities.Page;
131                                 return caps;
132                         }
133                 }
134
135                 public int MaximumRows {
136                         get { return this.maxRows; }
137                         set { this.maxRows = value; }
138                 }
139
140                 public bool RetrieveTotalRowCount  {
141                         get { return this.getTotalRowCount; }
142                         set { this.getTotalRowCount = value; }
143                 }
144
145                 public string SortExpression {
146                         get {
147                                 if (sortExpression == null)
148                                         return String.Empty;
149                                 return this.sortExpression;
150                         }
151                         set { this.sortExpression = value; }
152                 }
153
154                 public int StartRowIndex {
155                         get { return this.startingRowIndex; }
156                         set { this.startingRowIndex = value; }
157                 }
158
159                 public int TotalRowCount {
160                         get { return this.totalRowCount; }
161                         set { this.totalRowCount = value; }
162                 }
163         }
164 }