org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl Java Examples

The following examples show how to use org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceServiceProviderServiceLoader.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private Registry loadRegistry() {
	ResourceServiceProviderRegistryImpl registry = new ResourceServiceProviderRegistryImpl();
	for (ISetup cp : setupLoader) {
		Injector injector = cp.createInjectorAndDoEMFRegistration();
		IResourceServiceProvider resourceServiceProvider = injector.getInstance(IResourceServiceProvider.class);
		FileExtensionProvider extensionProvider = injector.getInstance(FileExtensionProvider.class);
		String primaryFileExtension = extensionProvider.getPrimaryFileExtension();
		for (String ext : extensionProvider.getFileExtensions()) {
			if (registry.getExtensionToFactoryMap().containsKey(ext)) {
				if (primaryFileExtension.equals(ext))
					registry.getExtensionToFactoryMap().put(ext, resourceServiceProvider);
			} else {
				registry.getExtensionToFactoryMap().put(ext, resourceServiceProvider);
			}
		}
	}
	return registry;
}
 
Example #2
Source File: ResourceServiceProvideRegistryTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUninstallBadProvider() {
	final IResourceServiceProvider.Provider provider = new IResourceServiceProvider.Provider() {
		@Override
		public IResourceServiceProvider get(URI uri, String contentType) {
			throw new NullPointerException();
		}
	};
	
	final IResourceServiceProvider.Registry reg = new ResourceServiceProviderRegistryImpl();
	reg.getExtensionToFactoryMap().put("foo", provider);
	
	assertEquals(1, reg.getExtensionToFactoryMap().size());
	LoggingTester.captureLogging(Level.ERROR, ResourceServiceProviderRegistryImpl.class, new Runnable() {
		@Override
		public void run() {
			assertNull(reg.getResourceServiceProvider(URI.createURI("hubba.foo")));
		}
	}).assertLogEntry("Erroneous resource service provider registered for 'hubba.foo'. Removing it from the registry.");
	
	assertEquals(0, reg.getExtensionToFactoryMap().size());
}
 
Example #3
Source File: EcoreSupportTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testSimple() throws Exception {
	final ResourceServiceProviderRegistryImpl registry = new ResourceServiceProviderRegistryImpl();
	EcoreSupport support = new EcoreSupport();
	support.setGuiceModule(new EcoreRuntimeModuleForTest(registry));
	
	assertNull(registry.getExtensionToFactoryMap().get("ecore"));
	support.preInvoke();
	IResourceServiceProvider rsp = (IResourceServiceProvider) registry.getExtensionToFactoryMap().get("ecore");
	assertNotNull(rsp.getResourceDescriptionManager());
}
 
Example #4
Source File: ImportedNamespaceAwareLocalScopeProviderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	with(new IndexTestLanguageStandaloneSetup());

	globalScopeProvider = new ResourceSetGlobalScopeProvider();
	nameProvider = new DefaultDeclarativeQualifiedNameProvider();
	nameConverter = new IQualifiedNameConverter.DefaultImpl();
	final DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
	strategy.setQualifiedNameProvider(nameProvider);
	final DefaultResourceDescriptionManager resourceDescMnr = new DefaultResourceDescriptionManager() {
		@Override
		public IResourceDescription getResourceDescription(Resource resource) {
			DefaultResourceDescription resourceDescription = new DefaultResourceDescription(resource,
					strategy);
			return resourceDescription;
		}
		
	};
	final DefaultResourceServiceProvider provider = new DefaultResourceServiceProvider() {
		@Override
		public Manager getResourceDescriptionManager() {
			return resourceDescMnr;
		}
	};
	globalScopeProvider.setGlobalResourceDecriptionProvider(new GlobalResourceDescriptionProvider(new ResourceServiceProviderRegistryImpl() {
		@Override
		public IResourceServiceProvider getResourceServiceProvider(URI uri, String contentType) {
			return provider;
		}
	}));
	CaseInsensitivityHelper caseInsensitivityHelper = new CaseInsensitivityHelper();
	globalScopeProvider.setCaseInsensitivityHelper(caseInsensitivityHelper);
	scopeProvider = new ImportedNamespaceAwareLocalScopeProvider(globalScopeProvider, nameProvider, nameConverter, caseInsensitivityHelper);
}
 
