Source for file ModelFactory.php

Documentation is available at ModelFactory.php

  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------------
  4. * Class: ModelFactory
  5. * ----------------------------------------------------------------------------------
  6. *
  7. * @package model
  8. */
  9.  
  10.  
  11. /**
  12. * ModelFactory is a static class which provides methods for creating different
  13. * types of RAP models. RAP models have to be created trough a ModelFactory
  14. * instead of creating them directly with the 'new' operator because of RAP's
  15. * dynamic code inclusion mechanism.
  16. *
  17. * <BR><BR>History:
  18. * <LI>10-05-2004 : First version of this class.</LI>
  19. *
  20. * @version V0.9.1
  21. * @author Daniel Westphal <mail at d-westphal dot de>
  22. *
  23. *
  24. * @package model
  25. * @access public
  26. ***/
  27. class ModelFactory
  28. {
  29. /**
  30. * Returns a MemModel.
  31. * You can supply a base URI
  32. *
  33. * @param string $baseURI
  34. * @return object MemModel
  35. * @access public
  36. */
  37. function & getDefaultModel($baseURI = null)
  38. {
  39. return ModelFactory::getMemModel($baseURI);
  40. }
  41. /**
  42. * Returns a MemModel.
  43. * You can supply a base URI
  44. *
  45. * @param string $baseURI
  46. * @return object MemModel
  47. * @access public
  48. */
  49. function & getMemModel($baseURI = null)
  50. {
  51. return new MemModel($baseURI);
  52. }
  53. /**
  54. * Returns a DbModel with the database connection
  55. * defined in constants.php.
  56. * You can supply a base URI. If a model with the given base
  57. * URI exists in the DbStore, it'll be opened.
  58. * If not, a new model will be created.
  59. *
  60. * @param string $baseURI
  61. * @return object DbModel
  62. * @access public
  63. */
  64. function & getDefaultDbModel($baseURI = null)
  65. {
  66. $dbStore = ModelFactory::getDbStore();
  67. return ModelFactory::getDbModel($dbStore,$baseURI);
  68. }
  69. /**
  70. * Returns a new DbModel using the database connection
  71. * supplied by $dbStore.
  72. * You can supply a base URI. If a model with the given base
  73. * URI exists in the DbStore, it'll be opened.
  74. * If not, a new model will be created.
  75. *
  76. * @param object DbStore $dbStore
  77. * @param string $baseURI
  78. * @return object DbModel
  79. * @access public
  80. */
  81. function & getDbModel($dbStore, $baseURI = null)
  82. {
  83. if ($dbStore->modelExists($baseURI))
  84. return $dbStore->getModel($baseURI);
  85. return $dbStore->getNewModel($baseURI);
  86. }
  87. /**
  88. * Returns a database connection with the given parameters.
  89. * Paramters, which are not defined are taken from the constants.php
  90. *
  91. * @param string $dbDriver
  92. * @param string $host
  93. * @param string $dbName
  94. * @param string $user
  95. * @param string $password
  96. * @return object DbStore
  97. * @access public
  98. */
  99. function & getDbStore($dbDriver=ADODB_DB_DRIVER, $host=ADODB_DB_HOST, $dbName=ADODB_DB_NAME,
  100. $user=ADODB_DB_USER, $password=ADODB_DB_PASSWORD)
  101. {
  102. return new DbStore($dbDriver, $host, $dbName,$user, $password);
  103. }
  104. /**
  105. * Returns a InfModelF.
  106. * (MemModel with forward chaining inference engine)
  107. * Configurations can be done in constants.php
  108. * You can supply a base URI
  109. *
  110. * @param string $baseURI
  111. * @return object MemModel
  112. * @access public
  113. */
  114. function & getInfModelF($baseURI = null)
  115. {
  116. require_once( RDFAPI_INCLUDE_DIR . PACKAGE_INFMODEL);
  117. return new InfModelF($baseURI);
  118. }
  119. /**
  120. * Returns a InfModelB.
  121. * (MemModel with backward chaining inference engine)
  122. * Configurations can be done in constants.php
  123. * You can supply a base URI
  124. *
  125. * @param string $baseURI
  126. * @return object MemModel
  127. * @access public
  128. */
  129. function & getInfModelB($baseURI = null)
  130. {
  131. require_once( RDFAPI_INCLUDE_DIR . PACKAGE_INFMODEL);
  132. return new InfModelB($baseURI);
  133. }
  134. /**
  135. * Returns a ResModel.
  136. * $modelType has to be one of the following constants:
  137. * MEMMODEL,DBMODEL,INFMODELF,INFMODELB to create a resmodel with a new
  138. * model from defined type.
  139. * You can supply a base URI
  140. *
  141. * @param constant $modelType
  142. * @param string $baseURI
  143. * @return object MemModel
  144. * @access public
  145. */
  146. function & getResModel($modelType, $baseURI = null)
  147. {
  148. require_once( RDFAPI_INCLUDE_DIR . PACKAGE_RESMODEL);
  149. switch ($modelType) {
  150. case DBMODEL:
  151. $model = ModelFactory::getDbModel($baseURI);
  152. break;
  153. case INFMODELF:
  154. $model = ModelFactory::getInfModelF($baseURI);
  155. break;
  156. case INFMODELB:
  157. $model = ModelFactory::getInfModelB($baseURI);
  158. break;
  159. default:
  160. $model = ModelFactory::getMemModel($baseURI);
  161. break;
  162. }
  163. return new ResModel($model);
  164. }
  165. /**
  166. * Returns an OntModel.
  167. * $modelType has to be one of the following constants:
  168. * MEMMODEL, DBMODEL, INFMODELF, INFMODELB to create a OntModel
  169. * with a new model from defined type.
  170. * $vocabulary defines the ontology language. Currently only
  171. * RDFS_VOCABULARY is supported. You can supply a model base URI.
  172. *
  173. * @param constant $modelType
  174. * @param string $baseURI
  175. * @return object MemModel
  176. * @access public
  177. */
  178. function & getOntModel($modelType,$vocabulary, $baseURI = null)
  179. {
  180. require_once( RDFAPI_INCLUDE_DIR . PACKAGE_ONTMODEL);
  181. switch ($modelType)
  182. {
  183. case DBMODEL:
  184. $model = ModelFactory::getDBModel($baseURI);
  185. break;
  186. case INFMODELF:
  187. $model = ModelFactory::getInfModelF($baseURI);
  188. break;
  189. case INFMODELB:
  190. $model = ModelFactory::getInfModelB($baseURI);
  191. break;
  192. default:
  193. $model = ModelFactory::getMemModel($baseURI);;
  194. }
  195. switch ($vocabulary)
  196. {
  197. case RDFS_VOCABULARY:
  198. require_once(RDFAPI_INCLUDE_DIR.'ontModel/'.RDFS_VOCABULARY);
  199. $vocab = new RdfsVocabulary();
  200. break;
  201. default:
  202. $vocab = new RdfsVocabulary();
  203. break;
  204. }
  205. return new OntModel($model,$vocab);
  206. }
  207. }
  208. ?>

Documentation generated on Fri, 17 Dec 2004 16:15:47 +0100 by phpDocumentor 1.3.0RC3