001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package test.javax.management.support;
010:
011: import javax.management.MBeanAttributeInfo;
012: import javax.management.MBeanConstructorInfo;
013: import javax.management.MBeanInfo;
014: import javax.management.MBeanOperationInfo;
015: import javax.management.MBeanParameterInfo;
016: import javax.management.NotCompliantMBeanException;
017: import javax.management.StandardMBean;
018:
019: import test.MutableInteger;
020:
021: /**
022: * @version $Revision: 1.5 $
023: */
024: public class StandardMBeanSupport {
025: /**
026: * No management interface and it is not a standard MBean
027: */
028: public static class SubclassNotCompliant extends StandardMBean {
029: public SubclassNotCompliant() throws NotCompliantMBeanException {
030: super (null);
031: }
032: }
033:
034: /**
035: * Valid StandardMBean with a standard MBean as implementation
036: */
037: public static class SubclassWithNoManagement extends StandardMBean
038: implements SubclassWithNoManagementMBean {
039: public SubclassWithNoManagement()
040: throws NotCompliantMBeanException {
041: super (null);
042: }
043:
044: public Object test() {
045: return new Object();
046: }
047: }
048:
049: public interface SubclassWithNoManagementMBean {
050: public Object test();
051: }
052:
053: public static class SubclassWithManagement extends StandardMBean
054: implements Management {
055: public SubclassWithManagement()
056: throws NotCompliantMBeanException {
057: super (Management.class);
058: }
059:
060: public void cannotCall() {
061: }
062:
063: public Object test() {
064: return new Object();
065: }
066: }
067:
068: public interface Management {
069: public Object test();
070: }
071:
072: public static class ImplementationWithNoManagement implements
073: ImplementationWithNoManagementMBean {
074: public Object test() {
075: return new Object();
076: }
077: }
078:
079: public interface ImplementationWithNoManagementMBean {
080: public Object test();
081: }
082:
083: public static class ImplementationWithManagement implements
084: Management {
085: public Object test() {
086: return new Object();
087: }
088: }
089:
090: public interface FullManagement {
091: public void setAttrib(int i);
092:
093: public void operation(int i);
094: }
095:
096: public interface PublicInterfaceMBean {
097: public Object test();
098: }
099:
100: private static class PublicInterface implements
101: PublicInterfaceMBean {
102: public PublicInterface() {
103: }
104:
105: public Object test() {
106: return new Object();
107: }
108: }
109:
110: public static PublicInterfaceMBean createPublicInterfaceMBean() {
111: return new PublicInterface();
112: }
113:
114: public static class CallbackCounter extends StandardMBean implements
115: FullManagement {
116: private MutableInteger count;
117:
118: public CallbackCounter(int dummy)
119: throws NotCompliantMBeanException {
120: // Variable dummy only serves to enable the callback on the constructor parameter
121: super (FullManagement.class);
122: }
123:
124: public void setAttrib(int i) {
125: }
126:
127: public void operation(int i) {
128: }
129:
130: public int getCount() {
131: return count.get();
132: }
133:
134: protected String getClassName(MBeanInfo info) {
135: increment();
136: return super .getClassName(info);
137: }
138:
139: protected String getDescription(MBeanInfo info) {
140: increment();
141: return super .getDescription(info);
142: }
143:
144: protected String getDescription(MBeanAttributeInfo info) {
145: increment();
146: return super .getDescription(info);
147: }
148:
149: protected String getDescription(MBeanConstructorInfo info) {
150: increment();
151: return super .getDescription(info);
152: }
153:
154: protected String getDescription(MBeanOperationInfo info) {
155: increment();
156: return super .getDescription(info);
157: }
158:
159: protected String getDescription(
160: MBeanConstructorInfo constructor,
161: MBeanParameterInfo param, int sequence) {
162: increment();
163: return super .getDescription(constructor, param, sequence);
164: }
165:
166: protected String getDescription(MBeanOperationInfo operation,
167: MBeanParameterInfo param, int sequence) {
168: increment();
169: return super .getDescription(operation, param, sequence);
170: }
171:
172: protected String getParameterName(
173: MBeanConstructorInfo constructor,
174: MBeanParameterInfo param, int sequence) {
175: increment();
176: return super .getParameterName(constructor, param, sequence);
177: }
178:
179: protected String getParameterName(MBeanOperationInfo operation,
180: MBeanParameterInfo param, int sequence) {
181: increment();
182: return super .getParameterName(operation, param, sequence);
183: }
184:
185: protected int getImpact(MBeanOperationInfo info) {
186: increment();
187: return super .getImpact(info);
188: }
189:
190: private void increment() {
191: if (count == null)
192: count = new MutableInteger(0);
193: count.set(count.get() + 1);
194: }
195:
196: }
197:
198: }
|