001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.tomcat.util.modeler;
019:
020: import java.io.Serializable;
021:
022: import javax.management.MBeanOperationInfo;
023: import javax.management.MBeanParameterInfo;
024:
025: /**
026: * <p>Internal configuration information for an <code>Operation</code>
027: * descriptor.</p>
028: *
029: * @author Craig R. McClanahan
030: */
031: public class OperationInfo extends FeatureInfo implements Serializable {
032: static final long serialVersionUID = 4418342922072614875L;
033:
034: // ----------------------------------------------------------- Constructors
035:
036: /**
037: * Standard zero-arguments constructor.
038: */
039: public OperationInfo() {
040:
041: super ();
042:
043: }
044:
045: // ----------------------------------------------------- Instance Variables
046:
047: protected String impact = "UNKNOWN";
048: protected String role = "operation";
049: protected ParameterInfo parameters[] = new ParameterInfo[0];
050:
051: // ------------------------------------------------------------- Properties
052:
053: /**
054: * The "impact" of this operation, which should be a (case-insensitive)
055: * string value "ACTION", "ACTION_INFO", "INFO", or "UNKNOWN".
056: */
057: public String getImpact() {
058: return (this .impact);
059: }
060:
061: public void setImpact(String impact) {
062: if (impact == null)
063: this .impact = null;
064: else
065: this .impact = impact.toUpperCase();
066: }
067:
068: /**
069: * The role of this operation ("getter", "setter", "operation", or
070: * "constructor").
071: */
072: public String getRole() {
073: return (this .role);
074: }
075:
076: public void setRole(String role) {
077: this .role = role;
078: }
079:
080: /**
081: * The fully qualified Java class name of the return type for this
082: * operation.
083: */
084: public String getReturnType() {
085: if (type == null) {
086: type = "void";
087: }
088: return type;
089: }
090:
091: public void setReturnType(String returnType) {
092: this .type = returnType;
093: }
094:
095: /**
096: * The set of parameters for this operation.
097: */
098: public ParameterInfo[] getSignature() {
099: return (this .parameters);
100: }
101:
102: // --------------------------------------------------------- Public Methods
103:
104: /**
105: * Add a new parameter to the set of arguments for this operation.
106: *
107: * @param parameter The new parameter descriptor
108: */
109: public void addParameter(ParameterInfo parameter) {
110:
111: synchronized (parameters) {
112: ParameterInfo results[] = new ParameterInfo[parameters.length + 1];
113: System.arraycopy(parameters, 0, results, 0,
114: parameters.length);
115: results[parameters.length] = parameter;
116: parameters = results;
117: this .info = null;
118: }
119:
120: }
121:
122: /**
123: * Create and return a <code>ModelMBeanOperationInfo</code> object that
124: * corresponds to the attribute described by this instance.
125: */
126: MBeanOperationInfo createOperationInfo() {
127:
128: // Return our cached information (if any)
129: if (info == null) {
130: // Create and return a new information object
131: int impact = MBeanOperationInfo.UNKNOWN;
132: if ("ACTION".equals(getImpact()))
133: impact = MBeanOperationInfo.ACTION;
134: else if ("ACTION_INFO".equals(getImpact()))
135: impact = MBeanOperationInfo.ACTION_INFO;
136: else if ("INFO".equals(getImpact()))
137: impact = MBeanOperationInfo.INFO;
138:
139: info = new MBeanOperationInfo(getName(), getDescription(),
140: getMBeanParameterInfo(), getReturnType(), impact);
141: }
142: return (MBeanOperationInfo) info;
143: }
144:
145: protected MBeanParameterInfo[] getMBeanParameterInfo() {
146: ParameterInfo params[] = getSignature();
147: MBeanParameterInfo parameters[] = new MBeanParameterInfo[params.length];
148: for (int i = 0; i < params.length; i++)
149: parameters[i] = params[i].createParameterInfo();
150: return parameters;
151: }
152: }
|