Package com.cognifide.slice.api.injector

Examples of com.cognifide.slice.api.injector.InjectorWithContext


    if (null == contextProvider) {
      throw new IllegalStateException("ContextProvider is not available");
    }

    final InjectorWithContext injector = injectorsRepository.getInjector(injectorName);
    if (injector == null) {
      throw new IllegalStateException("Guice injector not found: " + injectorName);
    }

    injector.pushContextProvider(contextProvider);

    try {
      final ModelProvider modelProvider = injector.getInstance(ModelProvider.class);
      final Resource resource = request.getResource();
      return (T) modelProvider.get(type, resource);
    } finally {
      injector.popContextProvider();
    }
  }
View Full Code Here


   * @param injectorName Name of the desired injector
   * @param request Request used to provide context
   * @return Created injector
   */
  public static InjectorWithContext getInjector(String injectorName, SlingHttpServletRequest request) {
    InjectorWithContext injector = request.adaptTo(InjectorsRepository.class).getInjector(injectorName);
    RequestContextProvider requestContextProvider = request.adaptTo(RequestContextProvider.class);
    injector.pushContextProvider(requestContextProvider.getContextProvider(injectorName));
    return injector;
  }
View Full Code Here

   * @param injectorName Name of the desired injector
   * @param resolver Resolver used to provide context
   * @return Created injector
   */
  public static InjectorWithContext getInjector(String injectorName, ResourceResolver resolver) {
    InjectorWithContext injector = resolver.adaptTo(InjectorsRepository.class).getInjector(injectorName);
    ContextFactory factory = injector.getInstance(ContextFactory.class);
    Context context = factory.getResourceResolverContext(resolver);
    injector.pushContextProvider(new ConstantContextProvider(context));
    return injector;
  }
View Full Code Here

    return getInjector(injectorName);
  }

  @Override
  public InjectorWithContext getInjectorForResource(String resourcePath) {
    InjectorWithContext injector = null;
    try {
      injector = getInjectorForResourceAsAdmin(resourcePath);
    } catch (LoginException e) {
      // yikes! I can no longer login to repostiory with "null" credentials!
      LOG.error("Unexpected: could not access administrative resource resolver");
View Full Code Here

  }

  private InjectorWithContext getInjectorForResourceAsAdmin(String resourcePath) throws LoginException {
    ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
    Resource resource = resourceResolver.getResource(resourcePath);
    InjectorWithContext injector = getInjectorForResource(resource);
    resourceResolver.close();
    return injector;
  }
View Full Code Here

    if (null == contextProvider) {
      throw new IllegalStateException("ContextProvider is not available");
    }

    final InjectorWithContext injector = injectorsRepository.getInjector(injectorName);
    if (injector == null) {
      throw new IllegalStateException("Guice injector not found: " + injectorName);
    }

    injector.pushContextProvider(contextProvider);
    try {
      final ModelProvider modelProvider = injector.getInstance(ModelProvider.class);
      final Resource resource = request.getResource();
      return (T) modelProvider.get(type, resource);
    } finally {
      injector.popContextProvider();
    }
  }
View Full Code Here

   * @param injectorName Name of the desired injector
   * @return Created injector
   */
  public static InjectorWithContext getInjector(String injectorName, SlingHttpServletRequest request,
      SlingHttpServletResponse response) {
    InjectorWithContext injector = request.adaptTo(InjectorsRepository.class).getInjector(injectorName);
    RequestContextProvider requestContextProvider = request.adaptTo(RequestContextProvider.class);
    injector.pushContextProvider(requestContextProvider.getContextProvider(injectorName));
    return injector;
  }
View Full Code Here

   *
   * @param injectorName Name of the desired injector
   * @return Created injector
   */
  public static InjectorWithContext getInjector(String injectorName, ResourceResolver resolver) {
    InjectorWithContext injector = resolver.adaptTo(InjectorsRepository.class).getInjector(injectorName);
    ContextFactory factory = injector.getInstance(ContextFactory.class);
    Context context = factory.getResourceResolverContext(resolver);
    injector.pushContextProvider(new ConstantContextProvider(context));
    return injector;
  }
View Full Code Here

    return getInjector(injectorName);
  }

  @Override
  public InjectorWithContext getInjectorForResource(String resourcePath) {
    InjectorWithContext injector = null;
    try {
      injector = getInjectorForResourceAsAdmin(resourcePath);
    } catch (LoginException e) {
      // yikes! I can no longer login to repostiory with "null" credentials!
      LOG.error("Unexpected: could not access administrative resource resolver");
View Full Code Here

  }

  private InjectorWithContext getInjectorForResourceAsAdmin(String resourcePath) throws LoginException {
    ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
    Resource resource = resourceResolver.getResource(resourcePath);
    InjectorWithContext injector = getInjectorForResource(resource);
    resourceResolver.close();
    return injector;
  }
View Full Code Here

TOP

Related Classes of com.cognifide.slice.api.injector.InjectorWithContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.