Java Code Examples for com.intellij.openapi.application.Application

The following examples show how to use com.intellij.openapi.application.Application. These examples are extracted from open source projects. 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 Project: leetcode-editor   Source File: HttpRequests.java    License: Apache License 2.0 6 votes vote down vote up
private static <T> T process(RequestBuilderImpl builder, RequestProcessor<T> processor) throws IOException {
    Application app = ApplicationManager.getApplication();
    LOG.assertTrue(app == null || app.isUnitTestMode() || app.isHeadlessEnvironment() || !app.isReadAccessAllowed(),
            "Network shouldn't be accessed in EDT or inside read action");

    ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
    if (contextLoader != null && shouldOverrideContextClassLoader()) {
        // hack-around for class loader lock in sun.net.www.protocol.http.NegotiateAuthentication (IDEA-131621)
        try (URLClassLoader cl = new URLClassLoader(new URL[0], contextLoader)) {
            Thread.currentThread().setContextClassLoader(cl);
            return doProcess(builder, processor);
        }
        finally {
            Thread.currentThread().setContextClassLoader(contextLoader);
        }
    }
    else {
        return doProcess(builder, processor);
    }
}
 
Example 2
Source Project: consulo   Source File: RefreshProgress.java    License: Apache License 2.0 6 votes vote down vote up
private void updateIndicators(final boolean start) {
  Application application = Application.get();
  UIAccess uiAccess = application.getLastUIAccess();
  // wrapping in invokeLater here reduces the number of events posted to EDT in case of multiple IDE frames
  uiAccess.giveIfNeed(() -> {
    if (application.isDisposed()) return;

    WindowManager windowManager = WindowManager.getInstance();
    if (windowManager == null) return;

    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    if (projects.length == 0) projects = NULL_ARRAY;
    for (Project project : projects) {
      StatusBarEx statusBar = (StatusBarEx)windowManager.getStatusBar(project);
      if (statusBar != null) {
        if (start) {
          statusBar.startRefreshIndication(myMessage);
        }
        else {
          statusBar.stopRefreshIndication();
        }
      }
    }
  });
}
 
Example 3
Source Project: consulo   Source File: GeneralToSMTRunnerEventsConvertor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void dispose() {
  super.dispose();
  addToInvokeLater(() -> {

    disconnectListeners();
    if (!myRunningTestsFullNameToProxy.isEmpty()) {
      final Application application = ApplicationManager.getApplication();
      if (!application.isHeadlessEnvironment() && !application.isUnitTestMode()) {
        logProblem("Not all events were processed! " + dumpRunningTestsNames());
      }
    }
    myRunningTestsFullNameToProxy.clear();
    mySuitesStack.clear();
  });
}
 
Example 4
private void performRequestOnUiThread() {
  final Runnable doRun = () -> {
    if (requestScheduler.isDisposed()) {
      return;
    }
    performRequest();
  };
  final Application app = ApplicationManager.getApplication();
  if (app == null || app.isUnitTestMode()) {
    // This case exists to support unittesting.
    SwingUtilities.invokeLater(doRun);
  }
  else {
    app.invokeLater(doRun);
  }
}
 
Example 5
Source Project: consulo   Source File: ManagePackagesDialog.java    License: Apache License 2.0 6 votes vote down vote up
public void initModel() {
  setDownloadStatus(true);
  final Application application = ApplicationManager.getApplication();
  application.executeOnPooledThread(() -> {
    try {
      myPackagesModel = new PackagesModel(myController.getAllPackages());

      application.invokeLater(() -> {
        myPackages.setModel(myPackagesModel);
        ((MyPackageFilter)myFilter).filter();
        doSelectPackage(mySelectedPackageName);
        setDownloadStatus(false);
      }, ModalityState.any());
    }
    catch (final IOException e) {
      application.invokeLater(() -> {
        if (myMainPanel.isShowing()) {
          Messages.showErrorDialog(myMainPanel, "Error loading package list:" + e.getMessage(), "Packages");
        }
        setDownloadStatus(false);
      }, ModalityState.any());
    }
  });
}
 
