eclipse-uml2 / uml2

An EMF-based implementation of the UML 2.x metamodel for the Eclipse platform.
Eclipse Public License 2.0
5 stars 4 forks source link

Add contentType redirection in UMLResourceFactory #86

Open eclipse-uml2-bot opened 1 week ago

eclipse-uml2-bot commented 1 week ago

| --- | --- | | Bugzilla Link | 526375 | | Status | NEW | | Importance | P3 enhancement | | Reported | Oct 23, 2017 12:06 EDT | | Modified | Oct 24, 2017 04:59 EDT | | See also | 526217 | | Reporter | Ed Willink |

Description

Further to Bug 526217#c13.

EMF's failure to prioritize contentType over extension during ResourceFactory selection is not really a problem for createResource; the creator can be very forceful if it really wants to create an explicit old contentType. It is getResource that is at fault.

Suggestion: If UMLResourceFactoryImpl.getResource proactively 'loads' the input stream, it can peek at the nsURI and decide which UMLResource variant to create. The proactively loaded input stream can be re-used by the real load later.

(The proactive peek by getResource can perhaps share the proactive peek for IDE icon type.)

eclipse-uml2-bot commented 1 week ago

By Ed Willink on Oct 24, 2017 04:59

IIRC contentTypes were added to support UML 2.1/2.2, but they only sort of work with considerable configuration efforts. Isn't it time to make them work properly?

If you tunnel down through Window->Preferences->General->ContentTypes->Text->XML->XML(XMI)... you will find a huge number of possibilities, but I doubt that many of them will successfully open as xx.xmi or xx.xml files.

If the current ResourceSetImpl

protected Resource demandCreateResource(URI uri)\ {\ return createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);\ }

is redirected to

return createResourceFor(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);

we can use a new ResourceFactory API so that createResourceFor invokes

Resource result = resourceFactory.createResource(this, uri, contentType);

enabling a ResourceFactory to be contentType-aware if it so chooses.

UML users / UMLResourcesUtil.init could install a UMLContentTypeAwareResourceFactoryImpl for ".uml", ".cmof".

The contentType dispatch in a ContentTypeAwareResourceFactoryImpl could (re-)use ResourceFactoryRegistryImpl.getContentTypeIdentifier and could be provided by EMF where we might also find an XMLContentTypeAwareResourceFactoryImpl and an XMIContentTypeAwareResourceFactoryImpl. The backstop registration for "*" might even change to use XMLContentTypeAwareResourceFactoryImpl so that arbitrary XML files open with the correct support.