Search in sources :

Example 11 with XSDParticleContent

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

the class XSDUtilTest method testIsPrimaryKeyElement.

@Test
public void testIsPrimaryKeyElement() throws Exception {
    // $NON-NLS-1$
    String fileName = "Product_0.1.xsd";
    // $NON-NLS-1$
    String elementName = "Product";
    String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
    assertNotNull(xsdString);
    XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
    XSDElementDeclaration decl = null;
    for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
        if (element.getName().equals(elementName)) {
            decl = element;
        }
    }
    if (decl != null) {
        XSDComplexTypeDefinition ctypeDefinition = (XSDComplexTypeDefinition) decl.getTypeDefinition();
        XSDComplexTypeContent ctypeContent = ctypeDefinition.getContent();
        if (ctypeContent instanceof XSDParticle) {
            XSDParticle typeParticle = (XSDParticle) ctypeContent;
            XSDParticleContent particleContent = typeParticle.getContent();
            if (particleContent instanceof XSDModelGroup) {
                XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
                for (XSDParticle particle : particleGroup.getContents()) {
                    if (particle.getContent() instanceof XSDElementDeclaration && ((XSDElementDeclaration) particle.getContent()).getName().equals("Id")) {
                        // $NON-NLS-1$
                        assertTrue(XSDUtil.isPrimaryKeyElement(particle));
                    } else {
                        assertFalse(XSDUtil.isPrimaryKeyElement(particle));
                    }
                }
            }
        }
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Example 12 with XSDParticleContent

use of org.eclipse.xsd.XSDParticleContent 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)

Example 13 with XSDParticleContent

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

the class XSDModelGroupAdapter method getChildren.

public ITreeElement[] getChildren() {
    XSDModelGroup xsdModelGroup = getXSDModelGroup();
    List list = new ArrayList();
    for (Iterator i = xsdModelGroup.getContents().iterator(); i.hasNext(); ) {
        Object object = i.next();
        XSDParticleContent particle = ((XSDParticle) object).getContent();
        if (particle instanceof XSDElementDeclaration) {
            list.add(particle);
        } else if (particle instanceof XSDWildcard) {
            list.add(particle);
        } else if (particle instanceof XSDModelGroup) {
            list.add(particle);
        } else if (particle instanceof XSDModelGroupDefinition) {
            // list.add(((XSDModelGroupDefinition)particle).getResolvedModelGroupDefinition());
            list.add(particle);
        }
    }
    List adapterList = new ArrayList();
    populateAdapterList(list, adapterList);
    return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDWildcard(org.eclipse.xsd.XSDWildcard) ArrayList(java.util.ArrayList) List(java.util.List) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) ITreeElement(org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 14 with XSDParticleContent

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

the class MultiplicitySection method updateMaxAttribute.

protected void updateMaxAttribute() {
    setErrorMessage(null);
    XSDParticle particle = null;
    if (input instanceof XSDParticleContent) {
        particle = getAssociatedParticle((XSDParticleContent) input);
    }
    if (particle != null) {
        String newValue = maxCombo.getText().trim();
        if (newValue.length() == 0) {
            particle.unsetMaxOccurs();
            return;
        }
        try {
            int newMax = 1;
            if (// $NON-NLS-1$ //$NON-NLS-2$
            newValue.equals("unbounded") || newValue.equals("*")) {
                newMax = XSDParticle.UNBOUNDED;
            } else {
                if (newValue.length() > 0) {
                    newMax = Integer.parseInt(newValue);
                }
            }
            setListenerEnabled(false);
            UpdateMaxOccursCommand command = new UpdateMaxOccursCommand(Messages._UI_ACTION_CHANGE_MAXIMUM_OCCURRENCE, particle, newMax);
            getCommandStack().execute(command);
            setListenerEnabled(true);
        } catch (NumberFormatException e) {
            setErrorMessage(Messages._UI_ERROR_INVALID_VALUE_FOR_MAXIMUM_OCCURRENCE);
        }
    }
}
Also used : XSDParticleContent(org.eclipse.xsd.XSDParticleContent) UpdateMaxOccursCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateMaxOccursCommand) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 15 with XSDParticleContent

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

the class MultiplicitySection method refreshMinMax.

protected void refreshMinMax() {
    boolean refreshMinText = true;
    boolean refreshMaxText = true;
    if (minCombo.isFocusControl()) {
        refreshMinText = false;
    }
    if (maxCombo.isFocusControl()) {
        refreshMaxText = false;
    }
    if (refreshMinText) {
        // $NON-NLS-1$
        minCombo.setText("");
    }
    if (refreshMaxText) {
        // $NON-NLS-1$
        maxCombo.setText("");
    }
    if (input != null) {
        if (input instanceof XSDParticleContent) {
            XSDParticle particle = getAssociatedParticle((XSDParticleContent) input);
            if (particle != null) {
                // minText.setText(String.valueOf(particle.getMinOccurs()));
                // maxText.setText(String.valueOf(particle.getMaxOccurs()));
                Element element = particle.getElement();
                if (element != null) {
                    if (element.hasAttribute(XSDConstants.MINOCCURS_ATTRIBUTE) && refreshMinText) {
                        String min = element.getAttribute(XSDConstants.MINOCCURS_ATTRIBUTE);
                        minCombo.setText(min);
                    }
                    if (element.hasAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE) && refreshMaxText) {
                        String max = element.getAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE);
                        maxCombo.setText(max);
                    }
                }
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDParticle (org.eclipse.xsd.XSDParticle)17 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)17 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)12 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)10 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)9 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)8 XSDSchema (org.eclipse.xsd.XSDSchema)6 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)6 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Iterator (java.util.Iterator)3 EList (org.eclipse.emf.common.util.EList)3 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)3 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 XSDTerm (org.eclipse.xsd.XSDTerm)3 Element (org.w3c.dom.Element)3 LinkedList (java.util.LinkedList)2 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)2