Search in sources :

Example 1 with XSDSchemaDirective

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

the class Util method IsAImporedElement.

public static boolean IsAImporedElement(XSDConcreteComponent component, XSDSchema schema) {
    EObject parent = null;
    EObject obj = component;
    do {
        if (null == obj) {
            return false;
        }
        parent = obj.eContainer();
        obj = parent;
    } while (!(parent instanceof XSDSchema));
    if (parent != null && parent instanceof XSDSchema) {
        if (parent.equals(schema)) {
            return false;
        }
        try {
            EList<XSDSchemaDirective> referencingDirectives = ((XSDSchema) parent).getReferencingDirectives();
            return !referencingDirectives.isEmpty();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) EObject(org.eclipse.emf.ecore.EObject) ConnectException(java.net.ConnectException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) MissingJarsException(com.amalto.workbench.service.MissingJarsException) MalformedURLException(java.net.MalformedURLException) SAXParseException(org.xml.sax.SAXParseException) InaccessibleWSDLException(com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 2 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class XSDSchemaAdapter method getDirectives.

public List getDirectives(XSDSchema schema) {
    List list = new ArrayList();
    for (Iterator i = schema.getContents().iterator(); i.hasNext(); ) {
        Object o = i.next();
        if (o instanceof XSDSchemaDirective) {
            list.add(o);
        }
    }
    List adapterList = new ArrayList();
    populateAdapterList(list, adapterList);
    return adapterList;
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class TopLevelComponentEditPart method performRequest.

public void performRequest(Request request) {
    // Do not open on or set focus on direct edit type
    if (request.getType() == RequestConstants.REQ_OPEN) {
        Object model = getModel();
        if (model instanceof IGraphElement) {
            if (((IGraphElement) model).isFocusAllowed()) {
                if (request instanceof LocationRequest) {
                    LocationRequest locationRequest = (LocationRequest) request;
                    Point p = locationRequest.getLocation();
                    if (hitTest(labelHolder, p)) {
                        performDrillDownAction();
                    }
                }
            }
        } else if (model instanceof XSDSchemaDirectiveAdapter) {
            if (request instanceof LocationRequest) {
                LocationRequest locationRequest = (LocationRequest) request;
                Point p = locationRequest.getLocation();
                if (hitTest(labelHolder, p)) {
                    XSDSchemaDirective dir = (XSDSchemaDirective) ((XSDSchemaDirectiveAdapter) model).getTarget();
                    String schemaLocation = "";
                    // force load of imported schema
                    if (dir instanceof XSDImportImpl) {
                        ((XSDImportImpl) dir).importSchema();
                    }
                    if (dir.getResolvedSchema() != null) {
                        schemaLocation = URIHelper.removePlatformResourceProtocol(dir.getResolvedSchema().getSchemaLocation());
                        if (schemaLocation != null) {
                            OpenOnSelectionHelper.openXSDEditor(dir.getResolvedSchema());
                        }
                    }
                }
            }
        }
    }
}
Also used : XSDSchemaDirectiveAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDImportImpl(org.eclipse.xsd.impl.XSDImportImpl) IGraphElement(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement) LocationRequest(org.eclipse.gef.requests.LocationRequest) Point(org.eclipse.draw2d.geometry.Point)

Example 4 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class OpenOnSelectionHelper method openOnSelection.

public boolean openOnSelection() {
    List selectedNodes = null;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
        selectedNodes = ((IStructuredSelection) selection).toList();
    }
    if (selectedNodes != null && !selectedNodes.isEmpty()) {
        for (Iterator i = selectedNodes.iterator(); i.hasNext(); ) {
            Object obj = i.next();
            if (xsdSchema != null) {
                XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node) obj);
                XSDConcreteComponent objectToReveal = null;
                if (xsdComp instanceof XSDElementDeclaration) {
                    XSDElementDeclaration elementDecl = (XSDElementDeclaration) xsdComp;
                    if (elementDecl.isElementDeclarationReference()) {
                        objectToReveal = elementDecl.getResolvedElementDeclaration();
                    } else {
                        XSDConcreteComponent typeDef = null;
                        if (elementDecl.getAnonymousTypeDefinition() == null) {
                            typeDef = elementDecl.getTypeDefinition();
                        }
                        XSDConcreteComponent subGroupAffiliation = elementDecl.getSubstitutionGroupAffiliation();
                        if (typeDef != null && subGroupAffiliation != null) {
                            // then jump to that, otherwise just go to the typeDef.
                            if (obj instanceof Attr && ((Attr) obj).getLocalName().equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) {
                                objectToReveal = subGroupAffiliation;
                            } else {
                                // if we fail, set the substitution group as the object to reveal as a backup plan.
                                if (revealObject(typeDef)) {
                                    return true;
                                } else {
                                    objectToReveal = subGroupAffiliation;
                                }
                            }
                        } else {
                            // one or more of these is null.  If the typeDef is non-null, use it.  Otherwise
                            // try and use the substitution group
                            objectToReveal = typeDef != null ? typeDef : subGroupAffiliation;
                        }
                    }
                } else if (xsdComp instanceof XSDModelGroupDefinition) {
                    XSDModelGroupDefinition elementDecl = (XSDModelGroupDefinition) xsdComp;
                    if (elementDecl.isModelGroupDefinitionReference()) {
                        objectToReveal = elementDecl.getResolvedModelGroupDefinition();
                    }
                } else if (xsdComp instanceof XSDAttributeDeclaration) {
                    XSDAttributeDeclaration attrDecl = (XSDAttributeDeclaration) xsdComp;
                    if (attrDecl.isAttributeDeclarationReference()) {
                        objectToReveal = attrDecl.getResolvedAttributeDeclaration();
                    } else if (attrDecl.getAnonymousTypeDefinition() == null) {
                        objectToReveal = attrDecl.getTypeDefinition();
                    }
                } else if (xsdComp instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroupDef = (XSDAttributeGroupDefinition) xsdComp;
                    if (attrGroupDef.isAttributeGroupDefinitionReference()) {
                        objectToReveal = attrGroupDef.getResolvedAttributeGroupDefinition();
                    }
                } else if (xsdComp instanceof XSDIdentityConstraintDefinition) {
                    XSDIdentityConstraintDefinition idConstraintDef = (XSDIdentityConstraintDefinition) xsdComp;
                    if (idConstraintDef.getReferencedKey() != null) {
                        objectToReveal = idConstraintDef.getReferencedKey();
                    }
                } else if (xsdComp instanceof XSDSimpleTypeDefinition) {
                    XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComp;
                    objectToReveal = typeDef.getItemTypeDefinition();
                    if (objectToReveal == null) {
                        // if itemType attribute is not set, then check for memberType
                        List memberTypes = typeDef.getMemberTypeDefinitions();
                        if (memberTypes != null && memberTypes.size() > 0) {
                            objectToReveal = (XSDConcreteComponent) memberTypes.get(0);
                        }
                    }
                } else if (xsdComp instanceof XSDTypeDefinition) {
                    XSDTypeDefinition typeDef = (XSDTypeDefinition) xsdComp;
                    objectToReveal = typeDef.getBaseType();
                } else if (xsdComp instanceof XSDSchemaDirective) {
                    XSDSchemaDirective directive = (XSDSchemaDirective) xsdComp;
                    // String schemaLocation = URIHelper.removePlatformResourceProtocol(directive.getResolvedSchema().getSchemaLocation());
                    // openXSDEditor(schemaLocation);
                    // return false;
                    objectToReveal = directive.getResolvedSchema();
                }
                // now reveal the object if this isn't null
                if (objectToReveal != null) {
                    return revealObject(objectToReveal);
                }
            }
        }
    }
    return false;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Attr(org.w3c.dom.Attr) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 5 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class XSDUnusedTests method testImport013.

public void testImport013() {
    XSDSchema schema = getXSDSchema(TC_ROOT_FOLDER + "/Unused/test/Main009c.xsd");
    importManager.performRemoval(schema);
    List list = importManager.getUnusedXSDDirectives();
    assertTrue(list.size() == 3);
    XSDSchemaDirective d1 = (XSDSchemaDirective) list.get(0);
    assertTrue("../Include1.xsd".equals(d1.getSchemaLocation()));
    XSDSchemaDirective d2 = (XSDSchemaDirective) list.get(1);
    assertTrue("../Include2.xsd".equals(d2.getSchemaLocation()));
    XSDSchemaDirective d3 = (XSDSchemaDirective) list.get(2);
    assertTrue("../Include3.xsd".equals(d3.getSchemaLocation()));
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) List(java.util.List) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDSchemaDirective (org.eclipse.xsd.XSDSchemaDirective)33 XSDSchema (org.eclipse.xsd.XSDSchema)28 List (java.util.List)24 Iterator (java.util.Iterator)5 XSDImport (org.eclipse.xsd.XSDImport)4 XSDRedefine (org.eclipse.xsd.XSDRedefine)4 EObject (org.eclipse.emf.ecore.EObject)3 ArrayList (java.util.ArrayList)2 Adapter (org.eclipse.emf.common.notify.Adapter)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 XSDSchemaDirectiveAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter)2 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)2 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)2 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)2 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)2 XSDInclude (org.eclipse.xsd.XSDInclude)2 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)2 MissingJarsException (com.amalto.workbench.service.MissingJarsException)1 InaccessibleWSDLException (com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException)1 IOException (java.io.IOException)1