Search in sources :

Example 1 with XSDXPathDefinition

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

the class Util method getRealKeyInfos.

public static List<Object> getRealKeyInfos(XSDElementDeclaration currentEntity, XSDParticle son) {
    if (currentEntity == null || son == null) {
        return null;
    }
    if (!isDirectChild(currentEntity, son)) {
        return null;
    }
    List<Object> list = new ArrayList<Object>();
    XSDTerm term = son.getTerm();
    if (term instanceof XSDElementDeclaration) {
        String primaryKey = ((XSDElementDeclaration) term).getName();
        EList<XSDIdentityConstraintDefinition> idtylist = currentEntity.getIdentityConstraintDefinitions();
        for (XSDIdentityConstraintDefinition idty : idtylist) {
            EList<XSDXPathDefinition> fields = idty.getFields();
            for (XSDXPathDefinition path : fields) {
                if ((path.getValue()).equals(primaryKey)) {
                    list.add(idty);
                    list.add(path);
                    break;
                }
            }
        }
    }
    return list;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDTerm(org.eclipse.xsd.XSDTerm) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 2 with XSDXPathDefinition

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

the class XSDUtil method getKeyFields.

public static List<String> getKeyFields(XSDElementDeclaration concept) {
    List<String> keyFields = new ArrayList<String>();
    EList<XSDIdentityConstraintDefinition> identityConstraintDefinitions = concept.getIdentityConstraintDefinitions();
    for (XSDIdentityConstraintDefinition icd : identityConstraintDefinitions) {
        if (concept.getName().equals(icd.getName())) {
            EList<XSDXPathDefinition> fields = icd.getFields();
            for (XSDXPathDefinition xpathdef : fields) {
                keyFields.add(xpathdef.getValue());
            }
        }
    }
    return keyFields;
}
Also used : ArrayList(java.util.ArrayList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 3 with XSDXPathDefinition

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

the class Util method getTopParent.

public static List<Object> getTopParent(Object son) {
    if (!((son instanceof XSDElementDeclaration))) {
        return null;
    }
    XSDElementDeclaration elem = null;
    elem = (XSDElementDeclaration) son;
    if (elem.getSchema() == null) {
        return null;
    }
    EList<XSDSchemaContent> parentList = elem.getSchema().getContents();
    List<Object> list = new ArrayList<Object>();
    for (XSDSchemaContent top : parentList) {
        list.clear();
        if (!(top instanceof XSDElementDeclaration)) {
            continue;
        }
        XSDElementDeclaration decl = (XSDElementDeclaration) top;
        if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
            String primaryKey = getTopElement(decl, elem);
            if (!"".equalsIgnoreCase(primaryKey)) {
                // $NON-NLS-1$
                EList<XSDIdentityConstraintDefinition> idtylist = decl.getIdentityConstraintDefinitions();
                for (XSDIdentityConstraintDefinition idty : idtylist) {
                    EList<XSDXPathDefinition> fields = idty.getFields();
                    for (XSDXPathDefinition path : fields) {
                        if ((path.getValue()).equals(primaryKey)) {
                            list.add(idty);
                            list.add(path);
                            return list;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 4 with XSDXPathDefinition

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

the class RepositoryResourceUtil method getBusinessConceptKey.

public static WSConceptKey getBusinessConceptKey(WSGetBusinessConceptKey businessConcepKey) throws XtentisException {
    String pk = businessConcepKey.getWsDataModelPK().getPk();
    String concept = businessConcepKey.getConcept();
    WSDataModelE dataModel = RepositoryQueryService.findDataModelByName(pk);
    if (dataModel != null) {
        try {
            XSDSchema xsdSchema = Util.getXSDSchema(dataModel.getXsdSchema());
            for (XSDIdentityConstraintDefinition idDef : xsdSchema.getIdentityConstraintDefinitions()) {
                if (idDef.getName().equals(concept)) {
                    WSConceptKey key = new WSConceptKey();
                    // 
                    XSDXPathDefinition selector = idDef.getSelector();
                    key.setSelector(selector.getValue());
                    // 
                    EList<XSDXPathDefinition> fields = idDef.getFields();
                    List<String> keyFields = new ArrayList<String>();
                    for (XSDXPathDefinition pathDef : fields) {
                        keyFields.add(pathDef.getValue());
                    }
                    key.getFields().clear();
                    key.getFields().addAll(keyFields);
                    return key;
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    return null;
}
Also used : WSDataModelE(org.talend.mdm.repository.model.mdmserverobject.WSDataModelE) ArrayList(java.util.ArrayList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) WSConceptKey(com.amalto.workbench.webservices.WSConceptKey) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) XtentisException(com.amalto.workbench.utils.XtentisException) FileNotFoundException(java.io.FileNotFoundException) PersistenceException(org.talend.commons.exception.PersistenceException) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 5 with XSDXPathDefinition

use of org.eclipse.xsd.XSDXPathDefinition 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)

Aggregations

XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)37 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)32 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)21 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)16 ArrayList (java.util.ArrayList)15 XSDParticle (org.eclipse.xsd.XSDParticle)15 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)14 XSDFactory (org.eclipse.xsd.XSDFactory)12 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)10 Iterator (java.util.Iterator)8 XSDTerm (org.eclipse.xsd.XSDTerm)8 Element (org.w3c.dom.Element)7 EList (org.eclipse.emf.common.util.EList)6 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)6 XSDSchema (org.eclipse.xsd.XSDSchema)6 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)6 TreeObject (com.amalto.workbench.models.TreeObject)5 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)5