take an object and export outside of its class
<p>I have this class and I want to export to outside of it (to another class), the object <code>httpdStatistics stats</code> created in it. Which could be the best way to make this?</p>

<pre><code>package org.w3c.jigsaw.status ;

import java.util.Date;

import org.w3c.tools.resources.Attribute;
import org.w3c.tools.resources.AttributeHolder;
import org.w3c.tools.resources.AttributeRegistry;
import org.w3c.tools.resources.FramedResource;
import org.w3c.tools.resources.IntegerAttribute;
import org.w3c.tools.resources.Resource;

import org.w3c.tools.resources.store.ResourceStoreManager;

import org.w3c.www.http.HTTP;
import org.w3c.www.http.HttpMessage;

import org.w3c.jigsaw.frames.HTTPFrame;

import org.w3c.jigsaw.http.Reply;
import org.w3c.jigsaw.http.Request;
import org.w3c.jigsaw.http.httpd;
import org.w3c.jigsaw.http.httpdStatistics;

import org.w3c.jigsaw.html.HtmlGenerator;

/**
 * This class exports the server statistics.
 * It makes available a bunch of various parameters about the current
 * server, and uses the Refresh meta-tag (as the ThreadStat) to 
 * make them redisplay.
 * &lt;p&gt;This would benefit from being an applet.
 */

public class StatisticsFrame extends HTTPFrame {
    private static int REFRESH_DEFAULT = 5;

    /**
     * Attribute index - Our refresh interval.
     */
    protected static int ATTR_REFRESH = -1 ;

    static {
    Attribute a   = null ;
    Class     cls = null ;
    try {
        cls = Class.forName("org.w3c.jigsaw.status.StatisticsFrame");
    } catch (Exception ex) {
        ex.printStackTrace() ;
        System.exit(1) ;
    }
    // The refresh interval attribute:
    a = new IntegerAttribute("refresh"
                 , new Integer(5)
                 , Attribute.EDITABLE) ;
    ATTR_REFRESH = AttributeRegistry.registerAttribute(cls, a) ;
    }

    static String time_tbl = ("&lt;table border=\"1\" class=\"time\"&gt;"
                  + "&lt;caption&gt;Request processing times"
                  + "&lt;/caption&gt;&lt;tr&gt;"
                  + "&lt;th&gt;min"
                  + "&lt;th&gt;avg"
                  + "&lt;th&gt;max"
                  + "&lt;/tr&gt;&lt;tr&gt;") ;

    static String dyn_time_tbl = ("&lt;table border=\"1\" class=\"time\"&gt;"
                  + "&lt;caption&gt;Dynamic request processing times"
                  + "&lt;/caption&gt;&lt;tr&gt;"
                  + "&lt;th&gt;min"
                  + "&lt;th&gt;avg"
                  + "&lt;th&gt;max"
                  + "&lt;/tr&gt;&lt;tr&gt;") ;

    static String sta_time_tbl = ("&lt;table border=\"1\" class=\"time\"&gt;"
                  + "&lt;caption&gt;Static request processing times"
                  + "&lt;/caption&gt;&lt;tr&gt;"
                  + "&lt;th&gt;min"
                  + "&lt;th&gt;avg"
                  + "&lt;th&gt;max"
                  + "&lt;/tr&gt;&lt;tr&gt;") ;

    public void registerResource(FramedResource resource) {
    super.registerOtherResource(resource);
    }

    /**
     * Get the current set of statistics.
     * Display the collected statistics in an HTML table.
     * @param request The request to process.
     */

