All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nakedobjects.nof.boot.system.Monitor Maven / Gradle / Ivy

There is a newer version: 3.0.3
Show newest version
package org.nakedobjects.nof.boot.system;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.nakedobjects.nof.core.system.MonitorEvent;
import org.nakedobjects.nof.core.system.MonitorListener;
import org.nakedobjects.nof.core.util.Assert;
import org.nakedobjects.nof.core.util.DebugString;

public class Monitor implements MonitorListener {
    private NakedObjectsSystem target;
    private List events = new ArrayList();
    
    public Monitor() {
        org.nakedobjects.nof.core.system.Monitor.addListener(this);
    }
    
    
    public void postEvent(MonitorEvent event) {
        // TODO use a stack of limited size so we have FIFO list
        if (events.size() > 50) {
            events.remove(0);
        }
        events.add(event);
    }
    
    public void writePage(final String section, final PrintWriter writer) throws IOException {
        Assert.assertNotNull(section);
        Assert.assertNotNull(writer);
        String sectionName = section.equals("") ? "Overview" : section;

        writer.println("NOF System Monitor - " + sectionName + "");
        writer.println("");

        writer.println("

" + sectionName + "

"); StringBuffer navigation = new StringBuffer("

"); String[] options = target.debugOptions(); for (int i = 0; i < options.length; i++) { if(i > 0) { navigation.append(" | "); } navigation.append(""); navigation.append(options[i]); navigation.append(""); } navigation.append("

"); writer.println(navigation); writer.println("
");       
        if (sectionName.equals("Events")) {
            Iterator it = events.iterator();
            int i = 1;
            while (it.hasNext()) {
                MonitorEvent event = (MonitorEvent) it.next();
                writer.println(i++  + ". " + event);
            }
        } else {
            // TODO use an HTML debug string
            DebugString debug = new DebugString();
            target.debug(sectionName, debug);
            writer.println(debug.toString());
        }
        writer.println("
"); writer.println(navigation); writer.println(""); } public void setTarget(NakedObjectsSystem system) { target = system; } } // Copyright (c) Naked Objects Group Ltd.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy