KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > nodes > ABENodeFactory


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 package org.netbeans.modules.xml.schema.abe.nodes;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.xml.axi.AXIComponent;
25 import org.netbeans.modules.xml.axi.AXIDocument;
26 import org.netbeans.modules.xml.axi.AXIModel;
27 import org.netbeans.modules.xml.axi.AbstractElement;
28 import org.netbeans.modules.xml.axi.AnyElement;
29 import org.netbeans.modules.xml.axi.Attribute;
30 import org.netbeans.modules.xml.axi.ContentModel;
31 import org.netbeans.modules.xml.axi.datatype.CustomDatatype;
32 import org.netbeans.modules.xml.axi.datatype.Datatype;
33 import org.openide.nodes.Children;
34 import org.openide.nodes.Node;
35 import org.openide.util.Lookup;
36
37 /**
38  *
39  * @author Todd Fast, todd.fast@sun.com
40  */

41 public class ABENodeFactory<T extends AXIComponent> extends Object JavaDoc
42 {
43     /**
44      *
45      *
46      */

47     public ABENodeFactory(AXIModel model, Lookup lookup)
48     {
49         super();
50         context=createContext(model,lookup);
51     }
52
53     /**
54      * Creates the ABEUIContext. Subclasses can override this method to
55      * customize the ABEUIContext instance.
56      */

57     protected ABEUIContext createContext(AXIModel model, Lookup lookup)
58     {
59         return new ABEUIContext(model,this,lookup);
60     }
61
62
63     /**
64      * Returns the context object used by this factory. All nodes created by
65      * this factory will share this context object.
66      *
67      */

68     public ABEUIContext getContext()
69     {
70         return context;
71     }
72
73     /**
74      * Convenience method to create a "root" node for representing the schema.
75      * This method is a convenience for calling <code>createNode()</code> and
76      * passing it a reference to the <code>Schema</code> component.
77      *
78      */

79     public Node createRootNode()
80     {
81         return createRootNode(null);
82     }
83
84     /**
85      * Convenience method to create a "root" node for representing the schema.
86      * This method is a convenience for calling <code>createNode()</code> and
87      * passing it a reference to the <code>Schema</code> component.
88      *
89      */

90     public Node createRootNode(List JavaDoc<Class JavaDoc> filterTypes)
91     {
92         return new CategorizedDocumentNode(context,
93                         context.getModel().getRoot(), filterTypes);
94     }
95
96
97
98     ////////////////////////////////////////////////////////////////////////////
99
// Primary factory methods
100
////////////////////////////////////////////////////////////////////////////
101

102     /**
103      * Creates a node for the specified schema component
104      *
105      */

106     public Node createNode(
107         Node parent, AXIComponent component)
108     {
109         if(component instanceof AnyElement)
110             return new AnyElementNode((AnyElement) component);
111         else if(component instanceof AbstractElement)
112             return new ElementNode((AbstractElement) component);
113         else if(component instanceof ContentModel)
114             return new ContentModelNode((ContentModel) component);
115                 else if(component instanceof Attribute)
116             return new AttributeNode((Attribute) component);
117         return null;
118     }
119     
120
121     /**
122      * Creates a node for the specified schema component
123      *
124      */

125     public Node createNode(
126         Node parent, Datatype component)
127     {
128         if(component instanceof CustomDatatype)
129             return new CustomDatatypeNode((CustomDatatype) component);
130         else
131             return new DatatypeNode(component);
132         
133     }
134
135
136
137     /**
138      * Creates the children object for the specified component reference. The
139      * defalut implementation returns <code>Children.LEAF</code>, meaning that
140      * any nodes created via <code>createNode()</code> will be lead nodes with
141      * no sub-structure. Subclasses should override this method to return
142      * more functional children objects.<p>
143      *
144      * Note, this method is only used by convention by methods in this class;
145      * subclasses are free to create and use any children object in the
146      * various node factory methods. This method provides a way to override
147      * the default children created by this class, but its use by particular
148      * node factory methods is not guaranteed.
149      *
150      * @param parent
151      * The parent node of the about-to-be created node for which this
152      * method will return the children object. Note, this node is
153      * <em>not</em> the node with which the return children object
154      * will be associated.
155      * @param reference
156      * The schema component reference associated with the about-to-be-
157      * created node.
158      */

159     public Children createChildren(
160         Node parent, AXIComponent component)
161     {
162         return Children.LEAF;
163     }
164
165     ////////////////////////////////////////////////////////////////////////////
166
// Instance members
167
////////////////////////////////////////////////////////////////////////////
168

169     private ABEUIContext context;
170 }
171
Popular Tags