View Javadoc

1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.commons.jelly.tags.jmx;
18  
19  import javax.management.MBeanServer;
20  import javax.management.MBeanServerFactory;
21  
22  import org.apache.commons.jelly.JellyTagException;
23  import org.apache.commons.jelly.MissingAttributeException;
24  import org.apache.commons.jelly.TagSupport;
25  import org.apache.commons.jelly.XMLOutput;
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  /***
30   * Binds a Java bean to the given named Jelly tag so that the attributes of
31   * the tag set the bean properties..
32   *
33   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
34   * @version $Revision: 155420 $
35   */
36  public class ServerTag extends TagSupport {
37  
38      /*** The Log to which logging calls will be made. */
39      private static final Log log = LogFactory.getLog(ServerTag.class);
40  
41      private MBeanServer server;
42  
43      public ServerTag() {
44      }
45  
46      // Tag interface
47      //-------------------------------------------------------------------------
48      public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
49  
50          // force the creation of a Server
51          MBeanServer server = getServer();
52  
53          // allow children to register beans
54          invokeBody(output);
55      }
56  
57  
58      // Properties
59      //-------------------------------------------------------------------------
60      /***
61       * @return MBeanServer
62       */
63      public MBeanServer getServer() {
64          if (server == null) {
65              server = createServer();
66          }
67          return server;
68      }
69  
70      /***
71       * Sets the server.
72       * @param server The server to set
73       */
74      public void setServer(MBeanServer server) {
75          this.server = server;
76      }
77  
78  
79  
80      // Implementation methods
81      //-------------------------------------------------------------------------
82      /***
83       * Factory method to lazily create an MBeanServer if none is supplied
84       *
85       * @return MBeanServer
86       */
87      protected MBeanServer createServer() {
88          return MBeanServerFactory.newMBeanServer();
89      }
90  
91  }