Example 6
Source Project: consulo   Source File: ToolbarUpdater.java    License: Apache License 2.0 6 votes vote down vote up
private void updateActions(boolean now, final boolean transparentOnly, final boolean forced) {
  final Runnable updateRunnable = new MyUpdateRunnable(this, transparentOnly, forced);
  final Application app = ApplicationManager.getApplication();

  if (now || (app.isUnitTestMode() && app.isDispatchThread())) {
    updateRunnable.run();
  }
  else {
    final IdeFocusManager fm = IdeFocusManager.getInstance(null);

    if (!app.isHeadlessEnvironment()) {
      if (app.isDispatchThread() && myComponent.isShowing()) {
        fm.doWhenFocusSettlesDown(updateRunnable);
      }
      else {
        UiNotifyConnector.doWhenFirstShown(myComponent, () -> fm.doWhenFocusSettlesDown(updateRunnable));
      }
    }
  }
}
 
Example 7
Source Project: consulo   Source File: InstalledPackagesPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void refreshLatestVersions(@Nonnull final PackageManagementService packageManagementService) {
  final Application application = ApplicationManager.getApplication();
  application.executeOnPooledThread(() -> {
    if (packageManagementService == myPackageManagementService) {
      try {
        List<RepoPackage> packages = packageManagementService.reloadAllPackages();
        final Map<String, RepoPackage> packageMap = buildNameToPackageMap(packages);
        application.invokeLater(() -> {
          for (int i = 0; i != myPackagesTableModel.getRowCount(); ++i) {
            final InstalledPackage pyPackage = (InstalledPackage)myPackagesTableModel.getValueAt(i, 0);
            final RepoPackage repoPackage = packageMap.get(pyPackage.getName());
            myPackagesTableModel.setValueAt(repoPackage == null ? null : repoPackage.getLatestVersion(), i, 2);
          }
          myPackagesTable.setPaintBusy(false);
        }, ModalityState.stateForComponent(myPackagesTable));
      }
      catch (IOException ignored) {
        myPackagesTable.setPaintBusy(false);
      }
    }
  });
}
 
Example 8
Source Project: consulo   Source File: ActionTracer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public JComponent getComponent() {
  if (myComponent == null) {
    myText = new JTextArea();
    final JBScrollPane log = new JBScrollPane(myText);
    final AnAction clear = new AnAction("Clear", "Clear log", AllIcons.General.Reset) {
      @Override
      public void actionPerformed(AnActionEvent e) {
        myText.setText(null);
      }
    };
    myComponent = new JPanel(new BorderLayout());
    final DefaultActionGroup group = new DefaultActionGroup();
    group.add(clear);
    myComponent.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent(), BorderLayout.NORTH);
    myComponent.add(log);

    myListenerDisposable = Disposable.newDisposable();
    Application.get().getMessageBus().connect(myListenerDisposable).subscribe(AnActionListener.TOPIC, this);
  }

  return myComponent;
}
 
Example 9
Source Project: intellij   Source File: TestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void createMockApplication(Disposable parentDisposable) {
  final BlazeMockApplication instance = new BlazeMockApplication(parentDisposable);

  // If there was no previous application,
  // ApplicationManager leaves the MockApplication in place, which can break future tests.
  Application oldApplication = ApplicationManager.getApplication();
  if (oldApplication == null) {
    Disposer.register(
        parentDisposable,
        () -> {
          new ApplicationManager() {
            {
              ourApplication = null;
            }
          };
        });
  }

  ApplicationManager.setApplication(instance, FileTypeManager::getInstance, parentDisposable);
  instance.registerService(EncodingManager.class, EncodingManagerImpl.class);
}
 
