Search in sources :

Example 1 with XSDAnnotation

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

the class AnnotationOrderedListsDialog method getConceptElements.

private List<String> getConceptElements() {
    DataModelMainPage page = parentPage;
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    List<String> childNames = new ArrayList<String>();
    XSDElementDeclaration decl = null;
    if (selection.getFirstElement() instanceof XSDElementDeclaration) {
        decl = (XSDElementDeclaration) selection.getFirstElement();
    // childNames = Util.getChildElementNames(decl.getElement());
    } else if (selection.getFirstElement() instanceof Element) {
        TreePath tPath = ((TreeSelection) selection).getPaths()[0];
        XSDComponent xSDCom = null;
        for (int i = 0; i < tPath.getSegmentCount(); i++) {
            if (tPath.getSegment(i) instanceof XSDAnnotation) {
                xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                break;
            }
        }
        decl = (XSDElementDeclaration) xSDCom.getContainer();
    }
    try {
        childNames = Util.getChildElementNames(decl.getName(), decl);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return childNames;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 2 with XSDAnnotation

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

the class XSDAnnotationsStructure method inputChanged.

protected void inputChanged(Object component) {
    if (component instanceof XSDAnnotation) {
        annotation = (XSDAnnotation) component;
        if (annotation.getContainer() instanceof XSDElementDeclaration) {
            declaration = (XSDElementDeclaration) annotation.getContainer();
        } else if (annotation.getContainer() instanceof XSDComplexTypeDefinition) {
            complexTypeDef = (XSDComplexTypeDefinition) annotation.getContainer();
        }
    }
    if (component instanceof XSDElementDeclaration) {
        declaration = (XSDElementDeclaration) component;
        if (declaration.getAnnotation() == null) {
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            annotation = factory.createXSDAnnotation();
        } else {
            annotation = declaration.getAnnotation();
        }
    }
    if (component instanceof XSDComplexTypeDefinition) {
        complexTypeDef = (XSDComplexTypeDefinition) component;
        componet = complexTypeDef;
        if (complexTypeDef.getAnnotation() == null) {
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            annotation = factory.createXSDAnnotation();
        } else {
            annotation = complexTypeDef.getAnnotation();
        }
    }
    if (component instanceof XSDModelGroup) {
        XSDModelGroup group = (XSDModelGroup) component;
        if (group.getContainer().getContainer() instanceof XSDComplexTypeDefinition) {
            complexTypeDef = (XSDComplexTypeDefinition) group.getContainer().getContainer();
            if (complexTypeDef.getAnnotation() == null) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                annotation = factory.createXSDAnnotation();
            } else {
                annotation = complexTypeDef.getAnnotation();
            }
        }
    }
    if (component instanceof XSDParticle) {
        XSDTerm term = ((XSDParticle) component).getTerm();
        if (term instanceof XSDElementDeclaration) {
            declaration = (XSDElementDeclaration) term;
            if (declaration.getAnnotation() == null) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                annotation = factory.createXSDAnnotation();
            } else {
                annotation = declaration.getAnnotation();
            }
        }
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 3 with XSDAnnotation

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

the class XSDParser 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 xsd) throws Exception {
    // XSDFactory xsdFactory = XSDFactory.eINSTANCE;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilderFactory.setValidating(false);
    InputSource source = new InputSource(new StringReader(xsd));
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(source);
    XSDSchema xsdSchema = XSDSchemaImpl.createSchema(document.getDocumentElement());
    // 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);
         * 
         * XSDResourceImpl res = new XSDResourceImpl();
         * 
         * 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());
    for (Iterator iter = all.iterator(); iter.hasNext(); ) {
        XSDElementDeclaration concept = (XSDElementDeclaration) iter.next();
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("CONCEPT: " + concept.getName() + "-- " + concept.getContainer().getClass().getName());
        // name of the concept in English
        XSDAnnotation annotation = concept.getAnnotation();
        if (annotation != null) {
            EList list = annotation.getApplicationInformation();
            for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
                Element appinfo = (Element) iterator.next();
                // $NON-NLS-1$
                String language = appinfo.getAttribute("source");
                if ("EN".equals(language.toUpperCase())) {
                    // $NON-NLS-1$
                    if (appinfo.getFirstChild() != null)
                        // $NON-NLS-1$
                        System.out.println("     " + appinfo.getFirstChild().getNodeValue());
                }
            }
        }
        // children
        XSDTypeDefinition typedef = concept.getTypeDefinition();
        if (typedef instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent xsdContent = ((XSDComplexTypeDefinition) typedef).getContent();
            XSDParticle xsdParticle = (XSDParticle) xsdContent;
            // $NON-NLS-1$
            String ident = "    ";
            processParticle(xsdParticle, ident);
        }
    }
