1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.modeler;
19
20
21 import java.io.File;
22 import java.net.URL;
23 import java.util.List;
24
25 import org.apache.commons.modeler.util.IntrospectionUtils;
26
27
28 /***
29 * Small main that loads mbeans.
30 *
31 * Requires: commons-logging-api.jar, jaxp ( including DOM ), jmx
32 *
33 * Arguments:
34 * -file FILE
35 * Will load mbeans from the file
36 *
37 * @author Costin Manolache
38 */
39
40 public class Main
41 {
42 String file;
43 String home;
44
45 public void setFile( String f ) {
46 this.file=f;
47 }
48
49
50 public void setF( String f ) {
51 this.file=f;
52 }
53
54 public void execute( )
55 throws Exception
56 {
57 if( home==null ) {
58 home=IntrospectionUtils.guessInstall("install.dir", "home.dir",
59 "commons-modeler.jar", "org.apache.commons.modeler.Main");
60 }
61
62 if( file==null ) throw new Exception( "No file, use -file file.xml");
63
64 Registry reg=Registry.getRegistry();
65 File fileF=new File( file );
66 URL url=new URL("file", null, fileF.getAbsolutePath());
67
68
69
70 List mbeans=reg.loadMBeans( url, null);
71 reg.invoke(mbeans, "init", false);
72 reg.invoke(mbeans, "start", false);
73 }
74
75 public static void main( String args[] ) {
76 try {
77 Main main=new Main();
78 IntrospectionUtils.processArgs(main, args);
79
80 main.execute();
81 } catch( Exception ex ) {
82 ex.printStackTrace();
83 }
84
85 }
86 }