Home » apache-tomcat-6.0.26-src » org.apache » tomcat » util » modeler » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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   
   19   package org.apache.tomcat.util.modeler;
   20   
   21   
   22   import java.io.Serializable;
   23   
   24   import javax.management.MBeanOperationInfo;
   25   import javax.management.MBeanParameterInfo;
   26   
   27   
   28   /**
   29    * <p>Internal configuration information for an <code>Operation</code>
   30    * descriptor.</p>
   31    *
   32    * @author Craig R. McClanahan
   33    */
   34   public class OperationInfo extends FeatureInfo implements Serializable {
   35       static final long serialVersionUID = 4418342922072614875L;
   36       // ----------------------------------------------------------- Constructors
   37   
   38   
   39       /**
   40        * Standard zero-arguments constructor.
   41        */
   42       public OperationInfo() {
   43   
   44           super();
   45   
   46       }
   47      
   48       // ----------------------------------------------------- Instance Variables
   49   
   50       protected String impact = "UNKNOWN";
   51       protected String role = "operation";
   52       protected ParameterInfo parameters[] = new ParameterInfo[0];
   53   
   54   
   55       // ------------------------------------------------------------- Properties
   56   
   57       /**
   58        * The "impact" of this operation, which should be a (case-insensitive)
   59        * string value "ACTION", "ACTION_INFO", "INFO", or "UNKNOWN".
   60        */
   61       public String getImpact() {
   62           return (this.impact);
   63       }
   64   
   65       public void setImpact(String impact) {
   66           if (impact == null)
   67               this.impact = null;
   68           else
   69               this.impact = impact.toUpperCase();
   70       }
   71   
   72   
   73       /**
   74        * The role of this operation ("getter", "setter", "operation", or
   75        * "constructor").
   76        */
   77       public String getRole() {
   78           return (this.role);
   79       }
   80   
   81       public void setRole(String role) {
   82           this.role = role;
   83       }
   84   
   85   
   86       /**
   87        * The fully qualified Java class name of the return type for this
   88        * operation.
   89        */
   90       public String getReturnType() {
   91           if(type == null) {
   92               type = "void";
   93           }
   94           return type;
   95       }
   96   
   97       public void setReturnType(String returnType) {
   98           this.type = returnType;
   99       }
  100   
  101       /**
  102        * The set of parameters for this operation.
  103        */
  104       public ParameterInfo[] getSignature() {
  105           return (this.parameters);
  106       }
  107   
  108       // --------------------------------------------------------- Public Methods
  109   
  110   
  111       /**
  112        * Add a new parameter to the set of arguments for this operation.
  113        *
  114        * @param parameter The new parameter descriptor
  115        */
  116       public void addParameter(ParameterInfo parameter) {
  117   
  118           synchronized (parameters) {
  119               ParameterInfo results[] = new ParameterInfo[parameters.length + 1];
  120               System.arraycopy(parameters, 0, results, 0, parameters.length);
  121               results[parameters.length] = parameter;
  122               parameters = results;
  123               this.info = null;
  124           }
  125   
  126       }
  127   
  128   
  129       /**
  130        * Create and return a <code>ModelMBeanOperationInfo</code> object that
  131        * corresponds to the attribute described by this instance.
  132        */
  133       MBeanOperationInfo createOperationInfo() {
  134   
  135           // Return our cached information (if any)
  136           if (info == null) {
  137               // Create and return a new information object
  138               int impact = MBeanOperationInfo.UNKNOWN;
  139               if ("ACTION".equals(getImpact()))
  140                   impact = MBeanOperationInfo.ACTION;
  141               else if ("ACTION_INFO".equals(getImpact()))
  142                   impact = MBeanOperationInfo.ACTION_INFO;
  143               else if ("INFO".equals(getImpact()))
  144                   impact = MBeanOperationInfo.INFO;
  145       
  146               info = new MBeanOperationInfo(getName(), getDescription(), 
  147                                             getMBeanParameterInfo(),
  148                                             getReturnType(), impact);
  149           }
  150           return (MBeanOperationInfo)info;
  151       }
  152   
  153       protected MBeanParameterInfo[] getMBeanParameterInfo() {
  154           ParameterInfo params[] = getSignature();
  155           MBeanParameterInfo parameters[] =
  156               new MBeanParameterInfo[params.length];
  157           for (int i = 0; i < params.length; i++)
  158               parameters[i] = params[i].createParameterInfo();
  159           return parameters;
  160       }
  161   }

Home » apache-tomcat-6.0.26-src » org.apache » tomcat » util » modeler » [javadoc | source]