use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class UtilMockTest method testUpdateReference.
@Test
public void testUpdateReference() {
// $NON-NLS-1$ //$NON-NLS-2$
String oldValue = "oldValue", newValue = "newValue";
// $NON-NLS-1$
String methodToExecute = "updateReference";
// $NON-NLS-1$
String method_private = "updatePrimaryKeyInfo";
XSDFactory factory = XSDFactory.eINSTANCE;
PowerMockito.mockStatic(Util.class);
try {
PowerMockito.when(Util.class, methodToExecute, any(), any(Object[].class), any(Object[].class), anyString(), anyString()).thenCallRealMethod();
Object[] objs = new Object[4];
Object[] allForeignKeyAndInfos = new Object[0];
Util.updateReference(new Object(), objs, allForeignKeyAndInfos, oldValue, newValue);
PowerMockito.verifyStatic(times(0));
Util.updateForeignKeyRelatedInfo(oldValue, newValue, allForeignKeyAndInfos);
Whitebox.invokeMethod(Util.class, method_private, any(XSDElementDeclaration.class), eq(oldValue), eq(newValue));
//
XSDModelGroup xsdModelGroup = factory.createXSDModelGroup();
XSDElementDeclaration xsdEleDecl = mock(XSDElementDeclaration.class);
XSDParticle particle1 = mock(XSDParticle.class);
when(particle1.getTerm()).thenReturn(xsdEleDecl);
XSDElementDeclaration mockDeclaration1 = mock(XSDElementDeclaration.class);
when(mockDeclaration1.isElementDeclarationReference()).thenReturn(true);
when(mockDeclaration1.getResolvedElementDeclaration()).thenReturn(xsdEleDecl);
when(particle1.getContent()).thenReturn(mockDeclaration1);
XSDParticle particle2 = mock(XSDParticle.class);
when(particle2.getTerm()).thenReturn(xsdEleDecl);
when(particle2.getContent()).thenReturn(xsdModelGroup);
XSDParticle particle3 = mock(XSDParticle.class);
when(particle3.getTerm()).thenReturn(xsdModelGroup);
XSDElementDeclaration mockDeclaration3 = mock(XSDElementDeclaration.class);
when(mockDeclaration3.isElementDeclarationReference()).thenReturn(true);
when(mockDeclaration3.getResolvedElementDeclaration()).thenReturn(xsdEleDecl);
when(particle3.getContent()).thenReturn(mockDeclaration3);
XSDParticle particle4 = mock(XSDParticle.class);
when(particle4.getTerm()).thenReturn(xsdModelGroup);
when(particle4.getContent()).thenReturn(xsdModelGroup);
objs[0] = particle1;
objs[1] = particle2;
objs[2] = particle3;
objs[3] = particle4;
Util.updateReference(xsdEleDecl, objs, allForeignKeyAndInfos, oldValue, newValue);
PowerMockito.verifyStatic();
Util.updateForeignKeyRelatedInfo(oldValue, newValue, allForeignKeyAndInfos);
Whitebox.invokeMethod(Util.class, method_private, any(XSDElementDeclaration.class), eq(oldValue), eq(newValue));
verify(particle1).setTerm(xsdEleDecl);
verify(particle1).updateElement();
verify(mockDeclaration1).setResolvedElementDeclaration(xsdEleDecl);
verify(particle2).setTerm(xsdEleDecl);
verify(particle2).updateElement();
verify(mockDeclaration3).setResolvedElementDeclaration(xsdEleDecl);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class AddBrowseItemsWizardR method getFieldsForViewElements.
public static List<String> getFieldsForViewElements(XSDElementDeclaration decl, List<String> idList) {
List<String> fields = new ArrayList<String>();
if (decl == null || idList.size() >= 5) {
return fields;
}
if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
String labelValue = null;
List childrenList = Util.getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) decl.getTypeDefinition(), true);
if (childrenList == null) {
return fields;
}
for (int j = 0; j < childrenList.size(); j++) {
List<XSDParticle> particles = new ArrayList<XSDParticle>();
if (childrenList.get(j) instanceof XSDModelGroup) {
particles = ((XSDModelGroup) childrenList.get(j)).getParticles();
}
if (particles != null) {
for (int k = 0; k < particles.size(); k++) {
// Only the top 5 attributes will be searchable and viewable when generating the default view
XSDParticle xSDCom = particles.get(k);
if ((xSDCom != null && xSDCom.getContent() != null) && xSDCom.getContent() instanceof XSDElementDeclaration) {
labelValue = getFieldName(xSDCom);
String field = decl.getName();
// $NON-NLS-1$//$NON-NLS-2$
field = field.replaceFirst("#.*", "");
// $NON-NLS-1$
field += "/" + labelValue;
if (!idList.contains(field)) {
fields.add(field);
}
}
if (idList.size() + fields.size() == 5) {
break;
}
}
}
}
}
return fields;
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class XSDVisitor method visitModelGroupDefinition.
public void visitModelGroupDefinition(XSDModelGroupDefinition modelGroupDef) {
if (!modelGroupDef.isModelGroupDefinitionReference()) {
if (modelGroupDef.getModelGroup() != null) {
if ((visitedGroups.contains(modelGroupDef.getResolvedModelGroupDefinition().getModelGroup()))) {
circularDefinitionFound = true;
return;
}
visitedGroups.push(modelGroupDef.getModelGroup());
visitModelGroup(modelGroupDef.getModelGroup());
visitedGroups.pop();
}
} else {
XSDModelGroupDefinition resolvedGroupDef = modelGroupDef.getResolvedModelGroupDefinition();
XSDModelGroup modelGroup = resolvedGroupDef.getModelGroup();
if ((visitedGroups.contains(modelGroup))) {
circularDefinitionFound = true;
return;
}
visitedGroups.push(modelGroup);
if (modelGroup != null) {
visitModelGroup(modelGroup);
}
visitedGroups.pop();
}
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class XSDVisitor method visitParticleContent.
public void visitParticleContent(XSDParticleContent particleContent) {
if (particleContent instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition modelGroupDef = (XSDModelGroupDefinition) particleContent;
if (particleStack.contains(modelGroupDef)) {
return;
}
particleStack.push(modelGroupDef);
visitModelGroupDefinition(modelGroupDef);
particleStack.pop();
} else if (particleContent instanceof XSDModelGroup) {
visitModelGroup((XSDModelGroup) particleContent);
} else if (particleContent instanceof XSDElementDeclaration) {
visitElementDeclaration((XSDElementDeclaration) particleContent);
} else if (particleContent instanceof XSDWildcard) {
visitWildcard((XSDWildcard) particleContent);
}
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class XSDComplexTypeDefinitionAdapter method getChildren.
public ITreeElement[] getChildren() {
XSDComplexTypeDefinition xsdComplexTypeDefinition = getXSDComplexTypeDefinition();
List list = new ArrayList();
// Add attributes
for (Iterator i = xsdComplexTypeDefinition.getAttributeContents().iterator(); i.hasNext(); ) {
Object obj = i.next();
if (obj instanceof XSDAttributeUse) {
list.add(((XSDAttributeUse) obj).getAttributeDeclaration());
} else if (obj instanceof XSDAttributeGroupDefinition) {
getAttributeUses((XSDAttributeGroupDefinition) obj, list);
}
}
// Add enumerations
boolean canHaveEnumerations = xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition && XSDDerivationMethod.RESTRICTION_LITERAL.equals(xsdComplexTypeDefinition.getDerivationMethod());
if (canHaveEnumerations) {
Object contentType = getContentType();
if (contentType != null) {
for (Iterator iterator = ((XSDSimpleTypeDefinition) contentType).getEnumerationFacets().iterator(); iterator.hasNext(); ) {
XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) iterator.next();
list.add(enumerationFacet);
}
}
}
XSDWildcard anyAttr = xsdComplexTypeDefinition.getAttributeWildcard();
if (anyAttr != null)
list.add(anyAttr);
// get immediate XSD Model Group of this complex type
if (xsdComplexTypeDefinition.getContent() != null) {
XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
if (particleContent instanceof XSDModelGroup) {
list.add(particleContent);
}
}
}
// get inherited XSD Model Group of this complex type
boolean showInheritedContent = XSDEditorPlugin.getPlugin().getShowInheritedContent();
if (showInheritedContent) {
XSDTypeDefinition typeDef = xsdComplexTypeDefinition.getBaseTypeDefinition();
if (typeDef instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition baseCT = (XSDComplexTypeDefinition) typeDef;
if (baseCT.getTargetNamespace() != null && !baseCT.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) {
if (baseCT.getContent() != null) {
XSDComplexTypeContent xsdComplexTypeContent = baseCT.getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
if (particleContent instanceof XSDModelGroup) {
list.add(particleContent);
}
}
}
}
}
}
List adapterList = new ArrayList();
populateAdapterList(list, adapterList);
return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
Aggregations