KickJava   Java API By Example, From Geeks To Geeks.

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


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
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 JavaDoc;
29 import org.xml.sax.*;
30 import javax.xml.parsers.ParserConfigurationException JavaDoc;
31 import org.netbeans.lib.jmi.util.Logger;
32
33 public class SAXReader extends XMIReader {
34
35     private XMIInputConfig config;
36
37     // init .....................................................................
38

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     // methods ..................................................................
53

54     public XMIInputConfig getConfiguration() {
55         return config;
56     }
57     
58     public Collection read (InputStream stream, String JavaDoc uri, RefPackage extent) throws IOException, MalformedXMIException {
59         // [PENDING] correct this code to throw exceptions correctly
60
try {
61             // [PENDING] correct this call to use both stream and URI
62
return new XmiSAXReader (config).read (stream, uri, new RefPackage[] {extent}, null);
63         } catch (ParserConfigurationException JavaDoc 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 JavaDoc uri, RefPackage extent)
75     throws IOException, MalformedXMIException {
76         return read (new URL JavaDoc(uri), new RefPackage[] {extent}, null);
77     }
78     
79     private Collection read (URL JavaDoc url, RefPackage[] extents, String JavaDoc encoding)
80         throws IOException, MalformedXMIException {
81         // [PENDING] correct this code to throw exceptions correctly
82
try {
83             return new XmiSAXReader (config).read (url, extents, encoding);
84         } catch (ParserConfigurationException JavaDoc 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