Search in sources :

Example 61 with XSDSimpleTypeDefinition

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

the class MetadataRepository method visitSimpleType.

@Override
public void visitSimpleType(XSDSimpleTypeDefinition type) {
    String typeName = type.getName();
    TypeMetadata typeMetadata = getNonInstantiableType(targetNamespace, typeName);
    if (typeMetadata == null) {
        typeMetadata = new SimpleTypeMetadata(targetNamespace, typeName);
    }
    List<TypeMetadata> superTypes = new LinkedList<TypeMetadata>();
    if (typeName == null) {
        // Anonymous simple type (expects this is a restriction of a simple type or fails).
        XSDSimpleTypeDefinition baseTypeDefinition = type.getBaseTypeDefinition();
        if (baseTypeDefinition != null) {
            typeName = baseTypeDefinition.getName();
        } else {
            throw new NotImplementedException("Support for " + type);
        }
    } else {
        // Simple type might inherit from other simple types (i.e. UUID from string).
        XSDSimpleTypeDefinition baseType = type.getBaseTypeDefinition();
        if (baseType != null && baseType.getName() != null) {
            superTypes.add(new SoftTypeRef(this, baseType.getTargetNamespace(), baseType.getName(), false));
            EList<XSDConstrainingFacet> facets = type.getFacetContents();
            for (XSDConstrainingFacet currentFacet : facets) {
                if (currentFacet instanceof XSDMaxLengthFacet) {
                    typeMetadata.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDMaxLengthFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDLengthFacet) {
                    typeMetadata.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDLengthFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDTotalDigitsFacet) {
                    // this is the totalDigits
                    typeMetadata.setData(MetadataRepository.DATA_TOTAL_DIGITS, String.valueOf(((XSDTotalDigitsFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDFractionDigitsFacet) {
                    // this is the fractionDigits
                    typeMetadata.setData(MetadataRepository.DATA_FRACTION_DIGITS, String.valueOf(((XSDFractionDigitsFacet) currentFacet).getValue()));
                } else if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Ignore simple type facet on type '" + typeName + "': " + currentFacet);
                }
            }
        }
    }
    if (getNonInstantiableType(targetNamespace, typeName) == null) {
        for (TypeMetadata superType : superTypes) {
            typeMetadata.addSuperType(superType);
        }
        addTypeMetadata(typeMetadata);
    }
}
Also used : XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) NotImplementedException(org.apache.commons.lang.NotImplementedException) LinkedList(java.util.LinkedList) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet)

Example 62 with XSDSimpleTypeDefinition

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

the class CustomTypeSorter method getCurSelectedCustomBaseType.

private XSDSimpleTypeDefinition getCurSelectedCustomBaseType() {
    IStructuredSelection selection = (IStructuredSelection) comboCustomTypes.getSelection();
    if (selection == null || selection.isEmpty()) {
        return null;
    }
    XSDSimpleTypeDefinition curSelectedCustomBaseType = xsdSimpleType.getSchema().resolveSimpleTypeDefinition(xsdSimpleType.getSchema().getSchemaForSchemaNamespace(), (String) selection.getFirstElement());
    if (!xsdSimpleType.getSchema().getTypeDefinitions().contains(curSelectedCustomBaseType)) {
        return xsdSimpleType.getSchema().resolveSimpleTypeDefinition(xsdSimpleType.getSchema().getSchemaForSchemaNamespace(), // $NON-NLS-1$
        "string");
    }
    return curSelectedCustomBaseType;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 63 with XSDSimpleTypeDefinition

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

the class ComplexTypeInputDialog method modifyText.

public void modifyText(ModifyEvent e) {
    getButton(IDialogConstants.OK_ID).setEnabled(true);
    // $NON-NLS-1$
    conceptPanel.setMessage("");
    String type = conceptPanel.getText();
    if (// $NON-NLS-1$
    Pattern.compile("^\\s+\\w+\\s*").matcher(type).matches() || type.trim().replaceAll("\\s", "").length() != type.trim().length()) {
        // $NON-NLS-1$//$NON-NLS-2$
        conceptPanel.setMessage(Messages._NameWithEmptyCharacters);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    }
    type = type.trim();
    if (!XSDUtil.isValidatedXSDName(type)) {
        conceptPanel.setMessage(Messages.InvalidName_Message);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    }
    for (XSDTypeDefinition specType : xsdSchema.getTypeDefinitions()) {
        String typeToCompare = specType.getName();
        // $NON-NLS-1$
        int delimiter = type.indexOf(" : ");
        if (delimiter != -1) {
            type = type.substring(0, delimiter);
        }
        if (typeToCompare.equals(type)) {
            if (caller instanceof XSDNewComplexTypeDefinition) {
                conceptPanel.setMessage(Messages._SameTypeNameExists);
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            } else if (caller instanceof XSDChangeToComplexTypeAction && specType instanceof XSDSimpleTypeDefinition) {
                conceptPanel.setMessage(Messages._SameTypeNameExists);
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
            break;
        }
    }
}
Also used : XSDChangeToComplexTypeAction(com.amalto.workbench.actions.XSDChangeToComplexTypeAction) XSDNewComplexTypeDefinition(com.amalto.workbench.actions.XSDNewComplexTypeDefinition) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 64 with XSDSimpleTypeDefinition

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

the class MatchRuleSelectionFilter method check.

public FilterResult check(Object obj) {
    if (obj instanceof XSDParticle) {
        XSDParticle particle = (XSDParticle) obj;
        int maxOccurs = particle.getMaxOccurs();
        if (maxOccurs > 1 || maxOccurs == -1) {
            return FilterResult.DISABLE;
        }
        XSDTerm term = particle.getTerm();
        if (term instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = ((XSDElementDeclaration) term);
            XSDTypeDefinition type = element.getType();
            if (type instanceof XSDSimpleTypeDefinition) {
                return FilterResult.ENABLE;
            }
        }
    }
    return FilterResult.DISABLE;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDTerm(org.eclipse.xsd.XSDTerm) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 65 with XSDSimpleTypeDefinition

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

the class TreeExpandHelper method getName.

private String getName(Object objA) {
    if (objA instanceof XSDElementDeclaration) {
        XSDElementDeclaration decl = (XSDElementDeclaration) objA;
        return decl.getName();
    }
    if (objA instanceof XSDModelGroup) {
        XSDModelGroup goup = (XSDModelGroup) objA;
        XSDParticle particle = (XSDParticle) goup.getContainer();
        XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) particle.getContainer();
        String name = complexTypeDefinition.getName();
        return name;
    }
    if (objA instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition goupDef = (XSDModelGroupDefinition) objA;
        return goupDef.getName();
    }
    if (objA instanceof XSDParticle) {
        XSDParticle particle = (XSDParticle) objA;
        if (particle.getTerm() instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
            return decl.getName();
        }
    }
    if (objA instanceof XSDAnnotation) {
        return null;
    }
    if (objA instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition constraint = (XSDIdentityConstraintDefinition) objA;
        return constraint.getName();
    }
    if (objA instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition simpleDefine = (XSDSimpleTypeDefinition) objA;
        return simpleDefine.getName();
    }
    if (objA instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition complexDefine = (XSDComplexTypeDefinition) objA;
        return complexDefine.getName();
    }
    return null;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

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