/[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.23 - (show annotations)
Mon Jul 14 10:02:32 2003 UTC (21 years ago) by jonen
Branch: MAIN
Changes since 1.22: +6 -3 lines
removed debug dumper

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

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