Bug 29802 - XSDModelGroup.getParticles() list is not updated after a particle removal
Summary: XSDModelGroup.getParticles() list is not updated after a particle removal
Status: VERIFIED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: XSD (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ed Merks CLA
QA Contact:
URL:
Whiteboard:
Keywords: core
Depends on:
Blocks:
 
Reported: 2003-01-20 11:09 EST by Achille Fokoue CLA
Modified: 2023-01-12 11:53 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Achille Fokoue CLA 2003-01-20 11:09:21 EST
When a particle is removed from a model group, g, using g.getContents().remove
(), the change is not propagated to g.getParticles() - the removed particle is 
still in the list returned by g.getParticles().

CODE illustrating the problem :

import java.util.Map;

import org.eclipse.xsd.XSDCompositor;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDFactory;
import org.eclipse.xsd.XSDForm;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDModelGroupDefinition;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.util.XSDConstants;

/**
 *
 *
 * When a particle is removed from a model group, g, using g.getContents
().remove(), the change
 * is not propagated to g.getParticles() - the removed particle is still in the 
list returned by
 * g.getParticles()..
 */
public class RemovalOfParticleSynchronizationBug {

	public static void main(String[] args) {
		XSDFactory xsdFac=XSDFactory.eINSTANCE;
		XSDSchema schema=xsdFac.createXSDSchema();
		
	    // associate "xsd" prefix to the schema namespace
  		schema.setSchemaForSchemaQNamePrefix("xsd");
		Map qNamePrefixToNamespaceMap = 
schema.getQNamePrefixToNamespaceMap();
  		qNamePrefixToNamespaceMap.put
(schema.getSchemaForSchemaQNamePrefix(), 
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
 		//
  		
  		//set target namespace
  		schema.setTargetNamespace("http://www.testcases.org");
  		qNamePrefixToNamespaceMap.put("tns", schema.getTargetNamespace
());
  		//
  		
  		XSDModelGroupDefinition 
groupDef=xsdFac.createXSDModelGroupDefinition();
  		// 1. add the group to the schema
  		schema.getContents().add(groupDef);
  		// 2. set the name of the group
  		groupDef.setName("group1");
  		
				
        // 3. add a sequence in groupDef
        XSDModelGroup group = xsdFac.createXSDModelGroup();
        group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
        groupDef.setModelGroup(group);
        
        // 4. create a local element declaration e and set its name
        XSDElementDeclaration e=xsdFac.createXSDElementDeclaration();
        e.setName("e");
        e.setForm(XSDForm.QUALIFIED_LITERAL);
	 
	 	

		// 5. create a particle containing e and
		// add it to the model group of the model group definition
		XSDParticle part=xsdFac.createXSDParticle();
		//part.setMaxOccurs(1);
		//part.setMinOccurs(1);
		part.setContent(e);
		group.getContents().add(part);
		
		
		// 6 create another local element declaration f and set its name
        XSDElementDeclaration f=xsdFac.createXSDElementDeclaration();
        f.setName("f");
        
        // 7. create a particle containing f and
		// add it to the model group of the model group definition
		XSDParticle partForf=xsdFac.createXSDParticle();
		partForf.setContent(f);
		group.getContents().add(partForf);
		
		// Display the number of particle
		System.out.println("Number of particles before removal 
(abstract level: getParticles()): "+group.getParticles().size());
		System.out.println("Number of components before removal 
(concrete level: getContents()): "+group.getContents().size());
		
		
		
		// 8. IMPORTANT : we remove part from group
		group.getContents().remove(part);
		
		// Display the number of particle
		System.out.println("Number of particles after removal (abstract 
level: getParticles()): "+group.getParticles().size());
		System.out.println("Number of components after removal 
(concrete level: getContents()): "+group.getContents().size());
		
		
       
	}
}
Comment 1 Ed Merks CLA 2003-01-24 11:58:24 EST
Achille,

Thanks for providing complete code samples for the problems! 
This really helps me fix problems very quickly.

I fixed it like this:

> etools-diff XSDModelGroupImpl.java
15,16c15,16
<  * plugins/org.eclipse.xsd/src/org/eclipse/xsd/impl/XSDModelGroupImpl.java, 
xsd, org.eclipse.dev, 20030123_0838TL
<  * @version 1.18 1/23/03
---
>  * %W%
>  * @version %I% %H%
466c466
<     Collection remainingParticles = new ArrayList();
---
>     Collection remainingParticles = new ArrayList(getParticles());
473a474,477
>       }
>       else
>       {
>         remainingParticles.remove(xsdParticle);
Comment 2 Nick Boldt CLA 2008-01-28 16:33:27 EST
Move to verified as per bug 206558.
Comment 3 Nick Boldt CLA 2008-01-28 16:41:17 EST
Move to verified as per bug 206558.