Search in sources :

Example 1 with XSDSchemaContent

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

the class Util method importSchema.

private static void importSchema(XSDSchema xsdSchema, List<XSDImport> imports, Map<String, Integer> schemaMonitor) {
    EList<XSDSchemaContent> list = xsdSchema.getContents();
    for (XSDSchemaContent schemaCnt : list) {
        if (schemaCnt instanceof XSDImport) {
            XSDImportImpl xsdImpl = (XSDImportImpl) schemaCnt;
            if (xsdImpl.getNamespace() == null || xsdImpl.getNamespace().trim().equals("")) {
                // $NON-NLS-1$
                URI fileURI = URI.createFileURI(xsdImpl.getSchemaLocation());
                // $NON-NLS-1$//$NON-NLS-2$
                xsdImpl.setNamespace(fileURI.toFileString().replaceAll("[\\W]", ""));
            }
            if (xsdImpl.getSchemaLocation() == null) {
                continue;
            }
            ((XSDImportImpl) schemaCnt).importSchema();
            imports.add(((XSDImportImpl) schemaCnt));
        } else if (schemaCnt instanceof XSDInclude) {
            XSDIncludeImpl xsdInclude = (XSDIncludeImpl) schemaCnt;
            ((XSDSchemaImpl) xsdSchema).included(xsdInclude);
        }
    }
}
Also used : XSDImportImpl(org.eclipse.xsd.impl.XSDImportImpl) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) XSDImport(org.eclipse.xsd.XSDImport) XSDIncludeImpl(org.eclipse.xsd.impl.XSDIncludeImpl) URI(org.eclipse.emf.common.util.URI) XSDInclude(org.eclipse.xsd.XSDInclude)

Example 2 with XSDSchemaContent

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

the class Util method getParent.

