use of org.eclipse.wst.xsd.ui.internal.util.XSDSchemaLocationResolverAdapterFactory in project webtools.sourceediting by eclipse.
the class XSDModelAdapter method createSchema.
public XSDSchema createSchema(Document document) {
try {
// (cs) note that we always want to ensure that a
// schema model object get's returned
schema = XSDFactory.eINSTANCE.createXSDSchema();
resourceSet = XSDSchemaImpl.createResourceSet();
resourceSet.getAdapterFactories().add(new XSDSchemaLocationResolverAdapterFactory());
IDOMNode domNode = (IDOMNode) document;
String baseLocation = domNode.getModel().getBaseLocation();
// TODO... gotta pester SSE folks to provide 'useful' baseLocations
//
URI uri = getURI(baseLocation);
Resource resource = new XSDResourceImpl();
resource.setURI(uri);
schema = XSDFactory.eINSTANCE.createXSDSchema();
resource.getContents().add(schema);
resourceSet.getResources().add(resource);
schema.setDocument(document);
final Element element = document.getDocumentElement();
if (element != null) {
// Force the loading of the "meta" schema for schema instance instance.
//
String schemaForSchemaNamespace = element.getNamespaceURI();
XSDSchemaImpl.getSchemaForSchema(schemaForSchemaNamespace);
}
IRunnableWithProgress setElementOperation = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Use the animated flavour as we don't know beforehand how many ticks we need.
// The task name will be displayed by the code in XSDResourceImpl.
// $NON-NLS-1$
monitor.beginTask("", IProgressMonitor.UNKNOWN);
Map loadOptions = resourceSet.getLoadOptions();
loadOptions.put(XSDResourceImpl.XSD_PROGRESS_MONITOR, monitor);
schema.setElement(element);
loadOptions.remove(XSDResourceImpl.XSD_PROGRESS_MONITOR);
}
};
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.busyCursorWhile(setElementOperation);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
// attach an adapter to keep the XSD model and DOM in sync
//
modelReconcileAdapter = new XSDModelReconcileAdapter(document, schema);
domNode.getModel().addModelStateListener(modelReconcileAdapter);
} catch (Exception ex) {
ex.printStackTrace();
}
return schema;
}
Aggregations