/[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.9 by jonen, Thu Mar 27 16:24:26 2003 UTC revision 1.18 by joko, Fri Apr 11 00:55:49 2003 UTC
# Line 15  Line 15 
15   * $Id$   * $Id$
16   *   *
17   * $Log$   * $Log$
18     * Revision 1.18  2003/04/11 00:55:49  joko
19     * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
20     *
21     * Revision 1.17  2003/04/09 02:07:33  joko
22     * CHANGE: renamed key 'classname' through 'nodename'
23     *
24     * Revision 1.16  2003/04/08 17:55:20  joko
25     * CHANGE: renamed property 'datasource' to 'transport'
26     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
27     * minor fixes: updated logging/debugging messages
28     *
29     * Revision 1.15  2003/04/06 04:46:33  joko
30     * renamed linking function
31     * mozilla fixes
32     *
33     * Revision 1.14  2003/04/04 21:19:21  joko
34     * modified exception handling (enhanced, purged redundant code)
35     *
36     * Revision 1.13  2003/04/04 02:37:14  jonen
37     * _query[action] == write
38     *
39     * Revision 1.12  2003/03/29 08:00:48  joko
40     * modified ErrorBoxing
41     *
42     * Revision 1.11  2003/03/28 06:45:26  joko
43     * VERBOSE mode
44     *
45     * Revision 1.10  2003/03/28 03:01:02  joko
46     * more fancy debugging-output
47     *
48   * Revision 1.9  2003/03/27 16:24:26  jonen   * Revision 1.9  2003/03/27 16:24:26  jonen
49   * + mugled namespace   * + mugled namespace
50   * + added enhanced 'queryData'   * + added enhanced 'queryData'
# Line 264  class DataSource_Generic extends DesignP Line 294  class DataSource_Generic extends DesignP
294      * other presets.      * other presets.
295      *      *
296      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
297      * depending on $_options[datasource].      * depending on $_options[transport].
298      * (main dispatching level)      * (main dispatching level)
299      *      *
300      * The structure of a full blown locator looks like this:      * The structure of a full blown locator looks like this:
# Line 353  class DataSource_Generic extends DesignP Line 383  class DataSource_Generic extends DesignP
383          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
384    
385                  // copy parameter from query to locator                  // copy parameter from query to locator
386                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
387                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
388                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
389                                    
390        /**        /**
391         * <!-- Autodia -->         * <!-- Autodia -->
# Line 365  class DataSource_Generic extends DesignP Line 395  class DataSource_Generic extends DesignP
395         */         */
396    
397                  // build master locator                  // build master locator
398                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
399                  //exit;                  //exit;
400                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
401                                    
# Line 402  class DataSource_Generic extends DesignP Line 432  class DataSource_Generic extends DesignP
432      // pre-flight: check locator metadata      // pre-flight: check locator metadata
433        //$locator->build();        //$locator->build();
434        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
435          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
436          exit;          //exit;
437           //return;           return;
438        }        }
439    
440  //exit;  //exit;
# Line 476  class DataSource_Generic extends DesignP Line 506  class DataSource_Generic extends DesignP
506    
507              break;              break;
508            default:            default:
509              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected!");
510              break;              break;
511          }          }
512    
# Line 672  class DataSource_Generic extends DesignP Line 702  class DataSource_Generic extends DesignP
702          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
703            case 'data':            case 'data':
704              $command = 'queryData';              $command = 'queryData';
705                
706              //$command = 'getObjects';   // FIXME!!!              //$command = 'getObjects';   // FIXME!!!
707              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
708  /*  /*
# Line 680  class DataSource_Generic extends DesignP Line 711  class DataSource_Generic extends DesignP
711                case 'objects':                case 'objects':
712                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
713                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
714                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
715                  }                  }
716                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
717                  break;                  break;
# Line 689  class DataSource_Generic extends DesignP Line 720  class DataSource_Generic extends DesignP
720              $query_args = array();              $query_args = array();
721               switch ($this->_query[abstract_type]) {               switch ($this->_query[abstract_type]) {
722                case 'list':                case 'list':
723                  if (!$this->_query[classname]) {                  if (!$this->_query[nodename]) {
724                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
725                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
726                  }                  }
727                  //array_push($query_args, $this->_query[classname]);                  //array_push($query_args, $this->_query[nodename]);
728                  $query_args[classname] = $this->_query[classname];                  $query_args[nodename] = $this->_query[nodename];
729                  break;                  break;
730                case 'item':                case 'item':
731                  if (!$this->_query[classname]) {                  if (!$this->_query[nodename]) {
732                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
733                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
734                  }                  }
735                  $query_args[guid] = $this->_query[ident];                  $query_args[guid] = $this->_query[ident];
736                  $query_args[classname] = $this->_query[classname];                  $query_args[nodename] = $this->_query[nodename];
737                  break;                                break;              
738              }              }
739                
740                // dispatch action
741                if ($this->_query[action] == 'write') {
742                 $query_args[action] = $this->_query[action];
743                 $query_args[data] = $this->_query[data];
744                } elseif ($this->_query[action] == 'delete') {
745                 $query_args[action] = $this->_query[action];
746                }
747              $args = array(              $args = array(
748                            'data_type' => $this->_query[abstract_type],                            'data_type' => $this->_query[abstract_type],
749                            'query_args' => $query_args                            'query_args' => $query_args
# Line 715  class DataSource_Generic extends DesignP Line 754  class DataSource_Generic extends DesignP
754            case 'schema':            case 'schema':
755              //print "Testing schema:" . "<br>";              //print "Testing schema:" . "<br>";
756              $command = 'querySchema';              $command = 'querySchema';
757                $args = array( $this->_query[filter] );
758                break;
759                
760              // remoteMethod
761              case 'method':
762                $command = $this->_query[method];
763                $args = $this->_query[args];
764              break;              break;
765    
766          }          }
767                
768          
769            // FIXME: bad behaviour?
770            if (!is_array($args)) { $args = array( $args ); }
771                    
772          /*          /*
773          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 750  class DataSource_Generic extends DesignP Line 800  class DataSource_Generic extends DesignP
800                
801    }    }
802    
803    
804    
805          function &fetch_result() {          function &fetch_result() {
806                
807        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
808    
809        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
810        $args = $this->_locator->_call[_arguments];        //print Dumper($call);
811          
812        // pre-flight checks        // pre-flight checks
813          if (!$method) {          if (!$call[method]) {
814            $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.";
815                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
816            return;            return;
817          }          }
818    
# Line 768  class DataSource_Generic extends DesignP Line 820  class DataSource_Generic extends DesignP
820    
821        // do remote call here and get result        // do remote call here and get result
822        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
823          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
824                    
825                    
826          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result
# Line 779  class DataSource_Generic extends DesignP Line 831  class DataSource_Generic extends DesignP
831          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
832    
833        // trace        // trace
834          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
835            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
836            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
837            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>";
838              $this->draw_status_box();
839          }          }
840            
841          return $this->_result;          return $this->_result;
842    
843          }          }
844    
845      function draw_status_box() {
846    
847        static $boxcount;
848        
849        $boxcount++;
850    
851        $box = container();
852    
853        // box style
854        $style = container(
855          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
856          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
857        );
858        $box->add( $style );
859        
860        // box content
861        $statusbox = html_div('box_dsg');
862        $statusbox->add( html_b("DataSource::Generic"), html_br() );
863        $locatorbox = html_div('box_dsg');
864        $locatorbox->set_id("locatorbox_$boxcount");
865        $locatorbox->add( Dumper($this->_locator) );
866        
867        // FIXME: ie/mozilla?
868        //$locatorbox->set_style('display:none;');
869        //$locatorbox->set_style('visibility:hidden;');
870        // already duplicate inside Tracer!!!
871        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
872        
873        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
874        $call = $this->_locator->get_call();
875        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
876        if (sizeof($call[args])) {
877          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
878        }
879        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
880        $box->add( $statusbox );
881    
882        //print $box->render();
883        trace( $box );
884    
885      }
886    
887    
888    function &query_data() {    function &query_data() {
889      //print "query!<br/>";      //print "query!<br/>";
# Line 803  class DataSource_Generic extends DesignP Line 899  class DataSource_Generic extends DesignP
899    function &get_result() {    function &get_result() {
900      return $this->_result;      return $this->_result;
901    }    }
902      
903      function get_result_count() {
904        return $this->_result_count;
905      }
906                    
907  }  }
908    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.18

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