KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > modeler > Main


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.commons.modeler;
19
20
21 import java.io.File JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.List JavaDoc;
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 JavaDoc file;
43     String JavaDoc home;
44
45     public void setFile( String JavaDoc f ) {
46         this.file=f;
47     }
48
49     // shortcut
50
public void setF( String JavaDoc f ) {
51         this.file=f;
52     }
53
54     public void execute( )
55         throws Exception JavaDoc
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 JavaDoc( "No file, use -file file.xml");
63
64         Registry reg=Registry.getRegistry();
65         File JavaDoc fileF=new File JavaDoc( file );
66         URL JavaDoc url=new URL JavaDoc("file", null, fileF.getAbsolutePath());
67
68         // Load the mbeans defined in the file and set all
69
// attributes
70
List JavaDoc 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 JavaDoc args[] ) {
76         try {
77             Main main=new Main();
78             IntrospectionUtils.processArgs(main, args);
79
80             main.execute();
81         } catch( Exception JavaDoc ex ) {
82             ex.printStackTrace();
83         }
84
85     }
86 }
87
Popular Tags