/[cvs]/nfo/php/libs/org.netfrag.glib/DesignPattern/RemoteProxy.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/DesignPattern/RemoteProxy.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Mon Mar 3 22:06:46 2003 UTC revision 1.12 by joko, Sat Mar 29 08:01:21 2003 UTC
# Line 1  Line 1 
1  <?php  <?php
2    /**
3     * This file contains the DesignPattern::RemoteProxy class
4     *
5     * @author Andreas Motl <andreas.motl@ilo.de>
6     * @package org.netfrag.glib
7     * @name DesignPattern::RemoteProxy
8     *
9     *
10     */
11    
12    
13  /**  /**
14     * <b>Cvs-Log:</b>
15     *
16     * <pre>
17   * -------------------------------------------------------------------------   * -------------------------------------------------------------------------
18   *    $Id$   *    $Id$
19   * -------------------------------------------------------------------------   * -------------------------------------------------------------------------
20   *    $Log$   *    $Log$
21     *    Revision 1.12  2003/03/29 08:01:21  joko
22     *    modified ErrorBoxing
23     *
24     *    Revision 1.11  2003/03/28 06:44:51  joko
25     *    VERBOSE mode
26     *
27     *    Revision 1.10  2003/03/28 03:05:54  joko
28     *    more fancy debugging-output
29     *
30     *    Revision 1.9  2003/03/10 23:05:25  joko
31     *    + fixed metadata for phpDocumentor
32     *
33     *    Revision 1.8  2003/03/10 22:31:56  joko
34     *    + fixed metadata for phpDocumentor
35     *
36     *    Revision 1.7  2003/03/09 15:51:44  joko
37     *    + additional metadata for Autodia
38     *
39     *    Revision 1.6  2003/03/05 17:28:43  joko
40     *    updated docu (phpDocumentor testing....)
41     *
42     *    Revision 1.5  2003/03/05 17:02:22  joko
43     *    updated docu (phpDocumentor testing....)
44     *
45     *    Revision 1.4  2003/03/05 16:32:19  joko
46     *    updated docu (phpDocumentor testing....)
47     *
48     *    Revision 1.3  2003/03/05 16:10:17  joko
49     *    updated docu (phpDocumentor testing....)
50     *
51     *    Revision 1.2  2003/03/05 12:14:02  joko
52     *    renamed method
53     *    constructor argument expansion
54     *
55   *    Revision 1.1  2003/03/03 22:06:46  joko   *    Revision 1.1  2003/03/03 22:06:46  joko
56   *    refactored from Data::Driver::Proxy   *    refactored from Data::Driver::Proxy
57   *   *
# Line 92  Line 139 
139   *    Revision 1.1  2002/10/09 00:51:39  cvsjoko   *    Revision 1.1  2002/10/09 00:51:39  cvsjoko
140   *    + new   *    + new
141   * -------------------------------------------------------------------------   * -------------------------------------------------------------------------
142     * </pre>
143     *
144   */   */
145    
146    
147    
148    
149  /**  /**
150     * Load required modules:
151   *   *
152   * Data::Driver::Proxy  --  Multiple stage data fetching and caching   */
153    loadModule('DesignPattern::Proxy');
154    
155    
156    /**
157     * DesignPattern::RemoteProxy  --  Multiple stage data fetching and caching
158   *   *
159   *   *
160   * This class (Data::Driver::Proxy) provides an abstract framework   * This class (DesignPattern::RemoteProxy) provides an abstract framework
161   * for loading/saving arbitrary data from/to data storages interfaced   * for loading/saving arbitrary data from/to data storages interfaced
162   * by storage *proxy*-drivers.   * by storage *proxy*-drivers.
163   * Don't mix these up with the concrete storage *handle*-drivers   * Don't mix these up with the concrete storage *handle*-drivers
# Line 108  Line 166 
166   * providing a more highlevel, consistent API making   * providing a more highlevel, consistent API making
167   * it easier for Data::Driver::Proxy to do its main work:   * it easier for Data::Driver::Proxy to do its main work:
168   *   *
169     * quote from: http://home.earthlink.net/~huston2/dp/proxy.html
170     * "A remote proxy provides a local representative for an
171     * object that resides in a different address space. This is
172     * what the "stub" code in RPC and CORBA provides."
173     *
174     *
175   * Multiple stage data fetching and caching:   * Multiple stage data fetching and caching:
176   *   *
177     * <pre>
178     *
179   * DATA, ...   * DATA, ...
180   *    ... also refered to as data, should be handled as   *    ... also refered to as data, should be handled as
181   *    something called data.   *    something called data.
# Line 152  Line 218 
218   *    o Data::Driver::PEAR::DB   *    o Data::Driver::PEAR::DB
219   *    x Data::Driver::PEAR::Tree (via Data::Lift)   *    x Data::Driver::PEAR::Tree (via Data::Lift)
220   *   *
221   */   * </pre>
   
 /**  
  * Todo:  
  *  x extend options to en-/disable caching via a) session and/or b) database  
  *    o make feature available via runtime setter-method to these options  
  *  o use PEAR::Cache for caching purposes!!!  
  *  o refactor database access: use PEAR for this! no more 'connectdb' here!!!  
  *  o make database connection more flexible to make possible  
  *      to have different (probably named) proxy databases (besides a "main database")  
  *  o rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper?  
222   *   *
223   */   *
224     * An attempt to implement some software design patterns
225  /**   * --- RemoteProxyPattern
226   * Load required modules:   *
227     * @link http://www.agcs.com/supportv2/techpapers/patterns/papers/tutnotes/sld017.htm
228     * @link http://home.earthlink.net/~huston2/dp/proxy.html
229     * @link http://wiki.cs.uiuc.edu/PatternStories/RemoteObject
230     * @link http://c2.com/cgi-bin/wiki?ProxyPattern
231     * @link http://c2.com/cgi-bin/wiki?LazyProxies
232     *
233     * @author Andreas Motl <andreas.motl@ilo.de>
234     * @link http://www.netfrag.org/~joko/
235     *
236     * @copyright (c) 2003 - All Rights reserved.
237     * @license GNU LGPL (GNU Lesser General Public License)
238     * @link http://www.gnu.org/licenses/lgpl.txt
239     *
240     * @package org.netfrag.glib
241     * @subpackage DesignPattern
242     * @name DesignPattern::RemoteProxy
243     *
244     *
245     * @todo extend options to en-/disable caching via a) session and/or b) database
246     *           make feature available via runtime setter-method to these options
247     * @todo PEAR::Cache for caching purposes!!!
248     * @todo refactor database access: use PEAR for this! no more 'connectdb' here!!!
249     * @todo make database connection more flexible to make possible
250     *           to have different (probably named) proxy databases (besides a "main database")
251     * @todo rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper?
252     * @todo refactor this to a "RemoteObject" class!!! (inheriting from DesignPattern::RemoteObject)
253     * @todo rename this to "DesignPattern::LazyRemoteProxy"???
254   *   *
255   */   */
 loadModule('DesignPattern::Proxy');  
   
