001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 019 package org.apache.commons.modeler; 020 021 022 import java.io.File; 023 import java.net.URL; 024 import java.util.List; 025 026 import org.apache.commons.modeler.util.IntrospectionUtils; 027 028 029 /** 030 * Small main that loads mbeans. 031 * 032 * Requires: commons-logging-api.jar, jaxp ( including DOM ), jmx 033 * 034 * Arguments: 035 * -file FILE 036 * Will load mbeans from the file 037 * 038 * @author Costin Manolache 039 */ 040 041 public class Main 042 { 043 String file; 044 String home; 045 046 public void setFile( String f ) { 047 this.file=f; 048 } 049 050 // shortcut 051 public void setF( String f ) { 052 this.file=f; 053 } 054 055 public void execute( ) 056 throws Exception 057 { 058 if( home==null ) { 059 home=IntrospectionUtils.guessInstall("install.dir", "home.dir", 060 "commons-modeler.jar", "org.apache.commons.modeler.Main"); 061 } 062 063 if( file==null ) throw new Exception( "No file, use -file file.xml"); 064 065 Registry reg=Registry.getRegistry(); 066 File fileF=new File( file ); 067 URL url=new URL("file", null, fileF.getAbsolutePath()); 068 069 // Load the mbeans defined in the file and set all 070 // attributes 071 List mbeans=reg.loadMBeans( url, null); 072 reg.invoke(mbeans, "init", false); 073 reg.invoke(mbeans, "start", false); 074 } 075 076 public static void main( String args[] ) { 077 try { 078 Main main=new Main(); 079 IntrospectionUtils.processArgs(main, args); 080 081 main.execute(); 082 } catch( Exception ex ) { 083 ex.printStackTrace(); 084 } 085 086 } 087 }