01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.modeler;
19:
20: import java.io.File;
21: import java.net.URL;
22: import java.util.List;
23:
24: import org.apache.commons.modeler.util.IntrospectionUtils;
25:
26: /**
27: * Small main that loads mbeans.
28: *
29: * Requires: commons-logging-api.jar, jaxp ( including DOM ), jmx
30: *
31: * Arguments:
32: * -file FILE
33: * Will load mbeans from the file
34: *
35: * @author Costin Manolache
36: */
37:
38: public class Main {
39: String file;
40: String home;
41:
42: public void setFile(String f) {
43: this .file = f;
44: }
45:
46: // shortcut
47: public void setF(String f) {
48: this .file = f;
49: }
50:
51: public void execute() throws Exception {
52: if (home == null) {
53: home = IntrospectionUtils.guessInstall("install.dir",
54: "home.dir", "commons-modeler.jar",
55: "org.apache.commons.modeler.Main");
56: }
57:
58: if (file == null)
59: throw new Exception("No file, use -file file.xml");
60:
61: Registry reg = Registry.getRegistry();
62: File fileF = new File(file);
63: URL url = new URL("file", null, fileF.getAbsolutePath());
64:
65: // Load the mbeans defined in the file and set all
66: // attributes
67: List mbeans = reg.loadMBeans(url, null);
68: reg.invoke(mbeans, "init", false);
69: reg.invoke(mbeans, "start", false);
70: }
71:
72: public static void main(String args[]) {
73: try {
74: Main main = new Main();
75: IntrospectionUtils.processArgs(main, args);
76:
77: main.execute();
78: } catch (Exception ex) {
79: ex.printStackTrace();
80: }
81:
82: }
83: }
|