Index: catalina/mbeans/MBeanFactory.java
===================================================================
--- catalina/mbeans/MBeanFactory.java (revision 930191)
+++ catalina/mbeans/MBeanFactory.java (working copy)
@@ -36,6 +36,7 @@
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardServer;
import org.apache.catalina.core.StandardService;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.realm.DataSourceRealm;
@@ -51,6 +52,7 @@
import org.apache.catalina.valves.RemoteHostValve;
import org.apache.catalina.valves.ValveBase;
import org.apache.tomcat.util.modeler.BaseModelMBean;
+import org.apache.tomcat.util.modeler.Registry;
/**
@@ -232,6 +234,69 @@
}
+ private Server getServer(ObjectName oname) throws Exception{
+ Server server=null;
+
+ if(container instanceof Service){
+ server=((StandardService)container).getServer();
+ } else if(container instanceof Server){
+ server=(Server)this.container;
+ }
+
+ StandardServer standardServer=null;
+ if(server instanceof StandardServer){
+ standardServer = (StandardServer)server;
+ }
+
+ if(oname != null && standardServer != null
+ && !oname.getDomain().equals(standardServer.getObjectName().getDomain())){
+ throw new Exception("Server with the domain is not found");
+ }
+
+ return server;
+ }
+
+ /**
+ * Creates a new StandardService.
+ *
+ * @param parent MBean Name of the associated parent component (Server)
+ * @param name Name of this service
+ * @param container Name of the associated container (Engine) instance with this service
+ * @param domain Domain name for the container instance
+ * @param defaultHost Name of the default host to be used in the Engine
+ * @param baseDir Base directory value for Engine
+ *
+ * @exception Exception if an MBean cannot be created or registered
+ */
+ public String createStandardService(String parent, String name,
+ String container, String domain, String defaultHost, String baseDir) throws Exception{
+
+ ObjectName pname = new ObjectName(parent);
+ Server server=getServer(pname);
+ StandardService service = new StandardService();
+ service.setName(name);
+
+ ObjectName oname;
+ if(domain != null){
+ oname=new ObjectName(domain + ":type=Service,serviceName="+name);
+ }else{
+ oname=new ObjectName(pname.getDomain() + ":type=Service,serviceName="+name);
+ }
+
+ service.preRegister(Registry.getRegistry(null, null).getMBeanServer(), oname);
+ Registry.getRegistry(null, null).registerComponent(service, oname, null);
+ server.addService(service);
+
+ StandardEngine engine = new StandardEngine();
+ engine.setName( container );
+ engine.setDomain(domain);
+ engine.setDefaultHost(defaultHost);
+ engine.setBaseDir(baseDir);
+ service.setContainer(engine);
+
+ return (oname.toString());
+
+ }
/**
* Create a new AccessLoggerValve.
@@ -685,7 +750,7 @@
}
-
+
/**
* Create a new StandardManager.
*
@@ -777,7 +842,22 @@
}
-
+ /**
+ * Remove an existing Service.
+ *
+ * @param name MBean Name of the service to remove
+ *
+ * @exception Exception if a component cannot be removed
+ */
+ public void removeService(String name) throws Exception{
+
+ ObjectName oname = new ObjectName(name);
+ Service service = getService(oname);
+ Server server = service.getServer();
+ server.removeService(service);
+
+ }
+
/**
* Remove an existing Connector.
*
Index: catalina/mbeans/mbeans-descriptors.xml
===================================================================
--- catalina/mbeans/mbeans-descriptors.xml (revision 930191)
+++ catalina/mbeans/mbeans-descriptors.xml (working copy)
@@ -27,6 +27,30 @@
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-