Search in sources :

Example 46 with XSDElementDeclaration

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

the class XSDPasteConceptAction method addAnnotationForXSDElementDeclaration.

public void addAnnotationForXSDElementDeclaration(XSDElementDeclaration fromElem, XSDElementDeclaration toElem) {
    if (fromElem.getAnnotation() != null) {
        // toElem.setAnnotation(cloneXSDAnnotation(toElem.getAnnotation(),fromElem.getAnnotation()));
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(toElem);
        addAnnotion(struc, fromElem.getAnnotation());
    }
    if (fromElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) fromElem.getTypeDefinition()).getContent();
        // in this situation,if not copy the complex type, the type change to simple type
        if (this.typeList.containsKey(toElem.getTypeDefinition().getName())) {
            this.copyTypeSet.add(this.typeList.get(toElem.getTypeDefinition().getName()));
        }
        if (toElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent tocomplexType = ((XSDComplexTypeDefinition) toElem.getTypeDefinition()).getContent();
            if (fromcomplexType instanceof XSDParticle) {
                XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
                XSDParticle toxsdParticle = (XSDParticle) tocomplexType;
                if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {
                    XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
                    XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());
                    EList<XSDParticle> fromlist = frommodelGroup.getContents();
                    EList<XSDParticle> tolist = tomodelGroup.getContents();
                    Iterator<XSDParticle> toIt = tolist.iterator();
                    for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
                        XSDParticle toel = toIt.next();
                        XSDTerm totm = toel.getTerm();
                        XSDTerm fromtm = fromel.getTerm();
                        if (fromtm instanceof XSDElementDeclaration) {
                            XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
                            if (fromannotation != null) {
                                // ((XSDElementDeclaration)
                                // totm).setAnnotation(cloneXSDAnnotation(((XSDElementDeclaration)
                                // totm).getAnnotation(),fromannotation));
                                XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                                if (((XSDElementDeclaration) totm).getType() != null) {
                                    addAnnotion(struc, fromannotation);
                                } else {
                                    MessageDialog.openInformation(page.getSite().getShell(), Messages.Warning, Messages.bind(Messages.XSDPasteConceptAction_Information, fromElem.getName()));
                                    return;
                                }
                            }
                            if (((XSDElementDeclaration) totm).getType() != null && this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
                                this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
                            }
                            addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
                        }
                    }
                }
            }
        }
    } else {
        String simpleType = fromElem.getTypeDefinition().getName();
        if (this.typeList.containsKey(simpleType)) {
            this.copyTypeSet.add(fromElem.getTypeDefinition());
        }
    }
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 47 with XSDElementDeclaration

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

the class XSDPasteConceptAction method isExist.

