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.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 NamedGraphSetMem.
  43. * You can supply a GraphSet name.
  44. *
  45. * @param string $graphSetId
  46. * @param string $uri
  47. * @access public
  48. */
  49. function & getDatasetMem($graphSetId = null)
  50. {
  51. include(RDFAPI_INCLUDE_DIR . PACKAGE_DATASET);
  52. return new DatasetMem($graphSetId);
  53. }
  54. /**
  55. * Returns a MemModel.
  56. * You can supply a base URI
  57. *
  58. * @param string $baseURI
  59. * @return object MemModel
  60. * @access public
  61. */
  62. function & getMemModel($baseURI = null)
  63. {
  64. return new MemModel($baseURI);
  65. }
  66. /**
  67. * Returns a DbModel with the database connection
  68. * defined in constants.php.
  69. * You can supply a base URI. If a model with the given base
  70. * URI exists in the DbStore, it'll be opened.
  71. * If not, a new model will be created.
  72. *
  73. * @param string $baseURI
  74. * @return object DbModel
  75. * @access public
  76. */
  77. function & getDefaultDbModel($baseURI = null)
  78. {
  79. $dbStore = ModelFactory::getDbStore();
  80. return ModelFactory::getDbModel($dbStore,$baseURI);
  81. }
  82. /**
  83. * Returns a new DbModel using the database connection
  84. * supplied by $dbStore.
  85. * You can supply a base URI. If a model with the given base
  86. * URI exists in the DbStore, it'll be opened.
  87. * If not, a new model will be created.
  88. *
  89. * @param object DbStore $dbStore
  90. * @param string $baseURI
  91. * @return object DbModel
  92. * @access public
  93. */
  94. function & getDbModel($dbStore, $baseURI = null)
  95. {
  96. if ($dbStore->modelExists($baseURI))
  97. return $dbStore->getModel($baseURI);
  98. return $dbStore->getNewModel($baseURI);
  99. }
  100. /**
  101. * Returns a database connection with the given parameters.
  102. * Paramters, which are not defined are taken from the constants.php
  103. *
  104. * @param string $dbDriver
  105. * @param string $host
  106. * @param string $dbName
  107. * @param string $user
  108. * @param string $password
  109. * @return object DbStore
  110. * @access public
  111. */
  112. function & getDbStore($dbDriver=ADODB_DB_DRIVER, $host=ADODB_DB_HOST, $dbName=ADODB_DB_NAME,
  113. $user=ADODB_DB_USER, $password=ADODB_DB_PASSWORD)
  114. {
  115. return new DbStore($dbDriver, $host, $dbName,$user, $password);
  116. }
  117. /**
  118. * Returns a InfModelF.
  119. * (MemModel with forward chaining inference engine)
  120. * Configurations can be done in constants.php
  121. * You can supply a base URI
  122. *
  123. * @param string $baseURI
  124. * @return object MemModel
  125. * @access public
  126. */
  127. function & getInfModelF($baseURI = null)
  128. {
  129. require_once( RDFAPI_INCLUDE_DIR . PACKAGE_INFMODEL);
  130. return new InfModelF($baseURI);
  131. }
  132. /**
  133. * Returns a InfModelB.
  134. * (MemModel with backward chaining inference engine)
  135. * Configurations can be done in constants.php
  136. * You can supply a base URI
  137. *
  138. * @param string $baseURI
  139. * @return object MemModel
  140. * @access public
  141. */
  142. function & getInfModelB($baseURI = null)
  143. {
  144. require_once( RDFAPI_INCLUDE_DIR . PACKAGE_INFMODEL);
  145. return new InfModelB($baseURI);
  146. }
  147. /**
  148. * Returns a ResModel.
  149. * $modelType has to be one of the following constants:
  150. * MEMMODEL,DBMODEL,INFMODELF,INFMODELB to create a resmodel with a new
  151. * model from defined type.
  152. * You can supply a base URI
  153. *
  154. * @param constant $modelType
  155. * @param string $baseURI
  156. * @return object MemModel
  157. * @access public
  158. */
  159. function & getResModel($modelType, $baseURI = null)
  160. {
  161. require_once( RDFAPI_INCLUDE_DIR . PACKAGE_RESMODEL);
  162. switch ($modelType) {
  163. case DBMODEL:
  164. $model = ModelFactory::getDbModel($baseURI);
  165. break;
  166. case INFMODELF:
  167. $model = ModelFactory::getInfModelF($baseURI);
  168. break;
  169. case INFMODELB:
  170. $model = ModelFactory::getInfModelB($baseURI);
  171. break;
  172. default:
  173. $model = ModelFactory::getMemModel($baseURI);
  174. break;
  175. }
  176. return new ResModel($model);
  177. }
  178. /**
  179. * Returns an OntModel.
  180. * $modelType has to be one of the following constants:
  181. * MEMMODEL, DBMODEL, INFMODELF, INFMODELB to create a OntModel
  182. * with a new model from defined type.
  183. * $vocabulary defines the ontology language. Currently only
  184. * RDFS_VOCABULARY is supported. You can supply a model base URI.
  185. *
  186. * @param constant $modelType
  187. * @param string $baseURI
  188. * @return object MemModel
  189. * @access public
  190. */
  191. function & getOntModel($modelType,$vocabulary, $baseURI = null)
  192. {
  193. require_once( RDFAPI_INCLUDE_DIR . PACKAGE_ONTMODEL);
  194. switch ($modelType)
  195. {
  196. case DBMODEL:
  197. $model = ModelFactory::getDBModel($baseURI);
  198. break;
  199. case INFMODELF:
  200. $model = ModelFactory::getInfModelF($baseURI);
  201. break;
  202. case INFMODELB:
  203. $model = ModelFactory::getInfModelB($baseURI);
  204. break;
  205. default:
  206. $model = ModelFactory::getMemModel($baseURI);;
  207. }
  208. switch ($vocabulary)
  209. {
  210. case RDFS_VOCABULARY:
  211. require_once(RDFAPI_INCLUDE_DIR.'ontModel/'.RDFS_VOCABULARY);
  212. $vocab = new RdfsVocabulary();
  213. break;
  214. default:
  215. $vocab = new RdfsVocabulary();
  216. break;
  217. }
  218. return new OntModel($model,$vocab);
  219. }
  220. }
  221. ?>

Documentation generated on Thu, 7 Jul 2005 13:42:06 +0200 by phpDocumentor 1.3.0RC3