Search in sources :

Example 1 with XSDVariety

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

the class XSDHyperlinkTargetLocator method caseXSDSimpleTypeDefinition.

public Object caseXSDSimpleTypeDefinition(XSDSimpleTypeDefinition typeDefinition) {
    XSDConcreteComponent target = null;
    // Simple types can be one of: atomic, list or union.
    XSDVariety variety = typeDefinition.getVariety();
    int varietyType = variety.getValue();
    switch(varietyType) {
        case XSDVariety.ATOMIC:
            {
                target = typeDefinition.getBaseTypeDefinition();
            }
            break;
        case XSDVariety.LIST:
            {
                target = typeDefinition.getItemTypeDefinition();
            }
            break;
        case XSDVariety.UNION:
            {
                List memberTypes = typeDefinition.getMemberTypeDefinitions();
                if (memberTypes != null && memberTypes.size() > 0) {
                    // ISSUE: What if there are more than one type?
                    // This could be a case for multiple hyperlinks at the same
                    // location.
                    target = (XSDConcreteComponent) memberTypes.get(0);
                }
            }
            break;
    }
    if (isFromSchemaForSchema(target)) {
        target = null;
    }
    return target;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) List(java.util.List) XSDVariety(org.eclipse.xsd.XSDVariety)

Example 2 with XSDVariety

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

the class SetBaseTypeCommand method execute.

public void execute() {
    try {
        beginRecording(concreteComponent.getElement());
        if (concreteComponent instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) concreteComponent;
            XSDComplexTypeContent contentType = (baseType instanceof XSDComplexTypeDefinition) ? ((XSDComplexTypeDefinition) baseType).getContentType() : null;
            // Complex type simple content
            if (baseType instanceof XSDSimpleTypeDefinition || (contentType != null && contentType instanceof XSDSimpleTypeDefinition)) {
                if (!(complexType.getContent() instanceof XSDSimpleTypeDefinition)) {
                    XSDSimpleTypeDefinition simpleContent = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
                    complexType.setContent(simpleContent);
                }
            } else // Complex type complex content
            if (baseType instanceof XSDComplexTypeDefinition) {
                if (!(complexType.getContent() instanceof XSDComplexTypeDefinition)) {
                    XSDComplexTypeDefinition complexContent = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
                    complexType.setContent(complexContent.getContent());
                }
            }
            complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
            complexType.setBaseTypeDefinition(baseType);
            // vb This call should not be needed. The XSD Infoset model should reconcile itself properly.
            complexType.updateElement(true);
            formatChild(complexType.getElement());
        } else if (concreteComponent instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) concreteComponent;
            if (baseType instanceof XSDSimpleTypeDefinition) {
                XSDVariety variety = simpleType.getVariety();
                if (variety.getValue() == XSDVariety.ATOMIC) {
                    simpleType.setBaseTypeDefinition((XSDSimpleTypeDefinition) baseType);
                } else if (variety.getValue() == XSDVariety.UNION) {
                    simpleType.getMemberTypeDefinitions().add(baseType);
                } else if (variety.getValue() == XSDVariety.LIST) {
                    simpleType.setItemTypeDefinition((XSDSimpleTypeDefinition) baseType);
                }
            }
        }
    } finally {
        endRecording();
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDVariety(org.eclipse.xsd.XSDVariety) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Aggregations

XSDVariety (org.eclipse.xsd.XSDVariety)2 List (java.util.List)1 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)1 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)1 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)1 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)1