for TARGET_J2EE only:
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / AccessDataSource.cs
1 //
2 // System.Web.UI.WebControls.AccessDataSource.cs
3 //
4 // Authors:
5 //   Sanjay Gupta (gsanjay@novell.com)
6 //
7 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if NET_2_0
30
31 using System.IO;
32 using System.ComponentModel;
33 using System.Data.Common;
34 using System.Drawing;
35 using System.Security.Permissions;
36
37 namespace System.Web.UI.WebControls {
38
39         // CAS
40         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42         // attributes
43         [DesignerAttribute ("System.Web.UI.Design.WebControls.AccessDataSourceDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
44         [ToolboxBitmap ("")]
45         public class AccessDataSource : SqlDataSource {
46
47                 const string PROVIDER_NAME = "System.Data.OleDb";
48                 const string PROVIDER_STRING = "Microsoft.Jet.OLEDB.4.0";
49
50                 //string dataFile;
51                 string connectionString;
52
53                 public AccessDataSource () : base ()
54                 {
55                         base.ProviderName = PROVIDER_NAME;
56                 }
57
58                 public AccessDataSource (string dataFile, string selectCommand) : 
59                         base (String.Empty, selectCommand)
60                 {
61                         //this.dataFile = dataFile;
62                         this.ProviderName = PROVIDER_NAME;
63                 }
64
65                 protected override SqlDataSourceView CreateDataSourceView (string viewName)
66                 {
67                         AccessDataSourceView view = new AccessDataSourceView (this, viewName, this.Context);
68                         if (IsTrackingViewState)
69                                 ((IStateManager) view).TrackViewState ();                               
70                         return view;
71                 }
72
73                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
74                 [Browsable (false)]
75                 [MonoTODO("AccessDataSource does not support SQL Cache Dependencies")]
76                 public override string SqlCacheDependency {
77                         get { throw new NotSupportedException ("AccessDataSource does not supports SQL Cache Dependencies."); }
78                         set { throw new NotSupportedException ("AccessDataSource does not supports SQL Cache Dependencies."); }
79                 }
80
81                 [MonoTODO ("why override?  maybe it doesn't call DbProviderFactories.GetFactory?")]
82                 protected override DbProviderFactory GetDbProviderFactory ()
83                 {
84                         return DbProviderFactories.GetFactory (PROVIDER_NAME);
85                 }
86
87                 string GetPhysicalDataFilePath ()
88                 {
89                         if (DataFile == null || DataFile == "")
90                                 return "";
91
92                         // more here?  how do we handle |DataDirectory|?
93                         return HttpContext.Current.Request.MapPath (DataFile);
94                 }
95
96                 [BrowsableAttribute (false), 
97                 DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
98                 public override string ConnectionString {
99                         get {
100                                 if (connectionString == null) {
101                                         connectionString = String.Concat ("Provider=", PROVIDER_STRING, "; Data Source=", GetPhysicalDataFilePath ());
102                                 }
103
104                                 return connectionString;
105                         }
106                         set {
107                                 throw new InvalidOperationException 
108                                         ("The ConnectionString is automatically generated for AccessDataSource and hence cannot be set."); 
109                         }
110                 }
111
112                 [UrlPropertyAttribute]
113                 [DefaultValueAttribute ("")]
114                 [WebCategoryAttribute ("Data")]
115                 [WebSysDescriptionAttribute ("MS Office Access database file name")]
116                 [EditorAttribute ("System.Web.UI.Design.MdbDataFileEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
117                 public string DataFile {
118                         get { return ViewState.GetString ("DataFile", ""); }
119                         set {
120                                 ViewState ["DataFile"] = value;
121                                 connectionString = null;
122                         }
123                 }
124
125                 [BrowsableAttribute (false), 
126                 DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]                      
127                 public override string ProviderName {
128                         get { return base.ProviderName; }
129                         set { throw new InvalidOperationException
130                                 ("Setting ProviderName on an AccessDataSource is not allowed");
131                         }
132                 }               
133         }
134 }
135 #endif