Skip to content
Snippets Groups Projects
GProactiveDesign.java 76.9 KiB
Newer Older
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
 * 
 * ludovic.apvrille AT enst.fr
 * 
 * This software is a computer program whose purpose is to allow the
 * edition of TURTLE analysis, design and deployment diagrams, to
 * allow the generation of RT-LOTOS or Java code from this diagram,
 * and at last to allow the analysis of formal validation traces
 * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
 * from INRIA Rhone-Alpes.
 * 
 * This software is governed by the CeCILL  license under French law and
 * abiding by the rules of distribution of free software.  You can  use,
 * modify and/ or redistribute the software under the terms of the CeCILL
 * license as circulated by CEA, CNRS and INRIA at the following URL
 * "http://www.cecill.info".
 * 
 * As a counterpart to the access to the source code and  rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty  and the software's author,  the holder of the
 * economic rights,  and the successive licensors  have only  limited
 * liability.
 * 
 * In this respect, the user's attention is drawn to the risks associated
 * with loading,  using,  modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean  that it is complicated to manipulate,  and  that  also
 * therefore means  that it is reserved for developers  and  experienced
 * professionals having in-depth computer knowledge. Users are therefore
 * encouraged to load and test the software's suitability as regards their
 * requirements in conditions enabling the security of their systems and/or
 * data to be ensured and,  more generally, to use and operate it in the
 * same conditions as regards security.
 * 
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
 */


Florian Lugou's avatar
Florian Lugou committed
import fr.inria.oasis.vercors.cttool.model.*;
import translator.*;
import ui.procsd.*;
import ui.prosmd.*;
import ui.prosmd.util.CorrespondanceSMDManager;

Florian Lugou's avatar
Florian Lugou committed
import java.util.*;

/**
 * Class GProactiveDesign
 * Translation of graphical proactive designs into TURTLE modeling
 * Creation: 10/07/2006
 * @version 1.0 10/07/2006
 * @author Ludovic APVRILLE
 */
public class GProactiveDesign  {
    private TURTLEModeling tm;
    private ProactiveDesignPanel pdp;
    private List<ProCSDPort> portsList=new LinkedList<ProCSDPort>(); //list of ProCSDPort 
    private List<TGConnectorProCSD> connectorsList =new LinkedList<TGConnectorProCSD>(); //list of TGConnectorProCSD
    private List<TGConnectorPortInterface> connectorsPortInterfacesList=new LinkedList<TGConnectorPortInterface>();
    private List<ProCSDInterface> interfacesList =new LinkedList<ProCSDInterface>(); //list of ProCSDInterface
    private List<ProCSDComponent> proCSDComponentsList=new LinkedList<ProCSDComponent>();
    private List<CheckingError> checkingErrors=new LinkedList<CheckingError> (); 
  //  private CorrespondanceTGElement listE;
    private CorrespondanceSMDManager corespManager;
    private boolean buildErrors;
    //Added by Solange ...and removed by Emil ..
  //  private ProCSDPort puerto, puerto2;
    private Component mainModelComp;
    
