Example #1
0
File: K9.java Project: kamilk/k-9
 /**
  * since Android invokes Application.onCreate() only after invoking all other components'
  * onCreate(), here is a way to notify interested component that the application is available and
  * ready
  */
 protected void notifyObservers() {
   for (final ApplicationAware aware : observers) {
     if (K9.DEBUG) {
       Log.v(K9.LOG_TAG, "Initializing observer: " + aware);
     }
     try {
       aware.initializeComponent(this);
     } catch (Exception e) {
       Log.w(K9.LOG_TAG, "Failure when notifying " + aware, e);
     }
   }
 }
Example #2
0
File: K9.java Project: klonikar/k-9
 /**
  * Register a component to be notified when the {@link K9} instance is ready.
  *
  * @param component Never <code>null</code>.
  */
 public static void registerApplicationAware(final ApplicationAware component) {
   synchronized (observers) {
     if (sInitialized) {
       component.initializeComponent(K9.app);
     } else if (!observers.contains(component)) {
       observers.add(component);
     }
   }
 }
  /**
   * Sets action properties based on the interfaces an action implements. Things like application
   * properties, parameters, session attributes, etc are set based on the implementing interface.
   *
   * @param invocation an encapsulation of the action execution state.
   * @throws Exception if an error occurs when setting action properties.
   */
  public String intercept(ActionInvocation invocation) throws Exception {
    final Object action = invocation.getAction();
    final ActionContext context = invocation.getInvocationContext();

    if (action instanceof ServletRequestAware) {
      HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
      ((ServletRequestAware) action).setServletRequest(request);
    }

    if (action instanceof ServletResponseAware) {
      HttpServletResponse response = (HttpServletResponse) context.get(HTTP_RESPONSE);
      ((ServletResponseAware) action).setServletResponse(response);
    }

    if (action instanceof ParameterAware) {
      ((ParameterAware) action).setParameters(context.getParameters());
    }

    if (action instanceof ApplicationAware) {
      ((ApplicationAware) action).setApplication(context.getApplication());
    }

    if (action instanceof SessionAware) {
      ((SessionAware) action).setSession(context.getSession());
    }

    if (action instanceof RequestAware) {
      ((RequestAware) action).setRequest((Map) context.get("request"));
    }

    if (action instanceof PrincipalAware) {
      HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
      if (request != null) {
        // We are in servtlet environment, so principal information resides in HttpServletRequest
        ((PrincipalAware) action).setPrincipalProxy(new ServletPrincipalProxy(request));
      }
    }
    if (action instanceof ServletContextAware) {
      ServletContext servletContext = (ServletContext) context.get(SERVLET_CONTEXT);
      ((ServletContextAware) action).setServletContext(servletContext);
    }
    return invocation.invoke();
  }