Search in sources :

Example 6 with XSDResourceImpl

use of org.eclipse.xsd.util.XSDResourceImpl in project webtools.sourceediting by eclipse.

the class BaseTestCase method getXSDSchema.

protected XSDSchema getXSDSchema(String path) {
    URI uri = URI.createFileURI(path);
    ResourceSet resourceSet = new ResourceSetImpl();
    XSDResourceImpl resource = (XSDResourceImpl) resourceSet.getResource(uri, true);
    XSDSchema schema = resource.getSchema();
    assertNotNull(schema);
    return schema;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XSDResourceImpl(org.eclipse.xsd.util.XSDResourceImpl) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 7 with XSDResourceImpl

use of org.eclipse.xsd.util.XSDResourceImpl in project webtools.sourceediting by eclipse.

the class UpdateComponentReferenceAndManageDirectivesCommand method computeComponent.

protected XSDComponent computeComponent() {
    XSDComponent result = null;
    XSDSchema schema = concreteComponent.getSchema();
    XSDSchemaDirective directive = null;
    // lets see if the element is already visible to our schema
    result = getDefinedComponent(schema, componentName, componentNamespace);
    if (result == null) {
        // includes/imports to get to it
        if (componentNamespace != null && componentNamespace.equals(schema.getTargetNamespace())) {
            // we need to add an include
            // if the component's namespace is not null and matches the schema's
            // target namespace
            directive = XSDFactory.eINSTANCE.createXSDInclude();
        } else if (componentNamespace == null) {
            // we need to add an include
            // if the component's namespace is null, then we can just add it
            // only if the current namespace is not null
            directive = XSDFactory.eINSTANCE.createXSDInclude();
            // we have to ensure the schema for schema prefix is NOT null
            if (schema.getSchemaForSchemaQNamePrefix() == null) {
                String targetNS = schema.getTargetNamespace();
                if (targetNS == null)
                    targetNS = "";
                // this will just update the schema for schema prefix to be, say, xsd
                UpdateNamespaceInformationCommand command = new UpdateNamespaceInformationCommand("", schema, "", targetNS);
                command.execute();
            }
        } else {
            // we need to add an import
            XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
            xsdImport.setNamespace(componentNamespace);
            directive = xsdImport;
        }
        String location = computeNiceLocation(schema.getSchemaLocation(), file);
        directive.setSchemaLocation(location);
        // TODO (cs) we should at the directive 'next' in the list of directives
        // for now I'm just adding as the first thing in the schema :-(
        // 
        schema.getContents().add(0, directive);
        XSDSchema resolvedSchema = directive.getResolvedSchema();
        if (resolvedSchema == null) {
            String platformLocation = "platform:/resource" + file.getFullPath();
            Resource resource = concreteComponent.eResource().getResourceSet().createResource(URI.createURI(platformLocation));
            if (resource instanceof XSDResourceImpl) {
                try {
                    resource.load(null);
                    XSDResourceImpl resourceImpl = (XSDResourceImpl) resource;
                    resolvedSchema = resourceImpl.getSchema();
                    if (resolvedSchema != null) {
                        directive.setResolvedSchema(resolvedSchema);
                    }
                } catch (Exception e) {
                }
            }
        }
        if (resolvedSchema != null) {
            result = getDefinedComponent(resolvedSchema, componentName, componentNamespace);
        } else {
        // TODO (cs) consider setting some error state so that the client can
        // provide a pop-dialog error
        // we should also remove the import/include so save from cluttering
        // the file with bogus directives
        }
    }
    return result;
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) Resource(org.eclipse.emf.ecore.resource.Resource) XSDResourceImpl(org.eclipse.xsd.util.XSDResourceImpl) XSDImport(org.eclipse.xsd.XSDImport) XSDComponent(org.eclipse.xsd.XSDComponent) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDResourceImpl (org.eclipse.xsd.util.XSDResourceImpl)7 XSDSchema (org.eclipse.xsd.XSDSchema)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)5 URI (org.eclipse.emf.common.util.URI)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)2 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)2 FileWriter (java.io.FileWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IProgressService (org.eclipse.ui.progress.IProgressService)1