Search in sources :

Example 76 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.

the class UtilTest method testFindElementsUsingType.

@Test
public void testFindElementsUsingType() {
    // $NON-NLS-1$
    String typenameA = "ComplexTypeA";
    // $NON-NLS-1$
    String typenameB = "ComplexTypeB";
    XSDParticle xsdParticle0 = XSDFactory.eINSTANCE.createXSDParticle();
    // 
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    List<Object> objList = new ArrayList<Object>();
    objList.add(xsdSimpleTypeDefinition);
    boolean findElements = Util.findElementsUsingType(objList, xsdSimpleTypeDefinition);
    assertFalse(findElements);
    // 
    objList.clear();
    XSDComplexTypeDefinition xsdComplexTypeDefinition1 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    objList.add(xsdComplexTypeDefinition1);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertFalse(findElements);
    // 
    objList.clear();
    xsdComplexTypeDefinition1.setName(typenameA);
    XSDComplexTypeDefinition xsdComplexTypeDefinition2 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    xsdComplexTypeDefinition2.setName(typenameA);
    objList.add(xsdComplexTypeDefinition2);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    // 
    objList.clear();
    XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    xsdElementDeclaration.setTypeDefinition(xsdComplexTypeDefinition2);
    objList.add(xsdElementDeclaration);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    objList.clear();
    xsdParticle0.setContent(xsdElementDeclaration);
    objList.add(xsdParticle0);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    // 
    objList.clear();
    XSDComplexTypeDefinition xsdComplexTypeDefinition_child = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    xsdComplexTypeDefinition_child.setName(typenameA);
    XSDElementDeclaration xsdElementDeclaration_child = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    xsdElementDeclaration_child.setTypeDefinition(xsdComplexTypeDefinition_child);
    XSDParticle xsdParticle_child = XSDFactory.eINSTANCE.createXSDParticle();
    xsdParticle_child.setContent(xsdElementDeclaration_child);
    EList<XSDParticle> elist = new BasicEList<XSDParticle>();
    elist.add(xsdParticle_child);
    XSDModelGroup xsdModelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
    xsdModelGroup.getContents().addAll(elist);
    XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
    xsdParticle.setTerm(xsdModelGroup);
    xsdComplexTypeDefinition2.setName(typenameB);
    xsdComplexTypeDefinition2.setContent(xsdParticle);
    objList.add(xsdElementDeclaration);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    objList.clear();
    xsdParticle0.setContent(xsdElementDeclaration);
    objList.add(xsdParticle0);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    // 
    objList.clear();
    objList.add(xsdComplexTypeDefinition2);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    // 
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition_child = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    xsdSimpleTypeDefinition_child.setName(typenameA);
    xsdElementDeclaration_child.setTypeDefinition(xsdSimpleTypeDefinition_child);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertFalse(findElements);
    // 
    objList.clear();
    XSDSimpleTypeDefinition xsdSimpleBaseTypeDef = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    xsdSimpleBaseTypeDef.setName(typenameA);
    XSDSimpleTypeDefinition xsdSimpleTypeDef = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    xsdSimpleTypeDef.setBaseTypeDefinition(xsdSimpleBaseTypeDef);
    XSDSimpleTypeDefinition xsdSimpleTypeDef_tosearch = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    xsdSimpleTypeDef_tosearch.setName(typenameA);
    objList.add(xsdSimpleTypeDef);
    findElements = Util.findElementsUsingType(objList, xsdSimpleTypeDef_tosearch);
    assertTrue(findElements);
    // 
    objList.clear();
    XSDElementDeclaration xsdElementDecl = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    xsdElementDecl.setTypeDefinition(xsdSimpleTypeDef);
    objList.add(xsdElementDecl);
    findElements = Util.findElementsUsingType(objList, xsdSimpleTypeDef_tosearch);
    assertTrue(findElements);
    objList.clear();
    xsdParticle0.setContent(xsdElementDecl);
    objList.add(xsdParticle0);
    findElements = Util.findElementsUsingType(objList, xsdSimpleTypeDef_tosearch);
    assertTrue(findElements);
    // 
    XSDComplexTypeDefinition xsdComplexTypedef_search = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    xsdComplexTypedef_search.setName(typenameB);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypedef_search);
    assertFalse(findElements);
    // 
    objList.clear();
    objList.add(xsdSimpleTypeDef);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypedef_search);
    assertFalse(findElements);
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) Test(org.junit.Test)

