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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by joko, Sun Mar 9 15:50:36 2003 UTC revision 1.17 by joko, Wed Apr 9 02:07:33 2003 UTC
# Line 9  Line 9 
9   */   */
10    
11  /**  /**
12     * <b>Cvs-Log:</b>
13     *
14     * <pre>
15   * $Id$   * $Id$
16   *   *
17   * $Log$   * $Log$
18     * Revision 1.17  2003/04/09 02:07:33  joko
19     * CHANGE: renamed key 'classname' through 'nodename'
20     *
21     * Revision 1.16  2003/04/08 17:55:20  joko
22     * CHANGE: renamed property 'datasource' to 'transport'
23     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
24     * minor fixes: updated logging/debugging messages
25     *
26     * Revision 1.15  2003/04/06 04:46:33  joko
27     * renamed linking function
28     * mozilla fixes
29     *
30     * Revision 1.14  2003/04/04 21:19:21  joko
31     * modified exception handling (enhanced, purged redundant code)
32     *
33     * Revision 1.13  2003/04/04 02:37:14  jonen
34     * _query[action] == write
35     *
36     * Revision 1.12  2003/03/29 08:00:48  joko
37     * modified ErrorBoxing
38     *
39     * Revision 1.11  2003/03/28 06:45:26  joko
40     * VERBOSE mode
41     *
42     * Revision 1.10  2003/03/28 03:01:02  joko
43     * more fancy debugging-output
44     *
45     * Revision 1.9  2003/03/27 16:24:26  jonen
46     * + mugled namespace
47     * + added enhanced 'queryData'
48     *
49     * Revision 1.8  2003/03/20 07:22:14  jonen
50     * + modified case 'object' to 'objects'
51     *   (cause its loads all *objects* of a given classname)
52     *
53     * Revision 1.7  2003/03/11 01:43:00  joko
54     * + fixed metadata for phpDocumentor
55     *
56     * Revision 1.6  2003/03/11 01:22:25  joko
57     * + fixed metadata for phpDocumentor
58     *
59     * Revision 1.5  2003/03/11 00:12:49  joko
60     * + fixed metadata for phpDocumentor
61     *
62     * Revision 1.4  2003/03/10 23:25:03  joko
63     * + fixed metadata for phpDocumentor
64     *
65   * Revision 1.3  2003/03/09 15:50:36  joko   * Revision 1.3  2003/03/09 15:50:36  joko
66   * + additional metadata for Autodia   * + additional metadata for Autodia
67   *   *
# Line 44  Line 94 
94   *   *
95   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
96   * + initial commit   * + initial commit
97   *   * </pre>
98   *   *
99   */   */
100    
# Line 123  loadModule('DesignPattern::AdapterProxy' Line 173  loadModule('DesignPattern::AdapterProxy'
173   * --- snipped into here from above ---   * --- snipped into here from above ---
174   * </pre>   * </pre>
175   *   *
176   *   * <p>
177   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
178   *   *
179   * Data::Driver::Proxy instantiates "handlers" below itself   * Data::Driver::Proxy instantiates "handlers" below itself
# Line 144  loadModule('DesignPattern::AdapterProxy' Line 194  loadModule('DesignPattern::AdapterProxy'
194   * </pre>   * </pre>
195   *   *
196   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
197     * </p>
198   *   *
199   *   *
200     * <p>
201   * <b>How to use?</b>   * <b>How to use?</b>
202   *   *
203   * Pass an array holding "locator metadata" to the constructor.   * Pass an array holding "locator metadata" to the constructor.
204   * GenericDataSource takes care of the rest.   * GenericDataSource takes care of the rest.
205   *   *
206     * <pre>
207   * Pass an array to the constructor: (e.g.)   * Pass an array to the constructor: (e.g.)
208   *   *
209   *  1. doing rpc-calls....   *  1. doing rpc-calls....
# Line 172  loadModule('DesignPattern::AdapterProxy' Line 225  loadModule('DesignPattern::AdapterProxy'
225   *    $source = ne w GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
226   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
227   *    </code>   *    </code>
228     * </pre>
229     * </p>
230     *
231   *   *
232   * @link http://www.netfrag.org/~joko/   * @link http://www.netfrag.org/~joko/
233   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
# Line 189  loadModule('DesignPattern::AdapterProxy' Line 245  loadModule('DesignPattern::AdapterProxy'
245   * @subpackage DataSource   * @subpackage DataSource
246   * @name DataSource::Generic   * @name DataSource::Generic
247   *   *
248   * @todo   * @todo this:
249   * <ul>   * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
250   *  o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles   * o implement another Data::Driver::Proxy container
  *  o implement another Data::Driver::Proxy container  
  * </ul>  
