View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     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  package org.apache.geronimo.system.main;
18  
19  import org.apache.geronimo.kernel.Kernel;
20  import org.apache.geronimo.gbean.AbstractName;
21  import org.apache.geronimo.gbean.AbstractNameQuery;
22  
23  import java.util.Map;
24  import java.util.HashMap;
25  import java.util.Set;
26  import java.util.Iterator;
27  
28  /**
29   * Utility functions for dealing with web applications
30   *
31   * @version $Rev: 391894 $ $Date: 2006-04-05 21:00:33 -0700 (Wed, 05 Apr 2006) $
32   */
33  public class WebAppUtil {
34      /**
35       * Generates a Map where the keys are web container object names (as Strings)
36       * and the values are URLs (as Strings) to connect to a web app running in
37       * the matching container (though the web app context needs to be added to
38       * the end to be complete).
39       *
40       * NOTE: same as a method in geronimo-jsr88 CommandSupport, but neither
41       *       module should obviously be dependent on the other and it's not
42       *       clear that this belongs in geronimo-common
43       */
44      public static Map mapContainersToURLs(Kernel kernel) throws Exception {
45          Map containers = new HashMap();
46          Set set = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.management.geronimo.WebManager"));
47          for (Iterator it = set.iterator(); it.hasNext();) {
48              AbstractName manager = (AbstractName) it.next();
49              Map results = (Map)kernel.invoke(manager, "mapContainersToURLs");
50              containers.putAll(results);
51          }
52          return containers;
53      }
54  }