/[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.19 - (show annotations)
Fri Apr 18 15:40:51 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.18: +46 -12 lines
NEW: tree data handling
  introduced new adapter: DataSource::Adapter::Free
  enhanced datasource_handler_buildoptions: now handles a) case 'tree'  b) _query[filter]

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

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