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 import org.xml.sax.helpers.LocatorImpl ; 25 26 import java.util.*; 27 import java.io.*; 28 import javax.jmi.reflect.RefPackage; 29 30 public class Producer extends XMIProducer { 31 32 private XMIOutputConfig config; 33 private Collection objects = null; 34 private RefPackage extent = null; 35 private String xmiVersion = null; 36 37 private DTDHandler dtdHandler = null; 38 private ContentHandler contentHandler = null; 39 private EntityResolver entityResolver = null; 40 private ErrorHandler errorHandler = null; 41 42 private ContentHandler defaultWriter = new DefaultWriter (); 43 44 46 public Producer () { 47 config = new OutputConfig (); 48 } 49 50 public Producer (XMIOutputConfig config) { 51 this.config = config; 52 } 53 54 56 public void setSource(Collection objects) { 57 this.objects = objects; 58 extent = null; 59 } 60 61 public void setSource(RefPackage extent) { 62 this.extent = extent; 63 objects = null; 64 } 65 66 public Object getSource() { 67 if (objects == null) 68 return extent; 69 else 70 return objects; 71 } 72 73 public void setXmiVersion(String xmiVersion) { 74 this.xmiVersion = xmiVersion; 75 } 76 77 public String getXmiVersion() { 78 return xmiVersion; 79 } 80 81 public XMIOutputConfig getConfiguration() { 82 return config; 83 } 84 85 87 public ContentHandler getContentHandler() { 88 return contentHandler; 89 } 90 91 public DTDHandler getDTDHandler() { 92 return dtdHandler; 93 } 94 95 public EntityResolver getEntityResolver() { 96 return entityResolver; 97 } 98 99 public ErrorHandler getErrorHandler() { 100 return errorHandler; 101 } 102 103 public boolean getFeature(String name) throws SAXNotSupportedException { 104 throw new SAXNotSupportedException (null); 105 } 106 107 public Object getProperty(String name) throws SAXNotSupportedException { 108 throw new SAXNotSupportedException (null); 109 } 110 111 public void parse(InputSource input) throws IOException, SAXException { 112 parse(input.getSystemId()); 113 } 114 115 public void parse(String systemId) throws IOException, SAXException { 116 ContentHandler handler = (contentHandler != null) ? contentHandler : defaultWriter; 117 LocatorImpl locator = new LocatorImpl (); 118 locator.setSystemId (systemId); 119 handler.setDocumentLocator (locator); 120 if (extent != null) { 121 getWriter ().write (contentHandler, systemId, extent, xmiVersion); 122 } else if (objects != null) { 123 getWriter ().write (contentHandler, systemId, objects, xmiVersion); 124 } else { 125 throw new SAXException ("Source not specified."); 126 } 127 } 128 129 public void setContentHandler(ContentHandler handler) { 130 contentHandler = handler; 131 } 132 133 public void setDTDHandler(DTDHandler handler) { 134 dtdHandler = handler; 135 } 136 137 public void setEntityResolver(EntityResolver resolver) { 138 entityResolver = resolver; 139 } 140 141 public void setErrorHandler(ErrorHandler handler) { 142 errorHandler = handler; 143 } 144 145 public void setFeature(String name, boolean value) throws SAXNotSupportedException { 146 throw new SAXNotSupportedException (null); 147 } 148 149 public void setProperty(String name, Object value) throws SAXNotSupportedException { 150 throw new SAXNotSupportedException (null); 151 } 152 153 private WriterBase getWriter () { 154 if ((xmiVersion != null) && xmiVersion.equals (DelegatingWriter.XMI_VERSION_20)) 155 return new XMI20Writer (config); 156 else 157 return new WriterBase (config); 158 } 159 160 } 161 | Popular Tags |