< prev index next >

application/tests/org.openjdk.jmc.rjmx.test/src/test/java/org/openjdk/jmc/rjmx/test/internal/TabularDataBeanTestMBean.java

Print this page




  43 import javax.management.openmbean.OpenType;
  44 import javax.management.openmbean.SimpleType;
  45 import javax.management.openmbean.TabularData;
  46 import javax.management.openmbean.TabularDataSupport;
  47 import javax.management.openmbean.TabularType;
  48 
  49 /**
  50  * When this bean is added to the management server of a JRockit, it provides a bean that exposes
  51  * nested TabularData and CompositeData structures through attributes and operations. This class is
  52  * meant to be used to test GUI components, such as the MBeanBrowser of the ManagementConsole, that
  53  * inspects such structures.
  54  */
  55 public class TabularDataBeanTestMBean implements ITabularDataBeanTestMBean {
  56 
  57         TabularDataSupport tabTest;
  58         CompositeData compTest;
  59 
  60         public TabularDataBeanTestMBean() {
  61                 CompositeType simpleCompositeType;
  62                 try {
  63                         simpleCompositeType = new CompositeType("simpleCompositeType", "compdescription", //$NON-NLS-1$ //$NON-NLS-2$
  64                                         new String[] {"djur", "bil", "apa", "båt"}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
  65                                         new String[] {"ett djur", "en bil", "en apa", "en båt"}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
  66                                         new OpenType[] {SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,});
  67 
  68                         TabularType simpleTabularType = new TabularType("simpleTabularTypeName", "tabdescription", //$NON-NLS-1$ //$NON-NLS-2$
  69                                         simpleCompositeType, new String[] {"djur", "bil", "apa", "båt"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
  70 
  71                         OpenType<?>[] compositeContentsTypes = new OpenType[5];
  72                         String[] compositeKeys = new String[5];
  73                         String[] compositeDescriptions = new String[5];
  74                         compositeContentsTypes[0] = simpleTabularType;
  75                         compositeKeys[0] = "Tab Data"; //$NON-NLS-1$
  76                         compositeDescriptions[0] = "tab data desc"; //$NON-NLS-1$
  77                         compositeContentsTypes[4] = simpleCompositeType;
  78                         compositeKeys[4] = "Comp Data"; //$NON-NLS-1$
  79                         compositeDescriptions[4] = "comp data desc"; //$NON-NLS-1$
  80                         compositeContentsTypes[3] = new ArrayType<String>(2, SimpleType.STRING);
  81                         compositeKeys[3] = "Array Data"; //$NON-NLS-1$
  82                         compositeDescriptions[3] = "comp data desc"; //$NON-NLS-1$
  83                         for (int i = 1; i < 3; i++) {
  84                                 compositeContentsTypes[i] = SimpleType.STRING;
  85                                 compositeKeys[i] = "StringIndex" + i; //$NON-NLS-1$
  86                                 compositeDescriptions[i] = "description" + i; //$NON-NLS-1$
  87                         }
  88                         CompositeType complexCompositeType = new CompositeType("ComplexCompositeTypeName", //$NON-NLS-1$
  89                                         "complex composite type desc", compositeKeys, compositeDescriptions, compositeContentsTypes); //$NON-NLS-1$
  90                         TabularType complexTabularType = new TabularType("ComplexTabularTypeName", "complex tabular type", //$NON-NLS-1$ //$NON-NLS-2$
  91                                         complexCompositeType, compositeKeys);
  92 
  93                         CompositeData simpleCompositeData = new CompositeDataSupport(simpleCompositeType,
  94                                         new String[] {"djur", "bil", "apa", "båt"}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
  95                                         new String[] {"häst", "corvette", "lemur", "nautilus"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
  96                         TabularDataSupport simpleTabularData = new TabularDataSupport(simpleTabularType);
  97                         simpleTabularData.put(simpleCompositeData);
  98                         /*
  99                          * simpleTabularData.put(simpleCompositeData);
 100                          * simpleTabularData.put(simpleCompositeData);
 101                          * simpleTabularData.put(simpleCompositeData);
 102                          */
 103 
 104                         compTest = new CompositeDataSupport(complexCompositeType, compositeKeys,
 105                                         new Object[] {simpleTabularData, "string2", "string3", //$NON-NLS-1$ //$NON-NLS-2$
 106                                                         new String[][] {{"string1_1", "string1_2"}, {"string2_1", "string2_2"}}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
 107                                                         simpleCompositeData});
 108                         tabTest = new TabularDataSupport(complexTabularType);
 109                         tabTest.put(compTest);
 110                         tabTest.put(new CompositeDataSupport(complexCompositeType, compositeKeys,
 111                                         new Object[] {simpleTabularData, "secondcomp2", "secondcomp3", //$NON-NLS-1$ //$NON-NLS-2$
 112                                                         new String[][] {{"array1_1", "array1_2"}, {"array2_1", "array2_2"}}, simpleCompositeData})); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
 113                         /*
 114                          * tabTest.put(complexCompositeData); tabTest.put(complexCompositeData);
 115                          * tabTest.put(complexCompositeData); tabTest.put(complexCompositeData);
 116                          */
 117 
 118                 } catch (OpenDataException e) {
 119                         // TODO: Add proper logging
 120                         e.printStackTrace();
 121                 }
 122         }
 123 
 124         /*
 125          * (non-Javadoc)
 126          *
 127          * @see com.jrockit.console.rjmx.TestMBean#getTabTest()
 128          */
 129         @Override
 130         public TabularData getTabTest() {
 131                 return tabTest;
 132         }


 138          */
 139         @Override
 140         public TabularData operationThatReturnsTabularData() {
 141                 return tabTest;
 142         }
 143 
 144         /*
 145          * (non-Javadoc)
 146          *
 147          * @see com.jrockit.console.rjmx.TestMBean#operationThatReturnsComposite()
 148          */
 149         @Override
 150         public CompositeData operationThatReturnsComposite() {
 151                 return compTest;
 152         }
 153 
 154         public static void main(String[] args) {
 155                 try {
 156                         try {
 157                                 ManagementFactory.getPlatformMBeanServer().createMBean(TabularDataBeanTestMBean.class.getName(),
 158                                                 new ObjectName("com.jrockit", "name", "TestMBean")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 159                         } catch (Exception e) {
 160                                 e.printStackTrace();
 161                         }
 162                         while (true) {
 163                                 Thread.sleep(1000);
 164                         }
 165                 } catch (InterruptedException e) {
 166                         // TODO: Add proper logging
 167                         e.printStackTrace();
 168                 }
 169         }
 170 }


  43 import javax.management.openmbean.OpenType;
  44 import javax.management.openmbean.SimpleType;
  45 import javax.management.openmbean.TabularData;
  46 import javax.management.openmbean.TabularDataSupport;
  47 import javax.management.openmbean.TabularType;
  48 
  49 /**
  50  * When this bean is added to the management server of a JRockit, it provides a bean that exposes
  51  * nested TabularData and CompositeData structures through attributes and operations. This class is
  52  * meant to be used to test GUI components, such as the MBeanBrowser of the ManagementConsole, that
  53  * inspects such structures.
  54  */
  55 public class TabularDataBeanTestMBean implements ITabularDataBeanTestMBean {
  56 
  57         TabularDataSupport tabTest;
  58         CompositeData compTest;
  59 
  60         public TabularDataBeanTestMBean() {
  61                 CompositeType simpleCompositeType;
  62                 try {
  63                         simpleCompositeType = new CompositeType("simpleCompositeType", "compdescription",
  64                                         new String[] {"djur", "bil", "apa", "båt"},
  65                                         new String[] {"ett djur", "en bil", "en apa", "en båt"},
  66                                         new OpenType[] {SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,});
  67 
  68                         TabularType simpleTabularType = new TabularType("simpleTabularTypeName", "tabdescription",
  69                                         simpleCompositeType, new String[] {"djur", "bil", "apa", "båt"});
  70 
  71                         OpenType<?>[] compositeContentsTypes = new OpenType[5];
  72                         String[] compositeKeys = new String[5];
  73                         String[] compositeDescriptions = new String[5];
  74                         compositeContentsTypes[0] = simpleTabularType;
  75                         compositeKeys[0] = "Tab Data";
  76                         compositeDescriptions[0] = "tab data desc";
  77                         compositeContentsTypes[4] = simpleCompositeType;
  78                         compositeKeys[4] = "Comp Data";
  79                         compositeDescriptions[4] = "comp data desc";
  80                         compositeContentsTypes[3] = new ArrayType<String>(2, SimpleType.STRING);
  81                         compositeKeys[3] = "Array Data";
  82                         compositeDescriptions[3] = "comp data desc";
  83                         for (int i = 1; i < 3; i++) {
  84                                 compositeContentsTypes[i] = SimpleType.STRING;
  85                                 compositeKeys[i] = "StringIndex" + i;
  86                                 compositeDescriptions[i] = "description" + i;
  87                         }
  88                         CompositeType complexCompositeType = new CompositeType("ComplexCompositeTypeName",
  89                                         "complex composite type desc", compositeKeys, compositeDescriptions, compositeContentsTypes);
  90                         TabularType complexTabularType = new TabularType("ComplexTabularTypeName", "complex tabular type",
  91                                         complexCompositeType, compositeKeys);
  92 
  93                         CompositeData simpleCompositeData = new CompositeDataSupport(simpleCompositeType,
  94                                         new String[] {"djur", "bil", "apa", "båt"},
  95                                         new String[] {"häst", "corvette", "lemur", "nautilus"});
  96                         TabularDataSupport simpleTabularData = new TabularDataSupport(simpleTabularType);
  97                         simpleTabularData.put(simpleCompositeData);
  98                         /*
  99                          * simpleTabularData.put(simpleCompositeData);
 100                          * simpleTabularData.put(simpleCompositeData);
 101                          * simpleTabularData.put(simpleCompositeData);
 102                          */
 103 
 104                         compTest = new CompositeDataSupport(complexCompositeType, compositeKeys,
 105                                         new Object[] {simpleTabularData, "string2", "string3",
 106                                                         new String[][] {{"string1_1", "string1_2"}, {"string2_1", "string2_2"}},
 107                                                         simpleCompositeData});
 108                         tabTest = new TabularDataSupport(complexTabularType);
 109                         tabTest.put(compTest);
 110                         tabTest.put(new CompositeDataSupport(complexCompositeType, compositeKeys,
 111                                         new Object[] {simpleTabularData, "secondcomp2", "secondcomp3",
 112                                                         new String[][] {{"array1_1", "array1_2"}, {"array2_1", "array2_2"}}, simpleCompositeData}));
 113                         /*
 114                          * tabTest.put(complexCompositeData); tabTest.put(complexCompositeData);
 115                          * tabTest.put(complexCompositeData); tabTest.put(complexCompositeData);
 116                          */
 117 
 118                 } catch (OpenDataException e) {
 119                         // TODO: Add proper logging
 120                         e.printStackTrace();
 121                 }
 122         }
 123 
 124         /*
 125          * (non-Javadoc)
 126          *
 127          * @see com.jrockit.console.rjmx.TestMBean#getTabTest()
 128          */
 129         @Override
 130         public TabularData getTabTest() {
 131                 return tabTest;
 132         }


 138          */
 139         @Override
 140         public TabularData operationThatReturnsTabularData() {
 141                 return tabTest;
 142         }
 143 
 144         /*
 145          * (non-Javadoc)
 146          *
 147          * @see com.jrockit.console.rjmx.TestMBean#operationThatReturnsComposite()
 148          */
 149         @Override
 150         public CompositeData operationThatReturnsComposite() {
 151                 return compTest;
 152         }
 153 
 154         public static void main(String[] args) {
 155                 try {
 156                         try {
 157                                 ManagementFactory.getPlatformMBeanServer().createMBean(TabularDataBeanTestMBean.class.getName(),
 158                                                 new ObjectName("com.jrockit", "name", "TestMBean"));
 159                         } catch (Exception e) {
 160                                 e.printStackTrace();
 161                         }
 162                         while (true) {
 163                                 Thread.sleep(1000);
 164                         }
 165                 } catch (InterruptedException e) {
 166                         // TODO: Add proper logging
 167                         e.printStackTrace();
 168                 }
 169         }
 170 }
< prev index next >