SJ/Config.pm

filter: Statementstmt 91.6% 22 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 93.7% 30 / 32 CC 1 SCAR 0.4
CC
1
Cov
92%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« SJ/Classpath.pm ↑ Summary SJ.pm »
1 ###########################################################################
2 #
3 # Java::SJ::Config
4 #
5 # $Id: Config.pm,v 1.3 2003/07/20 18:52:21 wiggly Exp $
6 #
7 # $Author: wiggly $
8 #
9 # $DateTime$
10 #
11 # $Revision: 1.3 $
12 #
13 ###########################################################################
14  
15 package Java::SJ::Config;
16  
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use File::Spec::Functions qw( tmpdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 0 ▶use XML::XPath;
Subroutine BEGIN: called CC=1 SCAR=2.6
25 use Java::SJ::Classpath;
26 use Java::SJ::VirtualMachine;
27  
28 our $VERSION = '0.01';
29  
30 my @CONFIG_FILE =
31 (
32 '/etc/sj.conf',
33 $ENV{'HOME'} . '/.sj.conf',
34 getcwd . '/.sj.conf',
35 );
36  
37 my $DEFAULT_DIR_BASE = '/usr/local';
38 my $DEFAULT_DIR_LIB = '${dir.base}/lib/sj';
39 my $DEFAULT_DIR_PID = '${dir.base}/var/run';
40 my $DEFAULT_DIR_LOG = '${dir.base}/var/log/sj';
41 my $DEFAULT_DIR_TMP = tmpdir;
42 my $DEFAULT_DIR_SCRIPT = '${dir.base}/var/sj/script';
43 my $DEFAULT_FILE_PID = '${app.name}.pid';
44  
45 ###########################################################################
46 #
47 # Constructor
48 #
49 ###########################################################################
50 sub new
51 {
52 my $class = shift;
53 my $self = {};
54 bless $self, $class;
55 $self->set_defaults;
56 $self->load_system_configuration;
57 #print STDERR "[DEBUG] CONFIG\n" . Dumper( $self ) . "\n\n";
58 return $self;
59 }
60  
61  
62 ###########################################################################
63 #
64 # get_var
65 #
66 ###########################################################################
67 sub get_var
68 {
69 my $self = shift;
70 my $name = shift;
71 my $var = $self->{'var'}{$name};
72 my $rep = undef;
73  
74 #
75 # resolve and replace any sub-vars such as ${app.name}
76 #
77 while( $var =~ m/\$\{(.*?)\}/ )
78 {
79 $rep = $self->get_var( $1 );
80 $var =~ s/\$\{(.*?)\}/$rep/;
81 }
82  
83 return $var;
84 }
85  
86  
87 ###########################################################################
88 #
89 # set_defaults
90 #
91 # Set defaults for those configuration options that have defaults
92 #
93 ###########################################################################
94 sub set_defaults
95 {
96 my $self = shift;
97  
98 # application variables
99 $self->{'var'}{'app.name'} = undef;
100 $self->{'var'}{'app.class'} = undef;
101  
102 # directories
103 $self->{'var'}{'dir.base'} = $DEFAULT_DIR_BASE;
104 $self->{'var'}{'dir.lib'} = $DEFAULT_DIR_LIB;
105 $self->{'var'}{'dir.pid'} = $DEFAULT_DIR_PID;
106 $self->{'var'}{'dir.log'} = $DEFAULT_DIR_LOG;
107 $self->{'var'}{'dir.tmp'} = $DEFAULT_DIR_TMP;
108 $self->{'var'}{'dir.script'} = $DEFAULT_DIR_SCRIPT;
109  
110 # pid filename
111 $self->{'var'}{'file.pid'} = $DEFAULT_FILE_PID;
112  
113 # properties
114 $self->{'prop'} = undef;
115  
116 # environment
117 $self->{'env'} = undef;
118  
119 # environment
120 $self->{'param'} = undef;
121  
122 # virtual machine
123 $self->{'var'}{'vm.default'} = undef;
124
125 $self->{'bootclasspath'} = new Java::SJ::Classpath;
126 $self->{'prepend_bootclasspath'} = new Java::SJ::Classpath;
127 $self->{'append_bootclasspath'} = new Java::SJ::Classpath;
128 $self->{'classpath'} = new Java::SJ::Classpath;
129 $self->{'write_pid'} = 0;
130 $self->{'vm'} = undef;
131 $self->{'vmref'} = undef;
132 $self->{'debug'} = 0;
133  
134 1;
135 }
136  
137  
138 ###########################################################################
139 #
140 # load_configuration
141 #
142 ###########################################################################
143 sub load_configuration
144 {
145 my $self = shift;
146  
147 my $handle = shift;
148 my $type = shift;
149  
150 my $xp;
151 my ( $nodeset, $dir_nodeset, $jar_nodeset, $property_nodeset, $environment_nodeset, $param_nodeset );
152 my ( $node, $dir_node, $jar_node, $property_node, $environment_node, $param_node );
153  
154 #print STDERR "[INFO] load_configuration\n";
155 #print STDERR "[INFO] HANDLE : $handle\n";
156 #print STDERR "[INFO] TYPE : $type\n";
157  
158 $xp = XML::XPath->new( ioref => $handle )
159 or croak "[ERROR] Could not create new XPath object from handle, $!\n";
160  
161 #
162 # get config parameters into our config object
163 #
164  
165 #
166 # DEBUG
167 #
168 $nodeset = $xp->find('/sj/debug');
169  
170 if( $nodeset->size() > 1 )
171 {
172 print STDERR "[WARN] Multiple DEBUG nodes.\n";
173 }
174 elsif( $nodeset->size() == 1 )
175 {
176 $node = $nodeset->shift();
177
178 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
179 #print STDERR "[INFO] Level : " . $node->getAttribute( 'level' ) . "\n";
180 $self->{'debug'} = $node->getAttribute( 'level' );
181 }
182 else
183 {
184 #print STDERR "[INFO] No DEBUG defined\n";
185 }
186  
187 #
188 # NAME
189 #
190 $nodeset = $xp->find('/sj/name');
191  
192 if( $nodeset->size() > 1 )
193 {
194 print STDERR "[WARN] Multiple NAME nodes.\n";
195 }
196 elsif( $nodeset->size() == 1 )
197 {
198 $node = $nodeset->shift();
199
200 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
201 #print STDERR "[INFO] Name : " . $node->string_value() . "\n";
202 $self->{'var'}{'app.name'} = $node->string_value();
203 }
204 else
205 {
206 #print STDERR "[INFO] No NAME defined\n";
207 }
208  
209 #
210 # CLASS
211 #
212 $nodeset = $xp->find('/sj/class');
213  
214 if( $nodeset->size() > 1 )
215 {
216 print STDERR "[WARN] Multiple CLASS nodes.\n";
217 }
218 elsif( $nodeset->size() == 1 )
219 {
220 $node = $nodeset->shift();
221
222 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
223 #print STDERR "[INFO] Class : " . $node->string_value() . "\n";
224 $self->{'var'}{'app.class'} = $node->string_value();
225 }
226 else
227 {
228 #print STDERR "[INFO] No CLASS defined\n";
229 }
230  
231 #
232 # VAR
233 #
234 $nodeset = $xp->find('/sj/var');
235  
236 while( $node = $nodeset->shift() )
237 {
238 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
239 #print STDERR "[INFO] Name : " . $node->getAttribute( 'name' ) . "\n";
240 #print STDERR "[INFO] Value : " . $node->getAttribute( 'value' ) . "\n";
241 $self->{'var'}{$node->getAttribute( 'name' )} = $node->getAttribute( 'value' );
242 }
243  
244 #
245 # PROPERTY
246 #
247 $nodeset = $xp->find('/sj/property');
248  
249 while( $node = $nodeset->shift() )
250 {
251 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
252 #print STDERR "[INFO] Name : " . $node->getAttribute( 'name' ) . "\n";
253 #print STDERR "[INFO] Value : " . $node->getAttribute( 'value' ) . "\n";
254 $self->{'prop'}{$node->getAttribute( 'name' )} = $node->getAttribute( 'value' );
255 }
256  
257 #
258 # ENVIRONMENT
259 #
260 $nodeset = $xp->find('/sj/environment');
261  
262 while( $node = $nodeset->shift() )
263 {
264 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
265 #print STDERR "[INFO] Name : " . $node->getAttribute( 'name' ) . "\n";
266 #print STDERR "[INFO] Value : " . $node->getAttribute( 'value' ) . "\n";
267 $self->{'env'}{$node->getAttribute( 'name' )} = $node->getAttribute( 'value' );
268 }
269  
270 #
271 # PARAM
272 #
273 $nodeset = $xp->find('/sj/param');
274  
275 while( $node = $nodeset->shift() )
276 {
277 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
278 #print STDERR "[INFO] Name : " . $node->getAttribute( 'name' ) . "\n";
279 #print STDERR "[INFO] Value : " . $node->getAttribute( 'value' ) . "\n";
280 #print STDERR "[INFO] Sep : " . $node->getAttribute( 'sep' ) . "\n";
281  
282 if( $node->getAttribute( 'value' ) !~ /^$/ )
283 {
284 if( $node->getAttribute( 'sep' ) !~ /^$/ )
285 {
286 $self->{'param'}{$node->getAttribute( 'name' )} = $node->getAttribute( 'sep' ) . $node->getAttribute( 'value' );
287 }
288 else
289 {
290 $self->{'param'}{$node->getAttribute( 'name' )} = ' ' . $node->getAttribute( 'value' );
291 }
292 }
293 else
294 {
295 $self->{'param'}{$node->getAttribute( 'name' )} = '';
296 }
297 }
298  
299 #
300 # PID
301 #
302 $nodeset = $xp->find('/sj/pid');
303  
304 while( $node = $nodeset->shift() )
305 {
306 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
307 #print STDERR "[INFO] Name : " . $node->getAttribute( 'name' ) . "\n";
308 #print STDERR "[INFO] Dir : " . $node->getAttribute( 'dir' ) . "\n";
309 #print STDERR "[INFO] File : " . $node->getAttribute( 'file' ) . "\n";
310  
311 $self->{'write_pid'} = 1;
312  
313 if( $node->getAttribute( 'dir' ) )
314 {
315 $self->{'var'}{'dir.pid'} = $node->getAttribute( 'dir' );
316 }
317
318 if( $node->getAttribute( 'file' ) )
319 {
320 $self->{'var'}{'file.pid'} = $node->getAttribute( 'file' );
321 }
322 }
323  
324 #
325 # BOOTCLASSPATH
326 #
327 $nodeset = $xp->find('/sj/bootclasspath');
328  
329 if( $nodeset->size() > 1 )
330 {
331 print STDERR "[WARN] Multiple BOOTCLASSPATH nodes.\n";
332 }
333 elsif( $nodeset->size() == 1 )
334 {
335 $node = $nodeset->shift();
336
337 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
338  
339 $dir_nodeset = $xp->find( 'dir', $node );
340  
341 while( $dir_node = $dir_nodeset->shift() )
342 {
343 #print STDERR "[INFO] Node : " . $dir_node->getName() . "\n";
344 #print STDERR "[INFO] Path : " . $dir_node->getAttribute( 'path' ) . "\n";
345  
346 $self->{'bootclasspath'}->add_dir( $dir_node->getAttribute( 'path' ) );
347 }
348  
349 $jar_nodeset = $xp->find( 'jar', $node );
350  
351 while( $jar_node = $jar_nodeset->shift() )
352 {
353 #print STDERR "[INFO] Node : " . $jar_node->getName() . "\n";
354 #print STDERR "[INFO] Path : " . $jar_node->getAttribute( 'name' ) . "\n";
355 #print STDERR "[INFO] Version : " . $jar_node->getAttribute( 'version' ) . "\n";
356 #print STDERR "[INFO] File : " . $jar_node->getAttribute( 'file' ) . "\n";
357  
358 my %jar_info =
359 (
360 name => $jar_node->getAttribute( 'name' ),
361 version => $jar_node->getAttribute( 'version' ),
362 file => $jar_node->getAttribute( 'file' ),
363 );
364  
365 $self->{'bootclasspath'}->add_jar( %jar_info );
366 }
367 }
368 else
369 {
370 #print STDERR "[INFO] No BOOTCLASSPATH defined\n";
371 }
372  
373 #
374 # PREPEND_BOOTCLASSPATH
375 #
376 $nodeset = $xp->find('/sj/prepend_bootclasspath');
377  
378 if( $nodeset->size() > 1 )
379 {
380 print STDERR "[WARN] Multiple PREPEND_BOOTCLASSPATH nodes.\n";
381 }
382 elsif( $nodeset->size() == 1 )
383 {
384 $node = $nodeset->shift();
385
386 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
387  
388 $dir_nodeset = $xp->find( 'dir', $node );
389  
390 while( $dir_node = $dir_nodeset->shift() )
391 {
392 #print STDERR "[INFO] Node : " . $dir_node->getName() . "\n";
393 #print STDERR "[INFO] Path : " . $dir_node->getAttribute( 'path' ) . "\n";
394  
395 $self->{'prepend_bootclasspath'}->add_dir( $dir_node->getAttribute( 'path' ) );
396 }
397  
398 $jar_nodeset = $xp->find( 'jar', $node );
399  
400 while( $jar_node = $jar_nodeset->shift() )
401 {
402 #print STDERR "[INFO] Node : " . $jar_node->getName() . "\n";
403  
404 #print STDERR "[INFO] Path : " . $jar_node->getAttribute( 'name' ) . "\n";
405 #print STDERR "[INFO] Version : " . $jar_node->getAttribute( 'version' ) . "\n";
406 #print STDERR "[INFO] File : " . $jar_node->getAttribute( 'file' ) . "\n";
407  
408 my %jar_info =
409 (
410 name => $jar_node->getAttribute( 'name' ),
411 version => $jar_node->getAttribute( 'version' ),
412 file => $jar_node->getAttribute( 'file' ),
413 );
414  
415 $self->{'prepend_bootclasspath'}->add_jar( %jar_info );
416 }
417 }
418 else
419 {
420 #print STDERR "[INFO] No PREPEND_BOOTCLASSPATH defined\n";
421 }
422  
423 #
424 # APPEND_BOOTCLASSPATH
425 #
426 $nodeset = $xp->find('/sj/append_bootclasspath');
427  
428 if( $nodeset->size() > 1 )
429 {
430 print STDERR "[WARN] Multiple APPEND_BOOTCLASSPATH nodes.\n";
431 }
432 elsif( $nodeset->size() == 1 )
433 {
434 $node = $nodeset->shift();
435
436 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
437  
438 $dir_nodeset = $xp->find( 'dir', $node );
439  
440 while( $dir_node = $dir_nodeset->shift() )
441 {
442 #print STDERR "[INFO] Node : " . $dir_node->getName() . "\n";
443 #print STDERR "[INFO] Path : " . $dir_node->getAttribute( 'path' ) . "\n";
444  
445 $self->{'append_bootclasspath'}->add_dir( $dir_node->getAttribute( 'path' ) );
446 }
447  
448 $jar_nodeset = $xp->find( 'jar', $node );
449  
450 while( $jar_node = $jar_nodeset->shift() )
451 {
452 #print STDERR "[INFO] Node : " . $jar_node->getName() . "\n";
453  
454 #print STDERR "[INFO] Path : " . $jar_node->getAttribute( 'name' ) . "\n";
455 #print STDERR "[INFO] Version : " . $jar_node->getAttribute( 'version' ) . "\n";
456 #print STDERR "[INFO] File : " . $jar_node->getAttribute( 'file' ) . "\n";
457  
458 my %jar_info =
459 (
460 name => $jar_node->getAttribute( 'name' ),
461 version => $jar_node->getAttribute( 'version' ),
462 file => $jar_node->getAttribute( 'file' ),
463 );
464  
465 $self->{'append_bootclasspath'}->add_jar( %jar_info );
466 }
467 }
468 else
469 {
470 #print STDERR "[INFO] No APPEND_BOOTCLASSPATH defined\n";
471 }
472  
473 #
474 # CLASSPATH
475 #
476 $nodeset = $xp->find('/sj/classpath');
477  
478 if( $nodeset->size() > 1 )
479 {
480 print STDERR "[WARN] Multiple CLASSPATH nodes.\n";
481 }
482 elsif( $nodeset->size() == 1 )
483 {
484 $node = $nodeset->shift();
485
486 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
487  
488 $dir_nodeset = $xp->find( 'dir', $node );
489  
490 while( $dir_node = $dir_nodeset->shift() )
491 {
492 #print STDERR "[INFO] Node : " . $dir_node->getName() . "\n";
493 #print STDERR "[INFO] Path : " . $dir_node->getAttribute( 'path' ) . "\n";
494  
495 $self->{'classpath'}->add_dir( $dir_node->getAttribute( 'path' ) );
496 }
497  
498 $jar_nodeset = $xp->find( 'jar', $node );
499  
500 while( $jar_node = $jar_nodeset->shift() )
501 {
502 #print STDERR "[INFO] Node : " . $jar_node->getName() . "\n";
503  
504 #print STDERR "[INFO] Path : " . $jar_node->getAttribute( 'name' ) . "\n";
505 #print STDERR "[INFO] Version : " . $jar_node->getAttribute( 'version' ) . "\n";
506 #print STDERR "[INFO] File : " . $jar_node->getAttribute( 'file' ) . "\n";
507  
508 my %jar_info =
509 (
510 name => $jar_node->getAttribute( 'name' ),
511 version => $jar_node->getAttribute( 'version' ),
512 file => $jar_node->getAttribute( 'file' ),
513 );
514  
515 $self->{'classpath'}->add_jar( %jar_info );
516 }
517 }
518 else
519 {
520 #print STDERR "[INFO] No CLASSPATH defined\n";
521 }
522  
523 #
524 # VM
525 #
526 $nodeset = $xp->find('/sj/vm');
527  
528 while( $node = $nodeset->shift() )
529 {
530 #print STDERR "[INFO] Node : " . $node->getName() . "\n";
531  
532 #print STDERR "[INFO] Name : " . $node->getAttribute( 'name' ) . "\n";
533 #print STDERR "[INFO] Vendor : " . $node->getAttribute( 'vendor' ) . "\n";
534 #print STDERR "[INFO] Version : " . $node->getAttribute( 'version' ) . "\n";
535 #print STDERR "[INFO] Language : " . $node->getAttribute( 'language' ) . "\n";
536 #print STDERR "[INFO] Home : " . $node->getAttribute( 'home' ) . "\n";
537 #print STDERR "[INFO] Default : " . $node->getAttribute( 'default' ) . "\n";
538 #print STDERR "[INFO] Ref : " . $node->getAttribute( 'ref' ) . "\n";
539  
540 if( $node->getAttribute( 'ref' ) !~ /^$/ )
541 {
542 # set the VM ref to use as required
543 $self->{'vmref'} = $node->getAttribute( 'ref' );
544  
545 # place env, prop and params into config
546  
547 # properties
548 $property_nodeset = $xp->find( 'property', $node );
549 while( $property_node = $property_nodeset->shift() )
550 {
551 #print STDERR "[INFO] Node : " . $property_node->getName() . "\n";
552 #print STDERR "[INFO] Name : " . $property_node->getAttribute( 'name' ) . "\n";
553 #print STDERR "[INFO] Value : " . $property_node->getAttribute( 'value' ) . "\n";
554 $self->{'prop'}{$property_node->getAttribute( 'name' )} = $property_node->getAttribute( 'value' );
555 }
556  
557 # environment
558 $environment_nodeset = $xp->find( 'environment', $node );
559 while( $environment_node = $environment_nodeset->shift() )
560 {
561 #print STDERR "[INFO] Node : " . $environment_node->getName() . "\n";
562 #print STDERR "[INFO] Name : " . $environment_node->getAttribute( 'name' ) . "\n";
563 #print STDERR "[INFO] Value : " . $environment_node->getAttribute( 'value' ) . "\n";
564 $self->{'env'}{$environment_node->getAttribute( 'name' )} = $environment_node->getAttribute( 'value' );
565 }
566  
567 # params
568 $param_nodeset = $xp->find('param', $node );
569  
570 while( $param_node = $param_nodeset->shift() )
571 {
572 #print STDERR "[INFO] Node : " . $param_node->getName() . "\n";
573 #print STDERR "[INFO] Name : " . $param_node->getAttribute( 'name' ) . "\n";
574 #print STDERR "[INFO] Value : " . $param_node->getAttribute( 'value' ) . "\n";
575 #print STDERR "[INFO] Sep : " . $param_node->getAttribute( 'sep' ) . "\n";
576  
577 if( $param_node->getAttribute( 'value' ) !~ /^$/ )
578 {
579 if( $param_node->getAttribute( 'sep' ) !~ /^$/ )
580 {
581 $self->{'param'}{$param_node->getAttribute( 'name' )} = $param_node->getAttribute( 'sep' ) . $param_node->getAttribute( 'value' );
582 }
583 else
584 {
585 $self->{'param'}{$param_node->getAttribute( 'name' )} = ' ' . $param_node->getAttribute( 'value' );
586 }
587 }
588 else
589 {
590 $self->{'param'}{$param_node->getAttribute( 'name' )} = '';
591 }
592 }
593 }
594 else
595 {
596 my $vm = new Java::SJ::VirtualMachine;
597  
598 $vm->name( $node->getAttribute( 'name' ) );
599 $vm->vendor( $node->getAttribute( 'vendor' ) );
600 $vm->version( $node->getAttribute( 'version' ) );
601 $vm->language( $node->getAttribute( 'language' ) );
602 $vm->home( $node->getAttribute( 'home' ) );
603 $vm->default( $node->getAttribute( 'default' ) );
604  
605 if( $vm->default )
606 {
607 $self->{'vmref'} = $vm->name;
608 }
609  
610 $property_nodeset = $xp->find( 'property', $node );
611  
612 while( $property_node = $property_nodeset->shift() )
613 {
614 #print STDERR "[INFO] Node : " . $property_node->getName() . "\n";
615 #print STDERR "[INFO] Name : " . $property_node->getAttribute( 'name' ) . "\n";
616 #print STDERR "[INFO] Value : " . $property_node->getAttribute( 'value' ) . "\n";
617 $vm->add_property( $property_node->getAttribute( 'name' ), $property_node->getAttribute( 'value' ) );
618 }
619  
620 $param_nodeset = $xp->find( 'param', $node );
621  
622 while( $param_node = $param_nodeset->shift() )
623 {
624 #print STDERR "[INFO] Node : " . $param_node->getName() . "\n";
625 #print STDERR "[INFO] Name : " . $param_node->getAttribute( 'name' ) . "\n";
626 #print STDERR "[INFO] Value : " . $param_node->getAttribute( 'value' ) . "\n";
627 #print STDERR "[INFO] Sep : " . $param_node->getAttribute( 'sep' ) . "\n";
628  
629 $vm->add_environment( $param_node->getAttribute( 'name' ), $param_node->getAttribute( 'value' ), $param_node->getAttribute( 'sep' ) );
630 }
631  
632 $environment_nodeset = $xp->find( 'environment', $node );
633  
634 while( $environment_node = $environment_nodeset->shift() )
635 {
636 #print STDERR "[INFO] Node : " . $environment_node->getName() . "\n";
637 #print STDERR "[INFO] Name : " . $environment_node->getAttribute( 'name' ) . "\n";
638 #print STDERR "[INFO] Value : " . $environment_node->getAttribute( 'value' ) . "\n";
639  
640 $vm->add_environment( $environment_node->getAttribute( 'name' ), $environment_node->getAttribute( 'value' ) );
641 }
642  
643 $self->{'vm'}{$vm->name} = $vm;
644 }
645 }
646  
647 $xp = undef;
648 1;
649 }
650  
651  
652 ###########################################################################
653 #
654 # load_system_configuration
655 #
656 # Load configuration from well known file locations
657 #
658 ###########################################################################
659 sub load_system_configuration
660 {
661 my $self = shift;
662  
663 my $file;
664 my $handle;
665  
666 #print STDERR "[INFO] load_system_configuration\n";
667  
668 foreach $file ( @CONFIG_FILE )
669 {
670 if( -f $file && -r _ )
671 {
672 #print STDERR "[INFO] configuration file found : $file\n";
673
674 $handle = new IO::File( "<$file" )
675 or croak "[ERROR] Cannot open file $file for reading, $!\n";
676
677 $self->load_configuration( $handle, 0 );
678 }
679 else
680 {
681 #print STDERR "[INFO] configuration file absent : $file\n";
682 }
683 }
684 1;
685 }
686  
687  
688 ###########################################################################
689 #
690 # load_app_configuration
691 #
692 # Load a configuration from a script file before it has been converted into
693 # a cached script with it's configuration in a DATA section.
694 #
695 ###########################################################################
696 sub load_app_configuration
697 {
698 my $self = shift;
699 my $handle = shift;
700  
701 $self->load_configuration( $handle, 1 );
702  
703 1;
704 }
705  
706  
707 ###########################################################################
708 #
709 # load_script_configuration
710 #
711 # Load a configuration from a Script's DATA section
712 #
713 ###########################################################################
714 sub load_script_configuration
715 {
716 my $self = shift;
717  
718 my $handle;
719  
720 #print STDERR "[INFO] load_script_configuration\n";
721  
722 $handle = new IO::Handle;
723  
724 $handle->fdopen( main::DATA, 'r' )
725 or croak "[ERROR] Could not create IO::Handle from main::DATA filehandle, $!\n";
726  
727 $self->load_configuration( $handle, 1 );
728  
729 1;
730 }
731  
732  
733 ###########################################################################
734 1;
735  
736 =pod
737  
738 =head1 NAME
739  
740 Java::SJ::Config - SJ Configuration File
741  
742 =head1 DESCRIPTION
743  
744 This module represents SJ configurations. It uses L<XML::XPath> to parse
745 configuration files and generates objects to represent the directives.
746  
747 Unless you're working on the module what you really want to know is what
748 directives are allowed and their meaning. You're in luck, its below.
749  
750 =head1 CONFIGURATION
751  
752 All the tags defined below may appear in either the system or application
753 configuration files. Some of course make more sense in one than the other.
754 It may appear that some (class for example) have no business being in the
755 system configuratino at all.
756  
757 This is allowed for two reasons. Firstly it makes parsing and overriding
758 configuration easier. Secondly it allows you to do things such as print nice
759 error message for people when classes are not defined in app config files.
760  
761 =head2 Name
762  
763 C<E<lt>name/E<gt>>
764  
765 Name to use for this application. If this is not set then the configuration
766 script filename is used without extension. So a script called 'hello.sj' would
767 be run as a program named 'hello'.
768  
769 It doesn't make much sense to place this in the system configuration but you
770 could do so if you felt kinky.
771  
772 =head2 Class
773  
774 C<E<lt>class/E<gt>>
775  
776 Full name of the class whose main method you wish to run for this
777 application.
778  
779 It makes no sense to place this in the system configuration unless you want
780 to do something really perverted.
781  
782 =head2 Var
783  
784 C<E<lt>var name="" value=""/E<gt>>
785  
786 Specify variables that can be used within configuration files. The names of
787 the variables may be used as values in the configuration file.
788  
789 =head2 Property
790  
791 C<E<lt>property name="" value=""/E<gt>>
792  
793 Specify properties to define for the VM that is eventually used to run the
794 application. These get turned into -D options to the VM
795  
796 =head2 Environment
797  
798 C<E<lt>environment name="" value=""/E<gt>>
799  
800 Specify environment settings to define for the interpreter and VM. This can
801 be useful to set things such as TimeZones, Locales etc.
802  
803 =head2 Param
804  
805 C<E<lt>param name="" value="" sep=""/E<gt>>
806  
807 Specify a command line argument. This may simply be a name for option
808 switches or can include a value. The sep attribute defines what to seperate
809 the argument name and value by, the default is a single space.
810  
811 Params can be defined for VMs and for applications generally. Params for VMs
812 will be passed to the VM whilst params defined in the application
813 configuration main section will be passed to the application after the class
814 name
815  
816 =head2 Dir
817  
818 C<E<lt>dir path=""/E<gt>>
819  
820 Specify a directory path. These are used in multiple places but primarily in
821 specifying where to look for classes.
822  
823 =head2 Jar
824  
825 C<E<lt>jar name="" version="" file=""/E<gt>>
826  
827 Specify the location of a JAR file.
828  
829 If only a name is provided then the highest version JAR available in the SJ
830 library directory will be used. Otherwise SJ will look for a specific
831 version number and attempt to use that.
832  
833 If file is given then that exact JAR file is used.
834  
835 =head2 Pid
836  
837 C<E<lt>pid dir="${dir.pid}" file="${app.name}.pid"/E<gt>>
838  
839 Specify whether or not to keep a PID file for this application.
840  
841 Additionally this tag allows you to change where the PID file is kept and
842 what it is called. These default to the ${dir.pid} directory and
843 ${app.name}.pid for filename.
844  
845 This tag when specified in the application configuration means that a PID
846 file should be written, otherwise one will not be created. You should only
847 wish to create PID files for programs that require control over time using
848 the other SJ admin scripts.
849  
850 Programs that run interactively or that can have multiple instances running
851 concurrently should not use the PID tag in their application config file
852 since the PID file will be overwritten for any currently running instances.
853  
854 =head2 Bootclasspath
855  
856 C<
857 E<lt>bootclasspathE<gt>
858 E<lt>dir/E<gt>*
859 E<lt>jar/E<gt>*
860 E<lt>/bootclasspathE<gt>
861 >
862  
863 Specify the boot classpath to use for the VM in full.
864  
865 =head2 Prepend_bootclasspath
866  
867 <prepend_bootclasspath>
868 <dir/>*
869 <jar/>*
870 </prepend_bootclasspath>
871  
872 Specify elements to prepend to the boot classpath.
873  
874 =head2 Append_bootclasspath
875  
876 <append_bootclasspath>
877 <dir/>*
878 <jar/>*
879 </append_bootclasspath>
880  
881 Specify elements to append to the boot classpath.
882  
883 =head2 Classpath
884  
885 <classpath>
886 <dir/>*
887 <jar/>*
888 </classpath>
889  
890 Specify elements to add to the classpath.
891  
892 =head2 VM
893  
894 <vm name="" vendor="" version="" language="" home="" default="true|false">
895 <property/>*
896 <param/>*
897 <environment/>*
898 </vm>
899  
900 <vm ref="">
901 <property/>*
902 <param/>*
903 <environment/>*
904 </vm>
905  
906  
907 The VM tag is used to define or refer to an existing VM description.
908  
909 In the first instance a VM definition includes;
910  
911 =over 4
912  
913 =item name
914  
915 A unique name to refer to this VM description
916  
917 =item vendor
918  
919 The vendor name
920  
921 =item version
922  
923 The version number
924  
925 =item language
926  
927 The Java language version this VM supports
928  
929 =item home
930  
931 The JAVA_HOME location for this VM
932  
933 =item default
934  
935 Whether or not to use this VM if one is not explicitly specified
936 by an application.
937  
938 =back
939  
940 The VM marked 'default' in the system config will be used unless the
941 application config specifically mentions another VM.
942  
943 Only a single VM should be marked as 'default'.
944  
945 When used with a ref attribute it refers to a previously defined VM by name
946 and possible adds/overrides some of the proeprties and environment settings.
947  
948 The VM tag allows you to specify properties to set on a per-vm bases and
949 also allows you to specify arbitrary command line arguments to pass to the
950 VM. It also allows you to specify environment settings to apply to the VM.
951  
952 =head2 Debug
953  
954 <debug level=""/>
955  
956 Set the debug level
957  
958  
959 =head1 VARIABLES
960  
961 The following variables and their relevant defaults are used by the system.
962 These defaults have been chosen to make it as easy as possible to install SJ
963 on a fairly standard UNIX system and have logs, and directories in places
964 that you would expect to find them.
965  
966 The full paths that will be used if every default is in effect is also shown
967 below.
968  
969  
970 dir.base
971 - default /usr/local
972 - full /usr/local
973  
974 The base directory for the system. This directory is used in conjunction
975 with defaults to find directories if they have not been defined elsewhere.
976  
977  
978 dir.lib
979 - default ${dir.base}/lib/sj
980 - full /usr/local/lib/sj
981  
982 The directory to find jar files in.
983  
984  
985 dir.pid
986 - default ${dir.base}/var/run
987 - full /usr/local/var/run
988  
989 The directory to store PID files in.
990  
991  
992 dir.log
993 - default ${dir.base}/var/log/sj
994 - full /usr/local/var/log/sj
995  
996 The directory to store log files in
997  
998  
999 dir.script
1000 - default ${dir.base}/var/sj/script
1001 - full /usr/local/var/sj/script
1002  
1003 The directory to store generated script files in.
1004  
1005  
1006 dir.tmp
1007 - default &File::Spec::Functions::tmpdir
1008 - full N/A (depends on system)
1009  
1010 The directory to store temporary files in.
1011  
1012  
1013 app.name
1014 - no default
1015  
1016 The name of the application
1017  
1018  
1019 app.class
1020 - no default
1021  
1022 The class file for the application
1023  
1024  
1025 vm.default
1026 - Defined by whichever VM has default=true attribute
1027  
1028 The default VM tag to use if none supplied by the application
1029  
1030 =head1 TODO
1031  
1032 Test, test, test.
1033  
1034 =head1 BUGS
1035  
1036 None known so far. Please report any and all to Nigel Rantor <F<wiggly@wiggly.org>>
1037  
1038 =head1 SUPPORT / WARRANTY
1039  
1040 This module is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
1041  
1042 =head1 LICENSE
1043  
1044 The Java::SJ::Config module is Copyright (c) 2003 Nigel Rantor. England.
1045 All rights reserved.
1046  
1047 You may distribute under the terms of either the GNU General Public License
1048 or the Artistic License, as specified in the Perl README file.
1049  
1050 =head1 AUTHORS
1051  
1052 Nigel Rantor <F<wiggly@wiggly.org>>
1053  
1054 =head1 SEE ALSO
1055  
1056 L<Java::SJ>.
1057  
1058 =cut
« SJ/Classpath.pm ↑ Summary SJ.pm »