/[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.27 by joko, Tue Jun 15 12:50:48 2004 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.27  2004/06/15 12:50:48  joko
18     * disabled caching in "datasource_handler_call"
19     *
20     * Revision 1.26  2003/12/14 01:53:42  jonen
21     * implemented 'SELECT' mode for selecting existing object-refereneces as child-nodes
22     *
23     * Revision 1.25  2003/11/17 18:01:03  jonen
24     * bugfix: php cannot use perl-syntax!! ;-)
25     *
26     * Revision 1.23  2003/07/14 10:02:32  jonen
27     * removed debug dumper
28     *
29     * Revision 1.22  2003/06/06 04:25:45  joko
30     * fix: query args get encapsulated once more
31     *
32     * Revision 1.21  2003/05/10 18:14:50  jonen
33     * + implements 'create' of item (query mapping part)
34     *
35     * Revision 1.20  2003/04/19 16:07:15  jonen
36     * + added '_query[list_meta]' at 'queryData' needed for meta query args
37     *    (e.g. at UserManagment)
38     *
39     * Revision 1.19  2003/04/18 15:40:51  joko
40     * NEW: tree data handling
41     *   introduced new adapter: DataSource::Adapter::Free
42     *   enhanced datasource_handler_buildoptions: now handles a) case 'tree'  b) _query[filter]
43     *
44     * Revision 1.18  2003/04/11 00:55:49  joko
45     * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
46     *
47     * Revision 1.17  2003/04/09 02:07:33  joko
48     * CHANGE: renamed key 'classname' through 'nodename'
49     *
50     * Revision 1.16  2003/04/08 17:55:20  joko
51     * CHANGE: renamed property 'datasource' to 'transport'
52     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
53     * minor fixes: updated logging/debugging messages
54     *
55     * Revision 1.15  2003/04/06 04:46:33  joko
56     * renamed linking function
57     * mozilla fixes
58     *
59     * Revision 1.14  2003/04/04 21:19:21  joko
60     * modified exception handling (enhanced, purged redundant code)
61     *
62     * Revision 1.13  2003/04/04 02:37:14  jonen
63     * _query[action] == write
64     *
65     * Revision 1.12  2003/03/29 08:00:48  joko
66     * modified ErrorBoxing
67     *
68     * Revision 1.11  2003/03/28 06:45:26  joko
69     * VERBOSE mode
70     *
71     * Revision 1.10  2003/03/28 03:01:02  joko
72     * more fancy debugging-output
73     *
74     * Revision 1.9  2003/03/27 16:24:26  jonen
75     * + mugled namespace
76     * + added enhanced 'queryData'
77     *
78   * Revision 1.8  2003/03/20 07:22:14  jonen   * Revision 1.8  2003/03/20 07:22:14  jonen
79   * + modified case 'object' to 'objects'   * + modified case 'object' to 'objects'
80   *   (cause its loads all *objects* of a given classname)   *   (cause its loads all *objects* of a given classname)
# Line 63  Line 123 
123   *   *
124   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
125   * + initial commit   * + initial commit
  * </pre>  
