KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > AXIModelFactory


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 package org.netbeans.modules.xml.axi;
20
21 import java.io.IOException JavaDoc;
22 import org.netbeans.modules.xml.axi.impl.AXIModelImpl;
23 import org.netbeans.modules.xml.schema.model.SchemaModel;
24 import org.netbeans.modules.xml.xam.AbstractModelFactory;
25 import org.netbeans.modules.xml.xam.ModelSource;
26 import org.openide.filesystems.FileObject;
27 import org.openide.util.Lookup;
28 import org.openide.util.lookup.Lookups;
29
30 /**
31  * Factory class to create an AXI model.
32  *
33  * @author Samaresh (Samaresh.Panda@Sun.Com)
34  */

35 public class AXIModelFactory extends AbstractModelFactory<AXIModel> {
36             
37     /**
38      * Creates a new instance of AXIModelFactory
39      */

40     private AXIModelFactory() {
41     }
42     
43     /**
44      * Return the single factory instance.
45      */

46     public static AXIModelFactory getDefault() {
47         return instance;
48     }
49     
50     /**
51      * Convenient method to get the AXI model.
52      */

53     public AXIModel getModel(SchemaModel schemaModel) {
54         FileObject file = (FileObject)schemaModel.getModelSource().
55                 getLookup().lookup(FileObject.class);
56         Lookup lookup = null;
57         if(file == null) {
58             Object JavaDoc[] objectsToLookup = {schemaModel};
59             lookup = Lookups.fixed(objectsToLookup);
60         } else {
61             Object JavaDoc[] objectsToLookup = {schemaModel, file};
62             lookup = Lookups.fixed(objectsToLookup);
63         }
64         ModelSource source = new ModelSource(lookup, true);
65         assert(source != null);
66         return getModel(source);
67     }
68     
69     /**
70      * Get model from given model source. Model source should at very least
71      * provide lookup for SchemaModel
72      */

73     protected AXIModel getModel(ModelSource modelSource) {
74         Lookup lookup = modelSource.getLookup();
75         assert lookup.lookup(SchemaModel.class) != null;
76         return super.getModel(modelSource);
77     }
78     
79     /**
80      * For AXI, SchemaModel is the key.
81      */

82     protected Object JavaDoc getKey(ModelSource modelSource) {
83         return modelSource.getLookup().lookup(SchemaModel.class);
84     }
85     
86     /**
87      * Creates the AXI model here.
88      */

89     protected AXIModel createModel(ModelSource modelSource) {
90         return new AXIModelImpl(modelSource);
91     }
92     
93     /////////////////////////////////////////////////////////////////////
94
////////////////////////// member variables ////////////////////////
95
/////////////////////////////////////////////////////////////////////
96
/**
97      * Singleton instance of the factory class.
98      */

99     private static AXIModelFactory instance = new AXIModelFactory();
100 }
101
Popular Tags