// for elements
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) EList(org.eclipse.emf.common.util.EList) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 4 with XSDAnnotation

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

the class XSDAddComplexTypeElementAction method createParticle.

private XSDParticle createParticle() {
    XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
    XSDElementDeclaration resultElementDeclaration = factory.createXSDElementDeclaration();
    resultElementDeclaration.setName(elementName);
    resultElementDeclaration.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), defaultTypeName));
    XSDParticle resultParticle = factory.createXSDParticle();
    resultParticle.setContent(resultElementDeclaration);
    resultParticle.setMinOccurs(this.minOccurs);
    XSDModelGroup group = modelGroup;
    if (maxOccurs > -1) {
        resultParticle.setMaxOccurs(this.maxOccurs);
        group.getContents().add(group.getContents().size(), resultParticle);
        group.updateElement();
    } else {
        resultParticle.setMaxOccurs(this.maxOccurs);
        group.getContents().add(group.getContents().size(), resultParticle);
        group.updateElement();
        if (resultParticle.getElement().getAttributeNode("maxOccurs") != null) {
            // $NON-NLS-1$
            // $NON-NLS-1$//$NON-NLS-2$
            resultParticle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
        } else {
            // $NON-NLS-1$//$NON-NLS-2$
            resultParticle.getElement().setAttribute("maxOccurs", "unbounded");
        }
    }
    Util.changeElementTypeToSequence(resultElementDeclaration, maxOccurs);
    if (dialogR.isInherit()) {
        XSDTerm totm = resultParticle.getTerm();
        XSDElementDeclaration concept = null;
        Object parent = Util.getParent(resultParticle);
        if (parent instanceof XSDElementDeclaration) {
            concept = (XSDElementDeclaration) parent;
        } else {
            concept = (XSDElementDeclaration) resultParticle.getContent();
        }
        XSDAnnotation fromannotation = null;
        if (concept != null) {
            fromannotation = concept.getAnnotation();
        }
        if (fromannotation != null) {
            XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
            if (((XSDElementDeclaration) totm).getType() != null) {
                addAnnotion(struc, fromannotation);
            }
        }
    }
    return resultParticle;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 5 with XSDAnnotation

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

the class XSDAnnotationLookupFieldsAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation)
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        } else
            xSDCom = (XSDComponent) selection.getFirstElement();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        struc.setXSDSchema(schema);
        // (XSDComponent) selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDAnnotationLookupFieldsAction_ExceptionInfo, xSDCom.getClass().getName()));
        }
        dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getLookupFields().values()), new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                dlg.close();
            }
        }, page.getSite().getShell(), Messages.XSDAnnotationLookupFieldsAction_SetLookupFields, Messages.XSDAnnotationLookupFieldsAction_LookupFields, page, AnnotationOrderedListsDialog.AnnotationLookupField_ActionType, null);
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        struc.setAccessRole(dlg.getXPaths(), false, (IStructuredContentProvider) page.getTreeViewer().getContentProvider(), // $NON-NLS-1$
        "X_Lookup_Field");
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDAnnotationLookupFieldsAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) AnnotationOrderedListsDialog(com.amalto.workbench.dialogs.AnnotationOrderedListsDialog) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

XSDAnnotation (org.eclipse.xsd.XSDAnnotation)55 Element (org.w3c.dom.Element)33 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)28 XSDParticle (org.eclipse.xsd.XSDParticle)21 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)20 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)20 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)17 ArrayList (java.util.ArrayList)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 XSDTerm (org.eclipse.xsd.XSDTerm)16 TreePath (org.eclipse.jface.viewers.TreePath)13 TreeSelection (org.eclipse.jface.viewers.TreeSelection)13 XSDComponent (org.eclipse.xsd.XSDComponent)13 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)12 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)10 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)10 EList (org.eclipse.emf.common.util.EList)9 XSDSchema (org.eclipse.xsd.XSDSchema)8 Iterator (java.util.Iterator)7