256  class DesignPattern_RemoteProxy extends DesignPattern_Proxy {  class DesignPattern_RemoteProxy extends DesignPattern_Proxy {
257    
258    var $objectId;    var $objectId;
# Line 185  class DesignPattern_RemoteProxy extends Line 266  class DesignPattern_RemoteProxy extends
266      logp(get_class($this) . "->new()", PEAR_LOG_INFO);      logp(get_class($this) . "->new()", PEAR_LOG_INFO);
267      global $proxy;      global $proxy;
268    
269        // 2003-03-05 - modified constructor
270        // expand objectId
271        if (is_array($objectId)) {
272          $options = $objectId[1];
273          $objectId = $objectId[0];
274        }
275    
276      // trace      // trace
277        //print Dumper($objectId, $options);        //print Dumper($objectId, $options);
278    
# Line 193  class DesignPattern_RemoteProxy extends Line 281  class DesignPattern_RemoteProxy extends
281        $this->_init_caching();        $this->_init_caching();
282        $this->_init_load();        $this->_init_load();
283    
284        //print Dumper($this);
285    
286    }    }
287    
288    function _init_meta_options( $objectId="", $options = array() ) {    function _init_meta_options( $objectId="", $options = array() ) {
# Line 215  class DesignPattern_RemoteProxy extends Line 305  class DesignPattern_RemoteProxy extends
305        session_register_safe("proxy");        session_register_safe("proxy");
306      }        }  
307    
308        /**
309         * <!-- Autodia -->
310         * can do: (this is metadata supplied for Autodia, don't delete!)
311         *  $this->backend = new DataSource_Proxy_XMLRPC()
312         *
313         */
314    
315      if ($this->meta[remote]) {      if ($this->meta[remote]) {
316        //$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]);        //$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]);
317        $this->backend = mkObject('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]);        $this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]);
318      }      }
319    }    }
320    
# Line 275  class DesignPattern_RemoteProxy extends Line 372  class DesignPattern_RemoteProxy extends
372    }      }  
373    */    */
374    
375    function getAttributes() {    function getResult() {
376      if (!$this->meta[decoded]) {      if (!$this->meta[decoded]) {
377        $this->_decode();        $this->_decode();
378        $this->_saveState();        $this->_saveState();
# Line 388  class DesignPattern_RemoteProxy extends Line 485  class DesignPattern_RemoteProxy extends
485            logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING);            logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING);
486            return;            return;
487          }          }
488            logp(get_class($this) . "->_loadRemote: getObjectByGuid", PEAR_LOG_DEBUG);
489          $args = array( guid => $this->objectId, classname => $this->meta[classname] );          $args = array( guid => $this->objectId, classname => $this->meta[classname] );
490          $result = $this->backend->send('getObjectByGuid', $args );          $result = $this->backend->send('getObjectByGuid', $args );
491    
# Line 396  class DesignPattern_RemoteProxy extends Line 494  class DesignPattern_RemoteProxy extends
494            logp(get_class($this) . "->_loadRemote: argument 'oid' requires valid objectId", PEAR_LOG_WARNING);            logp(get_class($this) . "->_loadRemote: argument 'oid' requires valid objectId", PEAR_LOG_WARNING);
495            return;            return;
496          }          }
497            logp(get_class($this) . "->_loadRemote: getObject", PEAR_LOG_DEBUG);
498          $result = $this->backend->send('getObject', $this->objectId);          $result = $this->backend->send('getObject', $this->objectId);
499    
500        } elseif ($this->meta[key]) {        } elseif ($this->meta[key]) {
# Line 409  class DesignPattern_RemoteProxy extends Line 508  class DesignPattern_RemoteProxy extends
508            return;            return;
509          }          }
510          */          */
511            //logp(get_class($this) . "->_loadRemote: $this->meta[command](" . join(' ', $this->meta[query]) . ")", PEAR_LOG_DEBUG);
512            //print Dumper(array($this->meta[command], $this->meta[query]));
513          $result = $this->backend->send($this->meta[command], $this->meta[query]);          $result = $this->backend->send($this->meta[command], $this->meta[query]);
514                    
515        }        }
516    
517        //print "result: " . dumpVar($result) . "<br>";
518    
519        $status = $this->backend->getStatus();
520        //print Dumper($status);
521            
522      if ($result) {      $style = html_style("text/css", '.boxlabel_yellow { color: yellow; font-weight:bold; }');
523        //print "result: " . dumpVar($result) . "<br>";      $statusbox = html_div();
524        if (count($result) == 0) { return; }      $statusbox->set_style('background: red; border: 2px black groove; width:640px; padding:10px; margin:40px;');
525        $statusbox->add( html_span('boxlabel_yellow', "Connected:"), $status[connected], html_br() );
526        foreach ($status[errors] as $error) {
527          $statusbox->add( html_span('boxlabel_yellow', "Error($error[code]):"), $error[message], html_br() );
528        }
529        
530        if (is_array($result)) {
531          $good = 1;
532        } else {
533          $message = get_class($this) . "->_loadRemote: Error while trying to talk to remote side. Please check wire, socket or api.";
534          logp($message, PEAR_LOG_CRIT);
535          $statusbox->add( html_span('boxlabel_yellow', "Critical:"), $message, html_br() );
536        }
537    
538        if ($good && sizeof($result)) {
539                
540        // FIXME: this is dangerous!        // FIXME: this is dangerous!
541        if ($_GET[debug]) {        if ($_GET[debug]) {
# Line 430  class DesignPattern_RemoteProxy extends Line 548  class DesignPattern_RemoteProxy extends
548        $this->_saveProxy();        $this->_saveProxy();
549        //print "oid: $this->objectId<br>";        //print "oid: $this->objectId<br>";
550        $this->flushState();        $this->flushState();
551        
552      } else {      } else {
553        //print "Error in _loadRemote!!!<br>";        if (constants::get('VERBOSE') || constants::get('ERRORS_ONLY')) {
554        logp(get_class($this) . "->_loadRemote: error while trying to talk to remote side", PEAR_LOG_CRIT);          print $style->render();
555            print $statusbox->render();
556          } else {
557            foreach ($status[errors] as $error) {
558              print Dumper($error);
559            }
560          }
561        
562      }      }
563            
564    }    }

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

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