001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.tmap.nodes;
020:
021: import org.netbeans.modules.soa.ui.nodes.ReflectionNodeFactory;
022: import org.netbeans.modules.xslt.tmap.model.api.Invoke;
023: import org.netbeans.modules.xslt.tmap.model.api.Param;
024: import org.netbeans.modules.xslt.tmap.model.api.TMapComponent;
025: import org.netbeans.modules.xslt.tmap.model.api.TMapModel;
026: import org.openide.nodes.Children;
027: import org.openide.nodes.Node;
028: import org.openide.util.Lookup;
029:
030: /**
031: *
032: * @author Vitaly Bychkov
033: * @version 1.0
034: */
035: public class NavigatorNodeFactory extends
036: ReflectionNodeFactory<NodeType> {
037:
038: private static NavigatorNodeFactory INSTANCE = new NavigatorNodeFactory();
039:
040: public static NavigatorNodeFactory getInstance() {
041: return INSTANCE;
042: }
043:
044: private NavigatorNodeFactory() {
045: super (6);
046: //
047: key2Class.put(NodeType.TRANSFORMMAP, TransformMapNode.class);
048: key2Class.put(NodeType.SERVICE, ServiceNode.class);
049: key2Class.put(NodeType.OPERATION, OperationNode.class);
050: key2Class.put(NodeType.INVOKE, InvokeNode.class);
051: key2Class.put(NodeType.TRANSFORM, TransformNode.class);
052: key2Class.put(NodeType.PARAM, ParamNode.class);
053: }
054:
055: public Node createNode(TMapComponent entity, Lookup lookup) {
056: Node node = null;
057: NodeType nodeType = NodeType.getNodeType(entity);
058: if (nodeType != null) {
059: node = createNode(nodeType, entity, lookup);
060: }
061: return node;
062: }
063:
064: public Node getTransformMapNode(TMapModel model, Lookup lookup) {
065: assert model != null && lookup != null;
066: return createNode(NodeType.TRANSFORMMAP, model
067: .getTransformMap(), lookup);
068: }
069:
070: @Override
071: public Node createNode(NodeType nodeType, Object ref, Lookup lookup) {
072: if (nodeType == null || ref == null || lookup == null) {
073: return null;
074: }
075:
076: // assert nodeType != null && ref != null && lookup != null;
077: if (NodeType.UNKNOWN_TYPE.equals(nodeType)) {
078: return createDefaultNode(ref, lookup);
079: }
080:
081: Node node = null;
082: switch (nodeType) {
083: case TRANSFORMMAP:
084: // assert ref instanceof TransformMap
085: // : "reference should be TransformMap type to create TransformMap type Node"; // NOI18N
086: // node = super.createNode(nodeType,ref,
087: // new TransformMapChildren((TransformMap)ref,lookup),lookup);
088: // break;
089: case SERVICE:
090: // assert ref instanceof Service
091: // : "reference should be Service type to create Service type Node"; // NOI18N
092: // node = super.createNode(nodeType,ref,
093: // new ServiceChildren((Service)ref,lookup),lookup);
094: // break;
095: case OPERATION:
096: case TRANSFORM:
097: // assert ref instanceof Operation
098: // : "reference should be Operation type to create Operation type Node"; // NOI18N
099: // node = super.createNode(nodeType,ref,
100: // new OperationChildren((Operation)ref,lookup),lookup);
101: assert ref instanceof TMapComponent : "reference should be TMapComponent type to create TMapComponent type Node"; // NOI18N
102: node = super .createNode(nodeType, ref,
103: new TMapComponentNodeChildrenImpl(
104: (TMapComponent) ref, lookup), lookup);
105: break;
106: case PARAM:
107: assert ref instanceof Param : "reference should be Param type to create Param type Node"; // NOI18N
108: node = super .createNode(nodeType, ref, Children.LEAF,
109: lookup);
110: break;
111: case INVOKE:
112: assert ref instanceof Invoke : "reference should be Invoke type to create Invoke type Node"; // NOI18N
113: node = super .createNode(nodeType, ref, Children.LEAF,
114: lookup);
115: break;
116: }
117:
118: return node;
119: }
120:
121: @Override
122: public Node createNode(NodeType nodeType, Object ref,
123: Children children, Lookup lookup) {
124: return super .createNode(nodeType, ref, children, lookup);
125: }
126:
127: // TODO add impl for default node
128: private Node createDefaultNode(Object ref, Lookup lookup) {
129: return null;
130: }
131:
132: }
|