]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/javascript/opensrf_utils.js
Patch from Scott McKellar:
[OpenSRF.git] / src / javascript / opensrf_utils.js
1 // ------------------------------------------------------------------
2 // Houses utility functions
3 // ------------------------------------------------------------------
4
5 /** Prints to console.  If alert_bool = true, displays a popup as well */
6 function _debug( message, alert_bool ) {
7
8         dump( "\n" + new Date() + "\n--------------------------------\n" + 
9                         message + "\n-----------------------------------\n" );
10         if( alert_bool == true ) { alert( message ) };
11
12 }
13
14
15 /** Provides millisec sleep times, enjoy... */
16 function sleep(gap){ 
17
18         var threadService = Components.classes["@mozilla.org/thread;1"].
19                 getService(Components.interfaces.nsIThread);
20
21         var th = threadService.currentThread;
22         th.sleep(gap);
23 }
24
25
26
27 /** Top level exception classe */
28 function oils_ex() {}
29
30 /** Initializes an exception */
31 oils_ex.prototype.init_ex = function( name, message ) {
32         if( !(name && message) ) { return; }
33         this.name = name;
34         this.message = name + " : " + message;
35         new Logger().debug( "***\n" + this.message + "\n***", Logger.ERROR );
36 }
37
38 /** Returns a string representation of an exception */
39 oils_ex.prototype.toString = function() {
40         return this.message;
41 }
42
43
44 oils_ex_transport.prototype = new oils_ex();
45 oils_ex_transport.prototype.constructor = oils_ex_transport;
46 oils_ex_transport.baseClass = oils_ex.prototype.constructor;
47
48 /** Thrown when the transport connection has problems*/
49 function oils_ex_transport( message ) {
50         this.init_ex( "Transport Exception", message );
51 }
52
53
54 oils_ex_transport_auth.prototype = new oils_ex_transport(); 
55 oils_ex_transport_auth.prototype.constructor = oils_ex_transport_auth;
56 oils_ex_transport_auth.baseClass = oils_ex_transport.prototype.constructor;
57
58 /** Thrown when the initial transport connection fails */
59 function oils_ex_transport_auth( message ) {
60         this.init_ex( "Transport Authentication Error", message );
61 }
62
63 oils_ex_dom.prototype = new oils_ex(); 
64 oils_ex_dom.prototype.constructor = oils_ex_dom;
65 oils_ex_dom.baseClass = oils_ex.prototype.constructor;
66
67 /** Thrown when there is an XML problem */
68 function oils_ex_dom( message ) {
69         this.init_ex( "DOM Error", message );
70 }
71
72 oils_ex_message.prototype = new oils_ex();
73 oils_ex_message.prototype.constructor = oils_ex_message;
74 oils_ex_message.baseClass = oils_ex.prototype.constructor;
75
76 /** Thrown when there is a message problem */
77 function oils_ex_message( message ) {
78         this.init_ex( "OILS Message Layer Error", message ) ;
79 }
80
81 oils_ex_config.prototype = new oils_ex();
82 oils_ex_config.prototype.constructor = oils_ex_config;
83 oils_ex_config.prototype.baseClass = oils_ex.prototype.constructor;
84
85 /** Thrown when values cannot be retrieved from the config file */
86 function oils_ex_config( message ) {
87         this.init_ex( "OILS Config Exception", message );
88 }
89
90 oils_ex_logger.prototype = new oils_ex();
91 oils_ex_logger.prototype.constructor = oils_ex_logger;
92 oils_ex_logger.prototype.baseClass = oils_ex.prototype.constructor;
93
94 /** Thrown where there are logging problems */
95 function oils_ex_logger( message ) {
96         this.init_ex( "OILS Logger Exception", message );
97 }
98
99
100 oils_ex_args.prototype = new oils_ex();
101 oils_ex_args.prototype.constructor = oils_ex_args;
102 oils_ex_args.prototype.baseClass = oils_ex.prototype.constructor;
103
104 /** Thrown when when a method does not receive all of the required arguments */
105 function oils_ex_args( message ) {
106         this.init_ex( "Method Argument Exception", message );
107 }
108
109
110 oils_ex_session.prototype = new oils_ex();
111 oils_ex_session.prototype.constructor = oils_ex_session;
112 oils_ex_session.prototype.baseClass = oils_ex.prototype.constructor;
113
114 /** Thrown where there is a session processing problem */
115 function oils_ex_session( message ) {
116         this.init_ex( "Session Exception", message );
117 }