1 19 20 package org.netbeans.modules.j2ee.blueprints.catalog; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import javax.xml.parsers.ParserConfigurationException ; 25 import org.netbeans.modules.j2ee.blueprints.catalog.bpcatalogxmlparser.Nbcatalog; 26 import org.xml.sax.SAXException ; 27 28 33 public class SolutionsCatalog { 34 35 private static SolutionsCatalog theInstance = null; 36 37 private static final String NBCATALOG = 38 "/org/netbeans/modules/j2ee/blueprints/nbcatalog.xml"; 40 41 private Nbcatalog nbcatalogXml = null; 42 43 44 private SolutionsCatalog() {} 45 46 public static SolutionsCatalog getInstance() { 47 if(theInstance == null) { 48 createInstance(); 49 } 50 return theInstance; 51 } 52 53 private synchronized static void createInstance() { 54 if(theInstance == null) { 55 theInstance = new SolutionsCatalog(); 56 } 57 } 58 59 public Nbcatalog getCatalogXml() { 60 if(this.nbcatalogXml == null){ 61 parseCatalogXml(NBCATALOG); 62 } 63 return this.nbcatalogXml; 64 } 65 66 public Nbcatalog getCurrentNbcatalogXml() { 67 parseCatalogXml(NBCATALOG); 68 return nbcatalogXml; 69 } 70 71 private synchronized void parseCatalogXml(String catalogFile) { 72 this.nbcatalogXml = new Nbcatalog(); 73 try { 74 InputStream in = getClass().getResourceAsStream(catalogFile); 75 this.nbcatalogXml = Nbcatalog.read(in); 76 in.close(); 77 } 78 catch(ParserConfigurationException e) { 79 throw new RuntimeException (e); 80 } 81 catch(SAXException e) { 82 throw new RuntimeException (e); 83 } 84 catch(IOException e) { 85 throw new RuntimeException (e); 86 } 87 } 88 } 89 | Popular Tags |