3 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 // This facility was a contribution kindly
20 // donated by Gilles Bayon <gilles.bayon@gmail.com>
26 namespace Castle
.Facilities
.IBatisNetIntegration
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();
54 XmlDocument sqlMapConfig
= Resources
.GetEmbeddedResourceAsXmlDocument(fileName
);
55 sqlMapper
= domSqlMapBuilder
.Configure(sqlMapConfig
);
59 sqlMapper
= domSqlMapBuilder
.Configure(fileName
);
62 if (connectionString
!= null && connectionString
.Length
> 0)
64 sqlMapper
.DataSource
.ConnectionString
= connectionString
;
68 if (sqlMapper
!= null)
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
) {}