1 19 package org.netbeans.lib.jmi.xmi; 20 21 import org.netbeans.api.xmi.*; 22 23 import javax.jmi.reflect.RefPackage; 24 import javax.jmi.xmi.MalformedXMIException; 25 26 import java.util.*; 27 import java.io.*; 28 import java.net.URL ; 29 import org.xml.sax.*; 30 import javax.xml.parsers.ParserConfigurationException ; 31 import org.netbeans.lib.jmi.util.Logger; 32 33 public class SAXReader extends XMIReader { 34 35 private XMIInputConfig config; 36 37 39 public SAXReader () { 40 this (null); 41 } 42 43 public SAXReader (XMIInputConfig cfg) { 44 this.config = new InputConfig (); 45 if (cfg != null) { 46 this.config.setReferenceResolver (cfg.getReferenceResolver ()); 47 if (cfg instanceof InputConfig) 48 ((InputConfig)this.config).setHeaderConsumer(((InputConfig)cfg).getHeaderConsumer()); 49 } 50 } 51 52 54 public XMIInputConfig getConfiguration() { 55 return config; 56 } 57 58 public Collection read (InputStream stream, String uri, RefPackage extent) throws IOException, MalformedXMIException { 59 try { 61 return new XmiSAXReader (config).read (stream, uri, new RefPackage[] {extent}, null); 63 } catch (ParserConfigurationException e) { 64 MalformedXMIException ne = new MalformedXMIException(e.toString()); 65 Logger.getDefault().annotate(ne, e); 66 throw ne; 67 } catch (SAXException e) { 68 MalformedXMIException ne = new MalformedXMIException(e.toString()); 69 Logger.getDefault().annotate(ne, e); 70 throw ne; 71 } 72 } 73 74 public Collection read (String uri, RefPackage extent) 75 throws IOException, MalformedXMIException { 76 return read (new URL (uri), new RefPackage[] {extent}, null); 77 } 78 79 private Collection read (URL url, RefPackage[] extents, String encoding) 80 throws IOException, MalformedXMIException { 81 try { 83 return new XmiSAXReader (config).read (url, extents, encoding); 84 } catch (ParserConfigurationException e) { 85 MalformedXMIException ne = new MalformedXMIException(e.toString()); 86 Logger.getDefault().annotate(ne, e); 87 throw ne; 88 } catch (SAXException e) { 89 MalformedXMIException ne = new MalformedXMIException(e.toString()); 90 Logger.getDefault().annotate(ne, e); 91 throw ne; 92 } 93 } 94 95 } 96 | Popular Tags |