KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.Collection JavaDoc;
26 import javax.jmi.reflect.RefPackage;
27 import javax.jmi.xmi.MalformedXMIException;
28 import javax.jmi.xmi.XmiReader;
29 import javax.xml.parsers.ParserConfigurationException JavaDoc;
30 import org.netbeans.lib.jmi.util.Logger;
31 import org.xml.sax.SAXException JavaDoc;
32
33 public class XMISaxReaderImpl implements XmiReader {
34
35     /** Creates new XMISaxReaderImpl */
36     public XMISaxReaderImpl () {
37     }
38
39     public Collection JavaDoc read (InputStream JavaDoc stream, String JavaDoc uri, RefPackage extent) throws IOException JavaDoc, MalformedXMIException {
40         // [PENDING] correct this code to throw exceptions correctly
41
try {
42             // [PENDING] correct this call to use both stream and URI
43
return new XmiSAXReader ().read (stream, uri, new RefPackage[] {extent}, null);
44         } catch (ParserConfigurationException JavaDoc e) {
45             MalformedXMIException ne = new MalformedXMIException(e.getMessage());
46             Logger.getDefault().annotate(ne, e);
47             throw ne;
48         } catch (SAXException JavaDoc e) {
49             MalformedXMIException ne = new MalformedXMIException(e.getMessage());
50             Logger.getDefault().annotate(ne, e);
51             throw ne;
52         }
53     }
54     
55     public Collection JavaDoc read (String JavaDoc uri, RefPackage extent)
56     throws IOException JavaDoc, MalformedXMIException {
57         return read (new URL JavaDoc(uri), new RefPackage[] {extent}, null);
58     }
59     
60     private Collection JavaDoc read (URL JavaDoc url, RefPackage[] extents, String JavaDoc encoding)
61         throws IOException JavaDoc, MalformedXMIException {
62         // [PENDING] correct this code to throw exceptions correctly
63
try {
64             return new XmiSAXReader ().read (url, extents, encoding);
65         } catch (ParserConfigurationException JavaDoc e) {
66             MalformedXMIException ne = new MalformedXMIException(e.toString());
67             Logger.getDefault().annotate(ne, e);
68             throw ne;
69         } catch (SAXException JavaDoc e) {
70             MalformedXMIException ne = new MalformedXMIException(e.toString());
71             Logger.getDefault().annotate(ne, e);
72             throw ne;
73         }
74     }
75     
76 }
77
Popular Tags