Search in sources :

Example 31 with XSDTerm

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

the class Util method isReferrenced.

private static boolean isReferrenced(XSDElementDeclaration element, XSDElementDeclaration term) {
    if (element == term) {
        return true;
    }
    if (term.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) term.getTypeDefinition()).getContent();
        if (fromcomplexType instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) fromcomplexType;
            if (particle.getTerm() instanceof XSDModelGroup) {
                XSDModelGroup modelGroup = ((XSDModelGroup) particle.getTerm());
                EList<?> fromlist = modelGroup.getContents();
                for (Object obj : fromlist) {
                    XSDTerm t = ((XSDParticle) obj).getTerm();
                    if (t == element) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDTerm(org.eclipse.xsd.XSDTerm) 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) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 32 with XSDTerm

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

the class XSDUtilTest method testGetAnnotationValue.

@Test
public void testGetAnnotationValue() throws Exception {
    // $NON-NLS-1$
    String fileName = "Product_0.1.xsd";
    // $NON-NLS-1$
    String elementName = "Family";
    // $NON-NLS-1$
    String fk = "Store/Id";
    String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
    assertNotNull(xsdString);
    XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
    for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
        XSDTypeDefinition typeDefinition = element.getTypeDefinition();
        if (typeDefinition instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent xsdComplexTypeContent = ((XSDComplexTypeDefinition) typeDefinition).getContent();
            if (xsdComplexTypeContent instanceof XSDParticle) {
                XSDParticleContent content = ((XSDParticle) xsdComplexTypeContent).getContent();
                if (content instanceof XSDModelGroup) {
                    for (XSDParticle particle : ((XSDModelGroup) content).getParticles()) {
                        XSDTerm term = particle.getTerm();
                        if (term instanceof XSDElementDeclaration) {
                            XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) term;
                            if (elementDeclaration.getName().equals(elementName)) {
                                String value = XSDUtil.getAnnotationValue(elementDeclaration, X_FOREIGN_KEY);
                                assertEquals(fk, value);
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    fail();
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Test(org.junit.Test)

Example 33 with XSDTerm

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

the class XSDPasteConceptAction method addAnnotationForComplexType.

public void addAnnotationForComplexType(XSDComplexTypeDefinition fromType, XSDComplexTypeDefinition toType) {
    XSDComplexTypeContent tocomplexType = toType.getContent();
    XSDComplexTypeContent fromcomplexType = fromType.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) {
                        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                        addAnnotion(struc, fromannotation);
                        if (this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
                            this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
                        }
                        addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
                    }
                }
            }
        }
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) 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 34 with XSDTerm

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

the class XSDDeleteParticleAction method doAction.

public IStatus doAction() {
    try {
        // xsdPartle is to support the multiple delete action on key press,
        // which each delete action on particle must be explicit passed a xsd particle to
        // delete
        XSDParticle particle = (XSDParticle) xsdPartle;
        if (particle == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            particle = (XSDParticle) ((IStructuredSelection) selection).getFirstElement();
        }
        XSDTerm term = particle.getTerm();
        XSDElementDeclaration decl = null;
        if (term instanceof XSDElementDeclaration) {
            decl = (XSDElementDeclaration) particle.getTerm();
        }
        if (particle.getContainer() == null) {
            return Status.CANCEL_STATUS;
        }
        XSDIdentityConstraintDefinition identify = null;
        XSDXPathDefinition keyPath = null;
        List<Object> keyInfo = Util.getKeyInfo(decl);
        if (keyInfo != null && keyInfo.size() > 0) {
            identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
            keyPath = (XSDXPathDefinition) keyInfo.get(1);
            identify.getFields().remove(keyPath);
            if (identify.getFields().size() == 0) {
                XSDElementDeclaration top = (XSDElementDeclaration) Util.getParent(decl);
                top.getIdentityConstraintDefinitions().remove(identify);
            }
        }
        if (!(particle.getContainer() instanceof XSDModelGroup))
            throw new XtentisException(Messages.bind(Messages.XSDDeleteParticleAction_ExceptionInfo, particle.getContainer().getClass().getName()));
        XSDModelGroup group = (XSDModelGroup) particle.getContainer();
        group.getContents().remove(particle);
        // if (term instanceof XSDElementDeclaration) {
        // //remove type definition is no more used and type is not built in
        // XSDTypeDefinition typeDef = decl.getTypeDefinition();
        // if ( (typeDef.getName()!=null) && //anonymous type
        // (!typeDef.getSchema().getSchemaForSchemaNamespace().equals(typeDef.getTargetNamespace()))
        // ){
        // if (Util.findElementsUsingType(group.getSchema(),typeDef.getTargetNamespace(),
        // typeDef.getName()).size()==0)
        // group.getSchema().getContents().remove(typeDef);
        // }
        // }
        group.updateElement();
        xsdPartle = null;
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteParticleAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) XSDTerm(org.eclipse.xsd.XSDTerm) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XtentisException(com.amalto.workbench.utils.XtentisException) XtentisException(com.amalto.workbench.utils.XtentisException)

Example 35 with XSDTerm

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

the class XSDGetXPathAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDParticle particle = (XSDParticle) selection.getFirstElement();
        XSDTerm term = particle.getTerm();
        if (!(term instanceof XSDElementDeclaration))
            return Status.CANCEL_STATUS;
        Clipboard clipboard = Util.getClipboard();
        // $NON-NLS-1$
        String path = "";
        TreeItem item = page.getTreeViewer().getTree().getSelection()[0];
        do {
            XSDConcreteComponent component = (XSDConcreteComponent) item.getData();
            if (component instanceof XSDParticle) {
                if (((XSDParticle) component).getTerm() instanceof XSDElementDeclaration)
                    // $NON-NLS-1$
                    path = "/" + ((XSDElementDeclaration) ((XSDParticle) component).getTerm()).getName() + path;
            } else if (component instanceof XSDElementDeclaration) {
                path = ((XSDElementDeclaration) component).getName() + path;
            }
            // System.out.println("          "+path+ "             $$"+component.toString()+"$$");
            item = item.getParentItem();
        } while (item != null);
        xpath = path;
        clipboard.setContents(new Object[] { path }, new Transfer[] { TextTransfer.getInstance() });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDGetXPathAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) TreeItem(org.eclipse.swt.widgets.TreeItem) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDTerm (org.eclipse.xsd.XSDTerm)36 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)32 XSDParticle (org.eclipse.xsd.XSDParticle)31 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)28 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)16 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)13 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)10 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)10 TreeObject (com.amalto.workbench.models.TreeObject)9 ArrayList (java.util.ArrayList)9 EList (org.eclipse.emf.common.util.EList)9 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)8 XSDWildcard (org.eclipse.xsd.XSDWildcard)8 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)8 Iterator (java.util.Iterator)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)6 Element (org.w3c.dom.Element)6 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)5