    public Reply get (Request request) {
    HtmlGenerator g = new HtmlGenerator("Statistics") ;
    int refresh = getInt(ATTR_REFRESH, REFRESH_DEFAULT);
    if (refresh &gt; 0) {
        g.addMeta("Refresh", Integer.toString(refresh));
    }
    addStyleSheet(g);
    // Dump the statistics:
    httpdStatistics stats = ((httpd)getServer()).getStatistics() ;
    // Uptime:
    g.append("&lt;h1&gt;Server Statistics&lt;/h1&gt;");
    long start_time = stats.getStartTime();
    long uptime     = (System.currentTimeMillis() - start_time) / 1000;
    g.append("&lt;p&gt;Your server was started on &lt;span class=\"date\"&gt;");
    g.append(new Date(start_time).toString());
    long duptime = uptime / (3600L*24L);
    long htemp   = uptime % (3600L*24L);
    long huptime = htemp / 3600L;
    long mtemp   = htemp % 3600L;
    long muptime = mtemp / 60L;
    long suptime = mtemp % 60L;
    g.append("&lt;/span&gt;\n&lt;p&gt;It has now been running for &lt;span "+
         "class=\"uptime\"&gt;");
    g.append(Long.toString(duptime));
    g.append(" days, ");
    g.append(Long.toString(huptime));
    g.append(" hours, ");
    g.append(Long.toString(muptime));
    g.append(" minutes and ");
    g.append(Long.toString(suptime));
    g.append(" seconds.&lt;/span&gt;\n");
    // Hits and bytes:
    long  nb_hits      = stats.getHitCount();
    long  dyn_hits     = stats.getDynamicHitCount();
    long  static_hits  = stats.getStaticHitCount();
    float static_pcent = 0;
    float dyn_pcent    = 0;
    if (nb_hits &gt; 0) {
        static_pcent = ((float) static_hits / (float) nb_hits) * 100;
        dyn_pcent = ((float) dyn_hits / (float) nb_hits) * 100;
    }
    g.append("&lt;ul&gt;&lt;li&gt;hits: ", Long.toString(nb_hits));
    g.append("  &lt;ul&gt;\n    &lt;li&gt;static: ",Long.toString(static_hits));
    g.append(" (", Float.toString(static_pcent));
    g.append("%)&lt;/li&gt;\n    &lt;li&gt;dynamic: ", Long.toString(dyn_hits));
    g.append(" (", Float.toString(dyn_pcent));
    g.append("%)&lt;/li&gt;\n  &lt;/ul&gt;\n");
    long bytes = stats.getEmittedBytes();
    long kbytes = bytes / 1024;
    long mbytes = kbytes / 1024;
    long gbytes = mbytes / 1024;
        long tbytes = gbytes / 1024;
    if (tbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;bytes: ", Long.toString( tbytes),"TB, ");
        g.append(Long.toString(gbytes % 1024), "GB, ");
        g.append(Long.toString(mbytes % 1024), "MB, ");
        g.append(Long.toString(kbytes % 1024), "KB, ");
        g.append(Long.toString(bytes % 1024));
    } else if (gbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;bytes: ", Long.toString(gbytes), "GB, ");
        g.append(Long.toString(mbytes % 1024), "MB, ");
        g.append(Long.toString(kbytes % 1024), "KB, ");
        g.append(Long.toString(bytes % 1024));
    } else if (mbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;bytes: ", Long.toString(mbytes), "MB, ");
        g.append(Long.toString(kbytes % 1024), "KB, ");
        g.append(Long.toString(bytes % 1024));
    } else if (kbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;bytes: ", Long.toString(kbytes), "KB, ");
        g.append(Long.toString(bytes % 1024));
    } else {
        g.append("&lt;/li&gt;\n&lt;li&gt;bytes: ", Long.toString(bytes));
    }
    // avg hit/sec
    float avghits = 0;
    float avghitsday = 0;
    if (uptime &gt; 0) {
        avghits = ((float) nb_hits) / ((float) uptime);
        avghitsday = ((float) nb_hits * 86400) / ((float) uptime); 
    }
    g.append("&lt;/li&gt;\n&lt;li&gt;Average hits per second: ");
    g.append(Float.toString(avghits));
    g.append("&lt;/li&gt;\n&lt;li&gt;Average hits per day: ");
    g.append(Integer.toString((int) avghitsday));
    // avg bytes/hit
    long avgbph;

    if (nb_hits &gt; 0) {
        avgbph = bytes / nb_hits;
    } else {
        avgbph = 0;
    }
    kbytes = avgbph / 1024;
    mbytes = kbytes / 1024;
    gbytes = mbytes / 1024;
    if (gbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;Average bytes per hit: ");
        g.append(Long.toString(gbytes), "GB, ");
        g.append(Long.toString(mbytes % 1024), "MB, ");
        g.append(Long.toString(kbytes % 1024), "KB, ");
        g.append(Long.toString(avgbph % 1024));
    } else if (mbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;Average bytes per hit: ");
        g.append(Long.toString(mbytes), "MB, ");
        g.append(Long.toString(kbytes % 1024), "KB, ");
        g.append(Long.toString(avgbph % 1024));     
    } else if (kbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;Average bytes per hit: ");
        g.append(Long.toString(kbytes), "KB, ");
        g.append(Long.toString(avgbph % 1024));
    } else {
        g.append("&lt;/li&gt;\n&lt;li&gt;Average bytes per hit: ",
             Long.toString(avgbph));
    }
    // avg throughput
    long avgbps = 0;
    if (uptime &gt; 0) {
        avgbps = bytes / uptime;
    }
    kbytes = avgbps / 1024;
    mbytes = kbytes / 1024;
    gbytes = mbytes / 1024;
    if (gbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;Average bytes per second: ");
        g.append(Long.toString(gbytes),  "GB, ");
        g.append(Long.toString(mbytes % 1024), "MB, ");
        g.append(Long.toString(kbytes % 1024), "KB, ");
        g.append(Long.toString(avgbps % 1024));
    } else if (mbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;Average bytes per second: ");
        g.append(Long.toString(mbytes), "MB, ");
        g.append(Long.toString(kbytes % 1024), "KB, ");
        g.append(Long.toString(avgbps % 1024));
    } else if (kbytes != 0) {
        g.append("&lt;/li&gt;\n&lt;li&gt;Average bytes per second: ");
        g.append(Long.toString(kbytes), "KB, ");
        g.append(Long.toString(avgbps % 1024));
    } else {
        g.append("&lt;/li&gt;\n&lt;li&gt;Average bytes per second: ", 
             Long.toString(avgbps));
    }    
    g.append("&lt;/li&gt;\n&lt;/ul&gt;");
    // Request times:
    g.append(time_tbl) ;
    g.append("&lt;td&gt;"
         , Long.toString(stats.getMinRequestTime())
         , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
    g.append("&lt;/td&gt;\n&lt;td&gt;"
         , Long.toString(stats.getMeanRequestTime())
         , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
    g.append("&lt;/td&gt;\n&lt;td&gt;"
         , Long.toString(stats.getMaxRequestTime())
         , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
    g.append("&lt;/td&gt;\n&lt;/table&gt;\n") ;

    // static
    if (static_hits&gt;0) {
        g.append(sta_time_tbl) ;
        g.append("&lt;td&gt;"
             , Long.toString(stats.getMinStaticRequestTime())
             , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
        g.append("&lt;/td&gt;\n&lt;td&gt;"
             , Long.toString(stats.getMeanStaticRequestTime())
             , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
        g.append("&lt;/td&gt;\n&lt;td&gt;"
             , Long.toString(stats.getMaxStaticRequestTime())
             , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
        g.append("&lt;/td&gt;\n&lt;/table&gt;\n") ;
    }

    // dynamic 
    if (dyn_hits&gt;0) {
        g.append(dyn_time_tbl) ;
        g.append("&lt;td&gt;"
             , Long.toString(stats.getMinDynamicRequestTime())
             , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
        g.append("&lt;/td&gt;\n&lt;td&gt;"
             , Long.toString(stats.getMeanDynamicRequestTime())
             , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
        g.append("&lt;/td&gt;\n&lt;td&gt;"
             , Long.toString(stats.getMaxDynamicRequestTime())
             , " &lt;span class=\"unit\"&gt;ms&lt;/span&gt;") ;
        g.append("&lt;/td&gt;\n&lt;/table&gt;\n") ;
    }

    // Get Server internal Stats
    try {
        g.append(((httpd)getServer()).getHTMLStatus());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    Reply reply = request.makeReply(HTTP.OK) ;
    reply.setNoCache();
    reply.setStream (g) ;
    reply.setDynamic(true);
    return reply ;
    }
}
</code></pre>
