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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations)
Fri Apr 4 21:19:21 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.13: +10 -21 lines
modified exception handling (enhanced, purged redundant code)

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

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