public static Object getParent(Object son) {
    if (!((son instanceof XSDElementDeclaration) || (son instanceof XSDParticle))) {
        return null;
    }
    XSDElementDeclaration elem = null;
    if (son instanceof XSDParticle) {
        elem = (XSDElementDeclaration) ((XSDParticle) son).getContent();
    } else if (son instanceof XSDElementDeclaration) {
        elem = (XSDElementDeclaration) son;
    }
    if (elem == null || elem.getSchema() == null) {
        return null;
    }
    EList<XSDSchemaContent> parentList = elem.getSchema().getContents();
    for (XSDSchemaContent top : parentList) {
        if (!(top instanceof XSDElementDeclaration) && !(top instanceof XSDComplexTypeDefinition)) {
            continue;
        }
        if (top instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) top;
            if (decl == son) {
                return decl;
            }
            if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) decl.getTypeDefinition();
                if (type.getContent() instanceof XSDParticle) {
                    XSDParticle particle = (XSDParticle) type.getContent();
                    if (particle.getTerm() instanceof XSDModelGroup) {
                        XSDModelGroup group = (XSDModelGroup) particle.getTerm();
                        EList<XSDParticle> elist = group.getContents();
                        for (XSDParticle pt : elist) {
                            if (pt.getContent() instanceof XSDElementDeclaration) {
                                if (((XSDElementDeclaration) pt.getContent()) == elem) {
                                    return decl;
                                }
                            }
                            Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
                            XSDElementDeclaration spec = findOutSpecialSonElement((XSDElementDeclaration) pt.getContent(), elem, complexTypes);
                            if (spec != null) {
                                return spec;
                            }
                        }
                    }
                }
            }
        } else {
            XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) top;
            if (type.getContent() instanceof XSDParticle) {
                XSDParticle particle = (XSDParticle) type.getContent();
                if (particle.getTerm() instanceof XSDModelGroup) {
                    XSDModelGroup group = (XSDModelGroup) particle.getTerm();
                    EList<XSDParticle> elist = group.getContents();
                    for (XSDParticle pt : elist) {
                        if (pt.getContent() instanceof XSDElementDeclaration) {
                            if (((XSDElementDeclaration) pt.getContent()) == elem) {
                                return top;
                            }
                        }
                        if (pt.getContent() instanceof XSDElementDeclaration) {
                            Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
                            XSDElementDeclaration spec = findOutSpecialSonElement((XSDElementDeclaration) pt.getContent(), elem, complexTypes);
                            if (spec != null) {
                                return spec;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) HashSet(java.util.HashSet)

Example 3 with XSDSchemaContent

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

the class XSDUtil method getAllPKXpaths.

public static List<String> getAllPKXpaths(XSDSchema schema) {
    List<String> entity2xpaths = new LinkedList<String>();
    if (schema != null) {
        for (XSDSchemaContent content : schema.getContents()) {
            if (isEntity(content)) {
                XSDElementDeclaration concept = (XSDElementDeclaration) content;
                List<String> keyFields = getKeyFields(concept);
                entity2xpaths.add(0, concept.getName());
                for (String pkfield : keyFields) {
                    // $NON-NLS-1$
                    entity2xpaths.add(concept.getName() + "/" + pkfield);
                }
            }
        }
    }
    return entity2xpaths;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) LinkedList(java.util.LinkedList)

Example 4 with XSDSchemaContent

use of org.eclipse.xsd.XSDSchemaContent 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 5 with XSDSchemaContent

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

the class DataModelMainPage method doImportSchema.

protected void doImportSchema(final Collection<XSDSchemaContent> addtional) {
    if (null == addtional || addtional.isEmpty()) {
        return;
    }
    try {
        int flag = ConflictDialog.NONE;
        boolean dialogPopup = false;
        List<XSDSchemaContent> contents = xsdSchema.getContents();
        List<XSDSchemaContent> exists = new ArrayList<XSDSchemaContent>(contents);
        for (XSDSchemaContent content : addtional) {
            XSDSchemaContent exist = getContainedSchemaContent(exists, content);
            if (null == exist) {
                Node importElement = xsdSchema.getDocument().importNode(content.getElement(), true);
                xsdSchema.getElement().appendChild(importElement);
            } else {
                if (!dialogPopup) {
                    String type = null;
                    if (exist instanceof XSDElementDeclaration) {
                        type = Messages.DataModelMainPage_entity;
                    } else if (exist instanceof XSDTypeDefinition) {
                        type = Messages.DataModelMainPage_type;
                    } else {
                        continue;
                    }
                    LabelProvider provider = getContentLabelProvider(exist);
                    String message = Messages.bind(Messages.conflict_messages, type, provider.getText(exist));
                    ConflictDialog dialog = new ConflictDialog(getSite().getShell(), message);
                    if (dialog.open() == Dialog.OK) {
                        flag = dialog.getStatus();
                        dialogPopup = dialog.applyAll;
                    } else {
                        popupImportDialog();
                        return;
                    }
                }
                if (flag == ConflictDialog.OVERWRITE) {
                    contents.remove(exist);
                    Node importElement = xsdSchema.getDocument().importNode(content.getElement(), true);
                    xsdSchema.getElement().appendChild(importElement);
                }
            }
        }
        // 
        validateSchema();
        markDirtyWithoutCommit();
        setXsdSchema(xsdSchema);
        getSchemaRoleFilterFromSchemaTree().setDataModelFilter(dataModelFilter);
        // refresh types
        viewer.setInput(getSite());
        typesViewer.setInput(getSite());
        MessageDialog.openInformation(getSite().getShell(), Messages.ImportXSDSche, Messages.ImportingXSDSchemaCompleted);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        // $NON-NLS-1$
        String detail = "";
        if (ex.getMessage() != null && !ex.getMessage().equals("")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            detail += " , " + Messages.bind(Messages.Dueto, ex.getMessage());
        }
        MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.bind(Messages.ImportingXSDSchemaFailed, detail));
    }
}
Also used : Node(org.w3c.dom.Node) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) TypesLabelProvider(com.amalto.workbench.providers.TypesLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) XSDTreeLabelProvider(com.amalto.workbench.providers.XSDTreeLabelProvider) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SAXParseException(org.xml.sax.SAXParseException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Aggregations

XSDSchemaContent (org.eclipse.xsd.XSDSchemaContent)13 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)7 ArrayList (java.util.ArrayList)5 XSDImport (org.eclipse.xsd.XSDImport)5 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)4 TreeObject (com.amalto.workbench.models.TreeObject)3 XSDInclude (org.eclipse.xsd.XSDInclude)3 XSDSchema (org.eclipse.xsd.XSDSchema)3 WSDataModel (com.amalto.workbench.webservices.WSDataModel)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 CoreException (org.eclipse.core.runtime.CoreException)2 PartInitException (org.eclipse.ui.PartInitException)2 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)2 XSDImportImpl (org.eclipse.xsd.impl.XSDImportImpl)2 Test (org.junit.Test)2 SAXParseException (org.xml.sax.SAXParseException)2 TypesLabelProvider (com.amalto.workbench.providers.TypesLabelProvider)1 XSDTreeLabelProvider (com.amalto.workbench.providers.XSDTreeLabelProvider)1 XObject (com.sun.org.apache.xpath.internal.objects.XObject)1