/[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.22 by joko, Fri Jun 6 04:25:45 2003 UTC
# Line 9  Line 9 
9   */   */
10    
11  /**  /**
12     * Cvs-Log:
13     *
14   * $Id$   * $Id$
15   *   *
16   * $Log$   * $Log$
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   * Revision 1.3  2003/03/09 15:50:36  joko
83   * + additional metadata for Autodia   * + additional metadata for Autodia
84   *   *
# Line 45  Line 112 
112   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
113   * + initial commit   * + initial commit
114   *   *
  *  
115   */   */
116    
117  /**  /**
# Line 123  loadModule('DesignPattern::AdapterProxy' Line 189  loadModule('DesignPattern::AdapterProxy'
189   * --- snipped into here from above ---   * --- snipped into here from above ---
190   * </pre>   * </pre>
191   *   *
192   *   * <p>
193   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
194   *   *
195   * Data::Driver::Proxy instantiates "handlers" below itself   * Data::Driver::Proxy instantiates "handlers" below itself
# Line 144  loadModule('DesignPattern::AdapterProxy' Line 210  loadModule('DesignPattern::AdapterProxy'
210   * </pre>   * </pre>
211   *   *
212   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
213     * </p>
214   *   *
215   *   *
216     * <p>
217   * <b>How to use?</b>   * <b>How to use?</b>
218   *   *
219   * Pass an array holding "locator metadata" to the constructor.   * Pass an array holding "locator metadata" to the constructor.
220   * GenericDataSource takes care of the rest.   * GenericDataSource takes care of the rest.
221   *   *
222     * <pre>
223   * Pass an array to the constructor: (e.g.)   * Pass an array to the constructor: (e.g.)
224   *   *
225   *  1. doing rpc-calls....   *  1. doing rpc-calls....
# Line 172  loadModule('DesignPattern::AdapterProxy' Line 241  loadModule('DesignPattern::AdapterProxy'
241   *    $source = ne w GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
242   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
243   *    </code>   *    </code>
244     * </pre>
245     * </p>
246     *
247   *   *
248   * @link http://www.netfrag.org/~joko/   * @link http://www.netfrag.org/~joko/
249   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
# Line 189  loadModule('DesignPattern::AdapterProxy' Line 261  loadModule('DesignPattern::AdapterProxy'
261   * @subpackage DataSource   * @subpackage DataSource
262   * @name DataSource::Generic   * @name DataSource::Generic
263   *   *
264   * @todo   * @todo this:
265   * <ul>   * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
266   *  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>  
267   *   *
268     * <pre>
269  //              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!   *              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!
270  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!   *    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
271  //   *
272  //    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy   *    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
273  //    inheritance trees at the same time, which is *not* possible at   *    inheritance trees at the same time, which is *not* possible at
274  //    declare-time. We *do* need some runtime-infrastructure to solve this!   *    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!!!   *    TODO: move build- and check-locator stuff from ObjectList to this place!!!
277  //   *
278  //    ABOUT:   *    ABOUT:
279  //      1. otherwhere: WebApp - scope:   *      1. otherwhere: WebApp - scope:
280  //          x handles page vs. block vs. widget; dispatches MVC-View   *          x handles page vs. block vs. widget; dispatches MVC-View
281  //      2. here: DataSource - scope:   *      2. here: DataSource - scope:
282  //          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.))
283  //          o clean implementation using a DesignPattern::AdapterProxy   *          o clean implementation using a DesignPattern::AdapterProxy
284  //   * </pre>
285     *
286  */   *
287     */
288  class DataSource_Generic extends DesignPattern_AdapterProxy {  class DataSource_Generic extends DesignPattern_AdapterProxy {
289    
290  //    !!!!!!!!   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 307  class DataSource_Generic extends DesignP
307      * other presets.      * other presets.
308      *      *
309      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
310      * depending on $_options[datasource].      * depending on $_options[transport].
311      * (main dispatching level)      * (main dispatching level)
312      *      *
313      * 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 396  class DataSource_Generic extends DesignP
396          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
397    
398                  // copy parameter from query to locator                  // copy parameter from query to locator
399                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
400                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
401                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
402                                    
403        /**        /**
404         * <!-- Autodia -->         * <!-- Autodia -->
# Line 337  class DataSource_Generic extends DesignP Line 408  class DataSource_Generic extends DesignP
408         */         */
409    
410                  // build master locator                  // build master locator
411                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
412                  //exit;                  //exit;
413                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
414                                    
# Line 374  class DataSource_Generic extends DesignP Line 445  class DataSource_Generic extends DesignP
445      // pre-flight: check locator metadata      // pre-flight: check locator metadata
446        //$locator->build();        //$locator->build();
447        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
448          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
449          exit;          //exit;
450           //return;           return;
451        }        }
452    
453  //exit;  //exit;
# Line 435  class DataSource_Generic extends DesignP Line 506  class DataSource_Generic extends DesignP
506          // ... resolves this._modules.adapter._id to this._modules.adapter._module          // ... resolves this._modules.adapter._id to this._modules.adapter._module
507                    
508          switch ($locator->_adapter_type) {          switch ($locator->_adapter_type) {
509    
510            case 'phpHtmlLib':            case 'phpHtmlLib':
511              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
512                $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
             $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');  
513                            
514              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
515              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
516              // Exporter::export_symbol(from, to)              // Exporter::export_symbol(from, to)
517              $this->set_adapter_options($this);              $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;              break;
527    
528            default:            default:
529              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
530              break;              break;
531          }          }
532    
# Line 643  class DataSource_Generic extends DesignP Line 721  class DataSource_Generic extends DesignP
721        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
722          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
723            case 'data':            case 'data':
724              //$command = 'queryData';              $command = 'queryData';
725              $command = 'getObjects';   // FIXME!!!              
726                //$command = 'getObjects';   // FIXME!!!
727              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
728    /*
729              $args = array();              $args = array();
730              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
731                case 'object':                case 'objects':
732                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
733                    $msg = "_query[vartype] == 'object' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
734                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
735                  }                  }
736                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
737                  break;                  break;
738              }              }
739              break;   */
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':            case 'schema':
809                //print "Testing schema:" . "<br>";
810              $command = 'querySchema';              $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;              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;          $this->_query[rpc_command] = $command;
# Line 694  class DataSource_Generic extends DesignP Line 858  class DataSource_Generic extends DesignP
858                
859    }    }
860    
861    
862    
863          function &fetch_result() {          function &fetch_result() {
864    
865          //print Dumper($this);
866                
867        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
868    
869        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
870        $args = $this->_locator->_call[_arguments];  
871                //print Dumper($call);
872          //return;
873    
874        // pre-flight checks        // pre-flight checks
875          if (!$method) {          if (!$call[method]) {
876            $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.";
877                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
878            return;            return;
879          }          }
880    
# Line 712  class DataSource_Generic extends DesignP Line 882  class DataSource_Generic extends DesignP
882    
883        // do remote call here and get result        // do remote call here and get result
884        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
885          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
886                    
887                    
888          // 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 893  class DataSource_Generic extends DesignP
893          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
894    
895        // trace        // trace
896          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
897            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
898            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
899            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>";
900              $this->draw_status_box();
901          }          }
902            
903          return $this->_result;          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() {    function &query_data() {
951      //print "query!<br/>";      //print "query!<br/>";
# Line 747  class DataSource_Generic extends DesignP Line 961  class DataSource_Generic extends DesignP
961    function &get_result() {    function &get_result() {
962      return $this->_result;      return $this->_result;
963    }    }
964      
965      function get_result_count() {
966        return $this->_result_count;
967      }
968                    
969  }  }
970    

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

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