Example 10
Source Project: consulo   Source File: ChooseLibrariesDialogBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void collectChildren(Object element, final List<Object> result) {
  if (element instanceof Application) {
    Collections.addAll(result, ProjectManager.getInstance().getOpenProjects());
    final LibraryTablesRegistrar instance = LibraryTablesRegistrar.getInstance();
    result.add(instance.getLibraryTable()); //1
    result.addAll(instance.getCustomLibraryTables()); //2
  }
  else if (element instanceof Project) {
    Collections.addAll(result, ModuleManager.getInstance((Project)element).getModules());
    result.add(LibraryTablesRegistrar.getInstance().getLibraryTable((Project)element));
  }
  else if (element instanceof LibraryTable) {
    Collections.addAll(result, ((LibraryTable)element).getLibraries());
  }
  else if (element instanceof Module) {
    for (OrderEntry entry : ModuleRootManager.getInstance((Module)element).getOrderEntries()) {
      if (entry instanceof LibraryOrderEntry) {
        final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
        if (LibraryTableImplUtil.MODULE_LEVEL.equals(libraryOrderEntry.getLibraryLevel())) {
          final Library library = libraryOrderEntry.getLibrary();
          result.add(library);
        }
      }
    }
  }
}
 
Example 11
Source Project: consulo   Source File: PerApplicationInstance.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public V get() {
  V oldValue = myValue;
  if (oldValue == null) {
    synchronized (this) {
      oldValue = myValue;
      if (oldValue == null) {
        Application application = Application.get();
        V newValue = application.getInjectingContainer().getInstance(myTargetClass);
        Disposer.register(application, () -> myValue = null);
        myValue = newValue;
        return newValue;
      }
    }
  }

  return oldValue;
}
 
Example 12
Source Project: consulo   Source File: EditorActionHandlerBean.java    License: Apache License 2.0 6 votes vote down vote up
public EditorActionHandler getHandler(EditorActionHandler originalHandler) {
  if (myHandler == null) {
    try {
      InjectingContainer container = Application.get().getInjectingContainer();

      InjectingContainerBuilder builder = container.childBuilder();
      // bind original to EditorActionHandler
      builder.bind(EditorActionHandler.class).to(originalHandler);

      myHandler = instantiate(implementationClass, builder.build());
    }
    catch(Exception e) {
      LOG.error(e);
      return null;
    }
  }
  return myHandler;
}
 
Example 13
Source Project: consulo   Source File: LightFilePointer.java    License: Apache License 2.0 6 votes vote down vote up
private void refreshFile() {
  VirtualFile file = myFile;
  if (file != null && file.isValid()) return;
  VirtualFileManager vfManager = VirtualFileManager.getInstance();
  VirtualFile virtualFile = vfManager.findFileByUrl(myUrl);
  if (virtualFile == null && !myRefreshed) {
    myRefreshed = true;
    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread() || !application.isReadAccessAllowed()) {
      virtualFile = vfManager.refreshAndFindFileByUrl(myUrl);
    }
    else {
      application.executeOnPooledThread(() -> vfManager.refreshAndFindFileByUrl(myUrl));
    }
  }

  myFile = virtualFile != null && virtualFile.isValid() ? virtualFile : null;
}
 
Example 14
Source Project: p4ic4idea   Source File: MockThreadRunner.java    License: Apache License 2.0 6 votes vote down vote up
private MockThreadRunner(IdeaLightweightExtension extension, long waitTimeSeconds) {
    waitTimeoutSeconds = waitTimeSeconds;
    Application application = extension.getMockApplication();

    BlockingRunAnswer pooledThreadAnswer = new BlockingRunAnswer(pooledThreadsRun);
    when(application.executeOnPooledThread((Runnable) any())).then(pooledThreadAnswer);
    when(application.executeOnPooledThread((Callable<?>) any())).then(pooledThreadAnswer);

    BlockingRunAnswer edtLaterAnswer = new BlockingRunAnswer(edtLaterRun);
    doAnswer(edtLaterAnswer).when(application).invokeLater(any());
    doAnswer(edtLaterAnswer).when(application).invokeLater(any(), (Condition) any());
    doAnswer(edtLaterAnswer).when(application).invokeLater(any(), (ModalityState) any());

    InthreadRunAnswer edtWaitAnswer = new InthreadRunAnswer(edtWaitRun);
    doAnswer(edtWaitAnswer).when(application).invokeAndWait(any());
    doAnswer(edtWaitAnswer).when(application).invokeAndWait(any(), any());
}
 
