Community
Participate
Working Groups
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()); } }
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);
Move to verified as per bug 206558.