Search in sources :

Example 6 with XSDSimpleTypeDefinition

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

the class Util method isUUID.

public static boolean isUUID(XSDElementDeclaration decl) {
    XSDTypeDefinition typeDefinition = decl.getTypeDefinition();
    if (null == typeDefinition) {
        return false;
    }
    String type = typeDefinition.getName();
    if (type == null) {
        type = typeDefinition.getBaseType().getName();
    }
    // set enum
    if (typeDefinition instanceof XSDSimpleTypeDefinition && Util.isCustomrType(decl.getSchema(), type)) {
        XSDSimpleTypeDefinition typedef = (XSDSimpleTypeDefinition) typeDefinition;
        if (typedef.getBaseTypeDefinition() != null && typedef.getEnumerationFacets().size() > 0) {
            // $NON-NLS-1$
            type = "enum";
        }
    }
    if ("UUID".equals(type) || "AUTO_INCREMENT".equals(type)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        return true;
    }
    return false;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 7 with XSDSimpleTypeDefinition

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

the class XSDDeleteConceptWrapAction method doAction.

@Override
public IStatus doAction() {
    List<IStatus> results = new ArrayList<IStatus>();
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (delObjs.isEmpty()) {
            return Status.CANCEL_STATUS;
        } else {
            boolean sameType = checkInSameClassType(delObjs.toArray(), delObjs.get(0).getClass());
            String deleteLabel = Messages.DelLabel1;
            String elemDesc = ((Action) clsAction.get(delObjs.get(0).getClass())).getText();
            // $NON-NLS-1$
            int backPos = elemDesc.indexOf(" ");
            if (delObjs.size() > 1) {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.DelLabel2 + delObjs.size() + Messages.DelLabel2A + (!sameType ? Messages.DelLabel2B : elemDesc.substring(backPos + 1));
                if (deleteLabel.endsWith("y")) {
                    // $NON-NLS-1$
                    deleteLabel = deleteLabel.substring(0, deleteLabel.length() - 1) + Messages.DelLabel3;
                } else {
                    deleteLabel = deleteLabel + Messages.XSDDeleteXX_DelLabel4;
                }
            } else {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.XSDDeleteXX_DelLabel5 + (!sameType ? Messages.XSDDeleteXX_DelLabel5A : elemDesc.substring(backPos + 1));
            }
            if (!MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteXX_DialogTitle, deleteLabel)) {
                return Status.CANCEL_STATUS;
            }
        }
        for (Iterator iterator = delObjs.iterator(); iterator.hasNext(); ) {
            Object toDel = iterator.next();
            UndoAction delExecute = null;
            boolean isElem = true;
            if (toDel instanceof XSDElementDeclaration) {
                XSDElementDeclaration decl = (XSDElementDeclaration) toDel;
                EList l = decl.getIdentityConstraintDefinitions();
                for (Iterator iter = l.iterator(); iter.hasNext(); ) {
                    XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
                    if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                        isElem = false;
                        break;
                    }
                }
            }
            if (toDel instanceof XSDXPathDefinition) {
                XSDXPathDefinition xpath = (XSDXPathDefinition) toDel;
                if (!xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
                    continue;
                }
            }
            delExecute = clsAction.get(toDel.getClass());
            if (isElem && toDel instanceof XSDElementDeclaration) {
                delExecute = clsAction.get(null);
            }
            if (delExecute instanceof XSDDeleteConceptAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteConceptAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteElementAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteElementAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteParticleAction && toDel instanceof XSDParticle) {
                ((XSDDeleteParticleAction) delExecute).setXSDTODel((XSDParticle) toDel);
            } else if (delExecute instanceof XSDDeleteXPathAction && toDel instanceof XSDXPathDefinition) {
                ((XSDDeleteXPathAction) delExecute).setXSDTODel((XSDXPathDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteIdentityConstraintAction && toDel instanceof XSDIdentityConstraintDefinition) {
                ((XSDDeleteIdentityConstraintAction) delExecute).setXSDTODel((XSDIdentityConstraintDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDComplexTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDComplexTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDSimpleTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDSimpleTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeUse) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttributeUse((XSDAttributeUse) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeDeclaration) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttribute((XSDAttributeDeclaration) toDel);
            } else {
                return Status.CANCEL_STATUS;
            }
            results.add(delExecute.execute());
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage()));
        return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
    }
    return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Action(org.eclipse.jface.action.Action) XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Iterator(java.util.Iterator) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 8 with XSDSimpleTypeDefinition

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

the class XSDDeleteTypeDefinition method doAction.

@Override
public IStatus doAction() {
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    ArrayList<Object> objList = new ArrayList<Object>();
    Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getSchemaContentProvider());
    Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getTypeContentProvider());
    XSDTypeDefinition usingElement = findUsingElement(selection, objList);
    if (usingElement != null) {
        String message = getInfoDialogMessage(usingElement);
        MessageDialog.openInformation(page.getSite().getShell(), Messages.XSDDeleteTypeDefinition_ConfirmDel, message);
        return Status.CANCEL_STATUS;
    }
    // edit by ymli; fix the bug:0012228. Made the multiple types can be deleted.
    for (Iterator<XSDTypeDefinition> iter = selection.iterator(); iter.hasNext(); ) {
        XSDTypeDefinition type = iter.next();
        if (type instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) type;
            if (xsdSimpType != null) {
                simpleType = xsdSimpType;
            }
            schema.getContents().remove(simpleType);
        } else {
            XSDComplexTypeDefinition complxType = (XSDComplexTypeDefinition) type;
            if (xsdCmpexType != null) {
                complxType = xsdCmpexType;
            }
            schema.getContents().remove(complxType);
        }
    }
    xsdSimpType = null;
    xsdCmpexType = null;
    page.refresh();
    page.markDirty();
    return Status.OK_STATUS;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 9 with XSDSimpleTypeDefinition

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

