Search in sources :

Example 16 with XSDParticleContent

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

the class SetMultiplicityCommand method execute.

/* (non-Javadoc)
   * @see org.eclipse.wst.xsd.ui.internal.commands.AbstractCommand#run()
   */
public void execute() {
    try {
        beginRecording(parent.getElement());
        if (parent instanceof XSDParticleContent) {
            XSDParticleContent xsdParticleContent = (XSDParticleContent) parent;
            XSDParticle xsdParticle = (XSDParticle) xsdParticleContent.getContainer();
            if (maxOccurs < 0) {
                maxOccurs = XSDParticle.UNBOUNDED;
            }
            xsdParticle.setMaxOccurs(maxOccurs);
            xsdParticle.setMinOccurs(minOccurs);
        }
    } finally {
        endRecording();
    }
}
Also used : XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 17 with XSDParticleContent

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

the class MetadataRepository method visitComplexType.

@Override
public void visitComplexType(XSDComplexTypeDefinition type) {
    String typeName = type.getName();
    boolean isNonInstantiableType = currentTypeStack.isEmpty();
    if (isNonInstantiableType) {
        if (nonInstantiableTypes.get(getUserNamespace()) != null) {
            if (nonInstantiableTypes.get(getUserNamespace()).containsKey(typeName)) {
                // Ignore another definition of type (already processed).
                return;
            }
        }
        // There's no current 'entity' type being parsed, this is a complex type not to be used for entity but
        // might be referenced by others entities (for fields, inheritance...).
        ComplexTypeMetadata nonInstantiableType = new ComplexTypeMetadataImpl(targetNamespace, typeName, false, type.isAbstract());
        // Keep line and column of definition
        nonInstantiableType.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(type.getElement()));
        nonInstantiableType.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(type.getElement()));
        nonInstantiableType.setData(XSD_DOM_ELEMENT, type.getElement());
        addTypeMetadata(nonInstantiableType);
        currentTypeStack.push(nonInstantiableType);
        // If type is used, declare usage
        List<ComplexTypeMetadata> usages = entityTypeUsage.get(type);
        for (ComplexTypeMetadata usage : usages) {
            nonInstantiableType.declareUsage(usage);
        }
    } else {
        // Keep track of the complex type used for entity type (especially for inheritance).
        if (typeName != null) {
            currentTypeStack.peek().setData(MetadataRepository.COMPLEX_TYPE_NAME, typeName);
        }
    }
    XSDComplexTypeContent particle = type.getContent();
    if (particle instanceof XSDParticle) {
        XSDParticle currentParticle = (XSDParticle) particle;
        if (currentParticle.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup group = (XSDModelGroup) currentParticle.getTerm();
            EList<XSDParticle> particles = group.getContents();
            for (XSDParticle p : particles) {
                XSDParticleContent particleContent = p.getContent();
                XmlSchemaWalker.walk(particleContent, this);
            }
        }
    } else if (particle != null) {
        throw new IllegalArgumentException("Not supported XML Schema particle: " + particle.getClass().getName());
    }
    // Adds the type information about super types.
    XSDTypeDefinition contentModel = type.getBaseTypeDefinition();
    if (contentModel != null) {
        if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(contentModel.getTargetNamespace()) && !Types.ANY_TYPE.equals(contentModel.getName())) {
            SoftTypeRef superType = new SoftTypeRef(this, contentModel.getTargetNamespace(), contentModel.getName(), false);
            if (currentTypeStack.peek() instanceof ContainedComplexTypeMetadata) {
                superType.declareUsage(currentTypeStack.peek());
            }
            currentTypeStack.peek().addSuperType(superType);
            particle = type.getContent();
            if (particle instanceof XSDParticle) {
                XSDParticle currentParticle = (XSDParticle) particle;
                if (currentParticle.getTerm() instanceof XSDModelGroup) {
                    XSDModelGroup group = (XSDModelGroup) currentParticle.getTerm();
                    EList<XSDParticle> particles = group.getContents();
                    for (XSDParticle p : particles) {
                        XSDParticleContent particleContent = p.getContent();
                        XmlSchemaWalker.walk(particleContent, this);
                    }
                }
            } else if (particle != null) {
                throw new IllegalArgumentException("Not supported XML Schema particle: " + particle.getClass().getName());
            }
        }
    }
    if (isNonInstantiableType) {
        currentTypeStack.pop();
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) 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