/[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.12 by joko, Sat Mar 29 08:00:48 2003 UTC revision 1.19 by joko, Fri Apr 18 15:40:51 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.19  2003/04/18 15:40:51  joko
18     * NEW: tree data handling
19     *   introduced new adapter: DataSource::Adapter::Free
20     *   enhanced datasource_handler_buildoptions: now handles a) case 'tree'  b) _query[filter]
21     *
22     * Revision 1.18  2003/04/11 00:55:49  joko
23     * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
24     *
25     * Revision 1.17  2003/04/09 02:07:33  joko
26     * CHANGE: renamed key 'classname' through 'nodename'
27     *
28     * Revision 1.16  2003/04/08 17:55:20  joko
29     * CHANGE: renamed property 'datasource' to 'transport'
30     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
31     * minor fixes: updated logging/debugging messages
32     *
33     * Revision 1.15  2003/04/06 04:46:33  joko
34     * renamed linking function
35     * mozilla fixes
36     *
37     * Revision 1.14  2003/04/04 21:19:21  joko
38     * modified exception handling (enhanced, purged redundant code)
39     *
40     * Revision 1.13  2003/04/04 02:37:14  jonen
41     * _query[action] == write
42     *
43   * Revision 1.12  2003/03/29 08:00:48  joko   * Revision 1.12  2003/03/29 08:00:48  joko
44   * modified ErrorBoxing   * modified ErrorBoxing
45   *   *
# Line 76  Line 101 
101   *   *
102   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
103   * + initial commit   * + initial commit
  * </pre>  
