More patches from Eran Domb <erand@mainsoft.com>.
[mono.git] / mcs / class / System.Data / System.Data / Constraint.cs
1 //
2 // System.Data.Constraint.cs
3 //
4 // Author:
5 //      Franklin Wise <gracenote@earthlink.net>
6 //      Daniel Morgan
7 //      Tim Coleman (tim@timcoleman.com)
8 //   
9 //
10 // (C) Ximian, Inc. 2002
11 // Copyright (C) Tim Coleman, 2002
12 //
13
14 using System;
15 using System.Collections;
16 using System.ComponentModel;
17 using System.Runtime.InteropServices;
18 using System.Runtime.Serialization;
19
20 namespace System.Data {
21         [Serializable]
22         internal delegate void DelegateConstraintNameChange (object sender, string newName);
23
24         [DefaultProperty ("ConstraintName")]    
25         [Serializable]
26         public abstract class Constraint 
27         {
28                 internal event DelegateConstraintNameChange BeforeConstraintNameChange;
29
30                 //if constraintName is not set then a name is 
31                 //created when it is added to
32                 //the ConstraintCollection
33                 //it can not be set to null, empty or duplicate
34                 //once it has been added to the collection
35                 private string _constraintName = null;
36                 private PropertyCollection _properties = null;
37
38                 //Used for membership checking
39                 private ConstraintCollection _constraintCollection;
40
41                 DataSet dataSet;
42
43                 protected Constraint () 
44                 {
45                         dataSet = null;
46                         _properties = new PropertyCollection();
47                 }
48
49                 protected internal virtual DataSet _DataSet {
50                         get { return dataSet; }
51                 }
52
53                 [DataCategory ("Data")]
54                 [DataSysDescription ("Indicates the name of this constraint.")]
55                 [DefaultValue ("")]
56                 public virtual string ConstraintName {
57                         get{ return "" + _constraintName; } 
58                         set{
59                                 //This should only throw an exception when it
60                                 //is a member of a ConstraintCollection which
61                                 //means we should let the ConstraintCollection
62                                 //handle exceptions when this value changes
63                                 _onConstraintNameChange(value);
64                                 _constraintName = value;
65                         }
66                 }
67
68                 [Browsable (false)]
69                 [DataCategory ("Data")]
70                 [DataSysDescription ("The collection that holds custom user information.")]
71                 public PropertyCollection ExtendedProperties {
72                         get { return _properties; }
73                 }
74
75                 [DataSysDescription ("Indicates the table of this constraint.")]
76                 public abstract DataTable Table {
77                         get;
78                 }
79
80                 internal ConstraintCollection ConstraintCollection {
81                         get{ return _constraintCollection; }
82                         set{ _constraintCollection = value; }
83                 }
84                 
85                 private void _onConstraintNameChange (string newName)
86                 {
87                         if (null != BeforeConstraintNameChange)
88                         {
89                                 BeforeConstraintNameChange (this, newName);
90                         }
91                 }
92
93                 //call once before adding a constraint to a collection
94                 //will throw an exception to prevent the add if a rule is broken
95                 internal virtual void AddToConstraintCollectionSetup (ConstraintCollection collection)
96                 {
97                 }
98                                         
99                 internal virtual void AssertConstraint ()
100                 {
101                 }
102                 
103                 internal virtual void AssertConstraint (DataRow row)
104                 {
105                 }
106
107                 //call once before removing a constraint to a collection
108                 //can throw an exception to prevent the removal
109                 internal virtual void RemoveFromConstraintCollectionCleanup (ConstraintCollection collection)
110                 {
111                 }
112
113                 [MonoTODO]
114                 protected void CheckStateForProperty ()
115                 {
116                         throw new NotImplementedException ();
117                 }
118
119                 protected internal void SetDataSet (DataSet dataSet)
120                 {
121                         this.dataSet = dataSet;
122                 }
123
124                 /// <summary>
125                 /// Gets the ConstraintName, if there is one, as a string. 
126                 /// </summary>
127                 public override string ToString () 
128                 {
129                         return "" + _constraintName;
130                 }
131
132         }
133 }