1 19 package org.netbeans.modules.xml.retriever.catalog.impl; 20 21 import java.io.IOException ; 22 import java.util.WeakHashMap ; 23 import java.util.logging.Logger ; 24 import org.netbeans.api.project.FileOwnerQuery; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.modules.xml.retriever.catalog.Utilities; 27 import org.netbeans.modules.xml.retriever.catalog.CatalogWriteModel; 28 import org.netbeans.modules.xml.retriever.catalog.CatalogWriteModelFactory; 29 import org.netbeans.modules.xml.xam.ModelSource; 30 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 31 import org.netbeans.modules.xml.xam.locator.CatalogModel; 32 import org.openide.filesystems.FileObject; 33 import org.w3c.dom.ls.LSResourceResolver ; 34 35 39 public class CatalogModelFactoryImpl extends CatalogWriteModelFactory{ 40 private static final Logger logger = Utilities.getLogger(); 41 42 43 public CatalogWriteModel getCatalogWriteModelForProject(FileObject anyFileObjectExistingInAProject) throws CatalogModelException { 44 logger.entering("CatalogModelFactoryImpl","getCatalogModelForProject"); 45 Project project = FileOwnerQuery.getOwner(anyFileObjectExistingInAProject); 46 assert(project != null); 47 CatalogWriteModel result = null; 48 try { 49 result = new CatalogWriteModelImpl(project); 50 } catch (IOException ex) { 51 throw new CatalogModelException(ex); 52 } 53 return result; 54 } 55 56 57 private static WeakHashMap <Project, CatalogModel> proj2cm = new WeakHashMap <Project, CatalogModel>(); 58 59 public CatalogModel getCatalogModel(ModelSource modelSource) throws CatalogModelException { 60 if(modelSource == null) 61 throw new IllegalArgumentException ("modelSource arg is null."); 62 CatalogModel catalogModel = (CatalogModel) modelSource.getLookup().lookup(CatalogModel.class); 63 if(catalogModel == null){ 64 FileObject fo = (FileObject) modelSource.getLookup().lookup(FileObject.class); 65 if(fo == null) 66 throw new IllegalArgumentException ("ModelSource must have FileObject in its lookup"); 67 return getCatalogModel(fo); 68 } 69 return catalogModel; 70 } 71 72 public CatalogModel getCatalogModel(FileObject fo) throws CatalogModelException{ 73 CatalogModel catalogModel = null; 74 Project project = FileOwnerQuery.getOwner(fo); 75 if(project != null){ 76 catalogModel = proj2cm.get(fo); 77 if(catalogModel != null) 78 return catalogModel; 79 try { 80 catalogModel = new CatalogModelImpl(project); 81 } catch (IOException ex) { 82 throw new CatalogModelException(ex); 83 } 84 return catalogModel; 85 } 86 catalogModel = new CatalogModelImpl(); 87 return catalogModel; 88 } 89 90 public LSResourceResolver getLSResourceResolver() { 91 return new LSResourceResolverImpl(); 92 } 93 94 public CatalogWriteModel getCatalogWriteModelForCatalogFile(FileObject fileObjectOfCatalogFile) throws CatalogModelException { 95 try{ 96 return new CatalogWriteModelImpl(fileObjectOfCatalogFile); 97 } catch (IOException ex) { 98 throw new CatalogModelException(ex); 99 } 100 } 101 } 102 | Popular Tags |