001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.schema.abe.nodes;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import org.netbeans.modules.xml.axi.AXIComponent;
047: import org.netbeans.modules.xml.axi.AXIDocument;
048: import org.netbeans.modules.xml.axi.AXIModel;
049: import org.netbeans.modules.xml.axi.AbstractElement;
050: import org.netbeans.modules.xml.axi.AnyElement;
051: import org.netbeans.modules.xml.axi.Attribute;
052: import org.netbeans.modules.xml.axi.ContentModel;
053: import org.netbeans.modules.xml.axi.datatype.CustomDatatype;
054: import org.netbeans.modules.xml.axi.datatype.Datatype;
055: import org.openide.nodes.Children;
056: import org.openide.nodes.Node;
057: import org.openide.util.Lookup;
058:
059: /**
060: *
061: * @author Todd Fast, todd.fast@sun.com
062: */
063: public class ABENodeFactory<T extends AXIComponent> extends Object {
064: /**
065: *
066: *
067: */
068: public ABENodeFactory(AXIModel model, Lookup lookup) {
069: super ();
070: context = createContext(model, lookup);
071: }
072:
073: /**
074: * Creates the ABEUIContext. Subclasses can override this method to
075: * customize the ABEUIContext instance.
076: */
077: protected ABEUIContext createContext(AXIModel model, Lookup lookup) {
078: return new ABEUIContext(model, this , lookup);
079: }
080:
081: /**
082: * Returns the context object used by this factory. All nodes created by
083: * this factory will share this context object.
084: *
085: */
086: public ABEUIContext getContext() {
087: return context;
088: }
089:
090: /**
091: * Convenience method to create a "root" node for representing the schema.
092: * This method is a convenience for calling <code>createNode()</code> and
093: * passing it a reference to the <code>Schema</code> component.
094: *
095: */
096: public Node createRootNode() {
097: return createRootNode(null);
098: }
099:
100: /**
101: * Convenience method to create a "root" node for representing the schema.
102: * This method is a convenience for calling <code>createNode()</code> and
103: * passing it a reference to the <code>Schema</code> component.
104: *
105: */
106: public Node createRootNode(List<Class> filterTypes) {
107: return new CategorizedDocumentNode(context, context.getModel()
108: .getRoot(), filterTypes);
109: }
110:
111: ////////////////////////////////////////////////////////////////////////////
112: // Primary factory methods
113: ////////////////////////////////////////////////////////////////////////////
114:
115: /**
116: * Creates a node for the specified schema component
117: *
118: */
119: public Node createNode(Node parent, AXIComponent component) {
120: if (component instanceof AnyElement)
121: return new AnyElementNode((AnyElement) component);
122: else if (component instanceof AbstractElement)
123: return new ElementNode((AbstractElement) component);
124: else if (component instanceof ContentModel)
125: return new ContentModelNode((ContentModel) component);
126: else if (component instanceof Attribute)
127: return new AttributeNode((Attribute) component);
128: return null;
129: }
130:
131: /**
132: * Creates a node for the specified schema component
133: *
134: */
135: public Node createNode(Node parent, Datatype component) {
136: if (component instanceof CustomDatatype)
137: return new CustomDatatypeNode((CustomDatatype) component);
138: else
139: return new DatatypeNode(component);
140:
141: }
142:
143: /**
144: * Creates the children object for the specified component reference. The
145: * defalut implementation returns <code>Children.LEAF</code>, meaning that
146: * any nodes created via <code>createNode()</code> will be lead nodes with
147: * no sub-structure. Subclasses should override this method to return
148: * more functional children objects.<p>
149: *
150: * Note, this method is only used by convention by methods in this class;
151: * subclasses are free to create and use any children object in the
152: * various node factory methods. This method provides a way to override
153: * the default children created by this class, but its use by particular
154: * node factory methods is not guaranteed.
155: *
156: * @param parent
157: * The parent node of the about-to-be created node for which this
158: * method will return the children object. Note, this node is
159: * <em>not</em> the node with which the return children object
160: * will be associated.
161: * @param reference
162: * The schema component reference associated with the about-to-be-
163: * created node.
164: */
165: public Children createChildren(Node parent, AXIComponent component) {
166: return Children.LEAF;
167: }
168:
169: ////////////////////////////////////////////////////////////////////////////
170: // Instance members
171: ////////////////////////////////////////////////////////////////////////////
172:
173: private ABEUIContext context;
174: }
|