Search in sources :

Example 86 with XSDModelGroup

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);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 87 with XSDModelGroup

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;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 88 with XSDModelGroup

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();
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition)

Example 89 with XSDModelGroup

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);
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition)

Example 90 with XSDModelGroup

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]);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) ITreeElement(org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDModelGroup (org.eclipse.xsd.XSDModelGroup)119 XSDParticle (org.eclipse.xsd.XSDParticle)93 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)87 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)76 ArrayList (java.util.ArrayList)33 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)32 XSDTerm (org.eclipse.xsd.XSDTerm)28 XSDFactory (org.eclipse.xsd.XSDFactory)26 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)26 Test (org.junit.Test)25 XSDSchema (org.eclipse.xsd.XSDSchema)23 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)22 EList (org.eclipse.emf.common.util.EList)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)20 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)19 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 Iterator (java.util.Iterator)16 XSDWildcard (org.eclipse.xsd.XSDWildcard)16 TreeObject (com.amalto.workbench.models.TreeObject)15