KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > jmi > xmi > Producer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
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 JavaDoc 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     // init .....................................................................
45

46     public Producer () {
47         config = new OutputConfig ();
48     }
49     
50     public Producer (XMIOutputConfig config) {
51         this.config = config;
52     }
53     
54     // XMIProducer implementation ...............................................
55

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 JavaDoc getSource() {
67         if (objects == null)
68             return extent;
69         else
70             return objects;
71     }
72
73     public void setXmiVersion(String JavaDoc xmiVersion) {
74         this.xmiVersion = xmiVersion;
75     }
76
77     public String JavaDoc getXmiVersion() {
78         return xmiVersion;
79     }
80
81     public XMIOutputConfig getConfiguration() {
82         return config;
83     }
84
85     // XMLReader implementation .................................................
86

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 JavaDoc name) throws SAXNotSupportedException {
104         throw new SAXNotSupportedException (null);
105     }
106
107     public Object JavaDoc getProperty(String JavaDoc 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 JavaDoc systemId) throws IOException, SAXException {
116         ContentHandler handler = (contentHandler != null) ? contentHandler : defaultWriter;
117         LocatorImpl JavaDoc locator = new LocatorImpl JavaDoc ();
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 JavaDoc name, boolean value) throws SAXNotSupportedException {
146         throw new SAXNotSupportedException (null);
147     }
148
149     public void setProperty(String JavaDoc name, Object JavaDoc 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