    public GProactiveDesign(ProactiveDesignPanel _pdp) {
        pdp = _pdp;
        init();
     
        //System.out.println(mainModelComp.prettyPrint());
   }
    

    
    private void init()
    {   checkingErrors = new LinkedList<CheckingError> ();
      //  listE = new CorrespondanceTGElement();
    	portsList=new LinkedList<ProCSDPort>(); //list of ProCSDPort 
        connectorsList =new LinkedList<TGConnectorProCSD>(); //list of TGConnectorProCSD
        interfacesList =new LinkedList<ProCSDInterface>(); //list of ProCSDInterface
        proCSDComponentsList=new LinkedList<ProCSDComponent>();
    	ProactiveCSDPanel csd = (ProactiveCSDPanel)(pdp.panels.elementAt(0));
     	List<TGComponent> list = csd.getComponentList();
     	boolean cyclefound=false;
     	  for (int i=0;i<list.size();i++)
        {
        	TGComponent tmp= list.get(i);
//        	listElement(tmp);
          if  (!parseStructureAndFillUpLists(tmp)) cyclefound=true;
        }
        
    	  
     	  
     	  
        if (cyclefound)
        	addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR,"Cycle found in component diagrams structure."));
     	
        updatePortsInformation();
    
     	  
   //     updateAllMembranes(); 
     	  
     	  
    }
    
    
    public void updateAllMembranes()
    {
    	this.pdp.updateAllMembranes();    	
    }
    

    
    private Component createModelComp(ProCSDComponent comp)
    {
    	String modelCompName=comp.getValue();
    	
   	if (comp.getThisCompDesign()!=null)
    	 {comp=comp.getThisCompDesign();
   // 	  modelCompName+="_"+comp.getValue();
    	 }
   
    	
    	Component modelComp=new ComponentImpl(modelCompName,isPrimitive(comp));
    	    	
    	
    	
     //we add attributes
      List<TAttribute> attribs=comp.getMyAttributes();
	  for (int at=0;at<attribs.size();at++)
		{
			Attribute attrib=new fr.inria.oasis.vercors.cttool.model.AttributeImpl(a.getId(),a.getType(),a.getAccess(),a.getInitialValue());		
			modelComp.addAttribute(attrib);			
		}
			  
	  
	  //we add ports
	  //we do not set the ports bindings at this time as all ports in the model
	  //are not already
	  //created
	  
	  Vector<ProCSDPort> portsList=comp.getPortsList();
	  for (int k=0;k<portsList.size();k++)
	  {
		  ProCSDPort p = portsList.get(k);
		  Port modelPort=null;
		  if (p instanceof ProCSDInPort)
		  {
			  modelPort=new InPort(p.getValue(),modelComp);
	  	  }
		  if (p instanceof ProCSDOutPort)
		  {
			  modelPort=new OutPort(p.getValue(),modelComp);
		  }		  
		  if (p.getMyInterface()!=null)
		  {
			  ProCSDInterface proI=p.getMyInterface();
			  Interface modelI=new InterfaceImpl(proI.getValue(),proI.isMandatory());
			  List<TAttribute> proMsgs=proI.getMyMessages();
			  
			  for(int i=0; i<proMsgs.size(); i++) 
			  {
	               Message m=new MessageImpl(a.getId());
	               modelI.addMessage(m);	            		   
			  }
			  modelPort.setInterface(modelI);
		  }
		  modelComp.addPort(modelPort);
	  }
  
	  //we add the behaviour Panel
	  modelComp.setBehaviour(comp.getMySMD());
	  
	  
    	Vector<ProCSDComponent> subComps=comp.getComponentList();
		for (int k=0;k<subComps.size();k++)
		{
			ProCSDComponent subComp= subComps.get(k);
			Component sc=createModelComp(subComp);
			
			
			modelComp.addSubComponent(sc);
			sc.setFather(modelComp);				
		}
		return modelComp;
    }

    
    
    
    
    private Component initModel(ProactiveCSDPanel mainCsd) throws Exception
    {
    	Component mainAppComp=new ComponentImpl("Application");
    	List<TGComponent> comps = mainCsd.getComponentList();
    	for (int k=0;k<comps.size();k++)
    	{
    		if (t instanceof ProCSDComponent)
    		{
    			ProCSDComponent comp=(ProCSDComponent)t;
    			Component modelComp=createModelComp(comp);
    		    mainAppComp.addSubComponent(modelComp);
    		    modelComp.setFather(mainAppComp);
    		}
    	}
    	
    	mainAppComp=updatePortsBindingInModel(mainAppComp,mainCsd);
    	return mainAppComp;
    }
    
  /*
   * if the father of this port is designed in other diagram, 
   * it returns the port in that diagram corresponding to this port
   * if not it return this port
   */
    private ProCSDPort getRealPort(ProCSDPort p)
    {
    	if (p==null) return null;
    	ProCSDComponent father=(ProCSDComponent)p.getFather();
    	ProCSDComponent fatherDesign=father.getThisCompDesign();
    	if (fatherDesign!=null)
    	{
    		return fatherDesign.getPortByName(p.getValue());
    	}
    	else
    		return p;
     }
    
    
    private void updatePortsBindingInModel(Component modelComp, ProCSDComponent proComp) throws Exception
    {
    	//we consider pairs of  (model Out Port, ProCSDOutPort)
    	Vector<ProCSDPort> ports=proComp.getPortsList();
    	for (int k=0;k<ports.size();k++)
    	{
    		if (p instanceof ProCSDOutPort)
    		{
    			ProCSDOutPort proPort=(ProCSDOutPort)p;
    			Port modelPort=modelComp.getPortByName(proPort.getValue());
    			
    			ProCSDPort proToPort=getRealPort(proPort.getToPort());
    			if (proToPort!=null)
    			{
    				Port modelToPort=null;
    				ProCSDComponent proToPortFather =(ProCSDComponent)proToPort.getFather();
    				Component modelToPortFather=null;
    				if (proToPortFather==proComp.getFather())
    				{
    					 modelToPortFather=modelComp.getFather();
    				}
    				else
    				{
    					String modelToPortFatherName=proPort.getToPort().getFather().getValue();
    				
    					
    					
    					//	if (proToPortFather.getThisCompDesign()!=null)
    				//		modelToPortFatherName+="_"+proToPortFather.getThisCompDesign().getValue();
    					
    					modelToPortFather=modelComp.getFather().getSubComponentByName(modelToPortFatherName); 
    				}
    				modelToPort=modelToPortFather.getPortByName(proToPort.getValue());
				    modelPort.setToPort(modelToPort);
				    modelToPort.setFromPort(modelPort);
    				
    			}//if proToPort!=null

    			ProCSDPort proFromPort=getRealPort(proPort.getFromPort());
    			if (proFromPort!=null)
    			{
    				Port modelFromPort=null;
    				//ProCSDComponent proFromPortFather =(ProCSDComponent)proFromPort.getFather();
    				
    				String modelFromPortFatherName=proPort.getFromPort().getFather().getValue();
					if (proFromPort!=proPort.getFromPort())
					{
						modelFromPortFatherName=proPort.getFromPort().getFather().getValue();
					}
    				
    				//if (proFromPortFather.getThisCompDesign()!=null)
					//	modelFromPortFatherName+="_"+proFromPortFather.getThisCompDesign().getValue();
    				
    				Component modelFromPortFather=modelComp.getSubComponentByName(modelFromPortFatherName);
    				modelFromPort=modelFromPortFather.getPortByName(proFromPort.getValue());
    				modelPort.setFromPort(modelFromPort);
    				modelFromPort.setToPort(modelPort);  
    				
    			}//if proFromPort!=null
    		}//if p is ProCSDOutPort
    		else
    			if (p instanceof ProCSDInPort)  
    		{
    				ProCSDInPort proPort=(ProCSDInPort)p;
        			Port modelPort=modelComp.getPortByName(proPort.getValue());
        			
        			ProCSDPort proFromPort=getRealPort(proPort.getFromPort());
        			if (proFromPort!=null)
        			{
        				if (proFromPort instanceof ProCSDInPort)
        				{
        					Port modelFromPort=null;
        					ProCSDComponent proFromPortFather=(ProCSDComponent)proFromPort.getFather();
        					Component modelFromPortFather=null;
        					if (proFromPortFather==proComp.getFather())
            				{
            					 modelFromPortFather=modelComp.getFather();
            				}
            				else
            				{
            	
            					String modelFromPortFatherName=proPort.getFromPort().getFather().getValue();
            					if (proFromPortFather.getThisCompDesign()!=null)
            						modelFromPortFatherName=proFromPortFather.getThisCompDesign().getValue();
                				modelFromPortFather=modelComp.getFather().getSubComponentByName(modelFromPortFatherName); 
            				}
        					
        				modelFromPort=modelFromPortFather.getPortByName(proFromPort.getValue());
        				modelPort.setFromPort(modelFromPort);
        				modelFromPort.setToPort(modelPort);        				
        			}//if fromport=ProCSDInPort
       			}//if proFromPort!=null
    		}//if p instanceof ProCSDInport
    	}//for all ports
    	
    	if (proComp.getThisCompDesign()!=null)
    		proComp=proComp.getThisCompDesign();
    	Vector<ProCSDComponent> v = proComp.getComponentList();
    	
    	for (int k=0;k<v.size();k++)
    	{
    		ProCSDComponent proSubComp= v.get(k);
    		String proSubCompName=proSubComp.getValue();
    		//if (proSubComp.getThisCompDesign()!=null)
    			//proSubCompName+="_"+proSubComp.getThisCompDesign().getValue();
    		
    		Component modelSubComp=modelComp.getSubComponentByName(proSubCompName);
            updatePortsBindingInModel(modelSubComp,proSubComp);
    	
    	}
    	
    	
    	
    }//method update ports bindings in model
    
    
   private Component updatePortsBindingInModel(Component mainComp, ProactiveCSDPanel mainCsd ) throws Exception
   {
	   //we consider pairs of components (Component c, ProCSDComponent pc) and update potrs bindings in 
	   
	   	List<TGComponent> comps = mainCsd.getComponentList();
   		for (int k=0;k<comps.size();k++)
   		{
   			if (t instanceof ProCSDComponent)
   				{
   					ProCSDComponent proComp=(ProCSDComponent)t;
   					String proCompName=proComp.getValue();
   					//if (proComp.getThisCompDesign()!=null) 
   					// 	proCompName+="_"+proComp.getThisCompDesign().getValue();
   					Component modelComp=mainComp.getSubComponentByName(proCompName);
   					if (modelComp==null) {System.out.println("This is a fatal problem.");
   										  addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR,"Fatal error in the model translator. Please excuse us for this problem. "));	
   										}
   					
   					updatePortsBindingInModel(modelComp,proComp);
   				}
   		}
   		
   		
	   
	   return mainComp;
   }
    
    
    
    
    
    
    
    public TURTLEModeling generateTURTLEModeling() {
        tm = new TURTLEModeling();
        init();
   	 if (checkingErrors.size()==0)
       try{
        mainModelComp=initModel((ProactiveCSDPanel)(pdp.panels.elementAt(0)));
   	 }
   	  catch (Exception e)
   	  {
   		  System.out.println("This is probably just litle nice bug: Could not initializate model. Exception is: \n");
   		  e.printStackTrace();
   	  }
      if (checkingErrors.size()!=0) return null; 
        	addTClasses(tm,mainModelComp);
      if (checkingErrors.size()==0)	addSynchronisations(tm,mainModelComp);
        return tm;
    }
    
    
    
    public boolean checkSyntax() {

        return checkingErrors.size() <= 0;
    }
    
   
    
    
    /*
     * for each port :
     *  update the interface wich contains methods who pass through this port
     *  "push" the connection into the inside ports in order to have 
     *  the connections between the primitives 
     *  
     */
    
    private void updatePortsInformation()
    {
    	
    	for (int k=0;k<connectorsList.size();k++)
    	{
    		TGConnectorProCSD c= connectorsList.get(k);
    		c.doPostLoading();
    	}
    	
    	for (int k=0;k<connectorsPortInterfacesList.size();k++)
    	{
    		TGConnectorPortInterface c= connectorsPortInterfacesList.get(k);
    		c.doPostLoading();
    	}
    	
    	//ok 
    	//we need to update the toPort and fromPort for the ports 
    	//of the components who are designed in a diffrent diagram:
    	
/*    	for (int k=0;k<portsList.size();k++)
    	{
    		ProCSDPort p=(ProCSDPort)portsList.get(k);
    		ProCSDComponent portFather=(ProCSDComponent)p.getFather();
    		ProCSDPort pOkBindings=portFather.getThisCompDesign().getPort(p.getValue());
    	    if(pOkBindings!=null)
    	    {
    	    	p.setToPort(pOkBindings.getToPort());
    	    	p.setFromPort(pOkBindings.getFromPort());
    	    }
    	}
  */  	
    	
    	
    	
    	//all this code is just used for compatibility with old CTTool versions.
    	//normaly we shouldn't do this
    	//at least I think...
    	//needs to be verified
    	//and verry well improved before
    	//all this very-badly-designed-software will be well packed
    	//and nicelly put into a trash bin 
    	
    	
    	//Added by Solange
    	int isCompatible;  //0: OK
    					   //1: Port error
    					   //2: compatibility error
    	ProCSDInterface myInterface=null;
    	TGConnectorAttribute myInterfaceConnector;
    	
 	
    	//first we consider all out ports	
    	 for (int i=0;i<portsList.size();i++)
    	 {
    		 ProCSDPort op= portsList.get(i);
    		 if (op.getType()==TGComponentManager.PROCSD_OUT_PORT)
    		 {  
    			
    			 try {
    				 myInterface=op.getMyInterface(interfacesList);
    				 //Added by Solange
    				 op.setMyInterface(myInterface);
    				 // Added by Solange
    				 myInterfaceConnector=op.getTGConnectorInterface();
    				 // Added by Solange
    				 myInterface.setMyConnector(myInterfaceConnector);
        			 }
    			 catch (Exception e)
    			 {
    						 
    				 if (op.getFather()==null)
    				 {
    					 this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR,"Port "+op.getValue()+" doesn't belong to a component"));
    					 return;
    				 }
    				 if (((ProCSDComponent)op.getFather()).getThisCompDesign()==null) 
    				 {this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR,"No interface found corresponding to port "+op.getValue()));
    				 return;
    				 }
    			 
    			 }
    			 
    			 ProCSDPort toP=op.getToPort();
    			// if (toP==null) toP=getConnectedProCSDPort(op);
    			 //if(toP==null) toP=getDelegateConnectorProCSDPort(op);
    			 //Commented because is not always an error to be free, by Solange
    			 /* if (toP==null)
    			 {
    				addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: out connection not found for "+op.toString()+" in component "+op.getFather().getValue());
    				//System.out.println("Error: no connection found for "+op.toString());
    				  return; 
    			 }*/
    			  
    			 if (toP!=null)
    			 {
    			  op.setToPort(toP);	 
    			  toP.setFromPort(op);
    			 }
    			 
    			 //Added by Solange
    			 if (myInterface!=null)
    			 { 
    			 isCompatible=op.Compatibility(op,myInterface,interfacesList);
				 //Added by Solange
				 switch(isCompatible)
				 {
					 case 0:// System.out.println("Compatibility test Out port... OK");
					 		 break;
					 case 1: this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR,"Port "+ op.toString() + " not connected"));
					 		 break;
					 case 2: this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR,"No Interface Compatibility"));
					 		 break;
				 }
    			 } 
                /* Delegate ports removed, by Solange
    			 ProCSDPort dp = getConnectedDelegatePort(op);
    			 if (dp!=null)
    			 {   dp.setMyInterface(myInterface);
    				 dp.setToPort(toP);
    				 toP.setFromPort(dp);
    				 
    				 ProCSDPort ddp=getFromInsideConnectedPort(dp);
    				 while (ddp!=null)
    				 {   ddp.setMyInterface(myInterface);
    					 ddp.setToPort(toP);
    					 toP.setFromPort(ddp);
    					 ddp=getFromInsideConnectedPort(ddp);
    				 }//while ddp!=null
    			 }//if dp!=null
    			*/
    		 }//if this port is an out port
    	 }//for all ports (out)
    
         //now we consider all in ports
    	 for (int i=0;i<portsList.size();i++)
    	 {
    		 ProCSDPort ip= portsList.get(i);
    		 if (ip.getType()==TGComponentManager.PROCSD_IN_PORT)
    		 {    myInterface=ip.getMyInterface(interfacesList);	
    		  if (myInterface!=null)
    		  {
    		  //Added by Solange
    		      ip.setMyInterface(myInterface);
    		      // Added by Solange
 				 myInterfaceConnector=ip.getTGConnectorInterface();
 				 // Added by Solange
 				 myInterface.setMyConnector(myInterfaceConnector);
    		      //
    		  }
 				 ProCSDPort fromPort=ip.getFromPort();
                  //Added by Solange 
			  //    if(fromPort==null) fromPort=getDelegateConnectorProCSDPort(ip);
			      
			      if (fromPort!=null)
	    			 {
	    			  ip.setFromPort(fromPort);	 
	    			  fromPort.setToPort(ip);
	    			 }
		    		 
                //Commented because is not always an error to be free, by Solange
                /*if (fromPort==null)
                {
                	addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: in connection not found for "+ip.toString()+" in component "+ip.getFather().getValue());
                	return;
                }*/
                //Added by Solange
                isCompatible=ip.Compatibility(ip, myInterface, interfacesList);
				//Added by Solange
                switch(isCompatible)
				 {
					 case 0: //System.out.println("Compatibility test In port... OK");
					 		 break;
					 case 1: this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR,"Port "+ ip.toString() + " not connected"));
					 		 break;
					 case 2: this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR,"No Interface Compatibility"));
					 		 break;
				 }
                                
                /* Delegate ports removed, by Solange
    			ProCSDPort dp=getConnectedDelegatePort(ip);
    			if (dp!=null)
    			{   dp.setMyInterface(myInterface);
    				dp.setFromPort(fromPort);
    				fromPort.setToPort(dp);
                    ProCSDPort ddp=getToInsideConnectedPort(dp);
                    while (ddp!=null)
                    {   ddp.setMyInterface(myInterface);
                    	ddp.setFromPort(fromPort);
                    	fromPort.setToPort(ddp);
                    	ddp=getToInsideConnectedPort(ddp);
                    }//while ddp!=null
    			
    			}//dp!=null
    			*/
    		 }// ip is an input port
    	 } // for all ports in		 		 
    }
    
    private boolean isPrimitive(ProCSDComponent comp)
    {
    	List<TGComponent> l=getSubComponents(comp,TGComponentManager.PROCSD_COMPONENT);
    	if (l==null) return true;
    }
    
    
    /*
     * get subcomponents of type given as parameter
     * @param type The type id from TGComponentManager
     * @param tgc A component
     * @return selectedSubComps A LinkedList of subcomponents of the type
     */
    private List<TGComponent> getSubComponents(TGComponent tgc, int type)
    {
    	if (!(tgc.getType()==TGComponentManager.PROCSD_COMPONENT)) return null;
    	List<TGComponent> subcompList=getSubComponents(tgc);
    	List<TGComponent> selectedSubComps=new LinkedList<TGComponent>();
        for (int i=0;i<subcompList.size();i++)
        {
        	if (tmp.getType()==type)
        		selectedSubComps.add(tmp);
        	
        }
    	return selectedSubComps;
    	    	
    }
    
    
    
    /*
     * get subcomponents of all types
     * @param tgc A component
     * @return subcompList A LinkedList of subcomponents
     */
    private List<TGComponent> getSubComponents(TGComponent tgc)
    	List<TGComponent> subcompList=new LinkedList<TGComponent>();
    	int nb=tgc.getNbInternalTGComponent();
    	for (int j=0;j<nb;j++)
		{
			TGComponent tmp=tgc.getInternalTGComponent(j);
			subcompList.add(tmp);

		}
    	return subcompList;
    }
    
    /*
     * returns all ports of this component
     * @param tgc A component
     * @return portsList A LinkedList with ports of the component
     */
