summaryrefslogtreecommitdiff
path: root/framework/Data/SqlMap/DataMapper/TSqlMapException.php
blob: 694774d820cbf5e23c82ecb83c7138a182d0f65d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php

/**
 * TSqlMapException is the base exception class for all SqlMap exceptions.
 *
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
 * @version $Id$
 * @package System.Data.SqlMap
 * @since 3.1
 */
class TSqlMapException extends TException
{
	/**
	 * Constructor, similar to the parent constructor. For parameters that
	 * are of SimpleXmlElement, the tag name and its attribute names and values
	 * are expanded into a string.
	 */
	public function __construct($errorMessage)
	{
		$this->setErrorCode($errorMessage);
		$errorMessage=$this->translateErrorMessage($errorMessage);
		$args=func_get_args();
		array_shift($args);
		$n=count($args);
		$tokens=array();
		for($i=0;$i<$n;++$i)
		{
			if($args[$i] instanceof SimpleXmlElement)
				$tokens['{'.$i.'}']=$this->implodeNode($args[$i]);
			else
				$tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]);
		}
		parent::__construct(strtr($errorMessage,$tokens));
	}

	/**
	 * @param SimpleXmlElement node
	 * @return string tag name and attribute names and values.
	 */
	protected function implodeNode($node)
	{
		$attributes=array();
		foreach($node->attributes() as $k=>$v)
			$attributes[]=$k.'="'.(string)$v.'"';
		return '<'.$node->getName().' '.implode(' ',$attributes).'>';
	}

	/**
	 * @return string path to the error message file
	 */
	protected function getErrorMessageFile()
	{
		$lang=Prado::getPreferredLanguage();
		$dir=dirname(__FILE__);
		$msgFile=$dir.'/messages-'.$lang.'.txt';
		if(!is_file($msgFile))
			$msgFile=$dir.'/messages.txt';
		return $msgFile;
	}
}

/**
 * TSqlMapConfigurationException, raised during configuration file parsing.
 *
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
 * @version $Id$
 * @package System.Data.SqlMap
 * @since 3.1
 */
class TSqlMapConfigurationException extends TSqlMapException
{

}

/**
 * TSqlMapUndefinedException, raised when mapped statemented are undefined.
 *
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
 * @version $Id$
 * @package System.Data.SqlMap
 * @since 3.1
 */
class TSqlMapUndefinedException extends TSqlMapException
{

}

/**
 * TSqlMapDuplicateException, raised when a duplicate mapped statement is found.
 *
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
 * @version $Id$
 * @package System.Data.SqlMap
 * @since 3.1
 */
class TSqlMapDuplicateException extends TSqlMapException
{
}

/**
 * TInvalidPropertyException, raised when setting or getting an invalid property.
 *
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
 * @version $Id$
 * @package System.Data.SqlMap
 * @since 3.1
 */
class TInvalidPropertyException extends TSqlMapException
{
}

class TSqlMapExecutionException extends TSqlMapException
{
}