configuration.java

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

JAVA
146
字号
/*
 * 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.Iterator;
import java.util.List;



/**
 * @author sallai
 *
 */
public class Configuration extends Component {
	ConfigurationImplementation implementation = new ConfigurationImplementation();
	
	NesCConfigurationFile configurationFile;
	
	/**
	 * @return Returns the implementation.
	 */
	public ConfigurationImplementation getImplementation() {
		return implementation;
	}
	/**
	 * @param implementation The implementation to set.
	 */
	public void setImplementation(ConfigurationImplementation implementation) {
		this.implementation = implementation;
	}
	/**
	 * @return Returns the parent.
	 */
	public NesCConfigurationFile getParent() {
		return configurationFile;
	}
	/**
	 * @return Returns the configurationFile.
	 */
	public NesCConfigurationFile getConfigurationFile() {
		return configurationFile;
	}
	/**
	 * @param configurationFile The configurationFile to set.
	 */
	public void setConfigurationFile(NesCConfigurationFile configurationFile) {
		this.configurationFile = configurationFile;
	}
	
	public Port getPortByPath(List path, int direction, String hint) {
		int idx = 0;
		if(path.isEmpty()) return null;
		
		TNode n = (TNode)path.get(idx++);
		Component c = this.implementation.getComponentByAlias(n.getText());
		if(c!=null) {
			// it's a component name/alias
			if(idx<path.size()) {
				// get next path string
				n = (TNode)path.get(idx++);
				Port p = c.getPortByName(n.getText());
				if(p!=null && p.getDirection()==direction) {
					if(idx==path.size()) {
						return p;
					} else {

						// FIXME: error - port found but there are excess path elements
						return null;
					}
				} else {
					// FIXME: could not find port in component 
					return null;
				}
			} else {
				// no more strings in path: take next path string from hint

				// iterate through the ports of the component
				Iterator i = c.portMap.values().iterator();
				Port p = null;
				while (i.hasNext()) {
					Port port = (Port) i.next();
					if(port.getDirection()!=direction) continue;
					String typeString = port.getTypeString(); 
					if(typeString!=null) {
						if(typeString.equals(hint)) {
							if(p==null) {
									p = port;
							} else {
									// FIXME: error - more than one ports match
									return null;
							}
						}
					}
				}
				if(p!=null) {
					if(idx==path.size()) {
						return p;
					} else {
						// FIXME: error - port found but there are excess path elements
						return null;
					}
				} else {
					// FIXME: could not find port in component 
					return null;
				}
			}
		} else {
			// component not found
			Port p = this.getPortByName(n.getText());
			if(p!=null && p.getDirection()==direction) {
				return p;
			} else {
				// FIXME: could not find port in component 
				return null;
			}
		}
	}
	
	/* (non-Javadoc)
	 * @see parser.nesc.ot.Component#outline(int)
	 */
	public void outline(Outline o) {
		o.addTabs();
		o.append("configuration");
		o.ensureSpace();
		o.append(getName());
		o.ensureSpace();
		o.append("{\n");

		super.outline(o);

		o.addTabs();
		o.append("}\n");		
		
		getImplementation().outline(o);

		o.append("\n");		
	}
}

⌨️ 快捷键说明

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