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:
020: package org.netbeans.modules.xslt.mapper.model.nodes;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024: import org.netbeans.modules.soa.mapper.common.basicmapper.methoid.IMethoidNode;
025:
026: import org.netbeans.modules.xslt.mapper.model.nodes.visitor.NodeVisitor;
027:
028: import org.netbeans.modules.soa.mapper.common.basicmapper.methoid.IFieldNode;
029: import org.netbeans.modules.soa.mapper.common.IMapperNode;
030: import org.netbeans.modules.soa.mapper.common.basicmapper.tree.IMapperTreeNode;
031: import org.netbeans.modules.xslt.mapper.view.XsltMapper;
032:
033: public abstract class Node {
034:
035: private XsltMapper mapper;
036: private IMapperNode mMapperNode;
037: protected Object myDataObject;
038:
039: public Node(Object dataObject, XsltMapper mapper) {
040: this .myDataObject = dataObject;
041: this .mapper = mapper;
042: }
043:
044: /**
045: * Get the GUI Node for this Node.
046: * @return
047: */
048: public IMapperNode getMapperNode() {
049: return this .mMapperNode;
050: }
051:
052: public void setMapperNode(IMapperNode node) {
053: this .mMapperNode = node;
054: }
055:
056: public XsltMapper getMapper() {
057: return mapper;
058: }
059:
060: public List<Node> getNextNodes() {
061: IMapperNode node = getMapperNode();
062:
063: return (node != null) ? buildNodeList(node.getNextNodes())
064: : new ArrayList<Node>();
065: }
066:
067: /** Builds the list of all upstream nodes
068: * if some pin is not connected, returns null at that position
069: **/
070: public List<Node> getAllPreviousNodes() {
071: List<IMapperNode> mapperNodes = new ArrayList<IMapperNode>();
072: IMapperNode node = getMapperNode();
073: if (node instanceof IMethoidNode) {
074: IMapperNode n = ((IMethoidNode) node).getFirstNode();
075: while (n != null) {
076: if (n instanceof IFieldNode) {
077: IFieldNode field = (IFieldNode) n;
078: if (field.isInput()) {
079: List prevs = field.getPreviousNodes();
080: if (prevs.isEmpty()) {
081: mapperNodes.add(null);
082: } else {
083: mapperNodes.add((IMapperNode) prevs.get(0));
084: }
085:
086: }
087:
088: }
089: n = ((IMethoidNode) node).getNextNode((IMapperNode) n);
090: }
091:
092: }
093: return buildNodeList(mapperNodes);
094: }
095:
096: // TODO A documentation is strongly required for this method.
097: // Sometimes it returns not empty list with a null element.
098: // It looks strange, and it comes to many NPEs.
099: public List<Node> getPreviousNodes() {
100: IMapperNode node = getMapperNode();
101:
102: return (node != null) ? buildNodeList(node.getPreviousNodes())
103: : new ArrayList<Node>();
104:
105: }
106:
107: private List<Node> buildNodeList(List mapperNodes) {
108: ArrayList<Node> result = new ArrayList<Node>();
109: if (mapperNodes != null) {
110: for (Object n : mapperNodes) {
111: if (n instanceof IFieldNode) {
112: result.add((Node) ((IMapperNode) n).getGroupNode()
113: .getNodeObject());
114: } else if (n instanceof IMapperTreeNode) {
115: result.add(TreeNode.getNode((IMapperTreeNode) n));
116: } else {
117: result.add(null);
118: }
119:
120: }
121: }
122: return result;
123: }
124:
125: public abstract IMapperNode getOutputNode();
126:
127: public abstract IMapperNode getInputNode(Node node_from);
128:
129: /**
130: * Returns element of domain-specific object model, associated with this Node
131: * @returns AXIComponent, XSLComponent or XPAthexpression
132: **/
133:
134: public Object getDataObject() {
135: return this .myDataObject;
136: }
137:
138: // public void setSataObject(Object myDataObject) {
139: // this.myDataObject = myDataObject;
140: // }
141:
142: /**
143: * Gets the name of the node.
144: *
145: * @return String The name of the node
146: */
147:
148: public String getName() {
149: return "UNKNOWN NODE"; // NOI18N
150: }
151:
152: public abstract void accept(NodeVisitor visitor);
153: }
|