source: Dev/branches/rest-dojo-ui/server/rdfapi/model/ModelFactory.php @ 289

Last change on this file since 289 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 7.4 KB
Line 
1<?php
2require_once RDFAPI_INCLUDE_DIR . 'model/DbStore.php';
3
4// ----------------------------------------------------------------------------------
5// Class: ModelFactory
6// ----------------------------------------------------------------------------------
7
8
9/**
10* ModelFactory is a static class which provides methods for creating different
11* types of RAP models. RAP models have to be created trough a ModelFactory
12* instead of creating them directly with the 'new' operator because of RAP's
13* dynamic code inclusion mechanism.
14*
15* @version  $Id: ModelFactory.php 524 2007-08-14 11:12:45Z kobasoft $
16* @author Daniel Westphal <mail at d-westphal.de>
17* @author Richard Cyganiak <richard@cyganiak.de>
18*
19*
20* @package      model
21* @access       public
22**/
23class ModelFactory
24{
25        /**
26        * Returns a MemModel.
27        * You can supply a base URI
28        *
29        * @param   string  $baseURI
30        * @return       object  MemModel
31        * @access       public
32        */
33        function & getDefaultModel($baseURI = null)
34        {
35                return ModelFactory::getMemModel($baseURI);
36        }
37
38        /**
39        * Returns a NamedGraphSetMem.
40    * You can supply a GraphSet name.
41    *
42    * @param string $graphSetId
43    * @param string $uri
44        * @access       public
45    */
46        function & getDatasetMem($graphSetId = null)
47        {
48        require_once RDFAPI_INCLUDE_DIR . 'dataset/DatasetMem.php';
49                $m = new DatasetMem($graphSetId);
50                return $m;
51        }
52
53        /**
54        * Returns a MemModel.
55        * You can supply a base URI
56        *
57        * @param   string  $baseURI
58        * @return       object  MemModel
59        * @access       public
60        */
61        function & getMemModel($baseURI = null)
62        {
63        require_once RDFAPI_INCLUDE_DIR . 'model/MemModel.php';
64                $m = new MemModel($baseURI);
65                return $m;
66        }
67
68        /**
69        * Returns a DbModel with the database connection
70        * defined in constants.php.
71        * You can supply a base URI. If a model with the given base
72        * URI exists in the DbStore, it'll be opened.
73        * If not, a new model will be created.
74        *
75        * @param   string  $baseURI
76        * @return       object  DbModel
77        * @access       public
78        */
79        function & getDefaultDbModel($baseURI = null)
80        {
81                $dbStore = ModelFactory::getDbStore();
82                $m = ModelFactory::getDbModel($dbStore,$baseURI);
83                return $m;
84        }
85
86        /**
87        * Returns a new DbModel using the database connection
88        * supplied by $dbStore.
89        * You can supply a base URI. If a model with the given base
90        * URI exists in the DbStore, it'll be opened.
91        * If not, a new model will be created.
92        *
93        * @param   object       DbStore  $dbStore
94        * @param   string  $baseURI
95        * @return       object  DbModel
96        * @access       public
97        */
98        function & getDbModel($dbStore, $baseURI = null)
99        {
100                if ($dbStore->modelExists($baseURI)) {
101                        return $dbStore->getModel($baseURI);
102        }
103
104                return $dbStore->getNewModel($baseURI);
105        }
106
107        /**
108        * Returns a database connection with the given parameters.
109        * Paramters, which are not defined are taken from the constants.php
110        *
111        * @param   string   $dbDriver
112        * @param   string   $host
113        * @param   string   $dbName
114        * @param   string   $user
115        * @param   string   $password
116        * @return       object  DbStore
117        * @access       public
118        */
119        function & getDbStore($dbDriver=ADODB_DB_DRIVER, $host=ADODB_DB_HOST, $dbName=ADODB_DB_NAME,
120                                $user=ADODB_DB_USER, $password=ADODB_DB_PASSWORD)
121        {
122                $dbs = new DbStore($dbDriver, $host, $dbName,$user, $password);
123                return $dbs;
124        }
125
126        /**
127        * Returns a InfModelF.
128        * (MemModel with forward chaining inference engine)
129        * Configurations can be done in constants.php
130        * You can supply a base URI
131        *
132        * @param   string  $baseURI
133        * @return       object  MemModel
134        * @access       public
135        */
136        function & getInfModelF($baseURI = null)
137        {
138        require_once RDFAPI_INCLUDE_DIR . 'infModel/InfModelF.php';
139                $mod = new InfModelF($baseURI);
140                return $mod;
141        }
142
143        /**
144        * Returns a InfModelB.
145        * (MemModel with backward chaining inference engine)
146        * Configurations can be done in constants.php
147        * You can supply a base URI
148        *
149        * @param   string  $baseURI
150        * @return       object  MemModel
151        * @access       public
152        */
153        function & getInfModelB($baseURI = null)
154        {
155        require_once RDFAPI_INCLUDE_DIR . 'infModel/InfModelB.php';
156                $mod = new InfModelB($baseURI);
157                return $mod;
158        }
159
160        /**
161        * Returns a ResModel.
162        * $modelType has to be one of the following constants:
163        * MEMMODEL,DBMODEL,INFMODELF,INFMODELB to create a resmodel with a new
164        * model from defined type.
165        * You can supply a base URI
166        *
167        * @param   constant  $modelType
168        * @param   string  $baseURI
169        * @return       object  ResModel
170        * @access       public
171        */
172        function & getResModel($modelType, $baseURI = null)
173        {
174                switch ($modelType) {
175                        case DBMODEL:
176                                $baseModel = ModelFactory::getDefaultDbModel($baseURI);
177                                break;
178
179                        case INFMODELF:
180                                $baseModel = ModelFactory::getInfModelF($baseURI);
181                                break;
182
183                        case INFMODELB:
184                                $baseModel = ModelFactory::getInfModelB($baseURI);
185                                break;
186
187                        default:
188                                $baseModel = ModelFactory::getMemModel($baseURI);
189                                break;
190                }
191                return ModelFactory::getResModelForBaseModel($baseModel);
192        }
193
194        /**
195        * Creates a ResModel that wraps an existing base model.
196        *
197        * @param        object  Model   $baseModel
198        * @return       object  ResModel
199        * @access       public
200        */
201    function &getResModelForBaseModel(&$baseModel) {
202        require_once RDFAPI_INCLUDE_DIR . 'resModel/ResModel.php';
203        $mod = new ResModel($baseModel);
204        return $mod;
205    }
206
207        /**
208        * Returns an OntModel.
209        * $modelType has to be one of the following constants:
210        * MEMMODEL, DBMODEL, INFMODELF, INFMODELB to create a OntModel
211        * with a new model from defined type.
212        * $vocabulary defines the ontology language. Currently only
213        * RDFS_VOCABULARY is supported. You can supply a model base URI.
214        *
215        * @param        constant        $modelType
216        * @param        constant        $vocabulary
217        * @param        string          $baseURI
218        * @return       object          OntModel
219        * @access       public
220        */
221        function & getOntModel($modelType,$vocabulary, $baseURI = null)
222        {
223                switch ($modelType)
224                {
225                        case DBMODEL:
226                                $baseModel = ModelFactory::getDefaultDbModel($baseURI);
227                                break;
228
229                        case INFMODELF:
230                                $baseModel = ModelFactory::getInfModelF($baseURI);
231                                break;
232
233                        case INFMODELB:
234                                $baseModel = ModelFactory::getInfModelB($baseURI);
235                                break;
236
237                        default:
238                                $baseModel = ModelFactory::getMemModel($baseURI);;
239                }
240
241        $mod = ModelFactory::getOntModelForBaseModel($baseModel, $vocabulary);
242        return $mod;
243        }
244
245        /**
246        * Creates an OntModel that wraps an existing base model.
247        * $vocabulary defines the ontology language. Currently only
248        * RDFS_VOCABULARY is supported.
249        *
250        * @param        object  Model   $baseModel
251        * @param        constant        $vocabulary
252        * @return       object          OntModel
253        * @access       public
254        */
255        function &getOntModelForBaseModel(&$baseModel, $vocabulary)
256        {
257        require_once RDFAPI_INCLUDE_DIR . 'ontModel/OntModel.php';
258
259                switch ($vocabulary)
260                {
261                        case RDFS_VOCABULARY:
262                                require_once(RDFAPI_INCLUDE_DIR.'ontModel/'.RDFS_VOCABULARY);
263                                $vocab_object = new RdfsVocabulary();
264                                break;
265                        default:
266                trigger_error("Unknown vocabulary constant '$vocabulary'; only RDFS_VOCABULARY is supported", E_USER_WARNING);
267                $vocab_object = null;
268                                break;
269                }
270                $mod = new OntModel($baseModel, $vocab_object);
271                return $mod;
272        }
273
274
275
276        /**
277        * Creates a SparqlClient.
278        *
279        * @param        String  $server Link to a SPARQL endpoint.
280        * @return       SparqlClient the SparqlClient object.
281        * @access       public
282        */
283        function & getSparqlClient($server){
284                $cl = new SparqlClient($server);
285                return $cl;
286        }
287}
288?>
Note: See TracBrowser for help on using the repository browser.