1 19 package org.netbeans.lib.jmi.xmi; 20 21 import org.netbeans.api.xmi.*; 22 import org.netbeans.api.xmi.sax.*; 23 import org.xml.sax.*; 24 25 import javax.jmi.reflect.*; 26 27 28 public class Consumer extends XMIConsumer { 29 30 private RefPackage extent = null; 31 private XMIInputConfig config; 32 private XmiSAXReader reader; 33 34 36 public Consumer () { 37 this (null); 38 } 39 40 public Consumer (XMIInputConfig cfg) { 41 this.config = new InputConfig (); 42 if (cfg != null) 43 this.config.setReferenceResolver (cfg.getReferenceResolver ()); 44 } 45 46 48 public void setExtent(RefPackage extent) { 49 this.extent = extent; 50 } 51 52 public RefPackage getExtent() { 53 return extent; 54 } 55 56 public XMIInputConfig getConfiguration() { 57 return config; 58 } 59 60 62 public void startDocument() throws SAXException { 63 if (reader != null) 64 throw new SAXException ("Consuming is in process, cannot start a new document."); 65 if (extent == null) 66 throw new SAXException ("No target extent is set."); 67 reader = new XmiSAXReader (config); 68 reader.initConsumer (extent); 69 } 70 71 public void endDocument() throws SAXException { 72 check (); 73 reader.endDocument (); 74 reader = null; 75 } 76 77 public void characters(char[] ch, int start, int length) throws SAXException { 78 check (); 79 reader.characters (ch, start, length); 80 } 81 82 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 83 check (); 84 reader.startElement (namespaceURI, localName, qName, atts); 85 } 86 87 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 88 check (); 89 reader.endElement (namespaceURI, localName, qName); 90 } 91 92 public void endPrefixMapping(String prefix) throws SAXException { 93 } 94 95 public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { 96 } 97 98 public void processingInstruction(String target, String data) throws SAXException { 99 } 100 101 public void setDocumentLocator(Locator locator) { 102 } 103 104 public void skippedEntity(String name) throws SAXException { 105 } 106 107 public void startPrefixMapping(String prefix, String uri) throws SAXException { 108 } 109 110 112 private void check () throws SAXException { 113 if (reader == null) 114 throw new SAXException ("Consumer not started."); 115 } 116 117 } 118 | Popular Tags |