Source for file HarmoniLoggingManager.class.php

Documentation is available at HarmoniLoggingManager.class.php

  1. <?php
  2.  
  3. /**
  4. * @since 3/1/06
  5. * @package harmoni.osid_v2.logging
  6. *
  7. * @copyright Copyright &copy; 2005, Middlebury College
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  9. *
  10. * @version $Id: HarmoniLoggingManager.class.php,v 1.3 2007/09/04 20:25:43 adamfranco Exp $
  11. */
  12.  
  13. require_once(OKI2."/osid/logging/LoggingManager.php");
  14. require_once(dirname(__FILE__)."/HarmoniWritableLog.class.php");
  15.  
  16. /**
  17. * <p>
  18. * LoggingManager handles creating, deleting, and getting logs for reading or
  19. * writing. All log Entries have a formatType, a priorityType, and a
  20. * timestamp.
  21. * </p>
  22. *
  23. * <p>
  24. * All implementations of OsidManager (manager) provide methods for accessing
  25. * and manipulating the various objects defined in the OSID package. A manager
  26. * defines an implementation of an OSID. All other OSID objects come either
  27. * directly or indirectly from the manager. New instances of the OSID objects
  28. * are created either directly or indirectly by the manager. Because the OSID
  29. * objects are defined using interfaces, create methods must be used instead
  30. * of the new operator to create instances of the OSID objects. Create methods
  31. * are used both to instantiate and persist OSID objects. Using the
  32. * OsidManager class to define an OSID's implementation allows the application
  33. * to change OSID implementations by changing the OsidManager package name
  34. * used to load an implementation. Applications developed using managers
  35. * permit OSID implementation substitution without changing the application
  36. * source code. As with all managers, use the OsidLoader to load an
  37. * implementation of this interface.
  38. * </p>
  39. *
  40. * <p></p>
  41. *
  42. * <p>
  43. * OSID Version: 2.0
  44. * </p>
  45. *
  46. * <p>
  47. * Licensed under the {@link org.osid.SidImplementationLicenseMIT MIT}
  48. * O.K.I&#46; OSID Definition License}.
  49. * </p>
  50. *
  51. * @package harmoni.osid_v2.logging
  52. */
  53. class HarmoniLoggingManager
  54. extends LoggingManager
  55. {
  56. /**
  57. * The database connection as returned by the DBHandler.
  58. * @var integer _dbIndex
  59. * @access private
  60. */
  61. var $_dbIndex;
  62. /**
  63. * Assign the configuration of this Manager. Valid configuration options are as
  64. * follows:
  65. * database_index integer
  66. * database_name string
  67. *
  68. * @param object Properties $configuration (original type: java.util.Properties)
  69. *
  70. * @throws object OsidException An exception with one of the following
  71. * messages defined in org.osid.OsidException: {@link }
  72. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  73. * {@link org.osid.OsidException#PERMISSION_DENIED}
  74. * PERMISSION_DENIED}, {@link }
  75. * org.osid.OsidException#CONFIGURATION_ERROR
  76. * CONFIGURATION_ERROR}, {@link }
  77. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  78. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  79. *
  80. * @access public
  81. */
  82. function assignConfiguration ( $configuration ) {
  83. $this->_configuration =$configuration;
  84. $dbIndex = $configuration->getProperty('database_index');
  85. // ** parameter validation
  86. ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
  87. // ** end of parameter validation
  88. $this->_dbIndex = $dbIndex;
  89. }
  90. /**
  91. * Return context of this OsidManager.
  92. *
  93. * @return object OsidContext
  94. *
  95. * @throws object OsidException
  96. *
  97. * @access public
  98. */
  99. function getOsidContext () {
  100. return $this->_osidContext;
  101. }
  102.  
  103. /**
  104. * Assign the context of this OsidManager.
  105. *
  106. * @param object OsidContext $context
  107. *
  108. * @throws object OsidException An exception with one of the following
  109. * messages defined in org.osid.OsidException: {@link }
  110. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  111. *
  112. * @access public
  113. */
  114. function assignOsidContext ( $context ) {
  115. $this->_osidContext =$context;
  116. }
  117. /**
  118. * Return the format types available with this implementation.
  119. *
  120. * @return object TypeIterator
  121. *
  122. * @throws object LoggingException An exception with one of the
  123. * following messages defined in org.osid.logging.LoggingException
  124. * may be thrown: {@link }
  125. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  126. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  127. * OPERATION_FAILED}, {@link }
  128. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  129. * CONFIGURATION_ERROR}, {@link }
  130. * org.osid.logging.LoggingException#PERMISSION_DENIED
  131. * PERMISSION_DENIED}
  132. *
  133. * @access public
  134. */
  135. function getFormatTypes () {
  136. // $dbc = Services::getService("DatabaseManager");
  137. //
  138. // $query = new SelectQuery;
  139. // $query->addColumn("domain", "domain", "log_type");
  140. // $query->addColumn("authority", "authority", "log_type");
  141. // $query->addColumn("keyword", "keyword", "log_type");
  142. // $query->addColumn("description", "description", "log_type");
  143. //
  144. // $query->addTable("log_entry");
  145. // $query->addTable("log_type", INNER_JOIN, "log_entry.fk_format_type = log_type.id");
  146. // $query->addGroupBy("log_type.id");
  147. //
  148. // $results =$dbc->query($query, $this->_dbIndex);
  149. // $types = array();
  150. // while ($results->hasNext()) {
  151. // $types[] = new Type( $results->field("domain"),
  152. // $results->field("authority"),
  153. // $results->field("keyword"),
  154. // $results->field("description"));
  155. // $results->advanceRow();
  156. // }
  157. // $results->free();
  158. $types = array();
  159. $types[] = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  160. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  161. $iterator = new HarmoniIterator($types);
  162. return $iterator;
  163. }
  164.  
  165. /**
  166. * Return the priority types available with this implementation.
  167. *
  168. * @return object TypeIterator
  169. *
  170. * @throws object LoggingException An exception with one of the
  171. * following messages defined in org.osid.logging.LoggingException
  172. * may be thrown: {@link }
  173. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  174. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  175. * OPERATION_FAILED}, {@link }
  176. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  177. * CONFIGURATION_ERROR}, {@link }
  178. * org.osid.logging.LoggingException#PERMISSION_DENIED
  179. * PERMISSION_DENIED}
  180. *
  181. * @access public
  182. */
  183. function getPriorityTypes () {
  184. $dbc = Services::getService("DatabaseManager");
  185. $query = new SelectQuery;
  186. $query->addColumn("domain", "domain", "log_type");
  187. $query->addColumn("authority", "authority", "log_type");
  188. $query->addColumn("keyword", "keyword", "log_type");
  189. $query->addColumn("description", "description", "log_type");
  190. $query->addTable("log_entry");
  191. $query->addTable("log_type", INNER_JOIN, "log_entry.fk_priority_type = log_type.id");
  192. $query->setGroupBy(array("log_type.id"));
  193. $query->addOrderBy("keyword");
  194. $results =$dbc->query($query, $this->_dbIndex);
  195. $types = array();
  196. while ($results->hasNext()) {
  197. $types[] = new Type( $results->field("domain"),
  198. $results->field("authority"),
  199. $results->field("keyword"),
  200. $results->field("description"));
  201. $results->advanceRow();
  202. }
  203. $results->free();
  204. $iterator = new HarmoniIterator($types);
  205. return $iterator;
  206. }
  207.  
  208. /**
  209. * Return the names of writable Logs.
  210. *
  211. * @return object StringIterator
  212. *
  213. * @throws object LoggingException An exception with one of the
  214. * following messages defined in org.osid.logging.LoggingException
  215. * may be thrown: {@link }
  216. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  217. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  218. * OPERATION_FAILED}, {@link }
  219. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  220. * CONFIGURATION_ERROR}, {@link }
  221. * org.osid.logging.LoggingException#PERMISSION_DENIED
  222. * PERMISSION_DENIED}
  223. *
  224. * @access public
  225. */
  226. function getLogNamesForWriting () {
  227. $dbc = Services::getService("DatabaseManager");
  228. $query = new SelectQuery;
  229. $query->addColumn("log_name");
  230. $query->addTable("log_entry");
  231. $query->setDistinct(true);
  232. $query->addOrderBy("log_name");
  233. $results =$dbc->query($query, $this->_dbIndex);
  234. $names = array();
  235. while ($results->hasNext()) {
  236. $names[] = $results->field("log_name");
  237. $results->advanceRow();
  238. }
  239. $results->free();
  240. $iterator = new HarmoniIterator($names);
  241. return $iterator;
  242. }
  243.  
  244. /**
  245. * Get an existing log for writing.
  246. *
  247. * @param string $logName
  248. *
  249. * @return object WritableLog
  250. *
  251. * @throws object LoggingException An exception with one of the
  252. * following messages defined in org.osid.logging.LoggingException
  253. * may be thrown: {@link }
  254. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  255. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  256. * OPERATION_FAILED}, {@link }
  257. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  258. * CONFIGURATION_ERROR}, {@link }
  259. * org.osid.logging.LoggingException#PERMISSION_DENIED
  260. * PERMISSION_DENIED}, {@link }
  261. * org.osid.logging.LoggingException#UNKNOWN_NAME UNKNOWN_NAME}
  262. *
  263. * @access public
  264. */
  265. function getLogForWriting ( $logName ) {
  266. if (!isset($this->_logs[$logName]))
  267. $this->_logs[$logName] = new HarmoniWritableLog($logName, $this->_dbIndex);
  268. return $this->_logs[$logName];
  269. }
  270.  
  271. /**
  272. * Return the names of readable Logs.
  273. *
  274. * @return object StringIterator
  275. *
  276. * @throws object LoggingException An exception with one of the
  277. * following messages defined in org.osid.logging.LoggingException
  278. * may be thrown: {@link }
  279. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  280. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  281. * OPERATION_FAILED}, {@link }
  282. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  283. * CONFIGURATION_ERROR}, {@link }
  284. * org.osid.logging.LoggingException#PERMISSION_DENIED
  285. * PERMISSION_DENIED}
  286. *
  287. * @access public
  288. */
  289. function getLogNamesForReading () {
  290. return $this->getLogNamesForWriting();
  291. }
  292.  
  293. /**
  294. * Get an existing log for reading.
  295. *
  296. * @param string $logName
  297. *
  298. * @return object ReadableLog
  299. *
  300. * @throws object LoggingException An exception with one of the
  301. * following messages defined in org.osid.logging.LoggingException
  302. * may be thrown: {@link }
  303. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  304. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  305. * OPERATION_FAILED}, {@link }
  306. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  307. * CONFIGURATION_ERROR}, {@link }
  308. * org.osid.logging.LoggingException#PERMISSION_DENIED
  309. * PERMISSION_DENIED}, {@link }
  310. * org.osid.logging.LoggingException#UNKNOWN_NAME UNKNOWN_NAME}
  311. *
  312. * @access public
  313. */
  314. function getLogForReading ( $logName ) {
  315. return $this->getLogForWriting($logName);
  316. }
  317.  
  318. /**
  319. * Create a Writable Log.
  320. *
  321. * @param string $logName
  322. *
  323. * @return object WritableLog
  324. *
  325. * @throws object LoggingException An exception with one of the
  326. * following messages defined in org.osid.logging.LoggingException
  327. * may be thrown: {@link }
  328. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  329. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  330. * OPERATION_FAILED}, {@link }
  331. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  332. * CONFIGURATION_ERROR}, {@link }
  333. * org.osid.logging.LoggingException#PERMISSION_DENIED
  334. * PERMISSION_DENIED}, {@link }
  335. * org.osid.logging.LoggingException#DUPLICATE_NAME
  336. * DUPLICATE_NAME}
  337. *
  338. * @access public
  339. */
  340. function createLog ( $logName ) {
  341. return $this->getLogForWriting($logName);
  342. }
  343.  
  344. /**
  345. * Delete the log with the specified name.
  346. *
  347. * @param string $logName
  348. *
  349. * @throws object LoggingException An exception with one of the
  350. * following messages defined in org.osid.logging.LoggingException
  351. * may be thrown: {@link }
  352. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  353. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  354. * OPERATION_FAILED}, {@link }
  355. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  356. * CONFIGURATION_ERROR}, {@link }
  357. * org.osid.logging.LoggingException#PERMISSION_DENIED
  358. * PERMISSION_DENIED}, {@link }
  359. * org.osid.logging.LoggingException#UNKNOWN_NAME UNKNOWN_NAME}
  360. *
  361. * @access public
  362. */
  363. function deleteLog ( $logName ) {
  364. $log =$this->getLogForWriting($logName);
  365. $log = null;
  366. $dbc = Services::getService("DatabaseManager");
  367. // get the entry Ids
  368. $query = new SelectQuery;
  369. $query->addColumn("id");
  370. $query->addTable("log_entry");
  371. $query->addWhere("log_name = '".addslashes($logName)."'");
  372. $result =$dbc->query($query, $this->_dbIndex);
  373. $entryIds = array();
  374. while ($result->hasMoreRows()) {
  375. $entryIds[] = "'".addslashes($result->field("id"))."'";
  376. $result->advanceRow();
  377. }
  378. $result->free();
  379. // delete the agent keys
  380. $query = new DeleteQuery;
  381. $query->setTable("log_agent");
  382. $query->addWhere("fk_entry IN (".implode(", ", $entryIds).")");
  383. $dbc->query($query, $this->_dbIndex);
  384. // delete the node keys
  385. $query->setTable("log_node");
  386. $dbc->query($query, $this->_dbIndex);
  387. // delete the entries
  388. $query = new DeleteQuery;
  389. $query->setTable("log_entry");
  390. $query->addWhere("log_name = '".addslashes($logName)."'");
  391. $dbc->query($query, $this->_dbIndex);
  392. }
  393.  
  394. /**
  395. * This method indicates whether this implementation supports the
  396. * ReadableLog interface and the LoggingManager methods: getLogForReading
  397. * and getLogNamesForReading.
  398. *
  399. * @return boolean
  400. *
  401. * @throws object LoggingException An exception with one of the
  402. * following messages defined in org.osid.logging.LoggingException
  403. * may be thrown: {@link }
  404. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  405. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  406. * OPERATION_FAILED}, {@link }
  407. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  408. * CONFIGURATION_ERROR}, {@link }
  409. * org.osid.logging.LoggingException#PERMISSION_DENIED
  410. * PERMISSION_DENIED}
  411. *
  412. * @access public
  413. */
  414. function supportsReading () {
  415. return true;
  416. }
  417. }
  418.  
  419. ?>

Documentation generated on Wed, 19 Sep 2007 10:24:05 -0400 by phpDocumentor 1.3.0RC3