//    private List<ProCSDPort> getPorts(TGComponent tgc)
//    {
//    	if (!(tgc.getType()==TGComponentManager.PROCSD_COMPONENT)) return null;
//    	List<TGComponent> subcompList=getSubComponents(tgc);
//    	List<ProCSDPort> portsList=new LinkedList<ProCSDPort>();
//        for (int i=0;i<subcompList.size();i++)
//        {
//        	TGComponent tmp=subcompList.get(i);
//            //Remove option delegate ports, by Solange
//        	if ((tmp.getType()==TGComponentManager.PROCSD_IN_PORT) || (tmp.getType()==TGComponentManager.PROCSD_OUT_PORT))// || ( tmp.getType()==TGComponentManager.PROCSD_DELEGATE_PORT))
//        		portsList.add( (ProCSDPort) tmp);
//        }
//    	return portsList;
//    }
    
    /*
	 * gets the port connected to the port in parameter via a TGConnector ProCSD if there is one, null if not
	 * @param port A port
	 * @return p1 (or p2) The connected port, or null if not connected 
	 */
//    private ProCSDPort getConnectedProCSDPort(ProCSDPort port)
//    {
//         //Remove option delegate ports, by Solange
//    	//if (port.getType()==TGComponentManager.PROCSD_DELEGATE_PORT) return null;
//    	
//    	 //System.out.println("cherche un port pour le port " +port.getValue()); comented by Emil 
//    	
//    		TGConnectorProCSD myConnector=port.getTGConnector();
//    		
//    		if (myConnector==null)
//    		{
//                //Commented because is not always an error to be free, by Solange 
//    			//addCheckingError(CheckingError.STRUCTURE_ERROR,"We didn't find any connector for the port " +port.getValue());
//    			return null;
//    		}
//    		
//   // 		System.out.println("...... (ProCSDPort).. my connector is "+myConnector.toString());
//    	
//    		//ProCSDPort p1=myConnector.getMyPort1(portsList);
//    		ProCSDPort p1=myConnector.getMyPort1();
//            
//   /* 		if (p1!=null) System.out.println(p1.toString());
//    		else 
//    			System.out.println("NULL!!!!!!!!!");
//    */
//    		
//    		//System.out.println("......... my connector's Port1 is "+p1.toString());
//    		
//    				if ((p1!=null) && (!p1.equals(port))) return p1;
//    		 
//    		 ProCSDPort p2=myConnector.getMyPort2();
//    			
//    		 if ((p2!=null) && (!p2.equals(port))) return p2;
//    			
//    		return null;	
//    }
    
    //Added by Solange for the subcomponents
    /*
     * Method to find the port connected to a port when there are subcomponents involved
     * @param port The port to be analyzed
     * @return p1 (or p2) The port connected or null if not connected
     */
    /*
    public ProCSDPort getDelegateConnectorProCSDPort(ProCSDPort port)
    {
    	TGConnectorDelegateProCSD myDelegateConnector=port.getTGConnectorDelegateIn();
		if (myDelegateConnector==null)
			myDelegateConnector=port.getTGConnectorDelegateOut();
		
		if (myDelegateConnector==null)
		{
		//	System.out.println("We didn't find any delegate connector for the port " +port.getValue());
			return null;
		}

		ProCSDPort p1=myDelegateConnector.getMyPort1(portsList);
		 if ((p1!=null) && (!p1.equals(port))) return p1;
		 ProCSDPort p2=myDelegateConnector.getMyPort2(portsList);
		 if ((p2!=null) && (!p2.equals(port))) return p2;
		return null;	
    }
    */
    /*
	 * gets the delegate port connected to the port in parameter via a TGConnectorDelegateProCSD if there is one, null if not
	 * returns null for delegate ports
	 * 
	 */
    
    //Delegate ports removes. Method is no t needed. By Solange
    /*
    private ProCSDPort getConnectedDelegatePort(ProCSDPort port)
    {
    	if (port.getType()==TGComponentManager.PROCSD_DELEGATE_PORT) return null;
    	 //System.out.println("cherche un port pour le port " +port.getValue()); 
    	
    		TGConnectorDelegateProCSD myDelegateConnector=port.getTGConnectorDelegateIn();
    		if (myDelegateConnector==null)
    			myDelegateConnector=port.getTGConnectorDelegateOut();
    		
    		if (myDelegateConnector==null)
    		{
    			 //System.out.println("We didn't find any connector for the port " +port.getValue());
    			return null;
    		}
    		
   // 		System.out.println("...... (ProCSDPort).. my connector is "+myConnector.toString());
    
    		ProCSDPort p1=myDelegateConnector.getMyPort1(portsList);

    		//if (p1!=null) System.out.println(p1.toString());
    		//else 
    		//	System.out.println("NULL!!!!!!!!!");
    
    		
    		//System.out.println("......... my connector's Port1 is "+p1.toString());
    		
    				if ((p1!=null) && (!p1.equals(port))) return p1;
    		 
    		 ProCSDPort p2=myDelegateConnector.getMyPort2(portsList);
    			
    		 if ((p2!=null) && (!p2.equals(port))) return p2;
    			
    		return null;	
    	
    	
    	
    }
    */
    
  /* private ProCSDPort getToOutsideConnectedPort(ProCSDPort dp)
    {
    	TGComponent father=dp.getFather().getFather();
    	if (father==null)
    	{
    		addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: forbiden delegate port at this level "+dp.getValue());
    		return null;
    	}
    	
    	LinkedList fatherPorts=getPorts(father);
    	
    	
    	TGConnectorDelegateProCSD myDelegateConnectorOut=dp.getTGConnectorDelegateOut();
    	if (myDelegateConnectorOut==null) return null;
    	ProCSDPort p2=myDelegateConnectorOut.getMyPort2(fatherPorts);
			
		 if ((p2!=null) && (!p2.equals(dp))) return p2;
    	
    	return null;
    }
    */
    
