/[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.21 by jonen, Sat May 10 18:14:50 2003 UTC
# Line 9  Line 9 
9   */   */
10    
11  /**  /**
12     * Cvs-Log:
13     *
14   * $Id$   * $Id$
15   *   *
16   * $Log$   * $Log$
17     * Revision 1.21  2003/05/10 18:14:50  jonen
18     * + implements 'create' of item (query mapping part)
19     *
20     * Revision 1.20  2003/04/19 16:07:15  jonen
21     * + added '_query[list_meta]' at 'queryData' needed for meta query args
22     *    (e.g. at UserManagment)
23     *
24     * Revision 1.19  2003/04/18 15:40:51  joko
25     * NEW: tree data handling
26     *   introduced new adapter: DataSource::Adapter::Free
27     *   enhanced datasource_handler_buildoptions: now handles a) case 'tree'  b) _query[filter]
28     *
29     * Revision 1.18  2003/04/11 00:55:49  joko
30     * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
31     *
32     * Revision 1.17  2003/04/09 02:07:33  joko
33     * CHANGE: renamed key 'classname' through 'nodename'
34     *
35     * Revision 1.16  2003/04/08 17:55:20  joko
36     * CHANGE: renamed property 'datasource' to 'transport'
37     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
38     * minor fixes: updated logging/debugging messages
39     *
40     * Revision 1.15  2003/04/06 04:46:33  joko
41     * renamed linking function
42     * mozilla fixes
43     *
44     * Revision 1.14  2003/04/04 21:19:21  joko
45     * modified exception handling (enhanced, purged redundant code)
46     *
47     * Revision 1.13  2003/04/04 02:37:14  jonen
48     * _query[action] == write
49     *
50     * Revision 1.12  2003/03/29 08:00:48  joko
51     * modified ErrorBoxing
52     *
53     * Revision 1.11  2003/03/28 06:45:26  joko
54     * VERBOSE mode
55     *
56     * Revision 1.10  2003/03/28 03:01:02  joko
57     * more fancy debugging-output
58     *
59     * Revision 1.9  2003/03/27 16:24:26  jonen
60     * + mugled namespace
61     * + added enhanced 'queryData'
62     *
63     * Revision 1.8  2003/03/20 07:22:14  jonen
64     * + modified case 'object' to 'objects'
65     *   (cause its loads all *objects* of a given classname)
66     *
67     * Revision 1.7  2003/03/11 01:43:00  joko
68     * + fixed metadata for phpDocumentor
69     *
70     * Revision 1.6  2003/03/11 01:22:25  joko
71     * + fixed metadata for phpDocumentor
72     *
73     * Revision 1.5  2003/03/11 00:12:49  joko
74     * + fixed metadata for phpDocumentor
75     *
76     * Revision 1.4  2003/03/10 23:25:03  joko
77     * + fixed metadata for phpDocumentor
78     *
79   * Revision 1.3  2003/03/09 15:50:36  joko   * Revision 1.3  2003/03/09 15:50:36  joko
80   * + additional metadata for Autodia   * + additional metadata for Autodia
81   *   *
# Line 45  Line 109 
109   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
110   * + initial commit   * + initial commit
111   *   *
  *  
112   */   */
113    
114  /**  /**
# Line 123  loadModule('DesignPattern::AdapterProxy' Line 186  loadModule('DesignPattern::AdapterProxy'
186   * --- snipped into here from above ---   * --- snipped into here from above ---
187   * </pre>   * </pre>
188   *   *
189   *   * <p>
190   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
191   *   *
192   * Data::Driver::Proxy instantiates "handlers" below itself   * Data::Driver::Proxy instantiates "handlers" below itself
# Line 144  loadModule('DesignPattern::AdapterProxy' Line 207  loadModule('DesignPattern::AdapterProxy'
207   * </pre>   * </pre>
208   *   *
209   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
210     * </p>
211   *   *
212   *   *
213     * <p>
214   * <b>How to use?</b>   * <b>How to use?</b>
215   *   *
216   * Pass an array holding "locator metadata" to the constructor.   * Pass an array holding "locator metadata" to the constructor.
217   * GenericDataSource takes care of the rest.   * GenericDataSource takes care of the rest.
218   *   *
219     * <pre>
220   * Pass an array to the constructor: (e.g.)   * Pass an array to the constructor: (e.g.)
221   *   *
222   *  1. doing rpc-calls....   *  1. doing rpc-calls....
# Line 172  loadModule('DesignPattern::AdapterProxy' Line 238  loadModule('DesignPattern::AdapterProxy'
238   *    $source = ne w GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
239   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
240   *    </code>   *    </code>
241     * </pre>
242     * </p>
243     *
244   *   *
245   * @link http://www.netfrag.org/~joko/   * @link http://www.netfrag.org/~joko/
246   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
# Line 189  loadModule('DesignPattern::AdapterProxy' Line 258  loadModule('DesignPattern::AdapterProxy'
258   * @subpackage DataSource   * @subpackage DataSource
259   * @name DataSource::Generic   * @name DataSource::Generic
260   *   *
261   * @todo   * @todo this:
262   * <ul>   * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
263   *  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>  
264   *   *
265     * <pre>
266  //              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!   *              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!
267  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!   *    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
268  //   *
269  //    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy   *    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
270  //    inheritance trees at the same time, which is *not* possible at   *    inheritance trees at the same time, which is *not* possible at
271  //    declare-time. We *do* need some runtime-infrastructure to solve this!   *    declare-time. We *do* need some runtime-infrastructure to solve this!
272  //   *
273  //    TODO: move build- and check-locator stuff from ObjectList to this place!!!   *    TODO: move build- and check-locator stuff from ObjectList to this place!!!
274  //   *
275  //    ABOUT:   *    ABOUT:
276  //      1. otherwhere: WebApp - scope:   *      1. otherwhere: WebApp - scope:
277  //          x handles page vs. block vs. widget; dispatches MVC-View   *          x handles page vs. block vs. widget; dispatches MVC-View
278  //      2. here: DataSource - scope:   *      2. here: DataSource - scope:
279  //          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.))
280  //          o clean implementation using a DesignPattern::AdapterProxy   *          o clean implementation using a DesignPattern::AdapterProxy
281  //   * </pre>
282     *
283  */   *
284     */
285  class DataSource_Generic extends DesignPattern_AdapterProxy {  class DataSource_Generic extends DesignPattern_AdapterProxy {
286    
287  //    !!!!!!!!   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 304  class DataSource_Generic extends DesignP
304      * other presets.      * other presets.
305      *      *
306      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
307      * depending on $_options[datasource].      * depending on $_options[transport].
308      * (main dispatching level)      * (main dispatching level)
309      *      *
310      * 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 393  class DataSource_Generic extends DesignP
393          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
394    
395                  // copy parameter from query to locator                  // copy parameter from query to locator
396                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
397                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
398                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
399                                    
400        /**        /**
401         * <!-- Autodia -->         * <!-- Autodia -->
# Line 337  class DataSource_Generic extends DesignP Line 405  class DataSource_Generic extends DesignP
405         */         */
406    
407                  // build master locator                  // build master locator
408                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
409                  //exit;                  //exit;
410                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
411                                    
# Line 374  class DataSource_Generic extends DesignP Line 442  class DataSource_Generic extends DesignP
442      // pre-flight: check locator metadata      // pre-flight: check locator metadata
443        //$locator->build();        //$locator->build();
444        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
445          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
446          exit;          //exit;
447           //return;           return;
448        }        }
449    
450  //exit;  //exit;
# Line 435  class DataSource_Generic extends DesignP Line 503  class DataSource_Generic extends DesignP
503          // ... resolves this._modules.adapter._id to this._modules.adapter._module          // ... resolves this._modules.adapter._id to this._modules.adapter._module
504                    
505          switch ($locator->_adapter_type) {          switch ($locator->_adapter_type) {
506    
507            case 'phpHtmlLib':            case 'phpHtmlLib':
508              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
509                $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
             $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');  
510                            
511              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
512              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
513              // Exporter::export_symbol(from, to)              // Exporter::export_symbol(from, to)
514              $this->set_adapter_options($this);              $this->set_adapter_options($this);
515                break;
516    
517              // NEW [2003-04-17]: Freedom for the adapter!
518              // phpHtmlLib didn't have a tree widget, but PEAR does.
519              // So: Free us from the phpHtmlLib-adapter in this case.
520              case 'free':
521                $this->set_adapter_module('DataSource::Adapter::Free');
522                $this->set_adapter_options($this);
523              break;              break;
524    
525            default:            default:
526              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
527              break;              break;
528          }          }
529    
# Line 643  class DataSource_Generic extends DesignP Line 718  class DataSource_Generic extends DesignP
718        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
719          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
720            case 'data':            case 'data':
721              //$command = 'queryData';              $command = 'queryData';
722              $command = 'getObjects';   // FIXME!!!              
723                //$command = 'getObjects';   // FIXME!!!
724              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
725    /*
726              $args = array();              $args = array();
727              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
728                case 'object':                case 'objects':
729                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
730                    $msg = "_query[vartype] == 'object' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
731                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
732                  }                  }
733                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
734                  break;                  break;
735              }              }
736              break;   */
737                $query_args = array();
738                
739                 $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
740                 switch ($this->_query[abstract_type]) {
741                  case 'item':
742                    if (!$this->_query[nodename] && $this->_query[action] != 'create') {
743                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
744                      user_error($msg_prefix . $msg);
745                    } elseif($this->_query[action] == 'create' && $this->_query[parent]) {
746                      if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
747                      if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
748                      $query_args[nodename] = $this->_query[ident];
749                      $query_args[parent][guid] = $this->_query[parent][guid];
750                      $query_args[parent][nodename] = $this->_query[parent][nodename];
751                    } else {
752                      $query_args[guid] = $this->_query[ident];
753                      $query_args[nodename] = $this->_query[nodename];
754                    }
755                    break;
756                  case 'list':
757                    if (!$this->_query[nodename]) {
758                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
759                      user_error($msg_prefix . $msg);
760                    }
761                    //array_push($query_args, $this->_query[nodename]);
762                    $query_args[nodename] = $this->_query[nodename];
763                    if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; }
764                    break;
765                  case 'tree':
766                    /*
767                    if (!$this->_query[nodename]) {
768                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
769                      user_error($msg_prefix . $msg);
770                    }
771                    */
772                    $query_args[guid] = $this->_query[ident];
773                    //$query_args[nodename] = $this->_query[nodename];
774                    break;
775                  default:
776                    $msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'.";
777                    user_error($msg_prefix . $msg);
778                    break;
779                }
780                
781                // filter???
782                print "Filter: " . Dumper($this->_query[filter]) . "<br>";
783                if ($this->_query[filter]) {
784                  $query_args[filter] = $this->_query[filter];
785                }
786                
787                // dispatch action
788                print "Action: " . $this->_query[action] . "<br>";
789                if ($this->_query[action] == 'write') {
790                 $query_args[action] = $this->_query[action];
791                 $query_args[data] = $this->_query[data];
792                } elseif ($this->_query[action] == 'delete') {
793                 $query_args[action] = $this->_query[action];
794                } elseif ($this->_query[action] == 'create') {
795                   $query_args[action] = $this->_query[action];
796                }
797                
798                $args = array(
799                              'data_type' => $this->_query[abstract_type],
800                              'query_args' => $query_args
801                              );
802               break;
803    
804              // querySchema
805            case 'schema':            case 'schema':
806                //print "Testing schema:" . "<br>";
807              $command = 'querySchema';              $command = 'querySchema';
808                $args = array( $this->_query[filter] );
809                break;
810                
811              // remoteMethod
812              case 'method':
813                $command = $this->_query[method];
814                $args = $this->_query[args];
815              break;              break;
816    
817          }          }
818                
819          
820            // FIXME: bad behaviour?
821            if (!is_array($args)) { $args = array( $args ); }
822                    
823          /*          /*
824          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 694  class DataSource_Generic extends DesignP Line 851  class DataSource_Generic extends DesignP
851                
852    }    }
853    
854    
855    
856          function &fetch_result() {          function &fetch_result() {
857    
858          //print Dumper($this);
859                
860        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
861    
862        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
863        $args = $this->_locator->_call[_arguments];  
864                //print Dumper($call);
865          //return;
866    
867        // pre-flight checks        // pre-flight checks
868          if (!$method) {          if (!$call[method]) {
869            $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.";
870                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
871            return;            return;
872          }          }
873    
# Line 712  class DataSource_Generic extends DesignP Line 875  class DataSource_Generic extends DesignP
875    
876        // do remote call here and get result        // do remote call here and get result
877        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
878          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
879                    
880                    
881          // 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 886  class DataSource_Generic extends DesignP
886          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
887    
888        // trace        // trace
889          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
890            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
891            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
892            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>";
893              $this->draw_status_box();
894          }          }
895            
896          return $this->_result;          return $this->_result;
897    
898          }          }
899    
900      function draw_status_box() {
901    
902        static $boxcount;
903        
904        $boxcount++;
905    
906        $box = container();
907    
908        // box style
909        $style = container(
910          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
911          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
912        );
913        $box->add( $style );
914        
915        // box content
916        $statusbox = html_div('box_dsg');
917        $statusbox->add( html_b("DataSource::Generic"), html_br() );
918        $locatorbox = html_div('box_dsg');
919        $locatorbox->set_id("locatorbox_$boxcount");
920        $locatorbox->add( Dumper($this->_locator) );
921        
922        // FIXME: ie/mozilla?
923        //$locatorbox->set_style('display:none;');
924        //$locatorbox->set_style('visibility:hidden;');
925        // already duplicate inside Tracer!!!
926        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
927        
928        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
929        $call = $this->_locator->get_call();
930        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
931        if (sizeof($call[args])) {
932          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
933        }
934        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
935        $box->add( $statusbox );
936    
937        //print $box->render();
938        trace( $box );
939    
940      }
941    
942    
943    function &query_data() {    function &query_data() {
944      //print "query!<br/>";      //print "query!<br/>";
# Line 747  class DataSource_Generic extends DesignP Line 954  class DataSource_Generic extends DesignP
954    function &get_result() {    function &get_result() {
955      return $this->_result;      return $this->_result;
956    }    }
957      
958      function get_result_count() {
959        return $this->_result_count;
960      }
961                    
962  }  }
963    

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

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