Package com.cognifide.slice.api.context

Examples of com.cognifide.slice.api.context.Context


   * Update Context instance for current thread to use current request and response values.
   */
  @Override
  public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
      throws IOException, ServletException {
    final Context previous = contexts.get();

    try {
      final Context context = (new SliceContextFactory()).getServletRequestContext(request, response);
      contexts.set(context);
      chain.doFilter(request, response);
    } finally {
      contexts.set(previous);
    }
View Full Code Here


   * @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 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

    final ContextProvider contextProvider = this.contextScope.getContextProvider();
    if (null == contextProvider) {
      return null;
    }

    final Context context = contextProvider.getContext();
    synchronized (context) {
      if (context.contains(key)) {
        return context.get(key);
      }

      final T t = unscopedProvider.get();
      context.put(key, t);

      return t;
    }
  }
View Full Code Here

  public Context getServletRequestContext(final ServletRequest request, final ServletResponse response) {
    if (null == request || null == response) {
      return null;
    }

    final Context context = new ServletRequestContext(request);
    context.put(Key.get(ServletRequest.class), request);
    context.put(Key.get(ServletResponse.class), response);

    final Resource requestedResource = getRequestedResource(request);
    context.put(Key.get(Resource.class, RequestedResource.class), requestedResource);

    return context;
  }
View Full Code Here

   * Update Context instance for current thread to use current request and response values.
   */
  @Override
  public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
      throws IOException, ServletException {
    final Context previous = contexts.get();

    try {
      final Context context = (new SliceContextFactory()).getServletRequestContext(request, response);
      contexts.set(context);
      chain.doFilter(request, response);
    } finally {
      contexts.set(previous);
    }
View Full Code Here

  public ContextProvider getContextProvider(final String injectorName) {
    Map<String, Context> contextMap = contexts.get();
    if (contextMap == null) {
      return null;
    }
    Context context = contextMap.get(injectorName);
    if (context == null) {
      return null;
    }
    return new ConstantContextProvider(context);
  }
View Full Code Here

      final ServletResponse response) {
    if (null == request || null == response) {
      throw new IllegalArgumentException("Request and response can't be null");
    }

    final Context context = new ServletRequestContext(injectorName, request);
    context.put(Key.get(ServletRequest.class), request);
    context.put(Key.get(ServletResponse.class), response);

    final Resource requestedResource = getRequestedResource(request);
    context.put(Key.get(Resource.class, RequestedResource.class), requestedResource);

    return context;
  }
View Full Code Here

  private InjectorWithContext getInjector(Resource resource) {
    InjectorWithContext injector = repository.getInjector(injectorName);
    ContextProvider contextProvider = requestContextProvider.getContextProvider(injectorName);
    if (contextProvider == null) {
      ContextFactory factory = injector.getInstance(ContextFactory.class);
      Context context = factory.getResourceResolverContext(resource.getResourceResolver());
      contextProvider = new ConstantContextProvider(context);
    }
    injector.pushContextProvider(contextProvider);
    return injector;
  }
View Full Code Here

TOP

Related Classes of com.cognifide.slice.api.context.Context

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.