Example 77 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.

the class UtilTest method testFilterOutDuplicatedElems.

@Test
public void testFilterOutDuplicatedElems() {
    // $NON-NLS-1$
    String simpletypeName = "simpletype";
    // $NON-NLS-1$
    String complextypeName = "complextype";
    // $NON-NLS-1$
    String concepName = "concept";
    // $NON-NLS-1$
    String idconstraintName = "identityconstraint";
    // $NON-NLS-1$
    String modelgroupName = "modelgroup";
    XSDFactory factory = XSDFactory.eINSTANCE;
    XSDSimpleTypeDefinition simpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
    XSDComplexTypeDefinition complexTypeDefinition = factory.createXSDComplexTypeDefinition();
    XSDElementDeclaration elementDeclaration = factory.createXSDElementDeclaration();
    XSDIdentityConstraintDefinition identityConstraintDefinition = factory.createXSDIdentityConstraintDefinition();
    XSDModelGroupDefinition modelGroupDefinition = factory.createXSDModelGroupDefinition();
    simpleTypeDefinition.setName(simpletypeName);
    complexTypeDefinition.setName(complextypeName);
    elementDeclaration.setName(concepName);
    identityConstraintDefinition.setName(idconstraintName);
    modelGroupDefinition.setName(modelgroupName);
    XSDNamedComponent[] checkedElements = { simpleTypeDefinition, complexTypeDefinition, elementDeclaration, identityConstraintDefinition, modelGroupDefinition };
    Object[] duplicatedElems = Util.filterOutDuplicatedElems(checkedElements);
    List<XSDNamedComponent> allElements = Arrays.asList(checkedElements);
    assertNotNull(duplicatedElems);
    assertTrue(checkedElements.length == duplicatedElems.length);
    for (int i = 0; i < duplicatedElems.length; i++) {
        assertTrue(allElements.contains(duplicatedElems[i]));
    }
    // 
    XSDSimpleTypeDefinition simpleTypeDefinition2 = factory.createXSDSimpleTypeDefinition();
    XSDComplexTypeDefinition complexTypeDefinition2 = factory.createXSDComplexTypeDefinition();
    XSDElementDeclaration elementDeclaration2 = factory.createXSDElementDeclaration();
    XSDIdentityConstraintDefinition identityConstraintDefinition2 = factory.createXSDIdentityConstraintDefinition();
    XSDModelGroupDefinition modelGroupDefinition2 = factory.createXSDModelGroupDefinition();
    simpleTypeDefinition2.setName(simpletypeName);
    complexTypeDefinition2.setName(complextypeName);
    elementDeclaration2.setName(concepName);
    identityConstraintDefinition2.setName(idconstraintName);
    modelGroupDefinition2.setName(modelgroupName);
    XSDNamedComponent[] checkedElements2 = { simpleTypeDefinition, complexTypeDefinition, elementDeclaration, identityConstraintDefinition, modelGroupDefinition, simpleTypeDefinition2, complexTypeDefinition2, elementDeclaration2, identityConstraintDefinition2, modelGroupDefinition2 };
    duplicatedElems = Util.filterOutDuplicatedElems(checkedElements2);
    assertNotNull(duplicatedElems);
    assertTrue(checkedElements.length == duplicatedElems.length);
    for (int i = 0; i < duplicatedElems.length; i++) {
        assertTrue(allElements.contains(duplicatedElems[i]));
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) Test(org.junit.Test)

Example 78 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.

the class XSDUtilTest method testIsSimpleTypeElement.

@Test
public void testIsSimpleTypeElement() {
    XSDFactory factory = XSDFactory.eINSTANCE;
    XSDParticle particle = factory.createXSDParticle();
    XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
    xsdElementDeclaration.setTypeDefinition(xsdSimpleTypeDefinition);
    particle.setContent(xsdElementDeclaration);
    boolean isSimpleTypeElement = XSDUtil.isSimpleTypeElement(particle);
    assertTrue(isSimpleTypeElement);
    xsdElementDeclaration.setTypeDefinition(factory.createXSDComplexTypeDefinition());
    isSimpleTypeElement = XSDUtil.isSimpleTypeElement(particle);
    assertFalse(isSimpleTypeElement);
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) Test(org.junit.Test)

Example 79 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class XSDSimpleTypeDefinitionAdapter method getText.

public String getText(boolean showType) {
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) target;
    StringBuffer result = new StringBuffer();
    result.append(xsdSimpleTypeDefinition.getName() == null ? Messages._UI_LABEL_LOCAL_TYPE : xsdSimpleTypeDefinition.getName());
    if (showType) {
        XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition();
        if (baseTypeDefinition != null && XSDVariety.ATOMIC_LITERAL == xsdSimpleTypeDefinition.getVariety()) {
            if (baseTypeDefinition.getName() != null && !xsdSimpleTypeDefinition.getContents().contains(baseTypeDefinition) && !XSDConstants.isAnySimpleType(baseTypeDefinition)) {
                try {
                    String qName = baseTypeDefinition.getQName(xsdSimpleTypeDefinition);
                    // $NON-NLS-1$
                    result.append(" : ");
                    result.append(qName);
                } catch (Exception e) {
                }
            }
        } else {
            XSDSimpleTypeDefinition itemTypeDefinition = xsdSimpleTypeDefinition.getItemTypeDefinition();
            if (itemTypeDefinition != null) {
                if (itemTypeDefinition.getName() != null) {
                    // $NON-NLS-1$
                    result.append(" : ");
                    result.append(itemTypeDefinition.getQName(xsdSimpleTypeDefinition));
                }
            } else {
                List memberTypeDefinitions = xsdSimpleTypeDefinition.getMemberTypeDefinitions();
                if (!memberTypeDefinitions.isEmpty()) {
                    boolean first = true;
                    for (Iterator members = memberTypeDefinitions.iterator(); members.hasNext(); ) {
                        XSDSimpleTypeDefinition memberTypeDefinition = (XSDSimpleTypeDefinition) members.next();
                        if (memberTypeDefinition.getName() != null) {
                            if (first) {
                                // $NON-NLS-1$
                                result.append(" : ");
                                first = false;
                            } else {
                                // $NON-NLS-1$
                                result.append(" | ");
                            }
                            result.append(memberTypeDefinition.getQName(xsdSimpleTypeDefinition));
                        } else {
                            break;
                        }
                    }
                } else if (result.length() == 0) {
                    result.append(Messages._UI_LABEL_ABSENT);
                }
            }
        }
    }
    return result.toString();
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 80 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class XSDSimpleTypeDefinitionAdapter method isReadOnly.

public boolean isReadOnly() {
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) target;
    if (hasSetReadOnlyField()) {
        deletedTypes.put(xsdSimpleTypeDefinition.getName(), new Boolean(true));
        changeReadOnlyField = false;
        return readOnly;
    } else {
        if (deletedTypes != null) {
            Boolean deleted = ((Boolean) deletedTypes.get(xsdSimpleTypeDefinition.getName()));
            if (deleted != null && deleted.booleanValue())
                return true;
            else
                return super.isReadOnly();
        } else
            return super.isReadOnly();
    }
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition)

Aggregations

XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)106 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)53 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)47 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)46 XSDParticle (org.eclipse.xsd.XSDParticle)34 ArrayList (java.util.ArrayList)33 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 Iterator (java.util.Iterator)24 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 XSDSchema (org.eclipse.xsd.XSDSchema)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)16 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)15 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)15 XSDFactory (org.eclipse.xsd.XSDFactory)15 EList (org.eclipse.emf.common.util.EList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)11