public boolean isExist(XSDModelGroup toGroup, XSDParticle particle) {
    for (XSDParticle paticleContent : toGroup.getContents()) {
        if (paticleContent.getTerm() instanceof XSDElementDeclaration) {
            String contentName = ((XSDElementDeclaration) paticleContent.getTerm()).getName();
            String copyParticleName = ((XSDElementDeclaration) particle.getTerm()).getName();
            if (contentName.equals(copyParticleName)) {
                return true;
            }
        }
    }
    return false;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 48 with XSDElementDeclaration

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

the class XSDNewParticleFromParticleAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        selParticle = (XSDParticle) selection.getFirstElement();
        if (!(selParticle.getContainer() instanceof XSDModelGroup))
            return Status.CANCEL_STATUS;
        ;
        XSDModelGroup group = (XSDModelGroup) selParticle.getContainer();
        // get position of the selected particle in the container
        int index = 0;
        int i = 0;
        for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
            XSDParticle p = (XSDParticle) iter.next();
            if (p.equals(selParticle)) {
                index = i;
                break;
            }
            i++;
        }
        EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations();
        List<String> elementDeclarations = new ArrayList<String>();
        for (Iterator<XSDElementDeclaration> iter = eDecls.iterator(); iter.hasNext(); ) {
            XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
            if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE))
                continue;
            // $NON-NLS-1$//$NON-NLS-2$
            elementDeclarations.add(d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));
        }
        // $NON-NLS-1$
        elementDeclarations.add("");
        dialog = new BusinessElementInputDialog(this, page.getSite().getShell(), Messages._AddANewBusinessElement, null, null, elementDeclarations, 0, 1, true, false);
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        XSDElementDeclaration elem = (XSDElementDeclaration) selParticle.getContent();
        if (Util.changeElementTypeToSequence(elem, maxOccurs) == Status.CANCEL_STATUS) {
            return Status.CANCEL_STATUS;
        }
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        XSDElementDeclaration decl = factory.createXSDElementDeclaration();
        decl.setName(this.elementName);
        if (!refName.equals("")) {
            // $NON-NLS-1$
            XSDElementDeclaration ref = Util.findReference(refName, schema);
            if (ref != null) {
                decl.setResolvedElementDeclaration(ref);
            }
        } else {
            decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), simpleTypeName));
        }
        XSDParticle particle = factory.createXSDParticle();
        particle.setContent(decl);
        particle.setMinOccurs(this.minOccurs);
        if (maxOccurs > -1) {
            particle.setMaxOccurs(this.maxOccurs);
        } else {
            particle.setMaxOccurs(this.maxOccurs);
            group.getContents().add(group.getContents().size(), particle);
            group.updateElement();
            if (// $NON-NLS-1$
            particle.getElement().getAttributeNode("maxOccurs") != null)
                // $NON-NLS-1$//$NON-NLS-2$
                particle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
            else {
                // $NON-NLS-1$//$NON-NLS-2$
                particle.getElement().setAttribute("maxOccurs", "unbounded");
            }
        }
        if (maxOccurs > -1) {
            group.getContents().add(group.getContents().size(), particle);
            group.updateElement();
        }
        if (dialog.isInherit()) {
            XSDTerm totm = particle.getTerm();
            XSDElementDeclaration concept = null;
            if (Util.getParent(selParticle) instanceof XSDElementDeclaration)
                concept = (XSDElementDeclaration) Util.getParent(selParticle);
            else if (Util.getParent(selParticle) instanceof XSDComplexTypeDefinition) {
                if (selParticle instanceof XSDParticle)
                    concept = (XSDElementDeclaration) ((XSDParticle) selParticle).getContent();
                else if (selParticle instanceof XSDElementDeclaration)
                    concept = (XSDElementDeclaration) selParticle;
            }
            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);
            }
        }
        page.refresh();
        page.getTreeViewer().setSelection(new StructuredSelection(particle), true);
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._ErrorCreatBusinessElement, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) BusinessElementInputDialog(com.amalto.workbench.dialogs.BusinessElementInputDialog) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 49 with XSDElementDeclaration

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