126   *   *
127   */   */
128    
# Line 260  class DataSource_Generic extends DesignP Line 319  class DataSource_Generic extends DesignP
319      * other presets.      * other presets.
320      *      *
321      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
322      * depending on $_options[datasource].      * depending on $_options[transport].
323      * (main dispatching level)      * (main dispatching level)
324      *      *
325      * 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 408  class DataSource_Generic extends DesignP
408          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
409    
410                  // copy parameter from query to locator                  // copy parameter from query to locator
411                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
412                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
413                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
414                                    
415        /**        /**
416         * <!-- Autodia -->         * <!-- Autodia -->
# Line 361  class DataSource_Generic extends DesignP Line 420  class DataSource_Generic extends DesignP
420         */         */
421    
422                  // build master locator                  // build master locator
423                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
424                  //exit;                  //exit;
425                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
426                                    
# Line 398  class DataSource_Generic extends DesignP Line 457  class DataSource_Generic extends DesignP
457      // pre-flight: check locator metadata      // pre-flight: check locator metadata
458        //$locator->build();        //$locator->build();
459        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
460          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
461          exit;          //exit;
462           //return;           return;
463        }        }
464    
465  //exit;  //exit;
# Line 459  class DataSource_Generic extends DesignP Line 518  class DataSource_Generic extends DesignP
518          // ... resolves this._modules.adapter._id to this._modules.adapter._module          // ... resolves this._modules.adapter._id to this._modules.adapter._module
519                    
520          switch ($locator->_adapter_type) {          switch ($locator->_adapter_type) {
521    
522            case 'phpHtmlLib':            case 'phpHtmlLib':
523              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
524                $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
             $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');  
525                            
526              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
527              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
528              // Exporter::export_symbol(from, to)              // Exporter::export_symbol(from, to)
529              $this->set_adapter_options($this);              $this->set_adapter_options($this);
530                break;
531    
532              // NEW [2003-04-17]: Freedom for the adapter!
533              // phpHtmlLib didn't have a tree widget, but PEAR does.
534              // So: Free us from the phpHtmlLib-adapter in this case.
535              case 'free':
536                $this->set_adapter_module('DataSource::Adapter::Free');
537                $this->set_adapter_options($this);
538              break;              break;
539    
540            default:            default:
541              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
542              break;              break;
543          }          }
544    
# Line 635  class DataSource_Generic extends DesignP Line 701  class DataSource_Generic extends DesignP
701                
702                
703        //$this->set_component_name( $proxy_name );        //$this->set_component_name( $proxy_name );
704        $this->set_component_options( $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );        $this->set_component_options( $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 0 ) ) );
705        //print Dumper($this);        //print Dumper($this);
706        //exit;        //exit;
707                
# Line 667  class DataSource_Generic extends DesignP Line 733  class DataSource_Generic extends DesignP
733        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
734          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
735            case 'data':            case 'data':
736              //$command = 'queryData';              $command = 'queryData';
737              $command = 'getObjects';   // FIXME!!!              
738                //$command = 'getObjects';   // FIXME!!!
739              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
740    /*
741              $args = array();              $args = array();
742              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
743                case 'objects':                case 'objects':
744                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
745                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
746                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
747                  }                  }
748                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
749                  break;                  break;
750              }              }
751              break;   */
752                $query_args = array();
753                
754                 $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
755                 switch ($this->_query[abstract_type]) {
756                  case 'item':
757                    if (!$this->_query[nodename] && $this->_query[action] != 'create') {
758                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
759                      user_error($msg_prefix . $msg);
760                    } elseif($this->_query[action] == 'create' && $this->_query[parent]) {
761                      if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
762                      if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
763                      $query_args[nodename] = $this->_query[ident];
764                      $query_args[parent][guid] = $this->_query[parent][guid];
765                      $query_args[parent][nodename] = $this->_query[parent][nodename];
766                    } elseif($this->_query[parent]) {
767                      $query_args[guid] = $this->_query[ident];
768                      $query_args[nodename] = $this->_query[nodename];
769                      $query_args[parent][guid] = $this->_query[parent][guid];
770                      $query_args[parent][nodename] = $this->_query[parent][nodename];
771                    } else {
772                      $query_args[guid] = $this->_query[ident];
773                      $query_args[nodename] = $this->_query[nodename];
774                      // 2003-11-17 NEW: use expand flag for real obj expand at backend
775                      if ($this->_query[expand]) {$query_args[expand] = 1; }
776                    }
777                    //print "generic_source->debug: args " . Dumper($query_args) . "<br>";
778                    break;
779                  case 'list':
780                    if (!$this->_query[nodename]) {
781                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
782                      user_error($msg_prefix . $msg);
783                    } elseif($this->_query[parent]) {
784                      //if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
785                      //if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
786                      //$query_args[nodename] = $this->_query[ident];
787                      $query_args[parent][guid] = $this->_query[parent][guid];
788                      $query_args[parent][nodename] = $this->_query[parent][nodename];
789                    }
790                    //array_push($query_args, $this->_query[nodename]);
791                    $query_args[nodename] = $this->_query[nodename];
792                    if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; }
793                    break;
794                  case 'tree':
795                    /*
796                    if (!$this->_query[nodename]) {
797                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
798                      user_error($msg_prefix . $msg);
799                    }
800                    */
801                    $query_args[guid] = $this->_query[ident];
802                    //$query_args[nodename] = $this->_query[nodename];
803                    break;
804                  default:
805                    $msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'.";
806                    user_error($msg_prefix . $msg);
807                    break;
808                }
809                
810                // filter???
811                //print "Filter: " . Dumper($this->_query[filter]) . "<br>";
812                if ($this->_query[filter]) {
813                  $query_args[filter] = $this->_query[filter];
814                }
815                
816                // dispatch action
817                //print "Action: " . $this->_query[action] . "<br>";
818                if ($this->_query[action] == 'write') {
819                 $query_args[action] = $this->_query[action];
820                 $query_args[data] = $this->_query[data];
821                } elseif ($this->_query[action] == 'delete') {
822                 $query_args[action] = $this->_query[action];
823                } elseif ($this->_query[action] == 'create') {
824                   $query_args[action] = $this->_query[action];
825                } elseif ($this->_query[action] == 'select') {
826                   $query_args[action] = $this->_query[action];
827                }
828                
829                $args = array(
830                              'data_type' => $this->_query[abstract_type],
831                              'query_args' => $query_args
832                              );
833               break;
834    
835              // querySchema
836            case 'schema':            case 'schema':
837                //print "Testing schema:" . "<br>";
838              $command = 'querySchema';              $command = 'querySchema';
839                $args = array( $this->_query[filter] );
840                break;
841                
842              // remoteMethod
843              case 'method':
844                $command = $this->_query[method];
845                //$args = $this->_query[args];
846                // FIX
847                $args = array( $this->_query[args] );
848              break;              break;
849    
850          }          }
851                
852          
853            // FIXME: bad behaviour?
854            if (!is_array($args)) { $args = array( $args ); }
855            
856            //print Dumper($args);
857                    
858          /*          /*
859          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 718  class DataSource_Generic extends DesignP Line 886  class DataSource_Generic extends DesignP
886                
887    }    }
888    
889    
890    
891          function &fetch_result() {          function &fetch_result() {
892    
893          //print Dumper($this);
894                
895        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
896    
897        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
898        $args = $this->_locator->_call[_arguments];  
899                //print Dumper($call);
900          //return;
901    
902        // pre-flight checks        // pre-flight checks
903          if (!$method) {          if (!$call[method]) {
904            $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.";
905                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
906            return;            return;
907          }          }
908    
# Line 736  class DataSource_Generic extends DesignP Line 910  class DataSource_Generic extends DesignP
910    
911        // do remote call here and get result        // do remote call here and get result
912        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
913          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
914                    
915                    
916          // 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 921  class DataSource_Generic extends DesignP
921          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
922    
923        // trace        // trace
924          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
925            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
926            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
927            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>";
928              $this->draw_status_box();
929          }          }
930            
931          return $this->_result;          return $this->_result;
932    
933          }          }
934    
935      function draw_status_box() {
936    
937        static $boxcount;
938        
939        $boxcount++;
940    
941        $box = container();
942    
943        // box style
944        $style = container(
945          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
946          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
947        );
948        $box->add( $style );
949        
950        // box content
951        $statusbox = html_div('box_dsg');
952        $statusbox->add( html_b("DataSource::Generic"), html_br() );
953        $locatorbox = html_div('box_dsg');
954        $locatorbox->set_id("locatorbox_$boxcount");
955        $locatorbox->add( Dumper($this->_locator) );
956        
957        // FIXME: ie/mozilla?
958        //$locatorbox->set_style('display:none;');
959        //$locatorbox->set_style('visibility:hidden;');
960        // already duplicate inside Tracer!!!
961        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
962        
963        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
964        $call = $this->_locator->get_call();
965        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
966        if (sizeof($call[args])) {
967          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
968        }
969        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
970        $box->add( $statusbox );
971    
972        //print $box->render();
973        trace( $box );
974    
975      }
976    
977    
978    function &query_data() {    function &query_data() {
979      //print "query!<br/>";      //print "query!<br/>";
# Line 771  class DataSource_Generic extends DesignP Line 989  class DataSource_Generic extends DesignP
989    function &get_result() {    function &get_result() {
990      return $this->_result;      return $this->_result;
991    }    }
992      
993      function get_result_count() {
994        return $this->_result_count;
995      }
996                    
997  }  }
998    

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

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