#region Apache Notice
/*****************************************************************************
* $Header: $
* $Revision: 469233 $
* $Date$
* Author : Gilles Bayon
* iBATIS.NET Data Mapper
* Copyright (C) 2004 - Apache Fondation
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
********************************************************************************/
#endregion
#region Using
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml.Serialization;
using Apache.Ibatis.DataMapper.MappedStatements.PropertyStrategy;
using Apache.Ibatis.DataMapper.Scope;
#endregion
namespace Apache.Ibatis.DataMapper.Configuration.ResultMapping
{
///
/// Summary description for Discriminator.
///
[Serializable]
[XmlRoot("discriminator", Namespace="http://ibatis.apache.org/mapping")]
public class Discriminator
{
#region Fields
[NonSerialized]
private ResultProperty _mapping = null;
///
/// (discriminatorValue (string), ResultMap)
///
[NonSerialized]
private HybridDictionary _resultMaps = null;
///
/// The subMaps name who used this discriminator
///
[NonSerialized]
private ArrayList _subMaps = null;
[NonSerialized]
private string _nullValue = string.Empty;
[NonSerialized]
private string _columnName = string.Empty;
[NonSerialized]
private int _columnIndex = ResultProperty.UNKNOWN_COLUMN_INDEX;
[NonSerialized]
private string _dbType = string.Empty;
[NonSerialized]
private string _clrType = string.Empty;
[NonSerialized]
private string _callBackName= string.Empty;
#endregion
#region Properties
///
/// Specify the custom type handlers to used.
///
/// Will be an alias to a class wchic implement ITypeHandlerCallback
[XmlAttribute("typeHandler")]
public string CallBackName
{
get { return _callBackName; }
set { _callBackName = value; }
}
///
/// Give an entry in the 'DbType' enumeration
///
///
/// For Sql Server, give an entry of SqlDbType : Bit, Decimal, Money...
///
/// For Oracle, give an OracleType Enumeration : Byte, Int16, Number...
///
[XmlAttribute("dbType")]
public string DbType
{
get { return _dbType; }
set { _dbType = value; }
}
///
/// Specify the CLR type of the result.
///
///
/// The type attribute is used to explicitly specify the property type of the property to be set.
/// Normally this can be derived from a property through reflection, but certain mappings such as
/// HashTable cannot provide the type to the framework.
///
[XmlAttribute("type")]
public string CLRType
{
get { return _clrType; }
set { _clrType = value; }
}
///
/// Column Index
///
[XmlAttribute("columnIndex")]
public int ColumnIndex
{
get { return _columnIndex; }
set { _columnIndex = value; }
}
///
/// Column Name
///
[XmlAttribute("column")]
public string ColumnName
{
get { return _columnName; }
set { _columnName = value; }
}
///
/// Null value replacement.
///
/// "no_email@provided.com"
[XmlAttribute("nullValue")]
public string NullValue
{
get { return _nullValue; }
set { _nullValue = value; }
}
///
/// Th underlying ResultProperty
///
[XmlIgnore]
public ResultProperty ResultProperty
{
get { return _mapping; }
}
#endregion
#region Constructor
///
/// Constructor
///
public Discriminator()
{
_resultMaps = new HybridDictionary();
_subMaps = new ArrayList();
}
#endregion
#region Methods
///
/// Initilaize the underlying mapping
///
///
///
public void SetMapping(ConfigurationScope configScope, Type resultClass)
{
configScope.ErrorContext.MoreInfo = "Initialize discriminator mapping";
_mapping = new ResultProperty();
_mapping.ColumnName = _columnName;
_mapping.ColumnIndex = _columnIndex;
_mapping.CLRType = _clrType;
_mapping.CallBackName = _callBackName;
_mapping.DbType = _dbType;
_mapping.NullValue = _nullValue;
_mapping.Initialize( configScope, resultClass );
}
///
/// Initialize the Discriminator
///
///
public void Initialize(ConfigurationScope configScope)
{
// Set the ResultMaps
int count = _subMaps.Count;
for(int index=0; index
/// Add a subMap that the discrimator must treat
///
/// A subMap
public void Add(SubMap subMap)
{
_subMaps.Add(subMap);
}
///
/// Find the SubMap to use.
///
/// the discriminator value
/// The find ResultMap
public IResultMap GetSubMap(string discriminatorValue)
{
return _resultMaps[discriminatorValue] as ResultMap;
}
#endregion
}
}