Example 15
Source Project: consulo   Source File: EditorTypedHandlerBean.java    License: Apache License 2.0 6 votes vote down vote up
public TypedActionHandler getHandler(TypedActionHandler originalHandler) {
  if (myHandler == null) {
    try {
      InjectingContainer container = Application.get().getInjectingContainer();

      InjectingContainerBuilder builder = container.childBuilder();
      // bind original to TypedActionHandler
      builder.bind(TypedActionHandler.class).to(originalHandler);

      myHandler = instantiate(implementationClass, builder.build());
    }
    catch(Exception e) {
      LOG.error(e);
      return null;
    }
  }
  return myHandler;
}
 
Example 16
Source Project: consulo   Source File: GeneralTestEventsProcessor.java    License: Apache License 2.0 6 votes vote down vote up
public void addToInvokeLater(final Runnable runnable) {
  final Application application = ApplicationManager.getApplication();
  if (application.isUnitTestMode()) {
    UIUtil.invokeLaterIfNeeded(() -> {
      if (!myProject.isDisposed()) {
        runnable.run();
      }
    });
  }
  else if (application.isHeadlessEnvironment() || SwingUtilities.isEventDispatchThread()) {
    runnable.run();
  }
  else {
    myTransferToEDTQueue.offer(runnable);
  }
}
 
Example 17
private AddModuleWizard openNewProjectWizard(VirtualFile projectFile) {
  PantsProjectImportProvider provider = new PantsProjectImportProvider();
  AddModuleWizard dialog = new AddModuleWizard(null, projectFile.getPath(), provider);

  ProjectImportBuilder builder = provider.getBuilder();
  builder.setUpdate(false);
  dialog.getWizardContext().setProjectBuilder(builder);

  // dialog can only be shown in a non-headless environment
  Application application = ApplicationManager.getApplication();
  if (application.isHeadlessEnvironment() || dialog.showAndGet()) {
    return dialog;
  }
  else {
    return null;
  }
}
 
Example 18
Source Project: consulo   Source File: DesktopIdeFrameImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void setupCloseAction() {
  myJFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  myJFrame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(@Nonnull final WindowEvent e) {
      if (isTemporaryDisposed()) return;

      final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
      if (openProjects.length > 1 || openProjects.length == 1 && TopApplicationMenuUtil.isMacSystemMenu) {
        if (myProject != null && myProject.isOpen()) {
          ProjectUtil.closeAndDispose(myProject);
        }
        ApplicationManager.getApplication().getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed();
        WelcomeFrame.showIfNoProjectOpened();
      }
      else {
        Application.get().exit();
      }
    }
  });
}
 
Example 19
Source Project: consulo   Source File: ExtensibleQueryFactory.java    License: Apache License 2.0 6 votes vote down vote up
protected ExtensibleQueryFactory(@NonNls final String epNamespace) {
  myPoint = new NotNullLazyValue<SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>>>() {
    @Override
    @Nonnull
    protected SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>> compute() {
      return new SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>>(new SmartList<QueryExecutor<Result, Parameters>>()){
        @Override
        @Nonnull
        protected ExtensionPoint<QueryExecutor<Result, Parameters>> getExtensionPoint() {
          String epName = ExtensibleQueryFactory.this.getClass().getName();
          int pos = epName.lastIndexOf('.');
          if (pos >= 0) {
            epName = epName.substring(pos+1);
          }
          epName = epNamespace + "." + StringUtil.decapitalize(epName);
          return Application.get().getExtensionPoint(ExtensionPointName.create(epName));
        }
      };
    }
  };
}
 
