Search in sources :

Example 1 with XSDSchemaLocatorAdapterFactory

use of org.eclipse.wst.xsd.contentmodel.internal.util.XSDSchemaLocatorAdapterFactory in project webtools.sourceediting by eclipse.

the class XSDImpl method buildXSDModel.

/**
 * Given uri for an XML Schema document, parse the document and build
 * corresponding CMDocument node.
 *
 * @param uri -
 *          the uri for an XML Schema document
 * @return the corresponding CMDocument node.
 */
public static XSDSchema buildXSDModel(String uriString) {
    XSDSchema xsdSchema = null;
    try {
        // if XML Schema for Schema is requested, get it through schema model
        if (uriString.endsWith("2001/XMLSchema.xsd")) {
            xsdSchema = XSDSchemaImpl.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
        } else {
            ResourceSet resourceSet = new ResourceSetImpl();
            // resourceSet.getAdapterFactories().add(new XSDSchemaLocationResolverAdapterFactory());
            resourceSet.getAdapterFactories().add(new XSDSchemaLocatorAdapterFactory());
            URI uri = createURI(uriString);
            // CS : bug 113537 ensure we perform physical resolution before opening a stream for the resource
            // 
            String physicalLocation = URIResolverPlugin.createResolver().resolvePhysicalLocation("", "", uriString);
            InputStream inputStream = resourceSet.getURIConverter().createInputStream(URI.createURI(physicalLocation));
            XSDResourceImpl resource = (XSDResourceImpl) resourceSet.createResource(URI.createURI("*.xsd"));
            resource.setURI(uri);
            resource.load(inputStream, null);
            xsdSchema = resource.getSchema();
        }
    } catch (Exception e) {
    }
    return xsdSchema;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) InputStream(java.io.InputStream) XSDResourceImpl(org.eclipse.xsd.util.XSDResourceImpl) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XSDSchemaLocatorAdapterFactory(org.eclipse.wst.xsd.contentmodel.internal.util.XSDSchemaLocatorAdapterFactory) URI(org.eclipse.emf.common.util.URI) IOException(java.io.IOException) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (org.eclipse.emf.common.util.URI)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 XSDSchemaLocatorAdapterFactory (org.eclipse.wst.xsd.contentmodel.internal.util.XSDSchemaLocatorAdapterFactory)1 XSDSchema (org.eclipse.xsd.XSDSchema)1 XSDResourceImpl (org.eclipse.xsd.util.XSDResourceImpl)1