Skip to content
Snippets Groups Projects
GProactiveDesign.java 74.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.
 */





package ui;

import fr.inria.oasis.vercors.cttool.model.*;
import translator.*;
import ui.procsd.*;
import ui.prosmd.*;
import ui.prosmd.util.CorrespondanceSMDManager;

import java.util.*;

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
 * 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++)
		{
			TAttribute a= attribs.get(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++) 
			  {
	               TAttribute a = proMsgs.get(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++)
    	{
    		TGComponent t= comps.get(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++)
    	{
    		ProCSDPort p= ports.get(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++)
   		{
   			TGComponent t= comps.get(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;
        return l.size() == 0;
    }
    
    
    /*
     * 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++)
        {
        	TGComponent tmp=subcompList.get(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))
      		 portsList.add( (ProCSDPort) t);      	    	
  
    
    	if ((t.getType()==TGComponentManager.PROCSD_COMPONENT) )
    	{
//    		if (ProCSDComponentsList.contains(t))