the class XSDEditParticleAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        String originalXpath = getOriginalXpath();
        // $NON-NLS-1$
        String entity = originalXpath.substring(0, originalXpath.indexOf("/"));
        selParticle = (XSDParticle) selection.getFirstElement();
        if (!(selParticle.getTerm() instanceof XSDElementDeclaration)) {
            return Status.CANCEL_STATUS;
        }
        XSDElementDeclaration decl = (XSDElementDeclaration) selParticle.getContent();
        XSDElementDeclaration ref = null;
        if (decl.isElementDeclarationReference()) {
            // it is a ref
            ref = decl.getResolvedElementDeclaration();
        }
        EList eDecls = decl.getSchema().getElementDeclarations();
        ArrayList<String> elementDeclarations = new ArrayList<String>();
        for (Iterator iter = eDecls.iterator(); iter.hasNext(); ) {
            XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
            if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) {
                continue;
            }
            if (!d.getQName().equals(entity)) {
                elementDeclarations.add(// $NON-NLS-1$ //$NON-NLS-2$
                d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));
            }
        }
        // $NON-NLS-1$
        elementDeclarations.add("");
        XSDIdentityConstraintDefinition identify = null;
        XSDXPathDefinition keyPath = null;
        List<Object> keyInfo = Util.getKeyInfo(decl);
        boolean isPK = false;
        if (keyInfo != null && keyInfo.size() > 0) {
            identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
            keyPath = (XSDXPathDefinition) keyInfo.get(1);
            isPK = true;
        }
        initEleName = decl.getName();
        dialog = new BusinessElementInputDialog(this, page.getSite().getShell(), Messages.XSDEditParticleAction_InputDialogTitle, decl.getName(), ref == null ? null : ref.getQName(), elementDeclarations, selParticle.getMinOccurs(), selParticle.getMaxOccurs(), false, isPK);
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        if (keyPath != null) {
            identify.getFields().remove(keyPath);
        }
        // find reference
        XSDElementDeclaration newRef = null;
        if (!"".equals(refName.trim())) {
            // $NON-NLS-1$
            newRef = Util.findReference(refName, schema);
            if (newRef == null) {
                MessageDialog.openError(this.page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditParticleAction_ErrorMsg, refName));
                return Status.CANCEL_STATUS;
            }
        }
        // ref
        // update validation rule
        Set<String> paths = new HashSet<String>();
        Util.collectElementPaths((IStructuredContentProvider) page.getElementsViewer().getContentProvider(), page.getSite(), selParticle, paths, null);
        // 
        // $NON-NLS-1$
        decl.setName("".equals(this.elementName) ? null : this.elementName);
        if (keyPath != null) {
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDXPathDefinition field = factory.createXSDXPathDefinition();
            field.setVariety(keyPath.getVariety());
            field.setValue(elementName);
            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) {
            // fliu
            // no more element declarations --> we create a new Declaration with String simpleType definition
            // instead
            // FIXME: dereferecning and element is buggy
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDElementDeclaration newD = factory.createXSDElementDeclaration();
            newD.setName(this.elementName);
            newD.updateElement();
            XSDSimpleTypeDefinition stringType = ((SchemaTreeContentProvider) page.getTreeViewer().getContentProvider()).getXsdSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, // $NON-NLS-1$
            "string");
            newD.setTypeDefinition(stringType);
            if (selParticle.getContainer() instanceof XSDModelGroup) {
                XSDModelGroup group = ((XSDModelGroup) selParticle.getContainer());
                ((XSDModelGroup) selParticle.getContainer()).getContents().remove(selParticle);
                selParticle = factory.createXSDParticle();
                selParticle.setContent(newD);
                group.getContents().add(selParticle);
            }
        }
        if (Util.changeElementTypeToSequence(decl, maxOccurs) == Status.CANCEL_STATUS) {
            return Status.CANCEL_STATUS;
        }
        selParticle.setMinOccurs(this.minOccurs);
        if (maxOccurs > -1) {
            selParticle.setMaxOccurs(this.maxOccurs);
        } else {
            if (selParticle.getElement().getAttributeNode("maxOccurs") != null) {
                // $NON-NLS-1$//$NON-NLS-2$
                selParticle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
            } else {
                // $NON-NLS-1$//$NON-NLS-2$
                selParticle.getElement().setAttribute("maxOccurs", "unbounded");
            }
        }
        selParticle.updateElement();
        updateReference(originalXpath);
        if (elementExAdapter != null) {
            elementExAdapter.renameElement(decl.getSchema(), paths, decl.getName());
        }
        if (mapinfoExAdapter != null) {
            mapinfoExAdapter.renameElementMapinfo(paths, decl.getName());
        }
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditParticleAction_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) Element(org.w3c.dom.Element) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EList(org.eclipse.emf.common.util.EList) BusinessElementInputDialog(com.amalto.workbench.dialogs.BusinessElementInputDialog) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) HashSet(java.util.HashSet)

