Search in sources :

Example 1 with Provider

use of com.google.inject.Provider in project camel by apache.

the class JndiContext method lookup.

public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object value = bindings.get(first);
                if (value == null) {
                    throw new NameNotFoundException(name);
                } else if (value instanceof Context && path.size() > 1) {
                    Context subContext = (Context) value;
                    value = subContext.lookup(path.getSuffix(1));
                }
                return value;
            }
        }
    }
    if (result instanceof Provider) {
        Provider provider = (Provider) result;
        result = provider.get();
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof JndiContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new JndiContext((JndiContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) Provider(com.google.inject.Provider) LinkRef(javax.naming.LinkRef)

Example 2 with Provider

use of com.google.inject.Provider in project che by eclipse.

the class BootstrapController method startComponents.

private void startComponents(final Iterator<Map.Entry<String, Provider<Component>>> componentIterator) {
    if (componentIterator.hasNext()) {
        Map.Entry<String, Provider<Component>> entry = componentIterator.next();
        final String componentName = entry.getKey();
        try {
            Provider<Component> componentProvider = entry.getValue();
            final Component component = componentProvider.get();
            component.start(new Callback<Component, Exception>() {

                @Override
                public void onSuccess(Component result) {
                    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                        @Override
                        public void execute() {
                            startComponents(componentIterator);
                        }
                    });
                }

                @Override
                public void onFailure(Exception reason) {
                    Log.error(getClass(), "Unable to start " + componentName, reason);
                    initializationFailed(reason.getMessage());
                }
            });
        } catch (Exception e) {
            Log.error(getClass(), "Unable to start " + componentName, e);
            initializationFailed(e.getMessage());
        }
    } else {
        startExtensionsAndDisplayUI();
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) WsAgentComponent(org.eclipse.che.ide.api.component.WsAgentComponent) Component(org.eclipse.che.ide.api.component.Component) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) OperationException(org.eclipse.che.api.promises.client.OperationException) Provider(com.google.inject.Provider)

Example 3 with Provider

use of com.google.inject.Provider in project che by eclipse.

the class ImportProjectWizardPresenter method getWizardForImporter.

/** Creates or returns import wizard for the specified importer. */
private ImportWizard getWizardForImporter(@NotNull ProjectImporterDescriptor importer) {
    if (wizardsCache.containsKey(importer)) {
        return wizardsCache.get(importer);
    }
    final ImportWizardRegistrar wizardRegistrar = wizardRegistry.getWizardRegistrar(importer.getId());
    if (wizardRegistrar == null) {
        // should never occur
        throw new IllegalStateException("WizardRegistrar for the importer " + importer.getId() + " isn't registered.");
    }
    List<Provider<? extends WizardPage<MutableProjectConfig>>> pageProviders = wizardRegistrar.getWizardPages();
    final ImportWizard importWizard = createDefaultWizard();
    for (Provider<? extends WizardPage<MutableProjectConfig>> provider : pageProviders) {
        importWizard.addPage(provider.get(), 1, false);
    }
    wizardsCache.put(importer, importWizard);
    return importWizard;
}
Also used : ImportWizardRegistrar(org.eclipse.che.ide.api.project.wizard.ImportWizardRegistrar) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) ImportWizard(org.eclipse.che.ide.projectimport.wizard.ImportWizard) WizardPage(org.eclipse.che.ide.api.wizard.WizardPage) Provider(com.google.inject.Provider)

Example 4 with Provider

use of com.google.inject.Provider in project che by eclipse.