Example #5
Source File: RegistryProvider.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
private Registry createRegistry() {
    registerDefaultFactories();

    IResourceServiceProvider.Registry registry = new ResourceServiceProviderRegistryImpl();
    register(registry, new ItemsIdeSetup().createInjector());
    register(registry, new PersistenceIdeSetup().createInjector());
    register(registry, new RulesIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine)
            .createInjector());
    register(registry, new ScriptIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine)
            .createInjector());
    register(registry, new SitemapIdeSetup().createInjector());
    register(registry, new ThingIdeSetup().createInjector());
    return registry;
}
 
Example #6
Source File: RegistryProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private Registry createRegistry() {
    registerDefaultFactories();

    IResourceServiceProvider.Registry registry = new ResourceServiceProviderRegistryImpl();
    register(registry, new ItemsIdeSetup().createInjector());
    register(registry, new PersistenceIdeSetup().createInjector());
    register(registry, new RulesIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine)
            .createInjector());
    register(registry, new ScriptIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine)
            .createInjector());
    register(registry, new SitemapIdeSetup().createInjector());
    register(registry, new ThingIdeSetup().createInjector());
    return registry;
}
 
Example #7
Source File: EcoreSupportTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public EcoreRuntimeModuleForTest(ResourceServiceProviderRegistryImpl registry) {
	this.registry = registry;
}
 
Example #8
Source File: DirtyStateEditorSupportTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	document = this;
	resourceSet = new ResourceSetImpl();
	resourceURI = URI.createURI("scheme://foo");
	resource = new XtextResource(resourceURI);
	resource.setLanguageName("FooLanguage");
	final DefaultResourceServiceProvider resourceServiceProvider = new DefaultResourceServiceProvider() {
		@Override
		public org.eclipse.xtext.resource.IResourceDescription.Manager getResourceDescriptionManager() {
			return DirtyStateEditorSupportTest.this;
		}
		
		@SuppressWarnings("unchecked")
		@Override
		public <T> T get(Class<T> t) {
			if(DirtyStateResourceDescription.Manager.class.isAssignableFrom(t)) 
				return (T) new DirtyStateResourceDescription.Manager(DirtyStateEditorSupportTest.this);
			if(LanguageInfo.class.isAssignableFrom(t))
				return (T) new LanguageInfo("FooLanguage");
			return super.get(t);
		}
	};
	ResourceServiceProviderRegistryImpl registry = new ResourceServiceProviderRegistryImpl() {
		@Override
		public IResourceServiceProvider getResourceServiceProvider(URI uri) {
			return resourceServiceProvider;
		}
	};
	resource.setResourceServiceProvider(resourceServiceProvider);
	resourceSet.getResources().add(resource);
	dirtyStateSupport = new DirtyStateEditorSupport();
	dirtyStateSupport.setConcurrentEditingWarningDialog(this);
	dirtyStateSupport.setResourceDescriptions(this);
	dirtyStateManager = new DirtyStateManager();
	stateChangeEventBroker = new StateChangeEventBroker();
	dirtyStateManager.addListener(stateChangeEventBroker);
	dirtyStateSupport.setDirtyStateManager(dirtyStateManager);
	dirtyStateSupport.setStateChangeEventBroker(stateChangeEventBroker);
	dirtyResource = new DocumentBasedDirtyResource();
	dirtyStateSupport.setDirtyResource(dirtyResource);
	dirtyStateSupport.setResourceServiceProviderRegistry(registry);
	ignoreConcurrentEditing = Lists.newLinkedList();
	exportedObjects = Collections.emptyList();
}
 
Example #9
Source File: ExtensionResourceServiceProviderRegistryReader.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Map<String, Object> getMap() {
	return ((ResourceServiceProviderRegistryImpl)IResourceServiceProvider.Registry.INSTANCE).getExtensionToFactoryMap();
}
 
Example #10
Source File: ContentResourceServiceProviderRegistryReader.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Map<String, Object> getMap() {
	return ((ResourceServiceProviderRegistryImpl)IResourceServiceProvider.Registry.INSTANCE).getContentTypeToFactoryMap();
}
 
Example #11
Source File: ProtocolResourceServiceProviderRegistryReader.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Map<String, Object> getMap() {
	return ((ResourceServiceProviderRegistryImpl) IResourceServiceProvider.Registry.INSTANCE)
			.getProtocolToFactoryMap();
}