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