Source Code Cross Referenced for ModelMBeanAttributeInfo.java in  » JMX » jfoxmx » javax » management » modelmbean » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » jfoxmx » javax.management.modelmbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.org
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package javax.management.modelmbean;
009:
010:        import java.lang.reflect.Method;
011:        import javax.management.RuntimeOperationsException;
012:        import javax.management.Descriptor;
013:        import javax.management.IntrospectionException;
014:        import javax.management.DescriptorAccess;
015:        import javax.management.MBeanAttributeInfo;
016:
017:        /**
018:         * The ModelMBeanAttributeInfo object describes an attribute of the ModelMBean.
019:         * It is a subclass of MBeanAttributeInfo with the addition of an associated Descriptor
020:         * and an implementation of the DescriptorAccess interface.
021:         * <P>
022:         * The fields in the descriptor are defined, but not limited to, the following: <P>
023:         * <PRE>
024:         * name           : attribute name
025:         * descriptorType : must be "attribute"
026:         * value          : current value for attribute
027:         * default        : default value for attribute
028:         * displayName    : name of attribute to be used in displays
029:         * getMethod      : name of operation descriptor for get method
030:         * setMethod      : name of operation descriptor for set method
031:         * protocolMap    : object which implements the ProtocolMap interface: map of protocol names and protocol hints
032:         * persistPolicy  : Update|OnTime|NoMoreOftenThan|Always|Never
033:         * persistPeriod  : seconds - frequency of persist cycle. Used when persistPolicy is"OnTime" or "NoMoreOftenThan".
034:         * currencyTimeLimit : how long value is valid, <0 never, =0 always, >0 seconds
035:         * lastUpdatedTimeStamp : when value was set
036:         * iterable       : T - object value supports Iterable interface, F - does not support Iterable interface
037:         * visibility     : 1-4 where 1: always visible 4: rarely visible
038:         * presentationString : xml formatted string to allow presentation of data
039:         * </PRE>
040:         * The default descriptor contains the name and descriptorType fields.
041:         *
042:         * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
043:         */
044:
045:        public class ModelMBeanAttributeInfo extends MBeanAttributeInfo
046:                implements  DescriptorAccess, Cloneable {
047:
048:            private Descriptor attrDescriptor;
049:
050:            /**
051:             * Constructs a ModelMBeanAttributeInfo object with a default descriptor.
052:             *
053:             * @param name The name of the attribute.
054:             * @param description A human readable description of the attribute. Optional.
055:             * @param getter The method used for reading the attribute value.
056:             *          May be null if the property is write-only.
057:             * @param setter The method used for writing the attribute value.
058:             *          May be null if the attribute is read-only.
059:             * @exception IntrospectionException There is a consistency problem in the definition of this attribute.
060:             *
061:             * The descriptor must be set before this
062:             * ModelMBeanAttributeInfo instance can be used.
063:             */
064:            public ModelMBeanAttributeInfo(String name, String description,
065:                    Method getter, Method setter) throws IntrospectionException {
066:                super (name, description, getter, setter);
067:                attrDescriptor = createDefaultDescriptor();
068:            }
069:
070:            /**
071:             * Constructs a ModelMBeanAttributeInfo object.
072:             *
073:             * @param name The name of the attribute.
074:             * @param description A human readable description of the attribute. Optional.
075:             * @param getter The method used for reading the attribute value.
076:             *          May be null if the property is write-only.
077:             * @param setter The method used for writing the attribute value.
078:             *          May be null if the attribute is read-only.
079:             * @param descriptor An instance of Descriptor containing the appropriate metadata
080:             *                   for this instance of the Attribute. If it is null or invalid then
081:             *			a default desriptor will be created.
082:             *
083:             * @exception IntrospectionException There is a consistency problem in the definition of this attribute.
084:             *
085:             * The descriptor must be set before this
086:             * ModelMBeanAttributeInfo instance can be used.
087:             */
088:            public ModelMBeanAttributeInfo(String name, String description,
089:                    Method getter, Method setter, Descriptor descriptor)
090:                    throws IntrospectionException {
091:                super (name, description, getter, setter);
092:                setDescriptor(descriptor);
093:            }
094:
095:            /**
096:             * Constructs a ModelMBeanAttributeInfo object with a default descriptor.
097:             *
098:             * @param name The name of the attribute
099:             * @param type The type or class name of the attribute
100:             * @param description A human readable description of the attribute.
101:             * @param isReadable True if the attribute has a getter method, false otherwise.
102:             * @param isWritable True if the attribute has a setter method, false otherwise.
103:             * @param isIs True if the attribute has an "is" getter, false otherwise.
104:             *
105:             */
106:            public ModelMBeanAttributeInfo(String name, String type,
107:                    String description, boolean isReadable, boolean isWritable,
108:                    boolean isIs) {
109:                super (name, type, description, isReadable, isWritable, isIs);
110:                attrDescriptor = createDefaultDescriptor();
111:            }
112:
113:            /**
114:             * Constructs a ModelMBeanAttributeInfo object with a default descriptor.
115:             *
116:             * @param name The name of the attribute
117:             * @param type The type or class name of the attribute
118:             * @param description A human readable description of the attribute.
119:             * @param isReadable True if the attribute has a getter method, false otherwise.
120:             * @param isWritable True if the attribute has a setter method, false otherwise.
121:             * @param isIs True if the attribute has an "is" getter, false otherwise.
122:             * @param descriptor An instance of Descriptor containing the appropriate metadata
123:             *                   for this instance of the Attribute. If it is null or invalid then
124:             *			a default desriptor will be created.
125:             *
126:             */
127:            public ModelMBeanAttributeInfo(String name, String type,
128:                    String description, boolean isReadable, boolean isWritable,
129:                    boolean isIs, Descriptor descriptor) {
130:                super (name, type, description, isReadable, isWritable, isIs);
131:                setDescriptor(descriptor);
132:            }
133:
134:            /**
135:             * Constructs a new ModelMBeanAttributeInfo object from this ModelMBeanAttributeInfo Object.
136:             * A default descriptor will be created.
137:             *
138:             * @param attributeInfo the ModelMBeanAttributeInfo to be duplicated
139:             */
140:            public ModelMBeanAttributeInfo(ModelMBeanAttributeInfo attributeInfo) {
141:                super (attributeInfo.getName(), attributeInfo.getType(),
142:                        attributeInfo.getDescription(), attributeInfo
143:                                .isReadable(), attributeInfo.isWritable(),
144:                        attributeInfo.isIs());
145:                Descriptor descriptor = attributeInfo.getDescriptor();
146:                setDescriptor(descriptor);
147:            }
148:
149:            /**
150:             * Gets a copy of the associated Descriptor for the ModelMBeanAttributeInfo
151:             *
152:             * @return Descriptor associated with the ModelMBeanAttributeInfo object.
153:             */
154:            public Descriptor getDescriptor() {
155:                return (Descriptor) attrDescriptor.clone();
156:            }
157:
158:            /**
159:             * Sets associated Descriptor (full replace) for the ModelMBeanAttributeDescriptor.
160:             * If the new Descriptor is null, then the associated Descriptor reverts to
161:             * a default descriptor.  The Descriptor is validated before it is assigned.  If
162:             * the new Descriptor is invalid, then an IllegalArgumentException is thrown.
163:             *
164:             * @param descriptor - replaces the Descriptor associated with the
165:             * ModelMBeanAttributeInfo
166:             *
167:             */
168:            public void setDescriptor(Descriptor descriptor) {
169:                if (descriptor == null) {
170:                    attrDescriptor = createDefaultDescriptor();
171:                } else if (isValid(descriptor))
172:                    attrDescriptor = (Descriptor) descriptor.clone();
173:                else
174:                    throw new RuntimeOperationsException(
175:                            new IllegalArgumentException(
176:                                    "Invalid descriptor passed in parameter"),
177:                            "Exception occured in ModelMBeanAttributeInfo setDescriptor");
178:            }
179:
180:            /**
181:             * Creates and returns a new ModelMBeanAttributeInfo which is a duplicate of this ModelMBeanAttributeInfo.
182:             *
183:             * @exception RuntimeOperationsException for illegal value for field URLName or field Values.
184:             *              If the descriptor construction fails for any reason, this exception will be thrown.
185:             */
186:            public Object clone() {
187:                return new ModelMBeanAttributeInfo(this );
188:            }
189:
190:            /**
191:             * Returns a human readable version of the ModelMBeanAttributeInfo instance
192:             */
193:            public String toString() {
194:                return "ModelMBeanAttributeInfo: " + getName()
195:                        + " ; Description: " + getDescription() + " ; Types: "
196:                        + getType() + " ; isReadable: " + isReadable()
197:                        + " ; isWritable: " + isWritable() + " ; Descriptor: "
198:                        + getDescriptor();
199:            }
200:
201:            /**
202:             * Creates and returns a Descriptor with default values set:
203:             *  descriptorType=attribute,name=this.getNameSpace(),displayName=this.getNameSpace(),
204:             * 		persistPolicy=never,visibility=1,iterable=F
205:             */
206:            private Descriptor createDefaultDescriptor() {
207:                return new DescriptorSupport(new String[] {
208:                        DescriptorConstants.DESCRIPTORTYPE + "="
209:                                + DescriptorConstants.ATTRIBUTE_TYPE,
210:                        DescriptorConstants.NAME + "=" + getName(),
211:                        DescriptorConstants.DISPLAYNAME + "=" + getName(),
212:                        DescriptorConstants.ATTRIBUTE_ITERABLE + "="
213:                                + DescriptorConstants.FALSE });
214:            }
215:
216:            /**
217:             * Tests that the descriptor is valid and adds appropriate default fields not already
218:             * specified. Field values must be correct for field names.
219:             * Descriptor must have the same name as the attribute,the descriptorType field must be "attribute",
220:             * The following fields will be defaulted if they are not already set:
221:             * displayName=this.getNameSpace(),persistPolicy=never,visibility=1,iterable=F
222:             */
223:            private boolean isValid(Descriptor descriptor) {
224:                boolean isValid = true;
225:                if (descriptor == null) {
226:                    isValid = false;
227:                } else if (!descriptor.isValid()) {
228:                    isValid = false;
229:                } else if (!((String) descriptor
230:                        .getFieldValue(DescriptorConstants.NAME))
231:                        .equalsIgnoreCase(getName())) {
232:                    isValid = false;
233:                } else if (!((String) descriptor
234:                        .getFieldValue(DescriptorConstants.DESCRIPTORTYPE))
235:                        .equalsIgnoreCase(DescriptorConstants.ATTRIBUTE_TYPE)) {
236:                    isValid = false;
237:                } else if (descriptor
238:                        .getFieldValue(DescriptorConstants.DISPLAYNAME) == null)
239:                    descriptor.setField(DescriptorConstants.DISPLAYNAME,
240:                            getName());
241:                else if (descriptor
242:                        .getFieldValue(DescriptorConstants.ATTRIBUTE_ITERABLE) == null)
243:                    descriptor.setField(DescriptorConstants.ATTRIBUTE_ITERABLE,
244:                            DescriptorConstants.FALSE);
245:
246:                return isValid;
247:            }
248:
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.