/*
 * Copyright (c) 2012 Tripwire, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *  o Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *  o Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.jmxdatamart.JMXTestServer;

import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.io.FileWriter;
import org.jmxdatamart.Extractor.*;

/**
 *
 * @author Binh Tran <mynameisbinh@gmail.com>
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {

        TestBean tb = new TestBean();
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mbeanName = new ObjectName("com.personal.JMXTestServer:type=TestBean");
        mbs.registerMBean(tb, mbeanName);

        FileWriter writer = new FileWriter(System.getProperty("user.dir") + "/JMXTestServer.txt");
        writer.write("Start exporting on " + new java.util.Date()+"\n");
        try {
            while (true) {
                tb.randomize();
                System.out.println(tb.toString());
                writer.write(tb.toString()+"\n");
                writer.flush();
                Thread.sleep(2000);
            }
        }
        catch (Exception e){
            System.err.println(e.getStackTrace());
            System.exit(1);
        }
        finally {
            writer.close();
        }
    }
}

@@ -1412,16 +1412,78 @@
 erver;%0A%0A
+import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;%0A
 import j
@@ -1617,24 +1617,103 @@
 FileWriter;%0A
+import javax.management.Attribute;%0Aimport javax.management.MBeanAttributeInfo;%0A
 import org.j
@@ -1952,26 +1952,42 @@
     
-Test
+RandomValueDynamicM
 Bean 
-t
+dm
 b = new 
 Test
@@ -1986,232 +1986,126 @@
 new 
-TestBean();%0A        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();%0A        ObjectName mbeanName = new ObjectName(%22com.personal.JMXTestServer:type=TestBean%22);%0A        mbs.registerMBean(tb, mbeanNam
+RandomValueDynamicMBean();%0A        dmb.addAttribute(%22Car%22, Car.class.toString(), %22a Car%22, true, true, fals
 e);%0A
-%0A
         
 File
@@ -2104,611 +2104,282 @@
     
-FileWriter writer = new FileWriter(System.getProperty(%22user.dir%22) + %22/JMXTestServer.txt%22);%0A        writer.write(%22Start exporting on %22 + new java.util.Date()+%22%5Cn%22);%0A        try %7B%0A            while (true) %7B%0A                tb.randomize();%0A                System.out.println(tb.toString());%0A                writer.write(tb.toString()+%22%5Cn%22);%0A                writer.flush();%0A                Thread.sleep(2000);%0A            %7D%0A        %7D%0A        catch (Exception e)%7B%0A            System.err.println(e.getStackTrace());%0A            System.exit(1);%0A        %7D%0A        finally %7B%0A            writer.close();%0A        %7D
+dmb.setAttribute(new Attribute(%22Car%22, new Car(%22123%22, %22234%22, 3, 2)));%0A        %0A        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();%0A        ObjectName on = new ObjectName(%22org.jmxdatamart.jmxtestserver:type=randomDMBean%22);%0A        mbs.registerMBean(dmb, on);
 %0A   

Modify JMXTestServer.Main to show bug with the implementation of Dynamic MBean