/[cvs]/nfo/php/libs/org.netfrag.glib/DataSource/Generic.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.glib/DataSource/Generic.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations)
Tue Apr 8 17:55:20 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.15: +28 -14 lines
CHANGE: renamed property 'datasource' to 'transport'
NEW: new case 'method' in 'function datasource_handler_buildoptions'
minor fixes: updated logging/debugging messages

1 joko 1.1 <?php
2     /**
3     * This file contains the GenericDataSource child class
4     *
5     * @author Andreas Motl <andreas.motl@ilo.de>
6 joko 1.2 * @package org.netfrag.glib
7     * @name DataSource::Generic
8 joko 1.1 *
9     */
10    
11     /**
12 joko 1.6 * <b>Cvs-Log:</b>
13     *
14     * <pre>
15 joko 1.16 * $Id: Generic.php,v 1.15 2003/04/06 04:46:33 joko Exp $
16 joko 1.2 *
17     * $Log: Generic.php,v $
18 joko 1.16 * Revision 1.15 2003/04/06 04:46:33 joko
19     * renamed linking function
20     * mozilla fixes
21     *
22 joko 1.15 * Revision 1.14 2003/04/04 21:19:21 joko
23     * modified exception handling (enhanced, purged redundant code)
24     *
25 joko 1.14 * Revision 1.13 2003/04/04 02:37:14 jonen
26     * _query[action] == write
27     *
28 jonen 1.13 * Revision 1.12 2003/03/29 08:00:48 joko
29     * modified ErrorBoxing
30     *
31 joko 1.12 * Revision 1.11 2003/03/28 06:45:26 joko
32     * VERBOSE mode
33     *
34 joko 1.11 * Revision 1.10 2003/03/28 03:01:02 joko
35     * more fancy debugging-output
36     *
37 joko 1.10 * Revision 1.9 2003/03/27 16:24:26 jonen
38     * + mugled namespace
39     * + added enhanced 'queryData'
40     *
41 jonen 1.9 * Revision 1.8 2003/03/20 07:22:14 jonen
42     * + modified case 'object' to 'objects'
43     * (cause its loads all *objects* of a given classname)
44     *
45 jonen 1.8 * Revision 1.7 2003/03/11 01:43:00 joko
46     * + fixed metadata for phpDocumentor
47     *
48 joko 1.7 * Revision 1.6 2003/03/11 01:22:25 joko
49     * + fixed metadata for phpDocumentor
50     *
51 joko 1.6 * Revision 1.5 2003/03/11 00:12:49 joko
52     * + fixed metadata for phpDocumentor
53     *
54 joko 1.5 * Revision 1.4 2003/03/10 23:25:03 joko
55     * + fixed metadata for phpDocumentor
56     *
57 joko 1.4 * Revision 1.3 2003/03/09 15:50:36 joko
58     * + additional metadata for Autodia
59     *
60 joko 1.3 * Revision 1.2 2003/03/05 17:28:43 joko
61     * updated docu (phpDocumentor testing....)
62     *
63 joko 1.2 * Revision 1.1 2003/03/05 12:04:00 joko
64     * + initial commit, from GenericDataSource
65 joko 1.1 *
66     * Revision 1.3 2003/03/03 21:24:18 joko
67     * now based on DesignPattern::RemoteProxy
68     *
69     * Revision 1.2 2003/03/02 01:05:13 joko
70     * - purged old code
71     *
72     * Revision 1.1 2003/03/01 21:47:15 joko
73     * renamed from AbstractDataSource.inc
74     *
75     * Revision 1.1 2003/03/01 20:17:15 joko
76     * renamed from GenericDataSource.inc
77     * replaced '_proxy' through '_handler' to better associate the ability to act as a generic dispatcher handler
78     *
79     * Revision 1.3 2003/03/01 15:36:11 joko
80     * + debugging
81     * + renamed some methods regarding new proposal (build_handler_options, fetch_result, etc.)
82     *
83     * Revision 1.2 2003/03/01 04:50:27 joko
84     * encapsulated all output into tracing mode
85     * disabled tracing
86     *
87     * Revision 1.1 2003/03/01 03:10:40 joko
88     * + initial commit
89 joko 1.6 * </pre>
90 joko 1.1 *
91     */
92    
93     /**
94     * This requires the MemoryDataSource base class
95     *
96     */
97    
98     // V1: compile-time-include, stable since years ;-)
99     //include_once($phphtmllib."/widgets/data_source/MemoryDataSource.inc");
100    
101     // V2: runtime-load proposal, more flexible
102     // loadModule('MemoryDataSource', 'inc'); // doesn't work (would do if basepath of module is in libpath)
103     // loadModule($phphtmllib . '::widgets::data_source::MemoryDataSource', 'inc'); // works (by accident)
104     // loadModule($phphtmllib . "/widgets/data_source/MemoryDataSource", "inc"); // works (should be stable)
105     // loadModule($phphtmllib . "/widgets/data_source/MemoryDataSource.inc", null); // works (should be stable)
106    
107    
108    
109     /**
110     * Have to have PEAR and DB included
111     * the pear dir must be in the
112     * include path.
113     */
114     // require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC?
115     // require_once("DB.php");
116    
117 joko 1.2
118     loadModule('DesignPattern::Proxy');
119     loadModule('DesignPattern::TransparentProxy');
120     loadModule('DesignPattern::RemoteProxy');
121    
122     //class GenericDataSource extends MemoryDataSource {
123     //class GenericDataSource extends DesignPattern_Proxy {
124     //class GenericDataSource extends DesignPattern_RemoteProxy {
125     //class GenericDataSource extends DesignPattern_TransparentProxy {
126    
127     //class GenericDataSource extends MemoryDataSource {
128     //loadModule("DataSource::Proxy::Memory");
129     //class GenericDataSource extends DataSource_Proxy_Memory {
130     //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
131     //class DataSource_GenericDataSource extends DesignPattern_Proxy {
132     //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
133    
134     // now independent!!! new class-inheritance-tree possible now!
135     // solved by having an Adapter *and* a Proxy here!
136     //class GenericDataSource {
137    
138     loadModule('DesignPattern::AdapterProxy');
139    
140    
141    
142 joko 1.1 /**
143     * This GenericDataSource child class is *completely* independent
144     * of a specific storage implementation and intended to be a wrapper
145 joko 1.2 * class on the way from phpHtmlLib to Xyz. <br>
146 joko 1.1 * ("Yyz" gets represented by Data::Storage by now.....)
147     *
148     * GenericDataSource interacts with an intermediate "proxy" object
149 joko 1.2 * (e.g. Data::Driver::Proxy) when doing queries. <br>
150     * <pre>
151 joko 1.1 * Don't mix this up with a persistent database handle which gets
152     * reused each and every time for different queries.
153     * Here *is* a new instance of Data::Driver::Proxy for *each* query.
154 joko 1.2 * </pre>
155 joko 1.1 *
156     * But the point is: Caching! The actual *data* isn't read redundant!
157     *
158 joko 1.2 * <pre>
159     * --- snipped into here from above ---
160     * that may use arbitrary code modules as database handlers.
161     * It's aims are to get together:
162     * o phpHtmlLibs "source-handlers"
163     * o PEAR's database handlers
164     * o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server)
165     * --- snipped into here from above ---
166     * </pre>
167     *
168 joko 1.7 * <p>
169 joko 1.1 * !!!!!! refactor this to Data::Driver::Proxy !!!!!! <-----------------
170     *
171     * Data::Driver::Proxy instantiates "handlers" below itself
172     * which act as encapsulated workers to actually do the stuff to do.
173     * It can cache data for "disconnected mode" using the
174     * php PEAR DB abstraction objects.
175     * One worker already implemented is Data::Driver::RPC::Remote, which
176     * talks to a RPC::XML server (todo: talk SOAP!) using PEAR::XML::RPC.
177     *
178 joko 1.2 * <pre>
179 joko 1.1 * --- refactored here, but: redundant somehow ---
180     * Data::Driver::Proxy uses a PEAR XML::RPC object to actually
181     * talk HTTP and serialize data chunks to and from XML,
182     * but adds some caching to this "process of fetching data from a remote side".
183     * It "proxies" arbitrary data chunks a) inside a native php4 session,
184     * b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache.
185     * --- refactored here, but: redundant somehow ---
186 joko 1.2 * </pre>
187 joko 1.1 *
188     * !!!!!! refactor this to Data::Driver::Proxy !!!!!! <-----------------
189 joko 1.7 * </p>
190 joko 1.1 *
191     *
192 joko 1.7 * <p>
193 joko 1.2 * <b>How to use?</b>
194 joko 1.1 *
195     * Pass an array holding "locator metadata" to the constructor.
196     * GenericDataSource takes care of the rest.
197     *
198 joko 1.7 * <pre>
199 joko 1.1 * Pass an array to the constructor: (e.g.)
200     *
201     * 1. doing rpc-calls....
202 joko 1.2 * <code>
203 joko 1.1 * $locator = array(
204     * type => 'rpc',
205     * metadata => array( Host => 'localhost', Port => '8765' ),
206     * );
207 joko 1.3 * $source = ne w GenericDataSource($locator);
208 joko 1.1 * $this->set_data_source( &$source );
209 joko 1.2 * </code>
210 joko 1.1 *
211     * 2. [proposal] common datahandles....
212 joko 1.2 * <code>
213 joko 1.1 * $locator = array(
214     * type => 'mysql',
215     * dsn => 'known dsn markup',
216     * );
217 joko 1.3 * $source = ne w GenericDataSource($locator);
218 joko 1.1 * $this->set_data_source( &$source );
219 joko 1.2 * </code>
220 joko 1.7 * </pre>
221     * </p>
222     *
223 joko 1.1 *
224 joko 1.2 * @link http://www.netfrag.org/~joko/
225 joko 1.1 * @author Andreas Motl <andreas.motl@ilo.de>
226 joko 1.2 *
227     * @link http://www.netfrag.org/~jonen/
228 joko 1.1 * @author Sebastian Utz <seut@tunemedia.de>
229 joko 1.2 *
230 joko 1.1 * @copyright (c) 2003 - All Rights reserved.
231 joko 1.2 *
232     * @link http://www.gnu.org/licenses/lgpl.txt
233 joko 1.1 * @license GNU LGPL (GNU Lesser General Public License)
234     *
235     *
236 joko 1.2 * @package org.netfrag.glib
237     * @subpackage DataSource
238     * @name DataSource::Generic
239 joko 1.1 *
240 joko 1.4 * @todo this:
241 joko 1.5 * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
242     * o implement another Data::Driver::Proxy container
243 joko 1.1 *
244 joko 1.5 * <pre>
245 joko 1.4 * !!!!!!!! THIS IS THE PROBLEM !!!!!!!!
246     * !!!!!!!! here is it where we have to break inheritance again !!!!!!!!
247     *
248     * THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
249     * inheritance trees at the same time, which is *not* possible at
250     * declare-time. We *do* need some runtime-infrastructure to solve this!
251     *
252     * TODO: move build- and check-locator stuff from ObjectList to this place!!!
253     *
254     * ABOUT:
255     * 1. otherwhere: WebApp - scope:
256     * x handles page vs. block vs. widget; dispatches MVC-View
257     * 2. here: DataSource - scope:
258     * x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))
259     * o clean implementation using a DesignPattern::AdapterProxy
260 joko 1.5 * </pre>
261 joko 1.4 *
262     *
263     */
264 joko 1.1 class DataSource_Generic extends DesignPattern_AdapterProxy {
265    
266     // !!!!!!!! here is it where we have to break inheritance again !!!!!!!!
267     // !!!!!!!! THIS IS THE PROBLEM !!!!!!!!
268    
269    
270    
271     /**
272     * This var holds the locator metadata hash
273     * that is used to feed metadata to a per-query-instance
274     * of an Adapter object.
275     *
276     */
277     //var $_locator = NULL;
278    
279     /**
280     * This var holds the locator metadata hash
281     * which is built from some predefined rules
282     * using metadata from $_options and some
283     * other presets.
284     *
285     * See '_buildLocator' which acts as a dispatcher
286 joko 1.16 * depending on $_options[transport].
287 joko 1.1 * (main dispatching level)
288     *
289     * The structure of a full blown locator looks like this:
290     *
291     * $locator = array(
292     * type => '<your type specifying the datasource-type>',
293     * metadata => array(
294     * ... your arbitrary deep metadata structure ...
295     * ),
296     * [dsn => '<your dsn markup>'],
297     * );
298     *
299     * Example 1 - data is inside a rdbms, using a dsn to connect to it:
300     * $locator = array(
301     * type => 'sql',
302     * dsn => 'mysql://username:password@localhost/database',
303     * );
304     *
305     * Example 2 - data is inside an odbms, reachable by doing remote procedure calls (rpc):
306     * $locator = array(
307     * type => 'rpc',
308     * metadata => array(
309     * package => 'Data::Driver::Proxy',
310     * Host => 'localhost',
311     * Port => '8765',
312     * )
313     * );
314     *
315     */
316     var $_locator = NULL;
317    
318    
319     /**
320     * This var holds the module information required to
321     * create instances of a Proxy and an Adapter.
322     * Information might get extracted from a
323     * DataSource::Locator instance.
324     *
325     * --- A skeleton:
326     *
327     * $this->_modules = array(
328     * _proxy => array( _id => '', _module => '', _options = array(), _instance => &$obj),
329     * _adapter => array( _id => '', _module => '', _options = array(), _instance => &$obj),
330     * );
331     *
332     *
333     * --- An example:
334     *
335     * $this->_modules = array(
336     * _proxy => array( _id => 'rpc', _module => 'DesignPattern::RemoteProxy', _instance => &$obj),
337     * _adapter => array( _id => 'phpHtmlLib', _module => 'DataSource::Adapter::phpHtmlLib::DataListSource', _instance => &$obj),
338     * );
339     *
340     *
341     */
342     //var $_modules = NULL;
343    
344    
345     /**
346     * This var holds the query hash
347     * that is used to feed as query to a per-query-instance
348     * of a Data::Driver::Proxy object.
349     *
350     */
351     var $_query = NULL;
352    
353    
354     /**
355     * this holds the query result from the
356     * Data::Driver::Proxy->queryXyz() call
357     *
358     */
359     var $_result = NULL;
360    
361    
362    
363     /**
364     * The constructor is used to pass in the
365     * locator metadata hash.
366     *
367     * @param LocatorMetadataHash array - layout: array( type => '', metadata => '', dsn => '' )
368     * @param Query array - layout: array( type => '', metadata => '', dsn => '' )
369     */
370    
371    
372     function DataSource_Generic( &$locator, $query ) {
373    
374     // copy parameter from query to locator
375 joko 1.16 //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
376     //$this->_locator->_datasource_type = $query[transport];
377     //$locator[_datasource_type] = $query[transport];
378 joko 1.1
379 joko 1.3 /**
380     * <!-- Autodia -->
381     * can do: (this is metadata supplied for Autodia, don't delete!)
382     * $this->_locator = new DataSource_Locator()
383     *
384     */
385    
386 joko 1.1 // build master locator
387 joko 1.16 $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
388 joko 1.1 //exit;
389     //$this->_locator = php::mkComponent('DataSource::Locator');
390    
391     $this->_locator->check();
392    
393     // trace
394     //print "locator-obj: " . Dumper($this->_locator);
395     //print "locator-data: " . Dumper($locator_data);
396     //exit;
397    
398    
399    
400     /*
401     $this->_modules = array(
402     _proxy => array( _id => $locator->_datasource_type ),
403     _adapter => array( _id => $locator->_adapter_type ),
404     );
405     */
406    
407     //$this->set_locator( $locator );
408     $this->set_query( $query );
409    
410    
411    
412     /*
413     // V1:
414     // pre-flight: establish and check locator metadata
415     $this->_buildLocator();
416     $this->_checkLocator();
417     */
418    
419    
420    
421     // pre-flight: check locator metadata
422     //$locator->build();
423     if (!$this->_locator->check()) {
424 joko 1.16 user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
425     //exit;
426     return;
427 joko 1.1 }
428    
429     //exit;
430    
431    
432 joko 1.3 /**
433     * <!-- Autodia -->
434     * can do: (this is metadata supplied for Autodia, don't delete!)
435     * $proxy = new DesignPattern_RemoteProxy()
436     *
437     */
438    
439    
440 joko 1.1 // --- Proxy selector/dispatcher ...
441    
442     switch ($this->_locator->_datasource_type) {
443     case 'rpc':
444     //$locator_data = $this->_locator->get_metadata();
445     //$this->_modules[_proxy][_options] = array( locator => $this->_locator, query => $query );
446     //$this->_modules[_proxy][_module] = 'DataSource::Proxy::XMLRPC';
447    
448     //$this->_modules[_proxy][_module] = 'DesignPattern::RemoteProxy';
449     //$this->_modules[_proxy][_options] = $locator_data;
450    
451     //$this->set_component_name('DesignPattern::RemoteProxy');
452     //$this->set_component_options($locator_data);
453    
454     $this->set_component_name('DesignPattern::RemoteProxy');
455    
456     break;
457     default:
458     user_error("Site::GenericPage: no Proxy could be selected!");
459     break;
460     }
461    
462    
463    
464     /*
465     // V1:
466     // make up dummy args by now
467     $args = array(
468     adapter => 'phpHtmlLib',
469     );
470     */
471    
472     // V2: now propagated from caller!
473    
474     //print Dumper(array( locator => $locator, query => $query ));
475     //exit;
476    
477     //$this->create_adapter($this->module, $this->function, $this->arguments);
478     //$this->set_handler( $this->get_adapter() );
479    
480    
481     // --- Adapter selector/dispatcher ...
482     // ... resolves this._modules.adapter._id to this._modules.adapter._module
483    
484     switch ($locator->_adapter_type) {
485     case 'phpHtmlLib':
486     //$adapter_arguments = $args[title];
487    
488 jonen 1.9 $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
489 joko 1.1
490     // in order to let the Adapter communicate with the Proxy,
491     // instantiate a wrapper method in a third namespace via
492     // Exporter::export_symbol(from, to)
493     $this->set_adapter_options($this);
494    
495    
496     break;
497     default:
498 joko 1.16 user_error("DataSource::Generic: no Adapter could be selected!");
499 joko 1.1 break;
500     }
501    
502    
503    
504     // --- module instantiation - Proxy and Adapter
505    
506     //user_error("handle proxy here!");
507     //$this->create_proxy();
508    
509     //print Dumper($this);
510    
511     //print "this: " . Dumper($this);
512    
513     // V1:
514     /*
515     $proxy = php::mkComponent($this->_modules[_proxy][_module], $this->_modules[_proxy][_options]);
516     print "proxy: " . Dumper($proxy);
517     //exit;
518     */
519    
520     // V2:
521     /*
522     $resultHandle = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
523     $result = $resultHandle->getAttributes();
524     return $result;
525     */
526    
527     // V3:
528     // $this->set_handler( $proxy );
529    
530     // V4: use _component_name & _component_options (proposal from GenericPage)
531     // $this->_component_name = ...
532     // $this->create_handler();
533    
534 joko 1.3
535     /**
536     * <!-- Autodia -->
537     * can do: (this is metadata supplied for Autodia, don't delete!)
538     * $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource()
539     *
540     */
541 joko 1.1
542     // V1:
543     //$this->create_adapter($adapter_module, $this->function, $this->arguments);
544    
545     // V2: FIXME - better use V1?
546     $adapter = php::mkComponent($this->get_adapter_module(), $this->get_adapter_options());
547     $this->set_adapter($adapter);
548    
549    
550    
551    
552     }
553    
554     function make_adapter_transparent() {
555    
556     // ... known from Site::Adapter::php::Class:
557    
558     // At this place the Adapter becomes a Proxy.
559     // This functionality currently correlates to the
560     // name of our ancestor, DesignPattern::AdapterProxy.
561     // FIXME: move this code to its namespace!!!
562     // FIXME: rename to set_proxy...
563    
564     // The reason this has to occour here is required
565     // by the TransparentProxy to actually make the
566     // _handler (_proxy) transparent later....
567     //$this->set_proxy( $this->get_adapter() );
568     }
569    
570     /**
571     * Set the metadata information
572     * (a DataSource::Locator) we will use
573     * to build encapsulated instances
574     * of both a Proxy and an Adapter.
575     *
576     * @param LocatorMetadataHash array -
577     *
578     */
579     function set_metadata( &$locator ) {
580     $this->_locator = &$locator;
581     }
582    
583     function &get_metadata() {
584     return $this->_locator;
585     }
586    
587    
588     /**
589     * Set the query metadata hash we will feed *completely*
590     * to an encapsulated Proxy instance.
591     *
592     * @param QueryDeclaration array -
593     *
594     */
595     function set_query( $query ) {
596     $this->_query = $query;
597     }
598    
599     /**
600     * Issue remote/proxy call
601     * Stolen from Application_AbstractBackend::_remote_method (RefactoringProposal?)
602     * Tweaked a bit: proxy package now taken from $this->_handler_name
603     *
604     * Create a new instance of a proxy and store it for later reuse.
605     * Read the locator metadata hash and create
606     * the proxy handler instance using passed-in name.
607     *
608     * @param string - $proxy_name (namespaced classname - perl syntax - e.g.: Data::Driver::Proxy)
609     *
610     */
611     function datasource_handler_call() {
612    
613    
614     // 1. read args and build cache key
615    
616     $arg_list = func_get_args();
617     $command = array_shift($arg_list);
618     $cache_key = join("-", array(session_id(), $command, join('_', $arg_list) ));
619     //print "cache_key: $cache_key<br>";
620    
621     // FIXME: what if arg_list still contains more elements after doing this?
622     $query = array_shift($arg_list);
623    
624     // 2. prepare proxy-options (read from locator)
625    
626     //print "this: " . Dumper($this);
627     //exit;
628    
629     // read from locator metadata
630     //$proxy_name = $this->_locator[metadata][package];
631    
632     // V1:
633     //$rpcinfo = array( Host => $this->_locator[metadata][Host], Port => $this->_locator[metadata][Port] );
634    
635     // V2:
636     $rpcinfo = $this->_locator->get_metadata();
637    
638     // FIXME! implement this into Data::Driver::RPC::Remote!
639     //$rpcinfo[to_latin] = 1;
640    
641     // FIXME! patch query
642     if (sizeof($query) == 1) {
643     $query = $query[0];
644     }
645    
646     //print "query: " . Dumper($query);
647    
648     // !!! use DesignPattern::Proxy here !!!
649     // $proxy = new DesignPattern_Proxy($proxy_name, ...)
650     // or:
651     // $proxy = mkObject('DesignPattern::Proxy');
652     // $this->set_handler( $proxy );
653     // or:
654     // $proxy = mkObject('DesignPattern::Proxy');
655     // $proxy->
656     // $this->set_handler( $proxy );
657    
658    
659    
660     //$this->set_component_name( $proxy_name );
661     $this->set_component_options( $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
662     //print Dumper($this);
663     //exit;
664    
665     $this->create_proxy();
666    
667     //print Dumper($this);
668     //exit;
669    
670     /*
671     // -------------------- clone this & modify ----------
672     $proxy = mkObject($proxy_name, $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
673     $this->set_handler( $proxy );
674     //$result = $resultHandle->getAttributes();
675     //return $result;
676     //$this->_result = $resultHandle->getAttributes();
677     //$this->_result = $this->_handler->getAttributes();
678     // -------------------- clone this & modify ----------
679     */
680    
681     }
682    
683    
684     function datasource_handler_buildoptions() {
685    
686     //print Dumper($this->_query);
687     //exit;
688    
689     // make up a command from metadata
690     // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
691     switch ($this->_query[metatype]) {
692     case 'data':
693 jonen 1.9 $command = 'queryData';
694 jonen 1.13
695 jonen 1.9 //$command = 'getObjects'; // FIXME!!!
696 joko 1.1 //$this->_locator->set_option('metadata.command', $command);
697 jonen 1.9 /*
698 joko 1.1 $args = array();
699     switch ($this->_query[vartype]) {
700 jonen 1.8 case 'objects':
701 joko 1.1 if (!$this->_query[classname]) {
702 jonen 1.8 $msg = "_query[vartype] == 'objects' requires _query[classname]";
703 joko 1.16 user_error("DataSource::Generic: query_data() - failed: " . $msg);
704 joko 1.1 }
705     array_push($args, $this->_query[classname]);
706     break;
707     }
708 jonen 1.9 */
709     $query_args = array();
710     switch ($this->_query[abstract_type]) {
711     case 'list':
712     if (!$this->_query[classname]) {
713     $msg = "_query[vartype] == 'objects' requires _query[classname]";
714 joko 1.16 user_error("DataSource::Generic: query_data() - failed: " . $msg);
715 jonen 1.9 }
716     //array_push($query_args, $this->_query[classname]);
717     $query_args[classname] = $this->_query[classname];
718     break;
719     case 'item':
720     if (!$this->_query[classname]) {
721     $msg = "_query[vartype] == 'objects' requires _query[classname]";
722 joko 1.16 user_error("DataSource::Generic: query_data() - failed: " . $msg);
723 jonen 1.9 }
724     $query_args[guid] = $this->_query[ident];
725     $query_args[classname] = $this->_query[classname];
726     break;
727 jonen 1.13 }
728     if($this->_query[action] == 'write') {
729     $query_args[action] = $this->_query[action];
730     $query_args[data] = $this->_query[data];
731 jonen 1.9 }
732     $args = array(
733     'data_type' => $this->_query[abstract_type],
734     'query_args' => $query_args
735     );
736     break;
737    
738     // querySchema
739 joko 1.1 case 'schema':
740 jonen 1.9 //print "Testing schema:" . "<br>";
741 joko 1.1 $command = 'querySchema';
742 joko 1.14 $args = array( $this->_query[filter] );
743 joko 1.1 break;
744 joko 1.16
745     // remoteMethod
746     case 'method':
747     $command = $this->_query[method];
748     $args = $this->_query[args];
749     break;
750    
751 joko 1.1 }
752    
753 joko 1.16
754     // FIXME: bad behaviour?
755     if (!is_array($args)) { $args = array( $args ); }
756 joko 1.1
757     /*
758     $this->_query[rpc_command] = $command;
759     $this->_query[rpc_args] = $command;
760     */
761    
762     // methods!!!
763     $this->_locator->_call[_method] = $command;
764     $this->_locator->_call[_arguments] = $args;
765    
766     //$adapter = $this->get_adapter();
767    
768     // trace
769     /*
770     print Dumper(null, '<b>= = = = = = = = = = = = = = = = = = = = = =</b>');
771     print Dumper('datasource_handler_buildoptions', array(
772     "_locator" => $this->_locator,
773     "_query" => $this->_query,
774     "command" => '<b>' . $command . "</b>",
775     "args" => $args
776     ));
777     */
778    
779     /*
780     $this->_handler_options = array(
781     method => $command,
782     args => $args,
783     );
784     */
785    
786     }
787    
788 joko 1.11
789    
790 joko 1.1 function &fetch_result() {
791    
792     $this->datasource_handler_buildoptions();
793    
794 joko 1.11 $call = $this->_locator->get_call();
795     //print Dumper($call);
796    
797 joko 1.1 // pre-flight checks
798 joko 1.11 if (!$call[method]) {
799     $msg = "Remote method is empty, please pass in proper metadata or check configuration.";
800 joko 1.16 user_error("DataSource::Generic: query_data() - failed: " . $msg);
801 joko 1.1 return;
802     }
803    
804     //print "fetch_result: this->_handler=" . Dumper($this->_handler);
805    
806     // do remote call here and get result
807     // FIXME: handle synchronous/asynchronous mode here!!!
808 joko 1.11 $this->datasource_handler_call($call[method], $call[args]);
809 joko 1.1
810    
811     // TODO: ... = $this->poll_handler_result and $this->get_handler_result
812     $proxy = $this->get_proxy();
813     $this->_result = $proxy->getResult();
814     //print "result: " . Dumper($this->_result); exit;
815    
816     $this->_result_count = sizeof($this->_result);
817    
818     // trace
819 joko 1.11 //if (constants::get('VERBOSE') && $this->_debug[notice]) {
820 joko 1.12 if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
821 joko 1.1 //print "_result = " . Dumper($this->_result);
822 joko 1.11 //print "<div><b><font color=\"darkgreen\">Debug:</font></b> DataSource::Generic->_result_count = <b>" . $this->_result_count . "</b></div>";
823     $this->draw_status_box();
824 joko 1.1 }
825 joko 1.11
826 joko 1.1 return $this->_result;
827    
828     }
829    
830 joko 1.11 function draw_status_box() {
831    
832     static $boxcount;
833    
834     $boxcount++;
835    
836 joko 1.12 $box = container();
837    
838 joko 1.11 // box style
839     $style = container(
840     html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
841     html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
842     );
843 joko 1.12 $box->add( $style );
844 joko 1.11
845     // box content
846     $statusbox = html_div('box_dsg');
847     $statusbox->add( html_b("DataSource::Generic"), html_br() );
848     $locatorbox = html_div('box_dsg');
849     $locatorbox->set_id("locatorbox_$boxcount");
850     $locatorbox->add( Dumper($this->_locator) );
851 joko 1.14
852     // FIXME: ie/mozilla?
853 joko 1.15 //$locatorbox->set_style('display:none;');
854     //$locatorbox->set_style('visibility:hidden;');
855     // already duplicate inside Tracer!!!
856     $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
857 joko 1.11
858 joko 1.15 $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
859 joko 1.11 $call = $this->_locator->get_call();
860     $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
861     if (sizeof($call[args])) {
862     $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
863     }
864     $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
865 joko 1.12 $box->add( $statusbox );
866    
867 joko 1.14 //print $box->render();
868     trace( $box );
869 joko 1.11
870     }
871    
872 joko 1.1
873     function &query_data() {
874     //print "query!<br/>";
875     return $this->fetch_result();
876     //$this->handle_result();
877     }
878    
879     function query_schema() {
880     user_error("FIXME: query_schema");
881     // $this->datasource_handler_call( ... );
882     }
883    
884     function &get_result() {
885     return $this->_result;
886 joko 1.11 }
887    
888     function get_result_count() {
889     return $this->_result_count;
890 joko 1.1 }
891    
892     }
893    
894     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed