KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > XMLDataObjectImpl


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
20 package org.openide.loaders;
21
22
23 import java.io.IOException JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import javax.xml.parsers.*;
26 import org.netbeans.modules.openide.loaders.RuntimeCatalog;
27 import org.openide.util.Exceptions;
28 import org.openide.util.Lookup;
29 import org.openide.xml.*;
30 import org.xml.sax.*;
31
32 /**
33  * Class that hide implementations details of deprecated utility
34  * methods provided at XMLDataObject.
35  *
36  * @author Petr Kuzel
37  */

38 class XMLDataObjectImpl extends Object JavaDoc {
39
40
41     /** Create DOM builder using JAXP libraries. */
42     static DocumentBuilder makeBuilder(boolean validate) throws IOException JavaDoc, SAXException {
43         
44         DocumentBuilder builder;
45         DocumentBuilderFactory factory;
46
47         //create factory according to javax.xml.parsers.SAXParserFactory property
48
//or platform default (i.e. com.sun...)
49
try {
50             factory = DocumentBuilderFactory.newInstance();
51             factory.setValidating(validate);
52             factory.setNamespaceAware(false);
53         } catch (FactoryConfigurationError err) {
54             notifyFactoryErr(err, "javax.xml.parsers.DocumentBuilderFactory"); //NOI18N
55
throw err;
56         }
57
58         try {
59             builder = factory.newDocumentBuilder();
60         } catch (ParserConfigurationException ex) {
61             SAXException sex = new SAXException("Configuration exception."); // NOI18N
62
sex.initCause(ex);
63             Exceptions.attachLocalizedMessage(sex,
64                                               "Can not create a DOM builder!\nCheck javax.xml.parsers.DocumentBuilderFactory property and the builder library presence on classpath."); // NOI18N
65
throw sex;
66         }
67         
68         return builder;
69     }
70     
71     @Deprecated JavaDoc
72     static Parser makeParser(boolean validate) {
73         
74         try {
75             return new org.xml.sax.helpers.XMLReaderAdapter JavaDoc (XMLUtil.createXMLReader(validate));
76         } catch (SAXException ex) {
77             notifyNewSAXParserEx(ex);
78             return null;
79         }
80         
81     }
82
83     /** Return XML reader or null if no provider exists. */
84     static XMLReader makeXMLReader(boolean validating, boolean namespaces) {
85
86         try {
87             return XMLUtil.createXMLReader(validating,namespaces);
88         } catch (SAXException ex) {
89             notifyNewSAXParserEx(ex);
90             return null;
91         }
92         
93     }
94     
95     /** Annotate & notify the exception. */
96     private static void notifyNewSAXParserEx (Exception JavaDoc ex) {
97         Exceptions.attachLocalizedMessage(ex,
98                                           "Can not create a SAX parser!\nCheck javax.xml.parsers.SAXParserFactory property features and the parser library presence on classpath."); // NOI18N
99
Exceptions.printStackTrace(ex);
100     }
101
102     /** Annotate & notify the error. */
103     private static void notifyFactoryErr(Error JavaDoc err, String JavaDoc property) {
104         Exceptions.attachLocalizedMessage(err,
105                                           "Can not create a factory!\nCheck " +
106                                           property +
107                                           " property and the factory library presence on classpath."); // NOI18N
108
Exceptions.printStackTrace(err);
109     }
110
111     // warning back compatability code!!!
112
static synchronized void registerCatalogEntry(String JavaDoc publicId, String JavaDoc uri) {
113         Iterator JavaDoc it = Lookup.getDefault().lookupAll(EntityCatalog.class).iterator();
114         while (it.hasNext()) {
115             Object JavaDoc o = it.next();
116             if (o instanceof RuntimeCatalog) {
117                 ((RuntimeCatalog) o).registerCatalogEntry(publicId, uri);
118                 return;
119             }
120         }
121         assert false;
122     }
123     
124 }
125
Popular Tags