the class ElementWrapperCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    try {
        String originalName = getCommitedObj().getSourceName();
        XSDElementDeclaration decl = getCommitedObj().getSourceXSDContent();
        XSDElementDeclaration ref = null;
        if (decl.isElementDeclarationReference()) {
            ref = decl.getResolvedElementDeclaration();
        }
        XSDAnnotationsStructure struct = new XSDAnnotationsStructure(getCommitedObj().getSourceElement());
        // remove first
        // struct.setAutoExpand(null);
        struct.setAutoExpand(String.valueOf(getCommitedObj().isAutoExpand()));
        // update validation rule
        Set<String> paths = new HashSet<String>();
        DataModelMainPage page = getPage();
        Util.collectElementPaths((IStructuredContentProvider) page.getElementsViewer().getContentProvider(), page.getSite(), getCommitedObj().getSourceElement(), paths, null);
        XSDElementDeclaration newRef = Util.findReference(getCommitedObj().getNewReference(), getCommitedObj().getSchema());
        XSDIdentityConstraintDefinition identify = null;
        XSDXPathDefinition keyPath = null;
        List<Object> keyInfo = Util.getKeyInfo(getCommitedObj().getSourceXSDContent());
        if (keyInfo != null && keyInfo.size() > 0) {
            identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
            keyPath = (XSDXPathDefinition) keyInfo.get(1);
            identify.getFields().remove(keyPath);
        }
        getCommitedObj().getSourceXSDContent().setName(// $NON-NLS-1$
        "".equals(getCommitedObj().getNewName()) ? null : getCommitedObj().getNewName());
        if (keyPath != null) {
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDXPathDefinition field = factory.createXSDXPathDefinition();
            field.setVariety(keyPath.getVariety());
            field.setValue(getCommitedObj().getNewName());
            identify.getFields().add(field);
        }
        if (newRef != null) {
            decl.setResolvedElementDeclaration(newRef);
            decl.setTypeDefinition(null);
            Element elem = decl.getElement();
            if (elem.getAttributes().getNamedItem("type") != null) {
                // $NON-NLS-1$
                elem.getAttributes().removeNamedItem("type");
            }
            decl.updateElement();
        } else if (ref != null) {
            XSDElementDeclaration sourceXSDContent = getCommitedObj().getSourceXSDContent();
            sourceXSDContent.setTypeDefinition(getCommitedObj().getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, // $NON-NLS-1$
            "string"));
            sourceXSDContent.setResolvedElementDeclaration(sourceXSDContent);
        // XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        // XSDElementDeclaration newD = (XSDElementDeclaration) factory.createXSDElementDeclaration();
        // newD.setName(getCommitedObj().getNewName());
        // newD.updateElement();
        // XSDSimpleTypeDefinition stringType = getCommitedObj().getSchema().getSchemaForSchema()
        // .resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string");
        // 
        // newD.setTypeDefinition(stringType);
        // if (getCommitedObj().getSourceElement().getContainer() instanceof XSDModelGroup) {
        // XSDModelGroup group = ((XSDModelGroup) getCommitedObj().getSourceElement().getContainer());
        // ((XSDModelGroup) getCommitedObj().getSourceElement().getContainer()).getContents().remove(
        // getCommitedObj().getSourceElement());
        // getCommitedObj().setSourceElement(factory.createXSDParticle());
        // getCommitedObj().getSourceElement().setContent(newD);
        // group.getContents().add(getCommitedObj().getSourceElement());
        // }
        }
        int newMaxOcur = getCommitedObj().getNewMaxOcur();
        if (Util.changeElementTypeToSequence(decl, newMaxOcur) == Status.CANCEL_STATUS) {
            return false;
        }
        int newMinOcur = getCommitedObj().getNewMinOcur();
        getCommitedObj().getSourceElement().setMinOccurs(newMinOcur);
        if (newMaxOcur == -1 || (newMaxOcur == 0 & newMinOcur == 0)) {
            if (!"unbounded".equals(getCommitedObj().getSourceElement().getElement().getAttribute("maxOccurs"))) {
                // $NON-NLS-1$//$NON-NLS-2$
                getCommitedObj().getSourceElement().getElement().setAttribute("maxOccurs", "unbounded");
            }
        } else {
            getCommitedObj().getSourceElement().setMaxOccurs(newMaxOcur);
        }
        getCommitedObj().getSourceElement().updateElement();
        updateReference(originalName);
        if (elementExAdapter != null) {
            elementExAdapter.renameElement(getCommitedObj().getSchema(), paths, getCommitedObj().getNewName());
        }
        if (mapinfoExAdapter != null) {
            mapinfoExAdapter.renameElementMapinfo(paths, decl.getName());
        }
    } catch (Exception e) {
        throw new CommitException(e.getMessage(), e);
    }
    return true;
}
Also used : CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDFactory(org.eclipse.xsd.XSDFactory) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) CommitValidationException(com.amalto.workbench.detailtabs.exception.CommitValidationException) CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) HashSet(java.util.HashSet)

Example 50 with XSDElementDeclaration

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

the class ElementFKInfosSection method getXSDSchemaChildren.

Object[] getXSDSchemaChildren(XSDSchema schema) {
    List<XSDElementDeclaration> declarations = new ArrayList<XSDElementDeclaration>();
    EList<XSDElementDeclaration> elementDeclarations = schema.getElementDeclarations();
    for (XSDElementDeclaration declaration : elementDeclarations) {
        if (declaration.eContainer().equals(schema)) {
            declarations.add(declaration);
        }
    }
    Object[] schemaChildren = Util.filterOutDuplicatedElems(declarations.toArray(new XSDNamedComponent[declarations.size()]));
    return schemaChildren;
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList)

Aggregations

XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)222 XSDParticle (org.eclipse.xsd.XSDParticle)103 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)87 ArrayList (java.util.ArrayList)60 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)57 XSDSchema (org.eclipse.xsd.XSDSchema)48 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)47 Test (org.junit.Test)44 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)38 XSDFactory (org.eclipse.xsd.XSDFactory)37 XSDTerm (org.eclipse.xsd.XSDTerm)32 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)30 EList (org.eclipse.emf.common.util.EList)29 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)28 Iterator (java.util.Iterator)27 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)21 Element (org.w3c.dom.Element)21