1 16 package org.apache.cocoon.components.profiler; 17 18 import org.apache.cocoon.components.sax.XMLByteStreamCompiler; 19 import org.apache.cocoon.components.sax.XMLByteStreamInterpreter; 20 import org.apache.cocoon.components.sax.XMLDeserializer; 21 import org.apache.cocoon.components.sax.XMLSerializer; 22 import org.apache.cocoon.xml.XMLConsumer; 23 import org.apache.cocoon.xml.XMLPipe; 24 import org.xml.sax.Attributes ; 25 import org.xml.sax.Locator ; 26 import org.xml.sax.SAXException ; 27 28 38 public class ProfilingXMLPipe implements XMLPipe { 39 40 private XMLConsumer consumer; 41 42 private ProfilerData data; 44 45 private int index; 47 48 private long time; 50 51 private long total; 53 54 private XMLDeserializer deserializer; 55 private XMLSerializer serializer; 56 57 63 public void setup(int index, ProfilerData data) { 64 this.index = index; 65 this.data = data; 66 67 this.deserializer = new XMLByteStreamInterpreter(); 69 this.serializer = new XMLByteStreamCompiler(); 70 } 71 72 75 public void setConsumer(XMLConsumer consumer) { 76 this.consumer = consumer; 77 } 78 79 public void startDocument() throws SAXException { 80 this.time = System.currentTimeMillis(); 82 this.serializer.startDocument(); 83 } 84 85 public void endDocument() throws SAXException { 86 this.total = System.currentTimeMillis() - this.time; 87 88 this.serializer.endDocument(); 89 if (this.index != -1) 90 this.data.setProcessingTime(this.index, this.total); 91 92 Object fragment = this.serializer.getSAXFragment(); 94 95 if (this.index != -1) 96 this.data.setSAXFragment(this.index, fragment); 97 98 this.deserializer.setConsumer(this.consumer); 99 100 this.time = System.currentTimeMillis(); this.deserializer.deserialize(fragment); 102 this.total = System.currentTimeMillis() - this.time; 103 104 if ((this.index != -1) && (this.index==(this.data.getCount()-2))) 105 this.data.setProcessingTime(this.index+1, this.total); 106 } 107 108 public void setDocumentLocator(Locator locator) { 109 this.serializer.setDocumentLocator(locator); 110 } 111 112 public void startPrefixMapping(String prefix, String uri) throws SAXException { 113 this.serializer.startPrefixMapping(prefix, uri); 114 } 115 116 public void endPrefixMapping(String prefix) throws SAXException { 117 this.serializer.endPrefixMapping(prefix); 118 } 119 120 public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException { 121 this.serializer.startElement(uri, loc, raw, a); 122 } 123 124 public void endElement(String uri, String loc, String raw) throws SAXException { 125 this.serializer.endElement(uri, loc, raw); 126 } 127 128 public void characters(char c[], int start, int len) throws SAXException { 129 this.serializer.characters(c, start, len); 130 } 131 132 public void ignorableWhitespace(char c[], int start, int len) throws SAXException { 133 this.serializer.ignorableWhitespace(c, start, len); 134 } 135 136 public void processingInstruction(String target, String data) throws SAXException { 137 this.serializer.processingInstruction(target, data); 138 } 139 140 public void skippedEntity(String name) throws SAXException { 141 this.serializer.skippedEntity(name); 142 } 143 144 public void startDTD(String name, String publicId, String systemId) throws SAXException { 145 this.serializer.startDTD(name, publicId, systemId); 146 } 147 148 public void endDTD() throws SAXException { 149 this.serializer.endDTD(); 150 } 151 152 public void startEntity(String name) throws SAXException { 153 this.serializer.startEntity(name); 154 } 155 156 public void endEntity(String name) throws SAXException { 157 this.serializer.endEntity(name); 158 } 159 160 public void startCDATA() throws SAXException { 161 this.serializer.startCDATA(); 162 } 163 164 public void endCDATA() throws SAXException { 165 this.serializer.endCDATA(); 166 } 167 168 public void comment(char ch[], int start, int len) throws SAXException { 169 this.serializer.comment(ch, start, len); 170 } 171 } 172 | Popular Tags |