Some more ServerFactory removal.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 24 May 2009 18:39:52 +0000 (18:39 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 24 May 2009 18:39:52 +0000 (18:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@778207 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/mbeans/MBeanFactory.java
java/org/apache/catalina/mbeans/ServerLifecycleListener.java

index 9113279..b4f90c4 100644 (file)
@@ -97,11 +97,20 @@ public class MBeanFactory extends BaseModelMBean {
 
     // ------------------------------------------------------------- Attributes
 
-
+    /**
+     * The container (Server/Service) for which this factory was created.
+     */
+    private Object container;
 
 
     // ------------------------------------------------------------- Operations
 
+    /**
+     * Set the container that this factory was created for.
+     */
+    public void setContainer(Object container) {
+        this.container = container;
+    }
 
     /**
      * Return the managed bean definition for the specified bean type
@@ -202,17 +211,25 @@ public class MBeanFactory extends BaseModelMBean {
     
     private Service getService(ObjectName oname) throws Exception {
     
-        String domain = oname.getDomain();
-        Server server = ServerFactory.getServer();
-        Service[] services = server.findServices();
+        if (container instanceof Service) {
+            // Don't bother checking the domain - this is the only option
+            return (Service) container;
+        }
+
         StandardService service = null;
-        for (int i = 0; i < services.length; i++) {
-            service = (StandardService) services[i];
-            if (domain.equals(service.getObjectName().getDomain())) {
-                break;
+        String domain = oname.getDomain();
+        if (container instanceof Service) {
+            Server server = ServerFactory.getServer();
+            Service[] services = server.findServices();
+            for (int i = 0; i < services.length; i++) {
+                service = (StandardService) services[i];
+                if (domain.equals(service.getObjectName().getDomain())) {
+                    break;
+                }
             }
         }
-        if (!service.getObjectName().getDomain().equals(domain)) {
+        if (service == null ||
+                !service.getObjectName().getDomain().equals(domain)) {
             throw new Exception("Service with the domain is not found");
         }        
         return service;
index 64ffcf9..a77c6bc 100644 (file)
@@ -128,12 +128,14 @@ public class ServerLifecycleListener
 
                 if (lifecycle instanceof Server) {
                     MBeanFactory factory = new MBeanFactory();
+                    factory.setContainer(lifecycle);
                     createMBeans(factory);
                     createMBeans((Server) lifecycle);
                 }
 
                 if( lifecycle instanceof Service ) {
                     MBeanFactory factory = new MBeanFactory();
+                    factory.setContainer(lifecycle);
                     createMBeans(factory);
                     createMBeans((Service)lifecycle);
                 }