/[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.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   * Revision 1.12  2003/03/29 08:00:48  joko
57   * modified ErrorBoxing   * modified ErrorBoxing
58   *   *
# Line 76  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 273  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 362  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 374  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 411  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 472  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::DataSource');
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 681  class DataSource_Generic extends DesignP Line 725  class DataSource_Generic extends DesignP
725          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
726            case 'data':            case 'data':
727              $command = 'queryData';              $command = 'queryData';
728                
729              //$command = 'getObjects';   // FIXME!!!              //$command = 'getObjects';   // FIXME!!!
730              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
731  /*  /*
# Line 689  class DataSource_Generic extends DesignP Line 734  class DataSource_Generic extends DesignP
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   */   */
743              $query_args = array();              $query_args = array();
744                
745                 $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
746               switch ($this->_query[abstract_type]) {               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':                case 'list':
763                  if (!$this->_query[classname]) {                  if (!$this->_query[nodename]) {
764                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
765                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error($msg_prefix . $msg);
766                  }                  }
767                  //array_push($query_args, $this->_query[classname]);                  //array_push($query_args, $this->_query[nodename]);
768                  $query_args[classname] = $this->_query[classname];                  $query_args[nodename] = $this->_query[nodename];
769                    if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; }
770                  break;                  break;
771                case 'item':                case 'tree':
772                  if (!$this->_query[classname]) {                  /*
773                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                  if (!$this->_query[nodename]) {
774                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
775                      user_error($msg_prefix . $msg);
776                  }                  }
777                    */
778                  $query_args[guid] = $this->_query[ident];                  $query_args[guid] = $this->_query[ident];
779                  $query_args[classname] = $this->_query[classname];                  //$query_args[nodename] = $this->_query[nodename];
780                  break;                                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(              $args = array(
805                            'data_type' => $this->_query[abstract_type],                            'data_type' => $this->_query[abstract_type],
806                            'query_args' => $query_args                            'query_args' => $query_args
# Line 724  class DataSource_Generic extends DesignP Line 811  class DataSource_Generic extends DesignP
811            case 'schema':            case 'schema':
812              //print "Testing schema:" . "<br>";              //print "Testing schema:" . "<br>";
813              $command = 'querySchema';              $command = 'querySchema';
814                $args = array( $this->_query[filter] );
815              break;              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;
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 762  class DataSource_Generic extends DesignP Line 864  class DataSource_Generic extends DesignP
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        $call = $this->_locator->get_call();        $call = $this->_locator->get_call();
873    
874        //print Dumper($call);        //print Dumper($call);
875          //return;
876    
877        // pre-flight checks        // pre-flight checks
878          if (!$call[method]) {          if (!$call[method]) {
879            $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.";
880                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
881            return;            return;
882          }          }
883    
# Line 809  class DataSource_Generic extends DesignP Line 915  class DataSource_Generic extends DesignP
915    
916      $box = container();      $box = container();
917    
     // 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 );  
       
918      // box style      // box style
919      $style = container(      $style = container(
920        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 928  class DataSource_Generic extends DesignP
928      $locatorbox = html_div('box_dsg');      $locatorbox = html_div('box_dsg');
929      $locatorbox->set_id("locatorbox_$boxcount");      $locatorbox->set_id("locatorbox_$boxcount");
930      $locatorbox->add( Dumper($this->_locator) );      $locatorbox->add( Dumper($this->_locator) );
     //$locatorbox->set_style('visibility:false;');  
     $locatorbox->set_style('display:none;');  
931            
932      $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), html_a("javascript:toggle_vis('locatorbox_$boxcount');", '[show]'), $locatorbox, html_br() );      // 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();      $call = $this->_locator->get_call();
940      $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );      $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
941      if (sizeof($call[args])) {      if (sizeof($call[args])) {
# Line 852  class DataSource_Generic extends DesignP Line 944  class DataSource_Generic extends DesignP
944      $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() );
945      $box->add( $statusbox );      $box->add( $statusbox );
946    
947      print $box->render();      //print $box->render();
948        trace( $box );
949    
950    }    }
951    

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

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