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.MBeanAttributeInfo;
023:
024: /**
025: * <p>Internal configuration information for an <code>Attribute</code>
026: * descriptor.</p>
027: *
028: * @author Craig R. McClanahan
029: */
030: public class AttributeInfo extends FeatureInfo implements Serializable {
031: static final long serialVersionUID = -2511626862303972143L;
032:
033: // ----------------------------------------------------- Instance Variables
034: protected String displayName = null;
035:
036: // Information about the method to use
037: protected String getMethod = null;
038: protected String setMethod = null;
039: protected boolean readable = true;
040: protected boolean writeable = true;
041: protected boolean is = false;
042:
043: // ------------------------------------------------------------- Properties
044:
045: /**
046: * The display name of this attribute.
047: */
048: public String getDisplayName() {
049: return (this .displayName);
050: }
051:
052: public void setDisplayName(String displayName) {
053: this .displayName = displayName;
054: }
055:
056: /**
057: * The name of the property getter method, if non-standard.
058: */
059: public String getGetMethod() {
060: if (getMethod == null)
061: getMethod = getMethodName(getName(), true, isIs());
062: return (this .getMethod);
063: }
064:
065: public void setGetMethod(String getMethod) {
066: this .getMethod = getMethod;
067: }
068:
069: /**
070: * Is this a boolean attribute with an "is" getter?
071: */
072: public boolean isIs() {
073: return (this .is);
074: }
075:
076: public void setIs(boolean is) {
077: this .is = is;
078: }
079:
080: /**
081: * Is this attribute readable by management applications?
082: */
083: public boolean isReadable() {
084: return (this .readable);
085: }
086:
087: public void setReadable(boolean readable) {
088: this .readable = readable;
089: }
090:
091: /**
092: * The name of the property setter method, if non-standard.
093: */
094: public String getSetMethod() {
095: if (setMethod == null)
096: setMethod = getMethodName(getName(), false, false);
097: return (this .setMethod);
098: }
099:
100: public void setSetMethod(String setMethod) {
101: this .setMethod = setMethod;
102: }
103:
104: /**
105: * Is this attribute writeable by management applications?
106: */
107: public boolean isWriteable() {
108: return (this .writeable);
109: }
110:
111: public void setWriteable(boolean writeable) {
112: this .writeable = writeable;
113: }
114:
115: // --------------------------------------------------------- Public Methods
116:
117: /**
118: * Create and return a <code>ModelMBeanAttributeInfo</code> object that
119: * corresponds to the attribute described by this instance.
120: */
121: MBeanAttributeInfo createAttributeInfo() {
122: // Return our cached information (if any)
123: if (info == null) {
124: info = new MBeanAttributeInfo(getName(), getType(),
125: getDescription(), isReadable(), isWriteable(),
126: false);
127: }
128: return (MBeanAttributeInfo) info;
129: }
130:
131: // -------------------------------------------------------- Private Methods
132:
133: /**
134: * Create and return the name of a default property getter or setter
135: * method, according to the specified values.
136: *
137: * @param name Name of the property itself
138: * @param getter Do we want a get method (versus a set method)?
139: * @param is If returning a getter, do we want the "is" form?
140: */
141: private String getMethodName(String name, boolean getter, boolean is) {
142:
143: StringBuffer sb = new StringBuffer();
144: if (getter) {
145: if (is)
146: sb.append("is");
147: else
148: sb.append("get");
149: } else
150: sb.append("set");
151: sb.append(Character.toUpperCase(name.charAt(0)));
152: sb.append(name.substring(1));
153: return (sb.toString());
154:
155: }
156:
157: }
|