Search in sources :

Example 1 with XSDMaxInclusiveFacet

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

the class XSDGenerateHTML method loadAndPrint.

/**
 * Load the XML Schema file and print the documentation based on it.
 *
 * @param xsdFile the name of an XML Schema file.
 */
public void loadAndPrint(String xsdFile) throws Exception {
    XSDFactory xsdFactory = XSDFactory.eINSTANCE;
    // Create a resource set and load the main schema file into it.
    // 
    ResourceSet resourceSet = new ResourceSetImpl();
    XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet.getResource(URI.createFileURI(xsdFile), true);
    XSDSchema xsdSchema = xsdResource.getSchema();
    // $NON-NLS-1$
    String elementContentHeaderDocumentation = getContentDocumentation("element-header");
    if (elementContentHeaderDocumentation != null) {
        System.out.println(elementContentHeaderDocumentation);
    }
    List all = new ArrayList(xsdSchema.getElementDeclarations());
    // $NON-NLS-1$
    XSDElementDeclaration simpleContent = xsdSchema.resolveElementDeclaration("simpleContent");
    // $NON-NLS-1$
    XSDElementDeclaration complexContent = xsdSchema.resolveElementDeclaration("complexContent");
    for (int i = 0; i <= 1; ++i) {
        for (int j = 0; j <= 1; ++j) {
            XSDElementDeclaration parentElement = (i == 0 ? complexContent : simpleContent);
            XSDComplexTypeDefinition xsdComplexTypeDefinition = (XSDComplexTypeDefinition) parentElement.getTypeDefinition();
            XSDElementDeclaration specialElementDeclaration = (XSDElementDeclaration) ((XSDParticle) ((XSDModelGroup) ((XSDParticle) ((XSDModelGroup) ((XSDParticle) (xsdComplexTypeDefinition.getContentType())).getTerm()).getParticles().get(1)).getTerm()).getParticles().get(j)).getTerm();
            all.add(specialElementDeclaration);
            specialAnchorMap.put(specialElementDeclaration, parentElement);
        }
    }
    all = XSDNamedComponentImpl.sortNamedComponents(all);
    for (Iterator i = all.iterator(); i.hasNext(); ) {
        XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) i.next();
        XSDElementDeclaration parentElementDeclaration = (XSDElementDeclaration) specialAnchorMap.get(xsdElementDeclaration);
        String elementDeclarationName = xsdElementDeclaration.getName();
        String key = // $NON-NLS-1$ //$NON-NLS-2$
        (parentElementDeclaration == null ? "" : parentElementDeclaration.getName() + "::") + elementDeclarationName;
        String elementDeclarationMarkup = getElementDeclarationMarkup(key);
        // $NON-NLS-1$
        System.out.print("<h2>");
        System.out.print(elementDeclarationName.substring(0, 1).toUpperCase());
        System.out.print(elementDeclarationName.substring(1));
        // $NON-NLS-1$
        System.out.println("</h2>");
        // $NON-NLS-1$
        System.out.println("<div class='reprdef'>");
        // $NON-NLS-1$
        System.out.println("<table cols=1 width='100%'><tr><td>");
        System.out.print(// $NON-NLS-1$
        "<div class='reprHeader'><span class='reprdef'>XML&nbsp;Representation&nbsp;Summary:&nbsp;</span><code>");
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.print("<a name='" + getLocalAnchor(xsdElementDeclaration) + "'>");
        System.out.print(getStandardLink(xsdElementDeclaration));
        System.out.print(elementDeclarationName);
        // $NON-NLS-1$
        System.out.print("</a></a></code>");
        // $NON-NLS-1$
        System.out.print("&nbsp;Element&nbsp;Information&nbsp;Item&nbsp;");
        if (parentElementDeclaration != null) {
            // $NON-NLS-1$
            System.out.print("<small>(");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.print("<a href='#" + getLocalAnchor(parentElementDeclaration) + "'>");
            System.out.print(parentElementDeclaration.getName());
            // $NON-NLS-1$
            System.out.print("</a>)</small>");
        } else if ("restriction".equals(elementDeclarationName)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            System.out.print("<small>(simpleType)</small>");
        }
        // $NON-NLS-1$
        System.out.println("</div>");
        // $NON-NLS-1$
        System.out.println("<div class='reprBody'>");
        if (elementDeclarationMarkup != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.print("<div class='" + elementDeclarationMarkup + "'>");
        }
        // $NON-NLS-1$
        System.out.print("<tt>&lt;");
        System.out.print(elementDeclarationName);
        // $NON-NLS-1$
        System.out.print("</tt>");
        String componentLinks = getComponentLinks(xsdElementDeclaration);
        if (componentLinks != null) {
            System.out.print(componentLinks);
        }
        // $NON-NLS-1$
        System.out.println("<br>");
        StringBuffer attributeDocumentationBuffer = new StringBuffer();
        Map repeatedDocumentationMap = new HashMap();
        XSDTypeDefinition xsdTypeDefinition = xsdElementDeclaration.getTypeDefinition();
        XSDComplexTypeDefinition generalType = xsdSchema.resolveComplexTypeDefinitionURI(xsdElementDeclaration.getURI());
        if (generalType.getContainer() != null) {
            xsdTypeDefinition = generalType;
        }
        if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition) {
            // $NON-NLS-1$
            System.out.println("<tt>></tt><br>");
        } else if (xsdTypeDefinition instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition xsdComplexTypeDefinition = (XSDComplexTypeDefinition) xsdTypeDefinition;
            for (Iterator attributeUses = xsdComplexTypeDefinition.getAttributeUses().iterator(); attributeUses.hasNext(); ) {
                XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) attributeUses.next();
                XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration();
                String attributeDeclarationName = xsdAttributeDeclaration.getName();
                // $NON-NLS-1$
                System.out.print("<tt>&nbsp;&nbsp;");
                if (xsdAttributeDeclaration.getTargetNamespace() != null) {
                    // $NON-NLS-1$
                    System.out.print("xml:");
                }
                String attributeDeclarationMarkup = null;
                String attributeDeclarationDocumentation = null;
                if (!"ignored".equals(elementDeclarationMarkup)) {
                    // $NON-NLS-1$
                    attributeDeclarationMarkup = getAttributeDeclarationMarkup(attributeDeclarationName);
                    if (attributeDeclarationMarkup == null) {
                        attributeDeclarationMarkup = getAttributeDeclarationMarkup(// $NON-NLS-1$
                        elementDeclarationName + "." + attributeDeclarationName);
                    }
                    attributeDeclarationDocumentation = getAttributeDeclarationDocumentation(attributeDeclarationName);
                    if (attributeDeclarationDocumentation == null) {
                        attributeDeclarationDocumentation = getAttributeDeclarationDocumentation(// $NON-NLS-1$
                        elementDeclarationName + "." + attributeDeclarationName);
                    }
                }
                if (attributeDeclarationDocumentation != null) {
                    Integer oldInsertIndex = (Integer) repeatedDocumentationMap.get(attributeDeclarationDocumentation);
                    if (oldInsertIndex != null) {
                        // $NON-NLS-1$
                        String insertion = "<br>" + attributeDeclarationName;
                        attributeDocumentationBuffer.insert(oldInsertIndex.intValue(), insertion);
                        repeatedDocumentationMap.put(attributeDeclarationDocumentation, new Integer(oldInsertIndex.intValue() + insertion.length()));
                    } else {
                        if (attributeDocumentationBuffer.length() == 0) {
                            // $NON-NLS-1$
                            attributeDocumentationBuffer.append("<table cols=2 width='100%'>\n");
                            attributeDocumentationBuffer.append(// $NON-NLS-1$
                            "<tr>\n<th width=25% valign=top align=left><b>Attribute</b></th>\n");
                            attributeDocumentationBuffer.append(// $NON-NLS-1$
                            "<th width=75% valign=top align=left><b>Description</b></th>\n</tr>\n");
                        }
                        // $NON-NLS-1$
                        attributeDocumentationBuffer.append("<tr><td><b>");
                        if (attributeDeclarationMarkup != null) {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            attributeDocumentationBuffer.append("<span class='" + attributeDeclarationMarkup + "'>");
                        }
                        attributeDocumentationBuffer.append(attributeDeclarationName);
                        int insertIndex = attributeDocumentationBuffer.length();
                        if (attributeDeclarationMarkup != null) {
                            // $NON-NLS-1$
                            attributeDocumentationBuffer.append("</span>");
                        }
                        // $NON-NLS-1$
                        attributeDocumentationBuffer.append("</b></td>\n<td valign=top>\n");
                        attributeDocumentationBuffer.append(attributeDeclarationDocumentation);
                        // $NON-NLS-1$
                        attributeDocumentationBuffer.append("</td></tr>");
                        repeatedDocumentationMap.put(attributeDeclarationDocumentation, new Integer(insertIndex));
                    }
                }
                if (attributeDeclarationMarkup != null) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.print("<span class='" + attributeDeclarationMarkup + "'>");
                }
                if (xsdAttributeUse.isRequired()) {
                    // $NON-NLS-1$
                    System.out.print("<b>");
                    System.out.print(attributeDeclarationName);
                    // $NON-NLS-1$
                    System.out.print("</b>");
                } else {
                    System.out.print(attributeDeclarationName);
                }
                if (attributeDeclarationMarkup != null) {
                    // $NON-NLS-1$
                    System.out.print("</span>");
                }
                // $NON-NLS-1$
                System.out.print("&nbsp;=&nbsp;</tt>");
                XSDSimpleTypeDefinition xsdSimpleTypeDefinition = xsdAttributeDeclaration.getTypeDefinition();
                printSimpleTypeDefinition(xsdSimpleTypeDefinition);
                if (xsdAttributeUse.getLexicalValue() != null) {
                    // $NON-NLS-1$
                    System.out.print("&nbsp;:&nbsp;");
                    if ("".equals(xsdAttributeUse.getLexicalValue())) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        System.out.print("\"\"");
                    } else {
                        System.out.print(xsdAttributeUse.getLexicalValue());
                    }
                }
                if (attributeUses.hasNext()) {
                    // $NON-NLS-1$
                    System.out.println("<br>");
                }
            }
            if (xsdComplexTypeDefinition.getAttributeWildcard() != null) {
                // $NON-NLS-1$
                System.out.println("<br>");
                System.out.println(// $NON-NLS-1$
                "<span class='" + ALLOWS + // $NON-NLS-1$
                "'><tt><em>&nbsp;&nbsp;{&nbsp;any&nbsp;attributes&nbsp;with&nbsp;non-schema&nbsp;namespace&nbsp;.&nbsp;.&nbsp;.&nbsp;}</em></tt></span>");
            }
            // $NON-NLS-1$
            System.out.println("<tt>></tt><br>");
            if (xsdComplexTypeDefinition.getContentType() instanceof XSDParticle) {
                // $NON-NLS-1$
                System.out.print("<tt><em>&nbsp;&nbsp;Content:</em>&nbsp;");
                printParticle((XSDParticle) xsdComplexTypeDefinition.getContentType(), elementDeclarationMarkup);
                // $NON-NLS-1$
                System.out.print("</tt>");
            } else if (xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition) {
                // $NON-NLS-1$
                System.out.print("<b>***** simple</b>");
            } else {
                // $NON-NLS-1$
                System.out.print("<b>{ **** empty }</b>");
            }
            // $NON-NLS-1$
            System.out.println("<br>");
        }
        // $NON-NLS-1$
        System.out.print("<tt>&lt;/");
        System.out.print(elementDeclarationName);
        // $NON-NLS-1$
        System.out.println("></tt>");
        if (elementDeclarationMarkup != null) {
            // $NON-NLS-1$
            System.out.print("</div>");
        }
        // $NON-NLS-1$
        System.out.println("</div>");
        String elementDeclarationDocumentation = getElementDeclarationDocumentation(key);
        if (elementDeclarationDocumentation != null) {
            // $NON-NLS-1$
            System.out.println("<div class='reprBody'>");
            System.out.println(elementDeclarationDocumentation);
            // $NON-NLS-1$
            System.out.println("</div>");
        }
        if (attributeDocumentationBuffer.length() > 0) {
            // $NON-NLS-1$
            System.out.println("<div class='reprBody'>");
            System.out.print(attributeDocumentationBuffer);
            // $NON-NLS-1$
            System.out.println("</table>");
            // $NON-NLS-1$
            System.out.println("</div>");
        }
        // $NON-NLS-1$
        System.out.println("</td></tr></table>");
        // $NON-NLS-1$
        System.out.println("</div>");
    }
    // System.out.println("<h1>Built-in Datatypes</h1>");
    // $NON-NLS-1$
    String typeContentHeaderDocumentation = getContentDocumentation("type-header");
    if (typeContentHeaderDocumentation != null) {
        System.out.println(typeContentHeaderDocumentation);
    }
    // $NON-NLS-1$
    System.out.println("<table border=true cols=3 width='100%'>");
    // $NON-NLS-1$
    System.out.println("<tr>");
    // $NON-NLS-1$
    System.out.println("<th width=33% valign=top align=left><b>Type</b></th>");
    // $NON-NLS-1$
    System.out.println("<th width=33% valign=top align=left><b>Properties&nbsp;&amp;&nbsp;Facets</b></th>");
    // $NON-NLS-1$
    System.out.println("<th width=34% valign=top align=left><b>Effective&nbsp;Value</b></th>");
    // $NON-NLS-1$
    System.out.println("</tr>");
    // $NON-NLS-1$
    XSDSimpleTypeDefinition anyTypeDefinition = xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("anyType");
    XSDSimpleTypeDefinition anySimpleTypeDefinition = xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition(// $NON-NLS-1$
    "anySimpleType");
    XSDSimpleTypeDefinition anyListTypeDefinition = xsdFactory.createXSDSimpleTypeDefinition();
    anyListTypeDefinition.setVariety(XSDVariety.LIST_LITERAL);
    // $NON-NLS-1$
    anyListTypeDefinition.setName("anyListType");
    anyListTypeDefinition.setItemTypeDefinition(anySimpleTypeDefinition);
    xsdSchema.getContents().add(anyListTypeDefinition);
    // $NON-NLS-1$
    anyListTypeDefinition.getElement().setAttribute(XSDConstants.ID_ATTRIBUTE, "anyListType");
    XSDSimpleTypeDefinition anyUnionTypeDefinition = xsdFactory.createXSDSimpleTypeDefinition();
    anyUnionTypeDefinition.setVariety(XSDVariety.UNION_LITERAL);
    // $NON-NLS-1$
    anyUnionTypeDefinition.setName("anyUnionType");
    anyUnionTypeDefinition.getMemberTypeDefinitions().add(anySimpleTypeDefinition);
    xsdSchema.getContents().add(anyUnionTypeDefinition);
    // $NON-NLS-1$
    anyUnionTypeDefinition.getElement().setAttribute(XSDConstants.ID_ATTRIBUTE, "anyUnionType");
    List allTypeDefinitions = new ArrayList(xsdSchema.getTypeDefinitions());
    allTypeDefinitions.add(0, anySimpleTypeDefinition);
    allTypeDefinitions.add(0, anyTypeDefinition);
    for (Iterator i = allTypeDefinitions.iterator(); i.hasNext(); ) {
        XSDTypeDefinition xsdTypeDefinition = (XSDTypeDefinition) i.next();
        if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition && xsdTypeDefinition.getElement() != null && xsdTypeDefinition.getName().equals(xsdTypeDefinition.getElement().getAttribute(XSDConstants.ID_ATTRIBUTE))) {
            XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) xsdTypeDefinition;
            // $NON-NLS-1$
            System.out.println("<tr>");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.println("<a name='" + xsdSimpleTypeDefinition.getName() + "-simple-type'>");
            // $NON-NLS-1$
            System.out.println("<td>");
            boolean isPrimitive = XSDVariety.ATOMIC_LITERAL == xsdSimpleTypeDefinition.getVariety() && xsdSimpleTypeDefinition.getBaseTypeDefinition() == anySimpleTypeDefinition;
            if (isPrimitive) {
                // $NON-NLS-1$
                System.out.print("<b>");
            }
            System.out.print(getSimpleTypeDefinitionLink(xsdSimpleTypeDefinition));
            if (isPrimitive) {
                // $NON-NLS-1$
                System.out.print("</b>");
            }
            for (XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition; ; baseTypeDefinition = baseTypeDefinition.getBaseTypeDefinition()) {
                String javaClass = (String) schemaTypeToJavaClassMap.get(baseTypeDefinition.getName());
                if (javaClass != null) {
                    // $NON-NLS-1$
                    System.out.println("<br>&nbsp;<br>");
                    if (baseTypeDefinition == xsdSimpleTypeDefinition) {
                        // ) //$NON-NLS-1$
                        System.out.print("<b>");
                    }
                    // $NON-NLS-1$
                    int dotIndex = javaClass.lastIndexOf(".");
                    // $NON-NLS-1$
                    System.out.print("<font size=-2>");
                    System.out.print(javaClass.substring(0, dotIndex + 1));
                    // $NON-NLS-1$
                    System.out.print("</font><br>&nbsp;&nbsp;");
                    System.out.print(javaClass.substring(dotIndex + 1));
                    if (baseTypeDefinition == xsdSimpleTypeDefinition) {
                        // (
                        // $NON-NLS-1$
                        System.out.print("<b>");
                    }
                    System.out.println();
                    break;
                }
            }
            // $NON-NLS-1$
            System.out.println("<br>");
            // $NON-NLS-1$
            System.out.println("</td>");
            // $NON-NLS-1$
            System.out.println("</a>");
            StringBuffer validFacets = new StringBuffer();
            StringBuffer effectiveFacetValues = new StringBuffer();
            // $NON-NLS-1$
            validFacets.append("variety<br>\n");
            effectiveFacetValues.append(xsdSimpleTypeDefinition.isSetVariety() ? // $NON-NLS-1$
            "<b>" + xsdSimpleTypeDefinition.getVariety() + "</b>" : // $NON-NLS-1$ //$NON-NLS-2$
            "<em>absent</em>");
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            // $NON-NLS-1$
            validFacets.append("base type definition<br>\n");
            XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition();
            while (baseTypeDefinition.getName() == null) {
                baseTypeDefinition = baseTypeDefinition.getBaseTypeDefinition();
            }
            // $NON-NLS-1$
            effectiveFacetValues.append("<a href='#");
            effectiveFacetValues.append(baseTypeDefinition.getName());
            // $NON-NLS-1$
            effectiveFacetValues.append("-simple-type'>");
            effectiveFacetValues.append(baseTypeDefinition.getName());
            // $NON-NLS-1$
            effectiveFacetValues.append("</a><br>\n");
            // $NON-NLS-1$
            validFacets.append("ordered<br>\n");
            effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
            "anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
            "*" : xsdSimpleTypeDefinition.getOrderedFacet().getValue().getName());
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            // $NON-NLS-1$
            validFacets.append("bounded<br>\n");
            effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
            "anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
            "*" : // $NON-NLS-1$ //$NON-NLS-2$
            xsdSimpleTypeDefinition.getBoundedFacet().isValue() ? "true" : "false");
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            // $NON-NLS-1$
            validFacets.append("cardinality<br>\n");
            effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
            "anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
            "*" : XSDCardinality.COUNTABLY_INFINITE_LITERAL == xsdSimpleTypeDefinition.getCardinalityFacet().getValue() ? "countably infinite" : // $NON-NLS-1$
            xsdSimpleTypeDefinition.getCardinalityFacet().getValue().getName());
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            // $NON-NLS-1$
            validFacets.append("numeric<br>\n");
            effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
            "anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
            "*" : // $NON-NLS-1$ //$NON-NLS-2$
            xsdSimpleTypeDefinition.getNumericFacet().isValue() ? "true" : "false");
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            if (xsdSimpleTypeDefinition.getValidFacets().contains("length")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("length<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveLengthFacet() != null) {
                    XSDLengthFacet xsdLengthFacet = xsdSimpleTypeDefinition.getEffectiveLengthFacet();
                    if (xsdLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdLengthFacet.getValue());
                    if (xsdLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("minLength")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("minLength<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMinLengthFacet() != null) {
                    XSDMinLengthFacet xsdMinLengthFacet = xsdSimpleTypeDefinition.getEffectiveMinLengthFacet();
                    if (xsdMinLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMinLengthFacet.getValue());
                    if (xsdMinLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("maxLength")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxLength<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMaxLengthFacet() != null) {
                    XSDMaxLengthFacet xsdMaxLengthFacet = xsdSimpleTypeDefinition.getEffectiveMaxLengthFacet();
                    if (xsdMaxLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMaxLengthFacet.getValue());
                    if (xsdMaxLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("pattern")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("pattern<br>\n");
                if (xsdSimpleTypeDefinition.getEffectivePatternFacet() != null) {
                    // XSDPatternFacet xsdPatternFacet =
                    // xsdSimpleTypeDefinition.getEffectivePatternFacet();
                    // $NON-NLS-1$
                    effectiveFacetValues.append("*");
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("enumeration")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("enumeration<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveEnumerationFacet() != null) {
                    XSDEnumerationFacet xsdEnumerationFacet = xsdSimpleTypeDefinition.getEffectiveEnumerationFacet();
                    for (Iterator enumerators = xsdEnumerationFacet.getValue().iterator(); enumerators.hasNext(); ) {
                        String enumerator = (String) enumerators.next();
                        effectiveFacetValues.append(enumerator);
                        // $NON-NLS-1$
                        effectiveFacetValues.append("&nbsp;");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("whiteSpace")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("whiteSpace<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveWhiteSpaceFacet() != null) {
                    XSDWhiteSpaceFacet xsdWhiteSpaceFacet = xsdSimpleTypeDefinition.getEffectiveWhiteSpaceFacet();
                    if (xsdWhiteSpaceFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdWhiteSpaceFacet.getValue());
                    if (xsdWhiteSpaceFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("maxInclusive")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxInclusive<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMaxFacet() instanceof XSDMaxInclusiveFacet) {
                    XSDMaxInclusiveFacet xsdMaxInclusiveFacet = (XSDMaxInclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMaxFacet();
                    if (xsdMaxInclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMaxInclusiveFacet.getValue());
                    if (xsdMaxInclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("maxExclusive")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxExclusive<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMaxFacet() instanceof XSDMaxExclusiveFacet) {
                    XSDMaxExclusiveFacet xsdMaxExclusiveFacet = (XSDMaxExclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMaxFacet();
                    if (xsdMaxExclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMaxExclusiveFacet.getValue());
                    if (xsdMaxExclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("minInclusive")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxInclusive<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMinFacet() instanceof XSDMinInclusiveFacet) {
                    XSDMinInclusiveFacet xsdMinInclusiveFacet = (XSDMinInclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMinFacet();
                    if (xsdMinInclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMinInclusiveFacet.getValue());
                    if (xsdMinInclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("minExclusive")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxExclusive<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMinFacet() instanceof XSDMinExclusiveFacet) {
                    XSDMinExclusiveFacet xsdMinExclusiveFacet = (XSDMinExclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMinFacet();
                    if (xsdMinExclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMinExclusiveFacet.getValue());
                    if (xsdMinExclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("totalDigits")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("totalDigits<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveTotalDigitsFacet() != null) {
                    XSDTotalDigitsFacet xsdTotalDigitsFacet = xsdSimpleTypeDefinition.getEffectiveTotalDigitsFacet();
                    if (xsdTotalDigitsFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdTotalDigitsFacet.getValue());
                    if (xsdTotalDigitsFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("fractionDigits")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("fractionDigits<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveFractionDigitsFacet() != null) {
                    XSDFractionDigitsFacet xsdFractionDigitsFacet = xsdSimpleTypeDefinition.getEffectiveFractionDigitsFacet();
                    if (xsdFractionDigitsFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdFractionDigitsFacet.getValue());
                    if (xsdFractionDigitsFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            // $NON-NLS-1$
            System.out.println("<td>");
            System.out.print(validFacets);
            // $NON-NLS-1$
            System.out.println("</td>");
            // $NON-NLS-1$
            System.out.print("<td>");
            System.out.println(effectiveFacetValues);
            // $NON-NLS-1$
            System.out.println("</td>");
            // $NON-NLS-1$
            System.out.println("</tr>");
        }
    }
    // $NON-NLS-1$
    System.out.println("</table>");
    // $NON-NLS-1$
    String appendixContentHeaderDocumentation = getContentDocumentation("appendix-header");
    if (appendixContentHeaderDocumentation != null) {
        System.out.println(appendixContentHeaderDocumentation);
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDFactory(org.eclipse.xsd.XSDFactory) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) HashMap(java.util.HashMap) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) ArrayList(java.util.ArrayList) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDWhiteSpaceFacet(org.eclipse.xsd.XSDWhiteSpaceFacet) XSDResourceImpl(org.eclipse.xsd.util.XSDResourceImpl) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet) Map(java.util.Map) HashMap(java.util.HashMap) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 2 with XSDMaxInclusiveFacet

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

the class DataModelMainPage method getElementType.

private int getElementType(Object decl) {
    if (Util.getParent(decl) == decl) {
        if (Util.checkConcept((XSDElementDeclaration) decl)) {
            return 0;
        }
        return 1;
    }
    if (decl instanceof XSDComplexTypeDefinition) {
        return 2;
    }
    if (decl instanceof XSDIdentityConstraintDefinition) {
        return 3;
    }
    if (decl instanceof XSDXPathDefinition) {
        return 4;
    }
    if (decl instanceof XSDSimpleTypeDefinition) {
        return 5;
    }
    if (decl instanceof XSDAnnotation) {
        return 6;
    }
    if (decl instanceof XSDParticle) {
        return 7;
    }
    if (decl instanceof XSDModelGroup) {
        return 8;
    }
    if (decl instanceof XSDWhiteSpaceFacet) {
        return 201;
    }
    if (decl instanceof XSDLengthFacet) {
        return 202;
    }
    if (decl instanceof XSDMinLengthFacet) {
        return 203;
    }
    if (decl instanceof XSDMaxLengthFacet) {
        return 204;
    }
    if (decl instanceof XSDTotalDigitsFacet) {
        return 205;
    }
    if (decl instanceof XSDFractionDigitsFacet) {
        return 206;
    }
    if (decl instanceof XSDMaxInclusiveFacet) {
        return 207;
    }
    if (decl instanceof XSDMaxExclusiveFacet) {
        return 208;
    }
    if (decl instanceof XSDMinInclusiveFacet) {
        return 209;
    }
    if (decl instanceof XSDMinExclusiveFacet) {
        return 210;
    }
    if (decl instanceof XSDPatternFacet) {
        return 211;
    }
    if (decl instanceof XSDEnumerationFacet) {
        return 212;
    }
    if (decl instanceof Element) {
        Element e = (Element) decl;
        if (e.getLocalName().equals("appinfo")) {
        // $NON-NLS-1$
        }
        // $NON-NLS-1$
        String source = e.getAttribute("source");
        if (source != null) {
            if (source.startsWith("X_Label_")) {
                // $NON-NLS-1$
                return 101;
            } else if (source.equals("X_ForeignKey")) {
                // $NON-NLS-1$
                return 102;
            } else if (source.equals("X_ForeignKeyInfo")) {
                // $NON-NLS-1$
                return 103;
            } else if (source.equals("X_SourceSystem")) {
                // $NON-NLS-1$
                return 104;
            } else if (source.equals("X_TargetSystem")) {
                // $NON-NLS-1$
                return 105;
            } else if (source.startsWith("X_Description_")) {
                // $NON-NLS-1$
                return 106;
            } else if (source.equals("X_Write")) {
                // $NON-NLS-1$
                return 107;
            } else if (source.equals("X_Hide")) {
                // $NON-NLS-1$
                return 108;
            } else if (source.equals("X_Schematron")) {
                // $NON-NLS-1$
                return 109;
            } else if (source.startsWith("X_Facet_")) {
                // $NON-NLS-1$
                return 110;
            } else if (source.startsWith("X_Workflow")) {
                // $NON-NLS-1$
                return 111;
            } else if (source.startsWith("X_ForeignKey_Filter")) {
                // $NON-NLS-1$
                return 112;
            } else if (source.startsWith("X_Display_Format_")) {
                // $NON-NLS-1$
                return 113;
            } else if (source.equals("X_Lookup_Field")) {
                // $NON-NLS-1$
                return 114;
            } else if (source.equals("X_PrimaryKeyInfo")) {
                // $NON-NLS-1$
                return 115;
            } else if (source.equals("X_Visible_Rule")) {
                // $NON-NLS-1$
                return 116;
            } else if (source.equals("X_Default_Value_Rule")) {
                // $NON-NLS-1$
                return 117;
            } else if (source.equals("X_Deny_Create")) {
                // $NON-NLS-1$
                return 118;
            } else if (source.equals("X_Deny_PhysicalDelete")) {
                // $NON-NLS-1$
                return 119;
            } else if (source.equals("X_Deny_LogicalDelete")) {
                // $NON-NLS-1$
                return 120;
            } else if (source.equals("X_FKIntegrity")) {
                // $NON-NLS-1$
                return 121;
            } else if (source.equals("X_FKIntegrity_Override")) {
                // $NON-NLS-1$
                return 122;
            } else if (source.equals("X_ForeignKeyInfoFormat")) {
                // $NON-NLS-1$
                return 123;
            }
        }
    }
    return -1;
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDWhiteSpaceFacet(org.eclipse.xsd.XSDWhiteSpaceFacet) Element(org.w3c.dom.Element) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 3 with XSDMaxInclusiveFacet

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

the class MetadataRepository method setFieldData.

private void setFieldData(XSDSimpleTypeDefinition simpleSchemaType, MetadataExtensible field) {
    EList<XSDConstrainingFacet> facets = simpleSchemaType.getFacetContents();
    List<String> enumerationList = new ArrayList<String>();
    for (XSDConstrainingFacet currentFacet : facets) {
        if (currentFacet instanceof XSDMaxLengthFacet) {
            field.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDMaxLengthFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinLengthFacet) {
            // this is the minLengthFacet
            field.setData(MetadataRepository.DATA_MIN_LENGTH, String.valueOf(((XSDMinLengthFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDLengthFacet) {
            // this is the lengthFacet
            field.setData(MetadataRepository.DATA_LENGTH, String.valueOf(((XSDLengthFacet) currentFacet).getValue()));
        } else if (currentFacet instanceof XSDTotalDigitsFacet) {
            // this is the totalDigits
            field.setData(MetadataRepository.DATA_TOTAL_DIGITS, String.valueOf(((XSDTotalDigitsFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDFractionDigitsFacet) {
            // this is the fractionDigits
            field.setData(MetadataRepository.DATA_FRACTION_DIGITS, String.valueOf(((XSDFractionDigitsFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDPatternFacet) {
            // this is the patternFacet
            field.setData(MetadataRepository.PATTERN, String.valueOf(((XSDPatternFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMaxExclusiveFacet) {
            // this is the  maxExclusiveFacet
            field.setData(MetadataRepository.MAX_EXCLUSIVE, String.valueOf(((XSDMaxExclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinExclusiveFacet) {
            // this is the  minExclusiveFacet
            field.setData(MetadataRepository.MIN_EXCLUSIVE, String.valueOf(((XSDMinExclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMaxInclusiveFacet) {
            // this is the  maxInclusiveFacet
            field.setData(MetadataRepository.MAX_INCLUSIVE, String.valueOf(((XSDMaxInclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinInclusiveFacet) {
            // this is the  minInclusiveFacet
            field.setData(MetadataRepository.MIN_INCLUSIVE, String.valueOf(((XSDMinInclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDEnumerationFacet) {
            // this is the  enumeration
            enumerationList.add(String.valueOf(((XSDEnumerationFacet) currentFacet).getLexicalValue()));
        }
    }
    field.setData(MetadataRepository.ENUMERATION_LIST, enumerationList);
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) ArrayList(java.util.ArrayList) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet)

Example 4 with XSDMaxInclusiveFacet

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

the class XSDFacetSection method doHandleEvent.

protected void doHandleEvent(Event event) {
    super.doHandleEvent(event);
    Command command = null;
    boolean doUpdateMax = false, doUpdateMin = false;
    boolean doSetInput = false;
    String minValue = minLengthText.getText().trim();
    String maxValue = maxLengthText.getText().trim();
    XSDLengthFacet lengthFacet = xsdSimpleTypeDefinition.getLengthFacet();
    XSDMinLengthFacet minLengthFacet = xsdSimpleTypeDefinition.getMinLengthFacet();
    XSDMaxLengthFacet maxLengthFacet = xsdSimpleTypeDefinition.getMaxLengthFacet();
    XSDMinInclusiveFacet minInclusiveFacet = xsdSimpleTypeDefinition.getMinInclusiveFacet();
    XSDMinExclusiveFacet minExclusiveFacet = xsdSimpleTypeDefinition.getMinExclusiveFacet();
    XSDMaxInclusiveFacet maxInclusiveFacet = xsdSimpleTypeDefinition.getMaxInclusiveFacet();
    XSDMaxExclusiveFacet maxExclusiveFacet = xsdSimpleTypeDefinition.getMaxExclusiveFacet();
    String currentMinInclusive = null, currentMinExclusive = null, currentMaxInclusive = null, currentMaxExclusive = null;
    if (minInclusiveFacet != null) {
        currentMinInclusive = minInclusiveFacet.getLexicalValue();
    }
    if (minExclusiveFacet != null) {
        currentMinExclusive = minExclusiveFacet.getLexicalValue();
    }
    if (maxInclusiveFacet != null) {
        currentMaxInclusive = maxInclusiveFacet.getLexicalValue();
    }
    if (maxExclusiveFacet != null) {
        currentMaxExclusive = maxExclusiveFacet.getLexicalValue();
    }
    String currentLength = null, currentMin = null, currentMax = null;
    if (lengthFacet != null) {
        currentLength = lengthFacet.getLexicalValue();
    }
    if (minLengthFacet != null) {
        currentMin = minLengthFacet.getLexicalValue();
    }
    if (maxLengthFacet != null) {
        currentMax = maxLengthFacet.getLexicalValue();
    }
    if (event.widget == minLengthText) {
        try {
            if (minValue.length() > 0) {
                if (!isNumericBaseType) {
                    Number big = new BigInteger(minValue);
                    big.toString();
                    if (minLengthFacet != null) {
                        if (minValue.equals(currentMin) || minValue.equals(currentLength))
                            return;
                    } else {
                        if (maxValue != null && minValue.equals(maxValue) && lengthFacet != null) {
                            return;
                        }
                    }
                } else {
                    if (// $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("double").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition.getBaseType())) {
                        BigDecimal bigDecimal = new BigDecimal(minValue);
                        bigDecimal.toString();
                        if ((currentMinInclusive != null && minValue.equals(currentMinInclusive)) || (currentMinExclusive != null && minValue.equals(currentMinExclusive))) {
                            return;
                        }
                    } else {
                        Number big = new BigInteger(minValue);
                        big.toString();
                    }
                    minimumInclusiveCheckbox.setEnabled(true);
                }
            } else {
                if (!isNumericBaseType) {
                    if (currentMin == null && currentLength == null)
                        return;
                } else {
                    if (currentMinInclusive == null && minimumInclusiveCheckbox.getSelection()) {
                        return;
                    } else if (currentMinExclusive == null && !minimumInclusiveCheckbox.getSelection()) {
                        return;
                    }
                }
                minimumInclusiveCheckbox.setEnabled(false);
                minValue = null;
            }
            doUpdateMin = true;
        } catch (NumberFormatException e) {
            // TODO show error message
            doUpdateMin = false;
        }
    }
    if (event.widget == maxLengthText) {
        try {
            if (maxValue.length() > 0) {
                if (!isNumericBaseType) {
                    Number big = new BigInteger(maxValue);
                    big.toString();
                    if (maxLengthFacet != null) {
                        if (maxValue.equals(currentMax) || maxValue.equals(currentLength))
                            return;
                    } else {
                        if (minValue != null && maxValue.equals(minValue) && lengthFacet != null) {
                            return;
                        }
                    }
                } else {
                    if (// $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("double").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition.getBaseType())) {
                        BigDecimal bigDecimal = new BigDecimal(maxValue);
                        bigDecimal.toString();
                    } else {
                        Number big = new BigInteger(maxValue);
                        big.toString();
                    }
                    maximumInclusiveCheckbox.setEnabled(true);
                }
            } else {
                if (!isNumericBaseType) {
                    if (currentMax == null && currentLength == null)
                        return;
                } else {
                    if (currentMaxInclusive == null && maximumInclusiveCheckbox.getSelection()) {
                        return;
                    } else if (currentMaxExclusive == null && !maximumInclusiveCheckbox.getSelection()) {
                        return;
                    }
                    maximumInclusiveCheckbox.setEnabled(false);
                }
                maxValue = null;
            }
            doUpdateMax = true;
        } catch (NumberFormatException e) {
            doUpdateMax = false;
        // TODO show error message
        }
    }
    if (XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace()) && (doUpdateMax || doUpdateMin)) {
        XSDSimpleTypeDefinition anonymousSimpleType = null;
        CompoundCommand compoundCommand = new CompoundCommand();
        ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = null;
        if (input instanceof XSDFeature) {
            anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType((XSDFeature) input, xsdSimpleTypeDefinition);
            if (anonymousSimpleType == null) {
                anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
                anonymousSimpleType.setBaseTypeDefinition(xsdSimpleTypeDefinition);
                changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CONSTRAIN_LENGTH, (XSDFeature) input);
                changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType);
                compoundCommand.add(changeToAnonymousCommand);
                doSetInput = true;
            }
            if (!isNumericBaseType) {
                // $NON-NLS-1$
                UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", anonymousSimpleType);
                if (doUpdateMax) {
                    updateCommand.setMax(maxValue);
                }
                if (doUpdateMin) {
                    updateCommand.setMin(minValue);
                }
                compoundCommand.add(updateCommand);
            } else {
                UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, anonymousSimpleType, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
                if (doUpdateMax) {
                    updateCommand.setMax(maxValue);
                }
                if (doUpdateMin) {
                    updateCommand.setMin(minValue);
                }
                compoundCommand.add(updateCommand);
            }
            command = compoundCommand;
            getCommandStack().execute(command);
        } else if (input instanceof XSDSimpleTypeDefinition) {
            if (!isNumericBaseType) {
                // $NON-NLS-1$
                UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", xsdSimpleTypeDefinition);
                if (doUpdateMax) {
                    updateCommand.setMax(maxValue);
                }
                if (doUpdateMin) {
                    updateCommand.setMin(minValue);
                }
                command = updateCommand;
            } else {
                UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
                if (doUpdateMax) {
                    updateCommand.setMax(maxValue);
                }
                if (doUpdateMin) {
                    updateCommand.setMin(minValue);
                }
                command = updateCommand;
            }
            getCommandStack().execute(command);
        }
    } else {
        if (!isNumericBaseType) {
            // $NON-NLS-1$
            UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", xsdSimpleTypeDefinition);
            if (doUpdateMax) {
                updateCommand.setMax(maxValue);
            }
            if (doUpdateMin) {
                updateCommand.setMin(minValue);
            }
            getCommandStack().execute(updateCommand);
        } else {
            UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
            if (doUpdateMax) {
                updateCommand.setMax(maxValue);
            }
            if (doUpdateMin) {
                updateCommand.setMin(minValue);
            }
            getCommandStack().execute(updateCommand);
        }
    }
    refresh();
    if (doSetInput)
        setInput(getPart(), getSelection());
}
Also used : UpdateStringLengthFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateStringLengthFacetCommand) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) UpdateNumericBoundsFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNumericBoundsFacetCommand) BigDecimal(java.math.BigDecimal) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDFeature(org.eclipse.xsd.XSDFeature) UpdateStringLengthFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateStringLengthFacetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeToLocalSimpleTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand) UpdateNumericBoundsFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNumericBoundsFacetCommand) UpdateXSDWhiteSpaceFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateXSDWhiteSpaceFacetCommand) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) ChangeToLocalSimpleTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand) BigInteger(java.math.BigInteger) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet)

Example 5 with XSDMaxInclusiveFacet

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

the class XSDEditFacetAction method editMaxInclusive.

private void editMaxInclusive() {
    XSDMaxInclusiveFacet currentValue = std.getMaxInclusiveFacet();
    String stringValue = null;
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    boolean isDateType = true;
    dialog = getInputDialog4Date(Messages.XSDEditFacetAction_DialogTitle8, Messages.XSDEditFacetAction_DialogTitle8Tip, stringValue);
    if (dialog == null) {
        isDateType = false;
        dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle8, Messages.XSDEditFacetAction_DialogTitle8Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
        IInputValidator() {

            public String isValid(String newText) {
                if (newText.trim().isEmpty()) {
                    return null;
                }
                return isValidBoundaryNumber(std, newText);
            }
        });
    }
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    String input = ((InputDialog) dialog).getValue();
    if (!input.trim().isEmpty()) {
        XSDMaxInclusiveFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMaxInclusiveFacet();
        if (isDateType) {
            f.setLexicalValue(input.trim());
            std.getFacetContents().add(f);
        } else if (Double.parseDouble(input) >= 0) {
            // $NON-NLS-1$
            f.setLexicalValue("" + getValidBoundaryNumber(std, input));
            std.getFacetContents().add(f);
        }
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

XSDMaxInclusiveFacet (org.eclipse.xsd.XSDMaxInclusiveFacet)5 XSDLengthFacet (org.eclipse.xsd.XSDLengthFacet)4 XSDMaxExclusiveFacet (org.eclipse.xsd.XSDMaxExclusiveFacet)4 XSDMaxLengthFacet (org.eclipse.xsd.XSDMaxLengthFacet)4 XSDMinExclusiveFacet (org.eclipse.xsd.XSDMinExclusiveFacet)4 XSDMinInclusiveFacet (org.eclipse.xsd.XSDMinInclusiveFacet)4 XSDMinLengthFacet (org.eclipse.xsd.XSDMinLengthFacet)4 XSDEnumerationFacet (org.eclipse.xsd.XSDEnumerationFacet)3 XSDFractionDigitsFacet (org.eclipse.xsd.XSDFractionDigitsFacet)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 XSDTotalDigitsFacet (org.eclipse.xsd.XSDTotalDigitsFacet)3 ArrayList (java.util.ArrayList)2 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)2 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)2 XSDParticle (org.eclipse.xsd.XSDParticle)2 XSDPatternFacet (org.eclipse.xsd.XSDPatternFacet)2 XSDWhiteSpaceFacet (org.eclipse.xsd.XSDWhiteSpaceFacet)2 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1