Example 20
Source Project: intellij-quarkus   Source File: CommandExecutor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unused") // ECJ compiler for some reason thinks handlerService == null is always false
private static boolean executeCommandClientSide(Command command, Document document) {
    Application workbench = ApplicationManager.getApplication();
    if (workbench == null) {
        return false;
    }
    URI context = LSPIJUtils.toUri(document);
    AnAction parameterizedCommand = createEclipseCoreCommand(command, context, workbench);
    if (parameterizedCommand == null) {
        return false;
    }
    DataContext dataContext = createDataContext(command, context, workbench);
    ActionUtil.invokeAction(parameterizedCommand, dataContext, ActionPlaces.UNKNOWN, null, null);
    return true;
}
 
Example 21
Source Project: intellij-quarkus   Source File: CommandExecutor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private static AnAction createEclipseCoreCommand(Command command, URI context,
                                                             Application workbench) {
    // Usually commands are defined via extension point, but we synthesize one on
    // the fly for the command ID, since we do not want downstream users
    // having to define them.
    String commandId = command.getCommand();
    return ActionManager.getInstance().getAction(commandId);
}
 
Example 22
public static void saveFile(String name, String content, Module javaProject) throws IOException {
    String modulePath = ModuleUtilCore.getModuleDirPath(javaProject);
    VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(modulePath + "/src/main/resources/" + name);
    Application application = ApplicationManager.getApplication();
    application.invokeAndWait(() -> application.runWriteAction(() -> {
        try {
            file.setBinaryContent(content.getBytes(file.getCharset()));
        } catch (IOException e) {}
    }));
}
 
Example 23
Source Project: consulo   Source File: Notifications.java    License: Apache License 2.0 5 votes vote down vote up
public static void notifyAndHide(@Nonnull final Notification notification, @Nullable Project project) {
  notify(notification);
  Alarm alarm = new Alarm(project == null ? Application.get() : project);
  alarm.addRequest(() -> {
    notification.expire();
    Disposer.dispose(alarm);
  }, 5000);
}
 
Example 24
Source Project: consulo   Source File: StatusBarUpdater.java    License: Apache License 2.0 5 votes vote down vote up
private void updateLater() {
  final Application application = ApplicationManager.getApplication();
  if (application.isUnitTestMode()) {
    myUpdateStatusRunnable.run();
  }
  else {
    updateStatusAlarm.cancelAllRequests();
    updateStatusAlarm.addRequest(myUpdateStatusRunnable, 100);
  }
}
 
Example 25
Source Project: consulo   Source File: ActionMacroManager.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public ActionMacroManager(Application application, ActionManager actionManager) {
  myActionManager = actionManager;
  application.getMessageBus().connect(this).subscribe(AnActionListener.TOPIC, new AnActionListener() {
    @Override
    public void beforeActionPerformed(AnAction action, DataContext dataContext, final AnActionEvent event) {
      String id = myActionManager.getId(action);
      if (id == null) return;
      //noinspection HardCodedStringLiteral
      if ("StartStopMacroRecording".equals(id)) {
        myLastActionInputEvent.add(event.getInputEvent());
      }
      else if (myIsRecording) {
        myRecordingMacro.appendAction(id);
        String shortcut = null;
        if (event.getInputEvent() instanceof KeyEvent) {
          shortcut = KeymapUtil.getKeystrokeText(KeyStroke.getKeyStrokeForEvent((KeyEvent)event.getInputEvent()));
        }
        notifyUser(id + (shortcut != null ? " (" + shortcut + ")" : ""), false);
        myLastActionInputEvent.add(event.getInputEvent());
      }
    }
  });

  myKeyProcessor = new MyKeyPostpocessor();

  Platform.runIfDesktopPlatform(() -> IdeEventQueue.getInstance().addPostprocessor(myKeyProcessor, null));
}
 
