KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > retriever > catalog > impl > CatalogModelFactoryImpl


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.modules.xml.retriever.catalog.impl;
20
21 import java.io.IOException JavaDoc;
22 import java.util.WeakHashMap JavaDoc;
23 import java.util.logging.Logger JavaDoc;
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 JavaDoc;
34
35 /**
36  *
37  * @author girix
38  */

39 public class CatalogModelFactoryImpl extends CatalogWriteModelFactory{
40     private static final Logger JavaDoc 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 JavaDoc ex) {
51             throw new CatalogModelException(ex);
52         }
53         return result;
54     }
55     
56     
57     private static WeakHashMap JavaDoc <Project, CatalogModel> proj2cm = new WeakHashMap JavaDoc<Project, CatalogModel>();
58     
59     public CatalogModel getCatalogModel(ModelSource modelSource) throws CatalogModelException {
60         if(modelSource == null)
61             throw new IllegalArgumentException JavaDoc("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 JavaDoc("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 JavaDoc ex) {
82                 throw new CatalogModelException(ex);
83             }
84             return catalogModel;
85         }
86         catalogModel = new CatalogModelImpl();
87         return catalogModel;
88     }
89     
90     public LSResourceResolver JavaDoc 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 JavaDoc ex) {
98             throw new CatalogModelException(ex);
99         }
100     }
101 }
102
Popular Tags