/[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.8 by jonen, Thu Mar 20 07:22:14 2003 UTC revision 1.23 by jonen, Mon Jul 14 10:02:32 2003 UTC
# Line 9  Line 9 
9   */   */
10    
11  /**  /**
12   * <b>Cvs-Log:</b>   * Cvs-Log:
13   *   *
  * <pre>  
14   * $Id$   * $Id$
15   *   *
16   * $Log$   * $Log$
17     * Revision 1.23  2003/07/14 10:02:32  jonen
18     * removed debug dumper
19     *
20     * Revision 1.22  2003/06/06 04:25:45  joko
21     * fix: query args get encapsulated once more
22     *
23     * Revision 1.21  2003/05/10 18:14:50  jonen
24     * + implements 'create' of item (query mapping part)
25     *
26     * 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     * 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     * Revision 1.18  2003/04/11 00:55:49  joko
36     * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
37     *
38     * Revision 1.17  2003/04/09 02:07:33  joko
39     * CHANGE: renamed key 'classname' through 'nodename'
40     *
41     * 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     * Revision 1.15  2003/04/06 04:46:33  joko
47     * renamed linking function
48     * mozilla fixes
49     *
50     * Revision 1.14  2003/04/04 21:19:21  joko
51     * modified exception handling (enhanced, purged redundant code)
52     *
53     * Revision 1.13  2003/04/04 02:37:14  jonen
54     * _query[action] == write
55     *
56     * Revision 1.12  2003/03/29 08:00:48  joko
57     * modified ErrorBoxing
58     *
59     * Revision 1.11  2003/03/28 06:45:26  joko
60     * VERBOSE mode
61     *
62     * Revision 1.10  2003/03/28 03:01:02  joko
63     * more fancy debugging-output
64     *
65     * Revision 1.9  2003/03/27 16:24:26  jonen
66     * + mugled namespace
67     * + added enhanced 'queryData'
68     *
69   * Revision 1.8  2003/03/20 07:22:14  jonen   * Revision 1.8  2003/03/20 07:22:14  jonen
70   * + modified case 'object' to 'objects'   * + modified case 'object' to 'objects'
71   *   (cause its loads all *objects* of a given classname)   *   (cause its loads all *objects* of a given classname)
# Line 63  Line 114 
114   *   *
115   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
116   * + initial commit   * + initial commit
  * </pre>  
117   *   *
118   */   */
119    
# Line 260  class DataSource_Generic extends DesignP Line 310  class DataSource_Generic extends DesignP
310      * other presets.      * other presets.
311      *      *
312      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
313      * depending on $_options[datasource].      * depending on $_options[transport].
314      * (main dispatching level)      * (main dispatching level)
315      *      *
316      * The structure of a full blown locator looks like this:      * The structure of a full blown locator looks like this:
# Line 349  class DataSource_Generic extends DesignP Line 399  class DataSource_Generic extends DesignP
399          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
400    
401                  // copy parameter from query to locator                  // copy parameter from query to locator
402                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
403                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
404                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
405                                    
406        /**        /**
407         * <!-- Autodia -->         * <!-- Autodia -->
# Line 361  class DataSource_Generic extends DesignP Line 411  class DataSource_Generic extends DesignP
411         */         */
412    
413                  // build master locator                  // build master locator
414                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
415                  //exit;                  //exit;
416                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
417                                    
# Line 398  class DataSource_Generic extends DesignP Line 448  class DataSource_Generic extends DesignP
448      // pre-flight: check locator metadata      // pre-flight: check locator metadata
449        //$locator->build();        //$locator->build();
450        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
451          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
452          exit;          //exit;
453           //return;           return;
454        }        }
455    
456  //exit;  //exit;
# Line 459  class DataSource_Generic extends DesignP Line 509  class DataSource_Generic extends DesignP
509          // ... resolves this._modules.adapter._id to this._modules.adapter._module          // ... resolves this._modules.adapter._id to this._modules.adapter._module
510                    
511          switch ($locator->_adapter_type) {          switch ($locator->_adapter_type) {
512    
513            case 'phpHtmlLib':            case 'phpHtmlLib':
514              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
515                $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
             $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');  
516                            
517              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
518              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
519              // Exporter::export_symbol(from, to)              // Exporter::export_symbol(from, to)
520              $this->set_adapter_options($this);              $this->set_adapter_options($this);
521                break;
522    
523              // 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;              break;
530    
531            default:            default:
532              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
533              break;              break;
534          }          }
535    
# Line 667  class DataSource_Generic extends DesignP Line 724  class DataSource_Generic extends DesignP
724        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
725          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
726            case 'data':            case 'data':
727              //$command = 'queryData';              $command = 'queryData';
728              $command = 'getObjects';   // FIXME!!!              
729                //$command = 'getObjects';   // FIXME!!!
730              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
731    /*
732              $args = array();              $args = array();
733              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
734                case 'objects':                case 'objects':
735                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
736                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
737                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
738                  }                  }
739                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
740                  break;                  break;
741              }              }
742              break;   */
743                $query_args = array();
744                
745                 $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
746                 switch ($this->_query[abstract_type]) {
747                  case 'item':
748                    if (!$this->_query[nodename] && $this->_query[action] != 'create') {
749                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
750                      user_error($msg_prefix . $msg);
751                    } 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                    }
761                    break;
762                  case 'list':
763                    if (!$this->_query[nodename]) {
764                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
765                      user_error($msg_prefix . $msg);
766                    }
767                    //array_push($query_args, $this->_query[nodename]);
768                    $query_args[nodename] = $this->_query[nodename];
769                    if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; }
770                    break;
771                  case 'tree':
772                    /*
773                    if (!$this->_query[nodename]) {
774                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
775                      user_error($msg_prefix . $msg);
776                    }
777                    */
778                    $query_args[guid] = $this->_query[ident];
779                    //$query_args[nodename] = $this->_query[nodename];
780                    break;
781                  default:
782                    $msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'.";
783                    user_error($msg_prefix . $msg);
784                    break;
785                }
786                
787                // filter???
788                //print "Filter: " . Dumper($this->_query[filter]) . "<br>";
789                if ($this->_query[filter]) {
790                  $query_args[filter] = $this->_query[filter];
791                }
792                
793                // dispatch action
794                //print "Action: " . $this->_query[action] . "<br>";
795                if ($this->_query[action] == 'write') {
796                 $query_args[action] = $this->_query[action];
797                 $query_args[data] = $this->_query[data];
798                } elseif ($this->_query[action] == 'delete') {
799                 $query_args[action] = $this->_query[action];
800                } elseif ($this->_query[action] == 'create') {
801                   $query_args[action] = $this->_query[action];
802                }
803                
804                $args = array(
805                              'data_type' => $this->_query[abstract_type],
806                              'query_args' => $query_args
807                              );
808               break;
809    
810              // querySchema
811            case 'schema':            case 'schema':
812                //print "Testing schema:" . "<br>";
813              $command = 'querySchema';              $command = 'querySchema';
814                $args = array( $this->_query[filter] );
815                break;
816                
817              // remoteMethod
818              case 'method':
819                $command = $this->_query[method];
820                //$args = $this->_query[args];
821                // FIX
822                $args = array( $this->_query[args] );
823              break;              break;
824    
825          }          }
826                
827          
828            // FIXME: bad behaviour?
829            if (!is_array($args)) { $args = array( $args ); }
830            
831            //print Dumper($args);
832                    
833          /*          /*
834          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 718  class DataSource_Generic extends DesignP Line 861  class DataSource_Generic extends DesignP
861                
862    }    }
863    
864    
865    
866          function &fetch_result() {          function &fetch_result() {
867    
868          //print Dumper($this);
869                
870        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
871    
872        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
873        $args = $this->_locator->_call[_arguments];  
874                //print Dumper($call);
875          //return;
876    
877        // pre-flight checks        // pre-flight checks
878          if (!$method) {          if (!$call[method]) {
879            $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.";
880                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
881            return;            return;
882          }          }
883    
# Line 736  class DataSource_Generic extends DesignP Line 885  class DataSource_Generic extends DesignP
885    
886        // do remote call here and get result        // do remote call here and get result
887        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
888          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
889                    
890                    
891          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result
# Line 747  class DataSource_Generic extends DesignP Line 896  class DataSource_Generic extends DesignP
896          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
897    
898        // trace        // trace
899          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
900            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
901            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
902            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>";
903              $this->draw_status_box();
904          }          }
905            
906          return $this->_result;          return $this->_result;
907    
908          }          }
909    
910      function draw_status_box() {
911    
912        static $boxcount;
913        
914        $boxcount++;
915    
916        $box = container();
917    
918        // box style
919        $style = container(
920          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
921          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
922        );
923        $box->add( $style );
924        
925        // box content
926        $statusbox = html_div('box_dsg');
927        $statusbox->add( html_b("DataSource::Generic"), html_br() );
928        $locatorbox = html_div('box_dsg');
929        $locatorbox->set_id("locatorbox_$boxcount");
930        $locatorbox->add( Dumper($this->_locator) );
931        
932        // FIXME: ie/mozilla?
933        //$locatorbox->set_style('display:none;');
934        //$locatorbox->set_style('visibility:hidden;');
935        // already duplicate inside Tracer!!!
936        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
937        
938        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
939        $call = $this->_locator->get_call();
940        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
941        if (sizeof($call[args])) {
942          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
943        }
944        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
945        $box->add( $statusbox );
946    
947        //print $box->render();
948        trace( $box );
949    
950      }
951    
952    
953    function &query_data() {    function &query_data() {
954      //print "query!<br/>";      //print "query!<br/>";
# Line 771  class DataSource_Generic extends DesignP Line 964  class DataSource_Generic extends DesignP
964    function &get_result() {    function &get_result() {
965      return $this->_result;      return $this->_result;
966    }    }
967      
968      function get_result_count() {
969        return $this->_result_count;
970      }
971                    
972  }  }
973    

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.23

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