component.java

来自「plugin for eclipse」· Java 代码 · 共 106 行

JAVA
106
字号
/*
 * Created on May 9, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package isis.anp.nesc.ot;

import isis.anp.common.TNode;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;


/**
 * @author sallai
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public abstract class Component {
	TNode defNode;
	TNode nameNode;
	String name;
	LinkedHashMap portMap = new LinkedHashMap();
	
	public void addPort(Port port) {
//		System.out.println("Component: Adding port " + port.getPortName());
		portMap.put(port.getPortName(), port);
		if(port!=null) {
			port.setComponent(this);
		}
	}
	
	public void addPortList(List portList) {
		Iterator i = portList.iterator();
		while (i.hasNext()) {
			Port p = (Port) i.next();
			addPort(p);
		}
	}
	
	public Port getPortByName(String portName) {
//		System.out.println(" getPortByName called : "+portName);
		// check if port name contains a "."
		String[] splitPortName = portName.split("\\.",2); 

		if(splitPortName.length == 1) {
			// "." not found - resolve name
			return (Port) portMap.get(splitPortName[0]);
		} else {
			// "." found
			
			// look up interface port
			Port ip = getPortByName(splitPortName[0]);
			if(ip == null || !(ip instanceof InterfacePort)) return null;
		
			// delegate function port lookup to interface port
			return ((InterfacePort) ip).getFunctionPortByName(splitPortName[1]);
		}
	}
	
	public TNode getDefNode() {
		return defNode;
	}
	public void setDefNode(TNode defNode) {
		this.defNode = defNode;
	}
	public String getName() {
		return name;
	}
	public void setName(String componentName) {
		this.name = componentName;
		if(nameNode!=null) {
			nameNode.setText(componentName);
		}
	}
	public TNode getNameNode() {
		return nameNode;
	}
	
	public void setNameNode(TNode componentNameNode) {
		this.nameNode = componentNameNode;
		this.name = componentNameNode.getText();
	}

	public Collection getPorts() {
		return portMap.values();
	}
	
	public void outline(Outline o) {

		Iterator i = getPorts().iterator();
		while (i.hasNext()) {
			Port p = (Port) i.next();
			o.incTabs();
					p.outline(o);
			o.decTabs();
			o.append("\n");
		}
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?