Example 10 with XSDSimpleTypeDefinition

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

the class XSDAbstractNewXPathAction method updateElementForAddedfield.

protected void updateElementForAddedfield(XSDIdentityConstraintDefinition icd, String fieldName) {
    if (icd == null || fieldName == null)
        return;
    XSDElementDeclaration entity = (XSDElementDeclaration) icd.getContainer();
    XSDComplexTypeDefinition ctype = (XSDComplexTypeDefinition) entity.getTypeDefinition();
    if (ctype.getContent() instanceof XSDParticle) {
        XSDParticleImpl particle = (XSDParticleImpl) ctype.getContent();
        if (particle.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup group = (XSDModelGroup) particle.getTerm();
            EList<XSDParticle> particles = group.getParticles();
            for (XSDParticle part : particles) {
                if (part.getTerm() instanceof XSDElementDeclaration) {
                    XSDElementDeclaration el = (XSDElementDeclaration) part.getTerm();
                    if (el.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
                        if (fieldName.equals(el.getName())) {
                            part.setMinOccurs(1);
                            part.setMaxOccurs(1);
                            break;
                        }
                    }
                }
            }
        }
    }
    entity.updateElement();
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDParticleImpl(org.eclipse.xsd.impl.XSDParticleImpl) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)106 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)53 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)47 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)46 XSDParticle (org.eclipse.xsd.XSDParticle)34 ArrayList (java.util.ArrayList)33 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 Iterator (java.util.Iterator)24 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 XSDSchema (org.eclipse.xsd.XSDSchema)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)16 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)15 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)15 XSDFactory (org.eclipse.xsd.XSDFactory)15 EList (org.eclipse.emf.common.util.EList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)11