104   *   *
105   */   */
106    
# Line 273  class DataSource_Generic extends DesignP Line 297  class DataSource_Generic extends DesignP
297      * other presets.      * other presets.
298      *      *
299      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
300      * depending on $_options[datasource].      * depending on $_options[transport].
301      * (main dispatching level)      * (main dispatching level)
302      *      *
303      * The structure of a full blown locator looks like this:      * The structure of a full blown locator looks like this:
# Line 362  class DataSource_Generic extends DesignP Line 386  class DataSource_Generic extends DesignP
386          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
387    
388                  // copy parameter from query to locator                  // copy parameter from query to locator
389                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
390                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
391                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
392                                    
393        /**        /**
394         * <!-- Autodia -->         * <!-- Autodia -->
# Line 374  class DataSource_Generic extends DesignP Line 398  class DataSource_Generic extends DesignP
398         */         */
399    
400                  // build master locator                  // build master locator
401                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
402                  //exit;                  //exit;
403                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
404                                    
# Line 411  class DataSource_Generic extends DesignP Line 435  class DataSource_Generic extends DesignP
435      // pre-flight: check locator metadata      // pre-flight: check locator metadata
436        //$locator->build();        //$locator->build();
437        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
438          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
439          exit;          //exit;
440           //return;           return;
441        }        }
442    
443  //exit;  //exit;
# Line 472  class DataSource_Generic extends DesignP Line 496  class DataSource_Generic extends DesignP
496          // ... resolves this._modules.adapter._id to this._modules.adapter._module          // ... resolves this._modules.adapter._id to this._modules.adapter._module
497                    
498          switch ($locator->_adapter_type) {          switch ($locator->_adapter_type) {
499    
500            case 'phpHtmlLib':            case 'phpHtmlLib':
501              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
   
502              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
503                            
504              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
505              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
506              // Exporter::export_symbol(from, to)              // Exporter::export_symbol(from, to)
507              $this->set_adapter_options($this);              $this->set_adapter_options($this);
508                break;
509    
510              // NEW [2003-04-17]: Freedom for the adapter!
511              // phpHtmlLib didn't have a tree widget, but PEAR does.
512              // So: Free us from the phpHtmlLib-adapter in this case.
513              case 'free':
514                $this->set_adapter_module('DataSource::Adapter::Free');
515                $this->set_adapter_options($this);
516              break;              break;
517    
518            default:            default:
519              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
520              break;              break;
521          }          }
522    
# Line 681  class DataSource_Generic extends DesignP Line 712  class DataSource_Generic extends DesignP
712          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
713            case 'data':            case 'data':
714              $command = 'queryData';              $command = 'queryData';
715                
716              //$command = 'getObjects';   // FIXME!!!              //$command = 'getObjects';   // FIXME!!!
717              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
718  /*  /*
# Line 689  class DataSource_Generic extends DesignP Line 721  class DataSource_Generic extends DesignP
721                case 'objects':                case 'objects':
722                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
723                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
724                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
725                  }                  }
726                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
727                  break;                  break;
728              }              }
729   */   */
730              $query_args = array();              $query_args = array();
731                
732                 $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
733               switch ($this->_query[abstract_type]) {               switch ($this->_query[abstract_type]) {
734                  case 'item':
735                    if (!$this->_query[nodename]) {
736                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
737                      user_error($msg_prefix . $msg);
738                    }
739                    $query_args[guid] = $this->_query[ident];
740                    $query_args[nodename] = $this->_query[nodename];
741                    break;
742                case 'list':                case 'list':
743                  if (!$this->_query[classname]) {                  if (!$this->_query[nodename]) {
744                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
745                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error($msg_prefix . $msg);
746                  }                  }
747                  //array_push($query_args, $this->_query[classname]);                  //array_push($query_args, $this->_query[nodename]);
748                  $query_args[classname] = $this->_query[classname];                  $query_args[nodename] = $this->_query[nodename];
749                  break;                  break;
750                case 'item':                case 'tree':
751                  if (!$this->_query[classname]) {                  /*
752                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                  if (!$this->_query[nodename]) {
753                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
754                      user_error($msg_prefix . $msg);
755                  }                  }
756                    */
757                  $query_args[guid] = $this->_query[ident];                  $query_args[guid] = $this->_query[ident];
758                  $query_args[classname] = $this->_query[classname];                  //$query_args[nodename] = $this->_query[nodename];
759                  break;                                break;
760                  default:
761                    $msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'.";
762                    user_error($msg_prefix . $msg);
763                    break;
764                }
765                
766                // filter???
767                if ($this->_query[filter]) {
768                  $query_args[filter] = $this->_query[filter];
769                }
770                
771                // dispatch action
772                if ($this->_query[action] == 'write') {
773                 $query_args[action] = $this->_query[action];
774                 $query_args[data] = $this->_query[data];
775                } elseif ($this->_query[action] == 'delete') {
776                 $query_args[action] = $this->_query[action];
777              }              }
778                
779              $args = array(              $args = array(
780                            'data_type' => $this->_query[abstract_type],                            'data_type' => $this->_query[abstract_type],
781                            'query_args' => $query_args                            'query_args' => $query_args
# Line 724  class DataSource_Generic extends DesignP Line 786  class DataSource_Generic extends DesignP
786            case 'schema':            case 'schema':
787              //print "Testing schema:" . "<br>";              //print "Testing schema:" . "<br>";
788              $command = 'querySchema';              $command = 'querySchema';
789                $args = array( $this->_query[filter] );
790                break;
791                
792              // remoteMethod
793              case 'method':
794                $command = $this->_query[method];
795                $args = $this->_query[args];
796              break;              break;
797    
798          }          }
799                
800          
801            // FIXME: bad behaviour?
802            if (!is_array($args)) { $args = array( $args ); }
803                    
804          /*          /*
805          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 762  class DataSource_Generic extends DesignP Line 835  class DataSource_Generic extends DesignP
835    
836    
837          function &fetch_result() {          function &fetch_result() {
838    
839          //print Dumper($this);
840                
841        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
842    
843        $call = $this->_locator->get_call();        $call = $this->_locator->get_call();
844    
845        //print Dumper($call);        //print Dumper($call);
846          //return;
847    
848        // pre-flight checks        // pre-flight checks
849          if (!$call[method]) {          if (!$call[method]) {
850            $msg = "Remote method is empty, please pass in proper metadata or check configuration.";            $msg = "Remote method is empty, please pass in proper metadata or check configuration.";
851                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
852            return;            return;
853          }          }
854    
# Line 809  class DataSource_Generic extends DesignP Line 886  class DataSource_Generic extends DesignP
886    
887      $box = container();      $box = container();
888    
     // box client code (javascript)  
     $code_js = "  
     <script language=\"javascript\">  
     function toggle_vis(id) {  
       elem = eval('document.all.' + id);  
       status = elem.style.getAttribute('display');  
       if (status == 'none') {  
         elem.style.setAttribute('display', 'block');  
       } else {  
         elem.style.setAttribute('display', 'none');  
       }  
     }  
     </script>  
     ";  
     //$script = html_script($code_js);  
     //print $script->render();  
     $box->add( $code_js );  
       
889      // box style      // box style
890      $style = container(      $style = container(
891        html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),        html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
# Line 840  class DataSource_Generic extends DesignP Line 899  class DataSource_Generic extends DesignP
899      $locatorbox = html_div('box_dsg');      $locatorbox = html_div('box_dsg');
900      $locatorbox->set_id("locatorbox_$boxcount");      $locatorbox->set_id("locatorbox_$boxcount");
901      $locatorbox->add( Dumper($this->_locator) );      $locatorbox->add( Dumper($this->_locator) );
     //$locatorbox->set_style('visibility:false;');  
     $locatorbox->set_style('display:none;');  
902            
903      $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), html_a("javascript:toggle_vis('locatorbox_$boxcount');", '[show]'), $locatorbox, html_br() );      // FIXME: ie/mozilla?
904        //$locatorbox->set_style('display:none;');
905        //$locatorbox->set_style('visibility:hidden;');
906        // already duplicate inside Tracer!!!
907        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
908        
909        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
910      $call = $this->_locator->get_call();      $call = $this->_locator->get_call();
911      $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );      $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
912      if (sizeof($call[args])) {      if (sizeof($call[args])) {
# Line 852  class DataSource_Generic extends DesignP Line 915  class DataSource_Generic extends DesignP
915      $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );      $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
916      $box->add( $statusbox );      $box->add( $statusbox );
917    
918      print $box->render();      //print $box->render();
919        trace( $box );
920    
921    }    }
922    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.19

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