/[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.25 - (hide annotations)
Mon Nov 17 18:01:03 2003 UTC (20 years, 9 months ago) by jonen
Branch: MAIN
Changes since 1.24: +1 -1 lines
bugfix: php cannot use perl-syntax!! ;-)

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

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