Discriminator.cs :  » Persistence-Frameworks » iBATIS.NET » IBatisNet » DataMapper » Configuration » ResultMapping » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » iBATIS.NET 
iBATIS.NET » IBatisNet » DataMapper » Configuration » ResultMapping » Discriminator.cs

#region Apache Notice
/*****************************************************************************
 * $Header: $
 * $Revision: 469233 $
 * $Date: 2006-10-30 20:09:11 +0100 (lun., 30 oct. 2006) $
 * 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 IBatisNet.DataMapper.MappedStatements.PropertyStrategy;
using IBatisNet.DataMapper.Scope;

#endregion

namespace IBatisNet.DataMapper.Configuration.ResultMapping{
  /// <summary>
  /// Summary description for Discriminator.
  /// </summary>
  [Serializable]
  [XmlRoot("discriminator", Namespace="http://ibatis.apache.org/mapping")]
  public class Discriminator
  {

    #region Fields
    [NonSerialized]
    private ResultProperty _mapping = null;
    /// <summary>
    /// (discriminatorValue (string), ResultMap)
    /// </summary>
    [NonSerialized]
    private HybridDictionary _resultMaps = null;
    /// <summary>
    /// The subMaps name who used this discriminator
    /// </summary>
    [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

    /// <summary>
    /// Specify the custom type handlers to used.
    /// </summary>
    /// <remarks>Will be an alias to a class wchic implement ITypeHandlerCallback</remarks>
    [XmlAttribute("typeHandler")]
    public string CallBackName
    {
      get { return _callBackName; }
      set { _callBackName = value; }
    }

    /// <summary>
    /// Give an entry in the 'DbType' enumeration
    /// </summary>
    /// <example >
    /// For Sql Server, give an entry of SqlDbType : Bit, Decimal, Money...
    /// <br/>
    /// For Oracle, give an OracleType Enumeration : Byte, Int16, Number...
    /// </example>
    [XmlAttribute("dbType")]
    public string DbType
    {
      get { return _dbType; }
      set { _dbType = value; }
    }

    /// <summary>
    /// Specify the CLR type of the result.
    /// </summary>
    /// <remarks>
    /// 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.
    /// </remarks>
    [XmlAttribute("type")]
    public string CLRType
    {
      get { return _clrType; }
      set { _clrType = value; }
    }

    /// <summary>
    /// Column Index
    /// </summary>
    [XmlAttribute("columnIndex")]
    public int ColumnIndex
    {
      get { return _columnIndex; }
      set { _columnIndex = value; }
    }

    /// <summary>
    /// Column Name
    /// </summary>
    [XmlAttribute("column")]
    public string ColumnName
    {
      get { return _columnName; }
      set { _columnName = value; }
    }

    /// <summary>
    /// Null value replacement.
    /// </summary>
    /// <example>"no_email@provided.com"</example>
    [XmlAttribute("nullValue")]
    public string NullValue
    {
      get { return _nullValue; }
      set { _nullValue = value; }
    }

    /// <summary>
    /// Th underlying ResultProperty
    /// </summary>
    [XmlIgnore]
    public ResultProperty ResultProperty
    {
      get { return _mapping; }
    }
    #endregion 

    #region Constructor

    /// <summary>
    /// Constructor
    /// </summary>
    public Discriminator()
    {
      _resultMaps = new HybridDictionary();
      _subMaps = new ArrayList();
    }
    #endregion 

    #region Methods

    /// <summary>
    /// Initilaize the underlying mapping
    /// </summary>
    /// <param name="configScope"></param>
    /// <param name="resultClass"></param>
    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 );
    }

    /// <summary>
    /// Initialize the Discriminator
    /// </summary>
    /// <param name="configScope"></param>
    public void Initialize(ConfigurationScope configScope)
    {
      // Set the ResultMaps
      int count = _subMaps.Count;
      for(int index=0; index<count; index++)
      {
        SubMap subMap = _subMaps[index] as SubMap;
        _resultMaps.Add(subMap.DiscriminatorValue, configScope.SqlMapper.GetResultMap( subMap.ResultMapName ) );
      }
    }

    /// <summary>
    /// Add a subMap that the discrimator must treat
    /// </summary>
    /// <param name="subMap">A subMap</param>
    public void Add(SubMap subMap)
    {
      _subMaps.Add(subMap);
    }

    /// <summary>
    /// Find the SubMap to use.
    /// </summary>
    /// <param name="discriminatorValue">the discriminator value</param>
    /// <returns>The find ResultMap</returns>
    public IResultMap GetSubMap(string discriminatorValue)
    {
      return _resultMaps[discriminatorValue] as ResultMap;
    }

    #endregion 


  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.