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: */package org.apache.geronimo.gbean;
017:
018: import java.io.Serializable;
019: import java.util.Arrays;
020:
021: import org.apache.geronimo.kernel.KernelRegistry;
022:
023: /**
024: * Describes an attibute of a GBean.
025: *
026: * @version $Rev: 564608 $ $Date: 2007-08-10 07:43:14 -0700 (Fri, 10 Aug 2007) $
027: */
028: public class GAttributeInfo implements Serializable {
029: private static final long serialVersionUID = 2805493042418685048L;
030:
031: /**
032: * Name of this attribute.
033: */
034: private final String name;
035:
036: /**
037: * Type of this attribute.
038: */
039: private final String type;
040:
041: /**
042: * Is this attribute persistent?
043: */
044: private final boolean persistent;
045:
046: /**
047: * Is this attribute manageable?
048: */
049: private final boolean manageable;
050:
051: /**
052: * Is this attribute readable?
053: */
054: private final boolean readable;
055:
056: /**
057: * Is this attribute writiable?
058: */
059: private final boolean writable;
060:
061: /**
062: * Name of the getter method.
063: * The default is "get" + name. In the case of a defualt value we do a caseless search for the name.
064: */
065: private final String getterName;
066:
067: /**
068: * Name of the setter method.
069: * The default is "set" + name. In the case of a defualt value we do a caseless search for the name.
070: */
071: private final String setterName;
072:
073: public GAttributeInfo(String name, String type, boolean persistent,
074: boolean manageable, String getterName, String setterName) {
075: this (name, type, persistent, manageable, getterName != null,
076: setterName != null, getterName, setterName);
077: }
078:
079: public GAttributeInfo(String name, String type, boolean persistent,
080: boolean manageable, boolean readable, boolean writable,
081: String getterName, String setterName) {
082: this .name = name;
083: this .type = type;
084: this .persistent = persistent;
085: //non persistent attributes cannot be manageable
086: this .manageable = manageable & persistent;
087: this .readable = readable;
088: this .writable = writable;
089: this .getterName = getterName;
090: this .setterName = setterName;
091: }
092:
093: public String getName() {
094: return name;
095: }
096:
097: public String getType() {
098: return type;
099: }
100:
101: public boolean isPersistent() {
102: return persistent;
103: }
104:
105: public boolean isManageable() {
106: return manageable;
107: }
108:
109: public boolean isReadable() {
110: return readable;
111: }
112:
113: public boolean isWritable() {
114: return writable;
115: }
116:
117: public String getGetterName() {
118: return getterName;
119: }
120:
121: public String getSetterName() {
122: return setterName;
123: }
124:
125: public String toString() {
126: return "[GAttributeInfo: name=" + name + " type=" + type
127: + " persistent=" + persistent + " manageable="
128: + manageable + " readable=" + readable + " writable="
129: + writable + " getterName=" + getterName
130: + " setterName=" + setterName + "]";
131: }
132:
133: public String toXML(AbstractName abstractName) {
134: StringBuilder xml = new StringBuilder();
135:
136: xml.append("<gAttributeInfo ");
137: xml.append("name='" + name + "' ");
138: xml.append("type='" + type + "' ");
139: xml.append("persistent='" + persistent + "' ");
140: xml.append("manageable='" + manageable + "' ");
141: xml.append("readable='" + readable + "' ");
142: xml.append("writable='" + writable + "' ");
143: xml.append(">");
144:
145: xml.append("<getterName>" + getterName + "</getterName>");
146: xml.append("<setterName>" + setterName + "</setterName>");
147:
148: if (readable) {
149: try {
150: Object value = KernelRegistry.getSingleKernel()
151: .getAttribute(abstractName, name);
152: if (value != null) {
153: if (value instanceof String[]) {
154: for (String valueString : Arrays
155: .asList((String[]) value))
156: xml.append("<value>" + valueString
157: + "</value>");
158: } else {
159: xml.append("<value>" + value + "</value>");
160: }
161: }
162: } catch (Exception e) {
163:
164: }
165: }
166:
167: xml.append("</gAttributeInfo>");
168:
169: return xml.toString();
170: }
171: }
|