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 package org.apache.tomcat.util.modeler;
19
20 import javax.management.MBeanAttributeInfo;
21
22
23 /**
24  * <p>Internal configuration information for an <code>Attribute</code>
25  * descriptor.</p>
26  *
27  * @author Craig R. McClanahan
28  */

29 public class AttributeInfo extends FeatureInfo {
30     static final long serialVersionUID = -2511626862303972143L;
31
32     // ----------------------------------------------------- Instance Variables
33     protected String displayName = null;
34
35     // Information about the method to use
36     protected String getMethod = null;
37     protected String setMethod = null;
38     protected boolean readable = true;
39     protected boolean writeable = true;
40     protected boolean is = false;
41
42     // ------------------------------------------------------------- Properties
43
44     /**
45      * @return the display name of this attribute.
46      */

47     public String getDisplayName() {
48         return this.displayName;
49     }
50
51     public void setDisplayName(String displayName) {
52         this.displayName = displayName;
53     }
54
55     /**
56      * @return the name of the property getter method, if non-standard.
57      */

58     public String getGetMethod() {
59         if(getMethod == null)
60             getMethod = getMethodName(getName(), true, isIs());
61         return this.getMethod;
62     }
63
64     public void setGetMethod(String getMethod) {
65         this.getMethod = getMethod;
66     }
67
68     /**
69      * Is this a boolean attribute with an "is" getter?
70      * @return <code>true</code> if this is a boolean attribute
71      *  with an "is" getter
72      */

73     public boolean isIs() {
74         return this.is;
75     }
76
77     public void setIs(boolean is) {
78         this.is = is;
79     }
80
81
82     /**
83      * Is this attribute readable by management applications?
84      * @return <code>true</code> if readable
85      */

86     public boolean isReadable() {
87         return this.readable;
88     }
89
90     public void setReadable(boolean readable) {
91         this.readable = readable;
92     }
93
94
95     /**
96      * @return the name of the property setter method, if non-standard.
97      */

98     public String getSetMethod() {
99         if( setMethod == null )
100             setMethod = getMethodName(getName(), falsefalse);
101         return this.setMethod;
102     }
103
104     public void setSetMethod(String setMethod) {
105         this.setMethod = setMethod;
106     }
107
108     /**
109      * Is this attribute writable by management applications?
110      * @return <code>true</code> if writable
111      */

112     public boolean isWriteable() {
113         return this.writeable;
114     }
115
116     public void setWriteable(boolean writeable) {
117         this.writeable = writeable;
118     }
119
120     // --------------------------------------------------------- Public Methods
121
122
123     /**
124      * Create and return a <code>ModelMBeanAttributeInfo</code> object that
125      * corresponds to the attribute described by this instance.
126      * @return the attribute info
127      */

128     MBeanAttributeInfo createAttributeInfo() {
129         // Return our cached information (if any)
130         if (info == null) {
131             info = new MBeanAttributeInfo(getName(), getType(), getDescription(),
132                             isReadable(), isWriteable(), false);
133         }
134         return (MBeanAttributeInfo)info;
135     }
136
137     // -------------------------------------------------------- Private Methods
138
139
140     /**
141      * Create and return the name of a default property getter or setter
142      * method, according to the specified values.
143      *
144      * @param name Name of the property itself
145      * @param getter Do we want a get method (versus a set method)?
146      * @param is If returning a getter, do we want the "is" form?
147      * @return the method name
148      */

149     private String getMethodName(String name, boolean getter, boolean is) {
150         StringBuilder sb = new StringBuilder();
151         if (getter) {
152             if (is)
153                 sb.append("is");
154             else
155                 sb.append("get");
156         } else
157             sb.append("set");
158         sb.append(Character.toUpperCase(name.charAt(0)));
159         sb.append(name.substring(1));
160         return sb.toString();
161     }
162
163
164 }
165