DBPort port = (DBPort)i2.next();
VDBPort port = (VDBPort)i2.next();
public static Map preparePorts(Group group, Map substitutions){	HashMap map = new HashMap();		Iterator i = group.getStructure().iterator();	while (i.hasNext())	{		Object obj = i.next();		if (obj instanceof Template)		{			Template t = (Template)obj;						Iterator i2 = t.getTemplateData().getTemplate().getPortsV().iterator();			while (i2.hasNext())			{				DBPort port = (DBPort)i2.next();								String target = port.getTarget();				// new macros				// !!! this is done twice - optimize with buffering	 			Map newSubstitutions = prepareSubstitutions(t.getTemplateData(), substitutions);				target = VDBTemplateInstance.applyProperties(target, newSubstitutions);								// if target is a contains a port definition it might be defined in lower levels				// try to resolve it				int pos = target.indexOf('$');				int posStart = 0;  // '(' char				int posMiddle = 0; // '.' char				int posEnd = 0;	// ')' char				while (pos>=0)				{										//System.out.println("Recursive: "+target);										posStart = target.indexOf('(', pos);					if (posStart>=0)					{						posMiddle = target.indexOf('.', posStart);						if (posMiddle>=0)						{							posEnd = target.indexOf(')', posStart);							// possible port definition							// we have sequence od '(' .. '.' .. ')'							if (posEnd>posMiddle)							{								Map lowerLevelPorts = preparePorts(t.getTemplateData().getTemplate().getGroup(), newSubstitutions);								/*								System.out.println("Ports at lower level:");								Iterator i3 = lowerLevelPorts.keySet().iterator();								while (i3.hasNext())								{									Object key = i3.next();									System.out.println("\t"+key+"="+lowerLevelPorts.get(key));									}								*/								target = VDBTemplateInstance.applyPorts(target, lowerLevelPorts);								break;							}						}					}						pos = target.indexOf('$', pos+1);		// no problems if pos == length					}								//System.out.println(port.getPortDefinition(t.getTemplateData().getName())+"="+target);					map.put(port.getPortDefinition(t.getTemplateData().getName()), target);						}		}	}		return map;}