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
18 package org.apache.geronimo.console.web.taglib;
19
20 import java.io.IOException;
21 import javax.management.MBeanServer;
22 import javax.servlet.jsp.JspWriter;
23
24 /**
25 * This tag presents the contents of an attribute from the MBeanServerContext
26 * tag to the screen. The attribute type is defined with the "type" parameter
27 * in the attribute tag.
28 *
29 */
30 public final class MBeanServerContextValueTag extends MBeanServerContextSupport {
31 private String type = "";
32 private MBeanServerContextTag ctx;
33 private MBeanServer server;
34
35 public int doStartTag() {
36 ctx = getMBeanServerContext();
37 server = ctx.getMBeanServer();
38 JspWriter out = pageContext.getOut();
39
40 try {
41 if (server != null) {
42 String output = getContextValue(getType());
43 out.print(output);
44 }
45 } catch (IOException e) {
46 e.printStackTrace();
47 }
48 return EVAL_BODY_INCLUDE;
49 }
50
51 public int doEndTag() {
52 return EVAL_PAGE;
53 }
54
55 public String getType() {
56 return type;
57 }
58
59 public void setType(String type) {
60 this.type = type;
61 }
62
63 private String getContextValue(String type) {
64 if (type.equals("ObjectNameFilter")) {
65 return ctx.getObjectNameFilter();
66 }
67 return "error, attribute [" + type + "] not recognized";
68 }
69 }