001: /*
002: * Copyright 2002,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.catalina.ant;
018:
019: import org.apache.tools.ant.BuildException;
020:
021: /**
022: * Ant task that implements the JMX Set command (<code>/jmxproxy/?set</code>)
023: * supported by the Tomcat manager application.
024: *
025: * @author Vivek Chopra
026: * @version $Revision: 1.4 $
027: */
028: public class JMXSetTask extends AbstractCatalinaTask {
029:
030: // Properties
031:
032: /**
033: * The full bean name
034: */
035: protected String bean = null;
036:
037: /**
038: * The attribute you wish to alter
039: */
040: protected String attribute = null;
041:
042: /**
043: * The new value for the attribute
044: */
045: protected String value = null;
046:
047: // Public Methods
048:
049: /**
050: * Get method for the bean name
051: * @return Bean name
052: */
053: public String getBean() {
054: return this .bean;
055: }
056:
057: /**
058: * Set method for the bean name
059: * @param bean Bean name
060: */
061: public void setBean(String bean) {
062: this .bean = bean;
063: }
064:
065: /**
066: * Get method for the attribute name
067: * @return Attribute name
068: */
069: public String getAttribute() {
070: return this .attribute;
071: }
072:
073: /**
074: * Set method for the attribute name
075: * @param attribute Attribute name
076: */
077: public void setAttribute(String attribute) {
078: this .attribute = attribute;
079: }
080:
081: /**
082: * Get method for the attribute value
083: * @return Attribute value
084: */
085: public String getValue() {
086: return this .value;
087: }
088:
089: /**
090: * Set method for the attribute value.
091: * @param value Attribute value
092: */
093: public void setValue(String value) {
094: this .value = value;
095: }
096:
097: /**
098: * Execute the requested operation.
099: *
100: * @exception BuildException if an error occurs
101: */
102: public void execute() throws BuildException {
103: super .execute();
104: if (bean == null || attribute == null || value == null) {
105: throw new BuildException(
106: "Must specify 'bean', 'attribute' and 'value' attributes");
107: }
108: System.out.println("INFO: Setting attribute " + attribute
109: + " in bean " + bean + " to " + value);
110: execute("/jmxproxy/?set=" + bean + "&att=" + attribute
111: + "&val=" + value);
112: }
113: }
|