Example 26
Source Project: json2java4idea   Source File: IdeaProjectTest.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@CheckReturnValue
protected Application getApplication() {
    if (fixture == null) {
        throw new AssertionError("getApplication() must call after setUp()");
    }
    return ApplicationManager.getApplication();
}
 
Example 27
Source Project: consulo   Source File: KeymapUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ShortcutSet getActiveKeymapShortcuts(@Nullable String actionId) {
  Application application = ApplicationManager.getApplication();
  KeymapManager keymapManager = application == null ? null : application.getComponent(KeymapManager.class);
  if (keymapManager == null || actionId == null) {
    return new CustomShortcutSet(Shortcut.EMPTY_ARRAY);
  }
  return new CustomShortcutSet(keymapManager.getActiveKeymap().getShortcuts(actionId));
}
 
Example 28
Source Project: ok-gradle   Source File: GradleDslFile.java    License: Apache License 2.0 5 votes vote down vote up
protected GradleDslFile(@NotNull VirtualFile file,
                        @NotNull Project project,
                        @NotNull String moduleName,
                        @NotNull BuildModelContext context) {
  super(null, null, GradleNameElement.fake(moduleName));
  myFile = file;
  myProject = project;
  myBuildModelContext = context;

  Application application = ApplicationManager.getApplication();
  PsiFile psiFile = application.runReadAction((Computable<PsiFile>)() -> PsiManager.getInstance(myProject).findFile(myFile));

  // Pick the language that should be used by this GradleDslFile, we do this by selecting the parser implementation.
  GroovyFile groovyPsiFile;
  if (psiFile instanceof GroovyFile) {
    groovyPsiFile = (GroovyFile)psiFile;
    myGradleDslParser = new GroovyDslParser(groovyPsiFile, this);
    myGradleDslWriter = new GroovyDslWriter();
  }
  else {
    // If we don't support the language we ignore the PsiElement and set stubs for the writer and parser.
    // This means this file will produce an empty model.
    myGradleDslParser = new GradleDslParser.Adapter();
    myGradleDslWriter = new GradleDslWriter.Adapter();
    return;
  }

  setPsiElement(groovyPsiFile);
}
 
Example 29
Source Project: consulo   Source File: ShowTextPopupHyperlinkInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(Project project) {
  Application.get().invokeLater(() -> {
    Document document = EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(myText));
    EditorTextField textField = new EditorTextField(document, project, PlainTextFileType.INSTANCE, true, false) {
      @Override
      protected EditorEx createEditor() {
        EditorEx editor = super.createEditor();
        editor.getScrollPane().setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        editor.getScrollPane().setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        editor.getSettings().setUseSoftWraps(true);
        return editor;
      }
    };

    Window frame = TargetAWT.to(WindowManager.getInstance().getWindow(project));
    if(frame != null) {
      Dimension size = frame.getSize();
      if(size != null) {
        textField.setPreferredSize(new Dimension(size.width / 2, size.height / 2));
      }
    }

    JBPopupFactory.getInstance()
            .createComponentPopupBuilder(textField, textField)
            .setTitle(myTitle)
            .setResizable(true)
            .setMovable(true)
            .setRequestFocus(true)
            .createPopup()
            .showCenteredInCurrentWindow(project);
  });
}
 
Example 30
Source Project: consulo   Source File: ToolWindowEP.java    License: Apache License 2.0 5 votes vote down vote up
public ToolWindowFactory getToolWindowFactory() {
  if (myFactory == null) {
    try {
      myFactory = instantiate(getFactoryClass(), Application.get().getInjectingContainer());
    }
    catch(Exception e) {
      LOG.error(e);
      return null;
    }
  }
  return myFactory;
}