Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Create GMFResource if default/gernic domain does not exist and resour… #785

Merged
merged 1 commit into from
Jun 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.gmf.runtime.emf.core.resources.GMFResource;
import org.yakindu.sct.domain.extension.DomainRegistry;
import org.yakindu.sct.domain.extension.IDomainDescriptor;

import com.google.inject.Injector;

/**
*
* @author andreas muelder - Initial contribution and API
*
*/
public class SCTResourceFactory extends XMIResourceFactoryImpl {

@Override
public Resource createResource(URI uri) {

// if file is not existing, AND no generic/default domain is available, resource creation will fail
if (!URIConverter.INSTANCE.exists(uri, null)) {
return new GMFResource(uri);
}

String determinedDomainID = DomainRegistry.determineDomainID(uri);
IDomainDescriptor domainDescriptor = DomainRegistry.getDomainDescriptor(determinedDomainID);
Injector injector = domainDescriptor.getDomainInjectorProvider().getResourceInjector();
Resource resource = injector.getInstance(Resource.class);

ResourceSet set = new ResourceSetImpl();
set.getResources().add(resource);
resource.setURI(uri);
Expand Down