Search in sources :

Example 1 with XSDImport

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

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

the class Util method createXsdSchema.

public static XSDSchema createXsdSchema(String xsd, TreeObject treeObj) throws Exception {
    List<XSDImport> imports = new ArrayList<XSDImport>();
    List<Exception> exceptons = new ArrayList<Exception>();
    Map<String, Integer> schemaMonitor = new HashMap<String, Integer>();
    // no import or include using old getXsdschema()
    // if (Util.getNodeList(doc.getDocumentElement(),"//xsd:import").getLength() ==0
    // || Util.getNodeList(doc.getDocumentElement(),
    // "//xsd:include").getLength() ==0)
    // {
    // return Util.getXSDSchema(xsd);
    // }
    // replace the old roles with the new role scheme
    String xsdCpy = new String(xsd);
    for (Map.Entry<String, String> pair : ICoreConstants.rolesConvert.oldRoleToNewRoleMap.entrySet()) {
        xsdCpy = xsdCpy.replaceAll(pair.getKey().toString(), pair.getValue().toString());
    }
    XSDSchema xsdSchema = Util.getXSDSchema(null, xsdCpy, imports, treeObj, false, exceptons, schemaMonitor);
    if (exceptons.size() > 0) {
        throw exceptons.get(0);
    } else if (schemaMonitor.containsValue(new Integer(-1))) {
        throw new Exception(Messages.Util_44);
    }
    addImport(xsdSchema, imports);
    return xsdSchema;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) XSDImport(org.eclipse.xsd.XSDImport) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) MultiKeyMap(org.apache.commons.collections.map.MultiKeyMap) HashMap(java.util.HashMap) 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 3 with XSDImport

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

the class AddXSDImportCommand method execute.

public void execute() {
    try {
        super.execute();
        // Add this after if we don't have a DOM Node yet
        beginRecording(xsdSchema.getElement());
        XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
        xsdSchema.getContents().add(findNextPositionToInsert(), xsdImport);
        addedXSDConcreteComponent = xsdImport;
        formatChild(xsdSchema.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDImport(org.eclipse.xsd.XSDImport)

Example 4 with XSDImport

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

the class XSDImportSection method refresh.

public void refresh() {
    setListenerEnabled(false);
    errorText.setText("");
    Element element = null;
    if (input instanceof XSDImport) {
        element = ((XSDImport) input).getElement();
        // $NON-NLS-1$
        String namespace = element.getAttribute("namespace");
        // $NON-NLS-1$
        String schemaLocation = element.getAttribute("schemaLocation");
        TypesHelper helper = new TypesHelper(xsdSchema);
        String prefix = helper.getPrefix(element.getAttribute(XSDConstants.NAMESPACE_ATTRIBUTE), false);
        if (namespace == null) {
            // $NON-NLS-1$
            namespace = "";
        }
        if (prefix == null) {
            // $NON-NLS-1$
            prefix = "";
        }
        if (schemaLocation == null) {
            // $NON-NLS-1$
            schemaLocation = "";
        }
        namespaceText.setText(namespace);
        prefixText.setText(prefix);
        schemaLocationText.setText(schemaLocation);
        oldPrefixValue = prefixText.getText();
    }
    setListenerEnabled(true);
}
Also used : TypesHelper(org.eclipse.wst.xsd.ui.internal.util.TypesHelper) Element(org.w3c.dom.Element) XSDImport(org.eclipse.xsd.XSDImport)

Example 5 with XSDImport

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

the class XSDCommonUIUtils method getInputXSDAnnotation.

public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
    XSDAnnotation xsdAnnotation = null;
    XSDFactory factory = XSDFactory.eINSTANCE;
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDNotationDeclaration) {
        XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDXPathDefinition) {
        XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroup) {
        XSDModelGroup xsdComp = (XSDModelGroup) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDWildcard) {
        XSDWildcard xsdComp = (XSDWildcard) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDSchema) {
        XSDSchema xsdComp = (XSDSchema) input;
        List list = xsdComp.getAnnotations();
        if (list.size() > 0) {
            xsdAnnotation = (XSDAnnotation) list.get(0);
        } else {
            if (createIfNotExist && xsdAnnotation == null) {
                xsdAnnotation = factory.createXSDAnnotation();
                if (xsdComp.getContents() != null) {
                    xsdComp.getContents().add(0, xsdAnnotation);
                }
            }
        }
        return xsdAnnotation;
    } else if (input instanceof XSDFacet) {
        XSDFacet xsdComp = (XSDFacet) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDTypeDefinition) {
        XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDInclude) {
        XSDInclude xsdComp = (XSDInclude) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDImport) {
        XSDImport xsdComp = (XSDImport) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDRedefine) {
        XSDRedefine xsdComp = (XSDRedefine) input;
        List contents = xsdComp.getContents();
        for (int i = 0; i < contents.size(); i++) {
            Object content = contents.get(i);
            if (content instanceof XSDAnnotation) {
                xsdAnnotation = (XSDAnnotation) content;
                break;
            }
        }
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            contents.add(0, xsdAnnotation);
        }
        return xsdAnnotation;
    } else if (input instanceof XSDAnnotation) {
        xsdAnnotation = (XSDAnnotation) input;
    }
    if (createIfNotExist) {
        formatAnnotation(xsdAnnotation);
    }
    return xsdAnnotation;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDNotationDeclaration(org.eclipse.xsd.XSDNotationDeclaration) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDImport(org.eclipse.xsd.XSDImport) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDInclude(org.eclipse.xsd.XSDInclude)

Aggregations

XSDImport (org.eclipse.xsd.XSDImport)14 XSDSchema (org.eclipse.xsd.XSDSchema)7 XSDInclude (org.eclipse.xsd.XSDInclude)6 ArrayList (java.util.ArrayList)4 XSDRedefine (org.eclipse.xsd.XSDRedefine)4 XSDSchemaContent (org.eclipse.xsd.XSDSchemaContent)4 XSDSchemaDirective (org.eclipse.xsd.XSDSchemaDirective)3 XSDImportImpl (org.eclipse.xsd.impl.XSDImportImpl)3 WSDataModel (com.amalto.workbench.webservices.WSDataModel)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 EObject (org.eclipse.emf.ecore.EObject)2 TypesHelper (org.eclipse.wst.xsd.ui.internal.util.TypesHelper)2 XSDFactory (org.eclipse.xsd.XSDFactory)2 Element (org.w3c.dom.Element)2 MissingJarsException (com.amalto.workbench.service.MissingJarsException)1 InaccessibleWSDLException (com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException)1 IOException (java.io.IOException)1