001: /*
002: * hgcommons 7
003: * Hammurapi Group Common Library
004: * Copyright (C) 2003 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.metrics;
024:
025: import java.util.Collection;
026: import java.util.Iterator;
027:
028: import org.w3c.dom.DOMException;
029: import org.w3c.dom.Document;
030: import org.w3c.dom.Element;
031:
032: import biz.hammurapi.metrics.Metric.Measurement;
033: import biz.hammurapi.render.RenderRequest;
034: import biz.hammurapi.render.RenderingException;
035: import biz.hammurapi.render.dom.AbstractRenderer;
036: import biz.hammurapi.render.dom.DomRenderer;
037:
038: /**
039: * @author Pavel Vlasov
040: * @version $Revision: 1.8 $
041: */
042: public class MetricRenderer extends AbstractRenderer implements
043: DomRenderer {
044:
045: public MetricRenderer(RenderRequest request) {
046: super (request);
047: }
048:
049: public MetricRenderer(RenderRequest request, String profile) {
050: super (request, profile);
051: }
052:
053: public Element render(Document document) throws RenderingException {
054: Element ret = document.createElement("metric");
055: Metric m = (Metric) request.getRenderee();
056:
057: toDom(ret, m);
058: return ret;
059: }
060:
061: /**
062: * @param document
063: * @param holder
064: * @param m
065: * @throws RenderingException
066: * @throws RenderingException
067: */
068: private void toDom(Element holder, Metric m)
069: throws RenderingException {
070: holder.setAttribute("name", m.getName());
071: holder.setAttribute("avg", String.valueOf(m.getAvg()));
072: holder.setAttribute("min", String.valueOf(m.getMin()));
073: holder.setAttribute("max", String.valueOf(m.getMax()));
074:
075: holder.setAttribute("total", String.valueOf(m.getTotal()));
076: holder.setAttribute("number", String.valueOf(m.getNumber()));
077: holder.setAttribute("deviation", String.valueOf(m
078: .getDeviation()));
079:
080: Collection measurements = m.getMeasurements();
081: if (measurements != null) {
082: Iterator it = measurements.iterator();
083: while (it.hasNext()) {
084: Measurement ms = (Measurement) it.next();
085: Element me = holder.getOwnerDocument().createElement(
086: "measurement");
087: holder.appendChild(me);
088: renderMeasurement(ms, me);
089: }
090: }
091: }
092:
093: /**
094: * @param ms
095: * @param me
096: * @throws RenderingException
097: * @throws
098: * @throws RenderingException
099: * @throws DOMException
100: */
101: protected void renderMeasurement(Measurement ms, Element me)
102: throws RenderingException {
103: me.setAttribute("value", String.valueOf(ms.getValue()));
104: me.setAttribute("time", String.valueOf(ms.getTime()));
105: }
106:
107: }
|