Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Facilities / IBatisNet / Castle.Facilities.IBatisNetIntegration / SqlMapActivator.cs
blob836df5a4c8f05b02d1a31bfc0135aa7b99d4cef6
1 #region License
3 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 // --
18 //
19 // This facility was a contribution kindly
20 // donated by Gilles Bayon <gilles.bayon@gmail.com>
21 //
22 // --
24 #endregion
26 namespace Castle.Facilities.IBatisNetIntegration
28 using System;
29 using System.Xml;
30 using Castle.Core;
31 using Castle.MicroKernel;
32 using Castle.MicroKernel.ComponentActivator;
33 using Castle.MicroKernel.Facilities;
34 using IBatisNet.Common.Utilities;
35 using IBatisNet.DataMapper;
36 using IBatisNet.DataMapper.Configuration;
38 public class SqlMapActivator : AbstractComponentActivator
40 public SqlMapActivator(ComponentModel model, IKernel kernel, ComponentInstanceDelegate onCreation, ComponentInstanceDelegate onDestruction)
41 : base(model, kernel, onCreation, onDestruction) {}
43 protected override object InternalCreate(CreationContext context)
45 String fileName = (String) Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_FILE];
46 bool isEmbedded = (bool) Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_EMBEDDED];
47 String connectionString = (String) Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_CONNECTION_STRING];
49 DomSqlMapBuilder domSqlMapBuilder = new DomSqlMapBuilder();
50 ISqlMapper sqlMapper;
52 if (isEmbedded)
54 XmlDocument sqlMapConfig = Resources.GetEmbeddedResourceAsXmlDocument(fileName);
55 sqlMapper = domSqlMapBuilder.Configure(sqlMapConfig);
57 else
59 sqlMapper = domSqlMapBuilder.Configure(fileName);
62 if (connectionString != null && connectionString.Length > 0)
64 sqlMapper.DataSource.ConnectionString = connectionString;
68 if (sqlMapper != null)
70 return sqlMapper;
72 else
74 throw new FacilityException(string.Format("The IBatisNetIntegration Facility was unable to successfully configure SqlMapper ID [{0}] with File [{1}] that was set to Embedded [{2}].", Model.Name, Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_FILE].ToString(), Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_EMBEDDED].ToString()));
78 protected override void InternalDestroy(object instance) {}