KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > completion > RuntimeCatalogModel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * RuntimeCatalogModel.java
22  *
23  * Created on January 18, 2007, 2:59 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.completion;
30
31 import java.io.IOException JavaDoc;
32 import java.io.InputStream JavaDoc;
33 import java.net.MalformedURLException JavaDoc;
34 import java.net.URI JavaDoc;
35 import java.net.URL JavaDoc;
36 import javax.swing.text.BadLocationException JavaDoc;
37 import javax.swing.text.Document JavaDoc;
38 import org.netbeans.api.xml.services.UserCatalog;
39 import org.netbeans.modules.xml.xam.ModelSource;
40 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel;
41 import org.netbeans.modules.xml.xam.locator.CatalogModel;
42 import org.netbeans.modules.xml.xam.locator.CatalogModelException;
43 import org.openide.util.lookup.Lookups;
44 import org.w3c.dom.ls.LSInput JavaDoc;
45 import org.xml.sax.InputSource JavaDoc;
46 import org.xml.sax.SAXException JavaDoc;
47
48 /**
49  *
50  * @author girix
51  */

52 public class RuntimeCatalogModel implements CatalogModel{
53     
54     /** Creates a new instance of RuntimeCatalogModel */
55     public RuntimeCatalogModel() {
56     }
57     
58     public ModelSource getModelSource(URI JavaDoc locationURI) throws CatalogModelException {
59         throw new RuntimeException JavaDoc("Method not implemented"); //NOI18N
60
}
61     
62     public ModelSource getModelSource(URI JavaDoc locationURI,
63             ModelSource modelSourceOfSourceDocument) throws CatalogModelException {
64         InputSource JavaDoc isrc;
65         try {
66             isrc = UserCatalog.getDefault().getEntityResolver().
67                     resolveEntity(null, locationURI.toString());
68             InputStream JavaDoc is = new URL JavaDoc(isrc.getSystemId()).openStream();
69             if(is != null)
70                 return createModelSource(is);
71         } catch (Exception JavaDoc ex) {
72             throw new CatalogModelException(ex);
73         }
74         
75         return null;
76     }
77     
78     private ModelSource createModelSource(InputStream JavaDoc is) throws CatalogModelException{
79         try {
80             Document JavaDoc d = AbstractDocumentModel.getAccessProvider().loadSwingDocument(is);
81             if(d != null)
82                 return new ModelSource(Lookups.fixed(new Object JavaDoc[]{this,d}), false);
83         } catch (Exception JavaDoc ex) {
84             throw new CatalogModelException(ex);
85         }
86                 
87         return null;
88     }
89     
90     public InputSource JavaDoc resolveEntity(String JavaDoc publicId,
91             String JavaDoc systemId) throws SAXException JavaDoc, IOException JavaDoc {
92         throw new RuntimeException JavaDoc("Method not implemented"); //NOI18N
93
}
94     
95     public LSInput JavaDoc resolveResource(String JavaDoc type, String JavaDoc namespaceURI,
96             String JavaDoc publicId, String JavaDoc systemId, String JavaDoc baseURI) {
97         throw new RuntimeException JavaDoc("Method not implemented"); //NOI18N
98
}
99     
100 }
101
Popular Tags