the class PomReconcilerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    Provider<ProjectRegistry> projectRegistryProvider = (Provider<ProjectRegistry>) mock(Provider.class);
    when(projectRegistryProvider.get()).thenReturn(projectRegistry);
    MavenServerManagerTest.MyMavenServerProgressNotifier mavenNotifier = new MavenServerManagerTest.MyMavenServerProgressNotifier();
    MavenTerminal terminal = new MavenTerminal() {

        @Override
        public void print(int level, String message, Throwable throwable) throws RemoteException {
            System.out.println(message);
            if (throwable != null) {
                throwable.printStackTrace();
            }
        }
    };
    File localRepository = new File(new File("target/localRepo").getAbsolutePath());
    localRepository.mkdirs();
    mavenServerManager.setLocalRepository(localRepository);
    MavenWrapperManager wrapperManager = new MavenWrapperManager(mavenServerManager);
    projectManager = new MavenProjectManager(wrapperManager, mavenServerManager, terminal, mavenNotifier, new EclipseWorkspaceProvider());
    ClasspathManager classpathManager = new ClasspathManager(root.getAbsolutePath(), wrapperManager, projectManager, terminal, mavenNotifier);
    mavenWorkspace = new MavenWorkspace(projectManager, mavenNotifier, new MavenExecutorService(), projectRegistryProvider, new MavenCommunication() {

        @Override
        public void sendUpdateMassage(Set<MavenProject> updated, List<MavenProject> removed) {
        }

        @Override
        public void sendNotification(NotificationMessage message) {
            System.out.println(message.toString());
        }

        @Override
        public void send(JsonObject object, MessageType type) {
        }
    }, classpathManager, eventService, new EclipseWorkspaceProvider());
}
Also used : ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Set(java.util.Set) JsonObject(com.google.gson.JsonObject) MavenCommunication(org.eclipse.che.plugin.maven.server.core.MavenCommunication) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) Provider(com.google.inject.Provider) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) MavenExecutorService(org.eclipse.che.plugin.maven.server.core.MavenExecutorService) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) List(java.util.List) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest) File(java.io.File) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with Provider

use of com.google.inject.Provider in project che by eclipse.

the class WorkspaceTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    Provider<ProjectRegistry> projectRegistryProvider = (Provider<ProjectRegistry>) mock(Provider.class);
    when(projectRegistryProvider.get()).thenReturn(projectRegistry);
    MavenServerManagerTest.MyMavenServerProgressNotifier mavenNotifier = new MavenServerManagerTest.MyMavenServerProgressNotifier();
    MavenTerminal terminal = new MavenTerminal() {

        @Override
        public void print(int level, String message, Throwable throwable) throws RemoteException {
            System.out.println(message);
            if (throwable != null) {
                throwable.printStackTrace();
            }
        }
    };
    MavenWrapperManager wrapperManager = new MavenWrapperManager(mavenServerManager);
    mavenProjectManager = new MavenProjectManager(wrapperManager, mavenServerManager, terminal, mavenNotifier, new EclipseWorkspaceProvider());
    mavenWorkspace = new MavenWorkspace(mavenProjectManager, mavenNotifier, new MavenExecutorService(), projectRegistryProvider, new MavenCommunication() {

        @Override
        public void sendUpdateMassage(Set<MavenProject> updated, List<MavenProject> removed) {
        }

        @Override
        public void sendNotification(NotificationMessage message) {
            System.out.println(message.toString());
        }

        @Override
        public void send(JsonObject object, MessageType type) {
        }
    }, new ClasspathManager(root.getAbsolutePath(), wrapperManager, mavenProjectManager, terminal, mavenNotifier), eventService, new EclipseWorkspaceProvider());
}
Also used : ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Set(java.util.Set) JsonObject(com.google.gson.JsonObject) MavenCommunication(org.eclipse.che.plugin.maven.server.core.MavenCommunication) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) Provider(com.google.inject.Provider) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) MavenExecutorService(org.eclipse.che.plugin.maven.server.core.MavenExecutorService) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) List(java.util.List) ArrayList(java.util.ArrayList) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Provider (com.google.inject.Provider)132 Injector (com.google.inject.Injector)72 AbstractModule (com.google.inject.AbstractModule)63 Module (com.google.inject.Module)44 Key (com.google.inject.Key)17 TypeLiteral (com.google.inject.TypeLiteral)10 ArrayList (java.util.ArrayList)10 ProvisionException (com.google.inject.ProvisionException)9 Dependency (com.google.inject.spi.Dependency)9 Map (java.util.Map)8 Before (org.junit.Before)7 CurrentUser (com.google.gerrit.server.CurrentUser)6 RequestContext (com.google.gerrit.server.util.RequestContext)6 ThreadLocalRequestContext (com.google.gerrit.server.util.ThreadLocalRequestContext)6 InMemoryModule (com.google.gerrit.testutil.InMemoryModule)6 PrivateModule (com.google.inject.PrivateModule)6 Scope (com.google.inject.Scope)6 List (java.util.List)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Annotation (java.lang.annotation.Annotation)5