251   *   *
252     * <pre>
253  //              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!   *              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!
254  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!   *    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
255  //   *
256  //    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy   *    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
257  //    inheritance trees at the same time, which is *not* possible at   *    inheritance trees at the same time, which is *not* possible at
258  //    declare-time. We *do* need some runtime-infrastructure to solve this!   *    declare-time. We *do* need some runtime-infrastructure to solve this!
259  //   *
260  //    TODO: move build- and check-locator stuff from ObjectList to this place!!!   *    TODO: move build- and check-locator stuff from ObjectList to this place!!!
261  //   *
262  //    ABOUT:   *    ABOUT:
263  //      1. otherwhere: WebApp - scope:   *      1. otherwhere: WebApp - scope:
264  //          x handles page vs. block vs. widget; dispatches MVC-View   *          x handles page vs. block vs. widget; dispatches MVC-View
265  //      2. here: DataSource - scope:   *      2. here: DataSource - scope:
266  //          x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))   *          x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))
267  //          o clean implementation using a DesignPattern::AdapterProxy   *          o clean implementation using a DesignPattern::AdapterProxy
268  //   * </pre>
269     *
270  */   *
271     */
272  class DataSource_Generic extends DesignPattern_AdapterProxy {  class DataSource_Generic extends DesignPattern_AdapterProxy {
273    
274  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
# Line 236  class DataSource_Generic extends DesignP Line 291  class DataSource_Generic extends DesignP
291      * other presets.      * other presets.
292      *      *
293      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
294      * depending on $_options[datasource].      * depending on $_options[transport].
295      * (main dispatching level)      * (main dispatching level)
296      *      *
297      * The structure of a full blown locator looks like this:      * The structure of a full blown locator looks like this:
# Line 325  class DataSource_Generic extends DesignP Line 380  class DataSource_Generic extends DesignP
380          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
381    
382                  // copy parameter from query to locator                  // copy parameter from query to locator
383                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
384                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
385                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
386                                    
387        /**        /**
388         * <!-- Autodia -->         * <!-- Autodia -->
# Line 337  class DataSource_Generic extends DesignP Line 392  class DataSource_Generic extends DesignP
392         */         */
393    
394                  // build master locator                  // build master locator
395                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
396                  //exit;                  //exit;
397                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
398                                    
# Line 374  class DataSource_Generic extends DesignP Line 429  class DataSource_Generic extends DesignP
429      // pre-flight: check locator metadata      // pre-flight: check locator metadata
430        //$locator->build();        //$locator->build();
431        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
432          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
433          exit;          //exit;
434           //return;           return;
435        }        }
436    
437  //exit;  //exit;
# Line 438  class DataSource_Generic extends DesignP Line 493  class DataSource_Generic extends DesignP
493            case 'phpHtmlLib':            case 'phpHtmlLib':
494              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
495    
496              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
497                            
498              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
499              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
# Line 448  class DataSource_Generic extends DesignP Line 503  class DataSource_Generic extends DesignP
503    
504              break;              break;
505            default:            default:
506              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected!");
507              break;              break;
508          }          }
509    
# Line 643  class DataSource_Generic extends DesignP Line 698  class DataSource_Generic extends DesignP
698        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
699          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
700            case 'data':            case 'data':
701              //$command = 'queryData';              $command = 'queryData';
702              $command = 'getObjects';   // FIXME!!!              
703                //$command = 'getObjects';   // FIXME!!!
704              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
705    /*
706              $args = array();              $args = array();
707              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
708                case 'object':                case 'objects':
709                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
710                    $msg = "_query[vartype] == 'object' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
711                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
712                  }                  }
713                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
714                  break;                  break;
715              }              }
716              break;   */
717                $query_args = array();
718                 switch ($this->_query[abstract_type]) {
719                  case 'list':
720                    if (!$this->_query[nodename]) {
721                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
722                      user_error("DataSource::Generic: query_data() - failed: " . $msg);
723                    }
724                    //array_push($query_args, $this->_query[nodename]);
725                    $query_args[nodename] = $this->_query[nodename];
726                    break;
727                  case 'item':
728                    if (!$this->_query[nodename]) {
729                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
730                      user_error("DataSource::Generic: query_data() - failed: " . $msg);
731                    }
732                    $query_args[guid] = $this->_query[ident];
733                    $query_args[nodename] = $this->_query[nodename];
734                    break;              
735                }
736                if($this->_query[action] == 'write') {
737                 $query_args[action] = $this->_query[action];
738                 $query_args[data] = $this->_query[data];
739                }
740                $args = array(
741                              'data_type' => $this->_query[abstract_type],
742                              'query_args' => $query_args
743                              );
744               break;
745    
746              // querySchema
747            case 'schema':            case 'schema':
748                //print "Testing schema:" . "<br>";
749              $command = 'querySchema';              $command = 'querySchema';
750                $args = array( $this->_query[filter] );
751              break;              break;
752                
753              // remoteMethod
754              case 'method':
755                $command = $this->_query[method];
756                $args = $this->_query[args];
757                break;
758    
759          }          }
760                
761          
762            // FIXME: bad behaviour?
763            if (!is_array($args)) { $args = array( $args ); }
764                    
765          /*          /*
766          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 694  class DataSource_Generic extends DesignP Line 793  class DataSource_Generic extends DesignP
793                
794    }    }
795    
796    
797    
798          function &fetch_result() {          function &fetch_result() {
799                
800        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
801    
802        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
803        $args = $this->_locator->_call[_arguments];        //print Dumper($call);
804          
805        // pre-flight checks        // pre-flight checks
806          if (!$method) {          if (!$call[method]) {
807            $msg = "Remote command could not be resolved, please pass in or check configuration.";            $msg = "Remote method is empty, please pass in proper metadata or check configuration.";
808                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
809            return;            return;
810          }          }
811    
# Line 712  class DataSource_Generic extends DesignP Line 813  class DataSource_Generic extends DesignP
813    
814        // do remote call here and get result        // do remote call here and get result
815        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
816          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
817                    
818                    
819          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result
# Line 723  class DataSource_Generic extends DesignP Line 824  class DataSource_Generic extends DesignP
824          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
825    
826        // trace        // trace
827          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
828            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
829            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
830            print "DataSource::Generic->_result_count = " . $this->_result_count . "<br/>";            //print "<div><b><font color=\"darkgreen\">Debug:</font></b> DataSource::Generic->_result_count = <b>" . $this->_result_count . "</b></div>";
831              $this->draw_status_box();
832          }          }
833            
834          return $this->_result;          return $this->_result;
835    
836          }          }
837    
838      function draw_status_box() {
839    
840        static $boxcount;
841        
842        $boxcount++;
843    
844        $box = container();
845    
846        // box style
847        $style = container(
848          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
849          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
850        );
851        $box->add( $style );
852        
853        // box content
854        $statusbox = html_div('box_dsg');
855        $statusbox->add( html_b("DataSource::Generic"), html_br() );
856        $locatorbox = html_div('box_dsg');
857        $locatorbox->set_id("locatorbox_$boxcount");
858        $locatorbox->add( Dumper($this->_locator) );
859        
860        // FIXME: ie/mozilla?
861        //$locatorbox->set_style('display:none;');
862        //$locatorbox->set_style('visibility:hidden;');
863        // already duplicate inside Tracer!!!
864        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
865        
866        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
867        $call = $this->_locator->get_call();
868        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
869        if (sizeof($call[args])) {
870          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
871        }
872        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
873        $box->add( $statusbox );
874    
875        //print $box->render();
876        trace( $box );
877    
878      }
879    
880    
881    function &query_data() {    function &query_data() {
882      //print "query!<br/>";      //print "query!<br/>";
# Line 747  class DataSource_Generic extends DesignP Line 892  class DataSource_Generic extends DesignP
892    function &get_result() {    function &get_result() {
893      return $this->_result;      return $this->_result;
894    }    }
895      
896      function get_result_count() {
897        return $this->_result_count;
898      }
899                    
900  }  }
901    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.17

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