use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class UtilMockTest method testFindOutAllSonElements.
@Test
public void testFindOutAllSonElements() {
XSDFactory factory = XSDFactory.eINSTANCE;
Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] targetNameSpaces = { "http://www.w3.org/2001/XMLSchema", "", "" };
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] names = { "p1", "p2", "p3" };
XSDTypeDefinition[] types = { factory.createXSDSimpleTypeDefinition(), factory.createXSDSimpleTypeDefinition(), factory.createXSDSimpleTypeDefinition() };
XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
xsdElementDeclaration.setName(names[0]);
xsdElementDeclaration.setTargetNamespace(targetNameSpaces[0]);
XSDComplexTypeDefinition xsdComplexTypeDef = factory.createXSDComplexTypeDefinition();
xsdElementDeclaration.setAnonymousTypeDefinition(xsdComplexTypeDef);
XSDParticle typeParticle = factory.createXSDParticle();
xsdComplexTypeDef.setContent(typeParticle);
XSDModelGroup xsdModelGroup = factory.createXSDModelGroup();
for (int i = 0; i < names.length; i++) {
XSDElementDeclaration xsdEleDec = factory.createXSDElementDeclaration();
xsdEleDec.setName(names[i]);
xsdEleDec.setTargetNamespace(targetNameSpaces[i]);
if (i == 0) {
xsdEleDec.setTypeDefinition(xsdComplexTypeDef);
} else {
xsdEleDec.setTypeDefinition(types[i]);
}
XSDParticle xsdParticle = factory.createXSDParticle();
xsdParticle.setContent(xsdEleDec);
xsdModelGroup.getContents().add(xsdParticle);
}
typeParticle.setContent(xsdModelGroup);
PowerMockito.mockStatic(Util.class);
try {
// $NON-NLS-1$
String methodToExecute = "findOutAllSonElements";
PowerMockito.when(Util.class, methodToExecute, any(XSDElementDeclaration.class), anySet()).thenCallRealMethod();
List<XSDElementDeclaration> allson = Whitebox.invokeMethod(Util.class, methodToExecute, xsdElementDeclaration, complexTypes);
assertNotNull(allson);
assertTrue(allson.size() == 2);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDParticle in project webtools.sourceediting by eclipse.
the class MoveXSDElementAction method run.
/*
* @see IAction#run()
*/
public void run() {
int originalIndex = 0;
for (Iterator particles = parentModelGroup.getContents().iterator(); particles.hasNext(); ) {
XSDParticle particle = (XSDParticle) particles.next();
XSDParticleContent particleContent = particle.getContent();
if (particleContent == selected) {
parentModelGroup.getContents().remove(particle);
break;
}
originalIndex++;
}
int index = 0;
boolean addedBack = false;
if (insertType == INSERT_DIRECT) {
XSDConcreteComponent container = selected.getContainer();
if (container != null) {
XSDConcreteComponent container2 = container.getContainer();
if (container2 instanceof XSDModelGroup) {
((XSDModelGroup) container2).getContents().remove(container);
}
if (insertAtEnd)
parentModelGroup.getContents().add(container);
else
parentModelGroup.getContents().add(0, container);
addedBack = true;
}
return;
}
List particles = parentModelGroup.getContents();
for (Iterator iterator = particles.iterator(); iterator.hasNext(); ) {
XSDParticle particle = (XSDParticle) iterator.next();
XSDParticleContent particleContent = particle.getContent();
if (insertType == INSERT_BEFORE) {
if (particleContent == nextRefComponent) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
if (selected == nextRefComponent && originalIndex == index) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
} else if (insertType == INSERT_AFTER) {
if (particleContent == previousRefComponent) {
parentModelGroup.getContents().add(index + 1, selected.getContainer());
addedBack = true;
break;
}
if (selected == previousRefComponent && originalIndex == index) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
}
index++;
}
if (particles.size() == 0) {
parentModelGroup.getContents().add(selected.getContainer());
addedBack = true;
}
if (!addedBack) {
parentModelGroup.getContents().add(originalIndex, selected.getContainer());
}
}
use of org.eclipse.xsd.XSDParticle in project webtools.sourceediting by eclipse.
the class AddXSDAnyElementCommand method execute.
public void execute() {
try {
if (doCreateModelGroupForComplexType) {
Assert.isNotNull(complexType);
beginRecording(complexType.getElement());
createModelGroup();
} else {
beginRecording(parent.getElement());
}
XSDWildcard wildCard = XSDFactory.eINSTANCE.createXSDWildcard();
XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
particle.setContent(wildCard);
parent.getContents().add(particle);
addedXSDConcreteComponent = wildCard;
formatChild(parent.getElement());
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDParticle in project webtools.sourceediting by eclipse.
the class AddXSDElementCommand method createXSDElementReference.
protected XSDParticle createXSDElementReference() {
List list = xsdModelGroup.getSchema().getElementDeclarations();
XSDElementDeclaration referencedElement = null;
if (list.size() > 0) {
referencedElement = (XSDElementDeclaration) list.get(0);
} else {
referencedElement = createGlobalXSDElementDeclaration();
// $NON-NLS-1$
Text textNode = xsdSchema.getDocument().createTextNode("\n");
xsdSchema.getElement().appendChild(textNode);
xsdSchema.getContents().add(referencedElement);
}
XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
element.setResolvedElementDeclaration(referencedElement);
XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
particle.setContent(element);
addedXSDConcreteComponent = element;
return particle;
}
use of org.eclipse.xsd.XSDParticle in project webtools.sourceediting by eclipse.
the class AddXSDElementCommand method createXSDElementDeclaration.
protected XSDParticle createXSDElementDeclaration() {
// $NON-NLS-1$
XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
XSDConcreteComponent comp = xsdModelGroup.getContainer();
ArrayList usedAttributeNames = new ArrayList();
XSDCommonUIUtils.resetVisitedGroupsStack();
usedAttributeNames.addAll(XSDCommonUIUtils.getChildElements(xsdModelGroup));
while (comp != null) {
if (comp instanceof XSDModelGroupDefinition) {
usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDModelGroupDefinition) comp));
break;
} else if (comp instanceof XSDComplexTypeDefinition) {
usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDComplexTypeDefinition) comp));
usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes((XSDComplexTypeDefinition) comp));
break;
}
comp = comp.getContainer();
}
element.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewElement" : nameToAdd, // $NON-NLS-1$
usedAttributeNames));
element.setTypeDefinition(type);
XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
particle.setContent(element);
addedXSDConcreteComponent = element;
return particle;
}
Aggregations