KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > modeler > AttributeInfo


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 JavaDoc;
23
24 import javax.management.MBeanAttributeInfo JavaDoc;
25
26
27 /**
28  * <p>Internal configuration information for an <code>Attribute</code>
29  * descriptor.</p>
30  *
31  * @author Craig R. McClanahan
32  */

33 public class AttributeInfo extends FeatureInfo implements Serializable JavaDoc {
34     static final long serialVersionUID = -2511626862303972143L;
35
36     // ----------------------------------------------------- Instance Variables
37
protected String JavaDoc displayName = null;
38
39     // Information about the method to use
40
protected String JavaDoc getMethod = null;
41     protected String JavaDoc setMethod = null;
42     protected boolean readable = true;
43     protected boolean writeable = true;
44     protected boolean is = false;
45     
46     // ------------------------------------------------------------- Properties
47

48     /**
49      * The display name of this attribute.
50      */

51     public String JavaDoc getDisplayName() {
52         return (this.displayName);
53     }
54
55     public void setDisplayName(String JavaDoc displayName) {
56         this.displayName = displayName;
57     }
58
59     /**
60      * The name of the property getter method, if non-standard.
61      */

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

75     public boolean isIs() {
76         return (this.is);
77     }
78
79     public void setIs(boolean is) {
80         this.is = is;
81     }
82
83
84     /**
85      * Is this attribute readable by management applications?
86      */

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

99     public String JavaDoc getSetMethod() {
100         if( setMethod == null )
101             setMethod = getMethodName(getName(), false, false);
102         return (this.setMethod);
103     }
104
105     public void setSetMethod(String JavaDoc setMethod) {
106         this.setMethod = setMethod;
107     }
108
109     /**
110      * Is this attribute writeable by management applications?
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      */

127     MBeanAttributeInfo JavaDoc createAttributeInfo() {
128         // Return our cached information (if any)
129
if (info == null) {
130             info = new MBeanAttributeInfo JavaDoc(getName(), getType(), getDescription(),
131                             isReadable(), isWriteable(), false);
132         }
133         return (MBeanAttributeInfo JavaDoc)info;
134     }
135
136     // -------------------------------------------------------- Private Methods
137

138
139     /**
140      * Create and return the name of a default property getter or setter
141      * method, according to the specified values.
142      *
143      * @param name Name of the property itself
144      * @param getter Do we want a get method (versus a set method)?
145      * @param is If returning a getter, do we want the "is" form?
146      */

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