/*   
    private ProCSDPort getFromOutsideConnectedPort(ProCSDPort dp)
    {
    	TGComponent father=dp.getFather().getFather();
    	if (father==null)
    	{
    		addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: forbiden delegate port at this level "+dp.getValue());
    		return null;
    	}
    
    	LinkedList fatherPorts=getPorts(father);
    	TGConnectorDelegateProCSD myDelegateConnectorIn=dp.getTGConnectorDelegateIn();
    	if (myDelegateConnectorIn==null) return null;
    	ProCSDPort p2=myDelegateConnectorIn.getMyPort1(fatherPorts);
			
		 if ((p2!=null) && (!p2.equals(dp))) return p2;
    	
    	return null;
    }
    
  */  

//    private ProCSDPort getToInsideConnectedPort(ProCSDPort dp)
//    {
//    	//we're looking for a port who's not a father port
//    	TGComponent father=dp.getFather().getFather();
//    	if (father==null)
//    	{
//    		addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: forbiden delegate port at this level "+dp.getValue());
//    		return null;
//    	}
//    	LinkedList fatherPorts=getPorts(father);
//    	
//    	TGConnectorDelegateProCSD myDelegateConnectorOut=dp.getTGConnectorDelegateOut();
//    	if (myDelegateConnectorOut==null) return null;
//    	ProCSDPort p2=myDelegateConnectorOut.getMyPort2(portsList);
//			
//		 if ((p2!=null) && (!p2.equals(dp)) && !fatherPorts.contains(p2)) return p2;
//    	
//    	return null;
//    	
//   	
//    
//    }
    
//    private ProCSDPort getFromInsideConnectedPort(ProCSDPort dp)
//    {
//    	
////    	we're looking for a port who's not a father's port
//    	TGComponent father=dp.getFather().getFather();
//    	if (father==null)
//    	{
//    		addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: forbiden delegate port at this level "+dp.getValue());
//    	
//    		return null;
//    	}
//    	LinkedList fatherPorts=getPorts(father);
//    	
//    	TGConnectorDelegateProCSD myDelegateConnectorIn=dp.getTGConnectorDelegateIn();
//    	if (myDelegateConnectorIn==null) return null;
//    	ProCSDPort p1=myDelegateConnectorIn.getMyPort1(portsList);
//			
//		 if ((p1!=null) && (!p1.equals(dp)) && !fatherPorts.contains(p1)) return p1;
//    	
//    	return null;
//    	
//    }
    
   
   /*
    * we are dealing with a comp specification within a 
    * ProActiveCompSpecificationCSDPanel
    * 
    */
   private boolean parseStructureAndFillUpListsForCompDefinition(TGComponent t)
   {  
   	
   	if (t.getType()==TGComponentManager.PROCSD_INTERFACE) 
   		{
   		  interfacesList.add( (ProCSDInterface) t);
   		}
   
   	if (t.getType()==TGComponentManager.CONNECTOR_PROCSD) 
   	  {
   		connectorsList.add( (TGConnectorProCSD) t);
   	  }
   	
   	if (t.getType()==TGComponentManager.CONNECTOR_PROCSD_PORT_INTERFACE) 
 	  {
 		connectorsPortInterfacesList.add( (TGConnectorPortInterface) t);
 	  }
 	 	
   /*	
   	//Delegate ports removed, by Solange
   	if ( (t.getType()==TGComponentManager.PROCSD_IN_PORT) || (t.getType()==TGComponentManager.PROCSD_OUT_PORT))// || (t.getType()==TGComponentManager.PROCSD_DELEGATE_PORT))
     		 portsList.add(t);      	    	
 
   */
   	
   	if ((t.getType()==TGComponentManager.PROCSD_COMPONENT) )
//   	if (ProCSDComponentsList.contains(t))
//   		return false;
//   		else
   	{
   		proCSDComponentsList.add( (ProCSDComponent) t);
	
	
   		int nb=t.getNbInternalTGComponent();
   	
   		for (int j=0;j<nb;j++)
   		{
   				TGComponent tgc=t.getInternalTGComponent(j);
   				if (!parseStructureAndFillUpListsForCompDefinition(tgc)) return false;  				
   	    }
   	
   	
   		if (((ProCSDComponent)t).getMyDesignPanel()!=null)
		{
			ProActiveCompSpecificationCSDPanel specPanel=((ProCSDComponent)t).getMyDesignPanel();
			
			
		    for (int q=0;q<specPanel.componentList.size();q++)
		    {
		    	TGComponent component= specPanel.componentList.get(q);
		    	if (!parseStructureAndFillUpListsForCompDefinition(component)) return false;
		    }
		    }
	}
   	
   	return true;
   	
   	}
  
   
    
   /*
    * Add a component to the corresponding list according to his type (interface, connector, port, component)
    * @param t The component
    */ 
    private boolean parseStructureAndFillUpLists(TGComponent t)
    {  
    	
    	if (t.getType()==TGComponentManager.PROCSD_INTERFACE) 
    		{
    		  interfacesList.add((ProCSDInterface) t);
    		}
    
    	if (t.getType()==TGComponentManager.CONNECTOR_PROCSD) 
    	  {
    		connectorsList.add( (TGConnectorProCSD) t);
    	  }
    	
    	if (t.getType()==TGComponentManager.CONNECTOR_PROCSD_PORT_INTERFACE) 
  	  {
  		connectorsPortInterfacesList.add( (TGConnectorPortInterface) t );
  	  }
  	 	
    	
    	//Delegate ports removed, by Solange
    	if ( (t.getType()==TGComponentManager.PROCSD_IN_PORT) || (t.getType()==TGComponentManager.PROCSD_OUT_PORT))// || (t.getType()==TGComponentManager.PROCSD_DELEGATE_PORT))
  
    
    	if ((t.getType()==TGComponentManager.PROCSD_COMPONENT) )
    	{
//    		if (ProCSDComponentsList.contains(t))