Example usage for org.apache.commons.chain Context remove

List of usage examples for org.apache.commons.chain Context remove

Introduction

In this page you can find the example usage for org.apache.commons.chain Context remove.

Prototype

V remove(Object key);

Source Link

Document

Removes the mapping for a key from this map if it is present (optional operation).

Usage

From source file:com.sf.ddao.chain.CtxHelper.java

public static <T> T remove(Context ctx, Class<T> clazz) {
    //noinspection unchecked
    return (T) ctx.remove(clazz.toString());
}

From source file:com.sf.ddao.conn.ConnectionHandlerHelper.java

public static void closeConnection(Context context) {
    Connection conn = (Connection) context.remove(CONNECTION_KEY);
    if (conn != null) {
        try {/* w  w  w.j a  v a2  s  .  com*/
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.sf.ddao.conn.ConnectionHandlerHelper.java

public static void putConnectionOnHold(Context context) {
    ConnectionHandlerHelper connectionHandlerHelper = CtxHelper.get(context, ConnectionHandlerHelper.class);
    Connection conn = (Connection) context.remove(CONNECTION_KEY);
    connectionHandlerHelper.connectionOnHold.set(conn);
}

From source file:org.apache.jackrabbit.standalone.cli.CommandHelper.java

/**
 * Sets the current <code>PrintWriter</code>.
 * @param ctx// w w w.  j a  v  a 2  s.  c  o m
 *        the <code>Context</code>
 * @param out
 *        the <code>PrintWriter</code>
 */
public static void setOutput(Context ctx, PrintWriter out) {
    if (out == null) {
        ctx.remove(OUTPUT_KEY);
    } else {
        ctx.put(OUTPUT_KEY, out);
    }
}

From source file:org.apache.jackrabbit.standalone.cli.CommandHelper.java

/**
 * Sets the current working <code>Node</code>.
 * @param ctx/*from  w  w w.j  a  v  a2  s  .c o m*/
 *        the <code>Context</code>
 * @param node
 *        the current working <code>Node</code>.
 */
public static void setCurrentNode(Context ctx, Node node) {
    if (node == null) {
        ctx.remove(CURRENT_NODE_KEY);
    } else {
        ctx.put(CURRENT_NODE_KEY, node);
    }
}

From source file:org.apache.jackrabbit.standalone.cli.CommandHelper.java

/**
 * Sets the current working <code>Repository</code>
 * @param ctx/*from w  ww.  java2s  .  c o m*/
 *        the <code>Context</code>
 * @param repository
 *        the current working <code>Repository</code>
 */
public static void setRepository(Context ctx, Repository repository, String address) {
    if (repository == null) {
        ctx.remove(REPOSITORY_KEY);
        ctx.remove(REPO_ADDRESS_KEY);
    } else {
        ctx.put(REPOSITORY_KEY, repository);
        ctx.put(REPO_ADDRESS_KEY, address);
    }
}

From source file:org.apache.jackrabbit.standalone.cli.CommandHelper.java

/**
 * Sets the current working <code>Session</code>
 * @param ctx/*from  w w  w  . j  av  a2  s .co m*/
 *        the <code>Context</code>
 * @param session
 *        the current working <code>Session</code>
 * @throws CommandException if there's an open working <code>Session</code>
 */
public static void setSession(Context ctx, Session session) throws CommandException {
    if (session == null) {
        ctx.remove(SESSION_KEY);
    } else {
        if (ctx.get(SESSION_KEY) != null) {
            throw new CommandException("exception.already.logged.in");
        }
        ctx.put(SESSION_KEY, session);
    }
}

From source file:org.apache.jackrabbit.standalone.cli.JcrParser.java

/**
 * Remove <code>Context</code> attribute specific to the parsed
 * <code>Command</code>/*from   w  w w  .j  a  va  2  s.  c o m*/
 * @param ctx
 *        the <code>Context</code>
 */
public void depopulateContext(Context ctx) {
    Iterator iter = cl.getAllParameters();
    while (iter.hasNext()) {
        AbstractParameter param = (AbstractParameter) iter.next();
        String ctxKey = param.getContextKey();
        log.debug("remove ctx attr: " + ctxKey + "=" + param.getValue());
        ctx.remove(ctxKey);
    }
}

From source file:org.apache.struts.chain.CreateActionForm.java

/**
 * <p>Create (if necessary) and cache a form bean for this request.</p>
 *
 * @param context The <code>Context</code> for the current request
 *
 * @return <code>false</code> so that processing continues
 *///from ww  w . ja v a2s.  c  o m
public boolean execute(Context context) throws Exception {

    // Is there a form bean associated with this ActionConfig?
    ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey());
    String name = actionConfig.getName();
    if (name == null) {
        context.remove(getActionFormKey());
        return (false);
    }

    log.trace("Look up form-bean " + name);

    // Look up the corresponding FormBeanConfig (if any)
    FormBeanConfig formBeanConfig = actionConfig.getModuleConfig().findFormBeanConfig(name);
    if (formBeanConfig == null) {
        log.warn("No FormBeanConfig found in module " + actionConfig.getModuleConfig().getPrefix()
                + " under name " + name);
        context.remove(getActionFormKey());
        return (false);
    }

    // Look up the session scope ActionForm instance (if any)
    WebContext wcontext = (WebContext) context;
    ActionForm instance = null;
    if ("session".equals(actionConfig.getScope())) {
        instance = (ActionForm) wcontext.getSessionScope().get(actionConfig.getAttribute());
    }

    // Can we recycle the existing instance (if any)?
    if (instance != null) {
        log.trace("Found an instance in the session; test for reusability");
        if (formBeanConfig.getDynamic()) {
            String className = ((DynaBean) instance).getDynaClass().getName();
            if (className.equals(formBeanConfig.getName())) {
                wcontext.put(getActionFormKey(), instance);
                /* It should already be in session scope
                if ("session".equals(actionConfig.getScope())) {
                wcontext.getSessionScope().put
                    (actionConfig.getAttribute(), instance);
                }
                */
                log.debug("Using existing instance (dynamic)");
                return (false);
            }
        } else {
            try {
                Class configClass = ClassUtils.getApplicationClass(formBeanConfig.getType());
                if (configClass.isAssignableFrom(instance.getClass())) {
                    wcontext.put(getActionFormKey(), instance);
                    /* It should already be in session scope
                       if ("session".equals(actionConfig.getScope())) {
                       wcontext.getSessionScope().put
                       (actionConfig.getAttribute(), instance);
                       }
                    */
                    log.debug("Using existing instance (non-dynamic)");
                    return (false);
                }
            } catch (Exception e) {
                log.debug("Error testing existing instance for reusability; just create a new instance", e);
            }
        }
    }

    log.trace("Make a new instance of: " + formBeanConfig);
    // Create a new form bean instance
    if (formBeanConfig.getDynamic()) {
        ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey());
        DynaActionFormClass dynaClass = DynaActionFormClass.createDynaActionFormClass(formBeanConfig);
        instance = (ActionForm) dynaClass.newInstance();
        ((DynaActionForm) instance).initialize((ActionMapping) actionConfig);
    } else {
        instance = (ActionForm) ClassUtils.getApplicationInstance(formBeanConfig.getType());
    }

    // Configure and cache the new instance
    ActionServlet servlet = (ActionServlet) wcontext.get(getActionServletKey());
    instance.setServlet(servlet);
    wcontext.put(getActionFormKey(), instance);
    if ("session".equals(actionConfig.getScope())) {
        wcontext.getSessionScope().put(actionConfig.getAttribute(), instance);
    } else if ("request".equals(actionConfig.getScope())) {
        wcontext.getRequestScope().put(actionConfig.getAttribute(), instance);
    }

    return (false);

}

From source file:org.apache.struts.chain.ExceptionCatcher.java

/**
 * <p>Clear any existing stored exception and pass the <code>context</code>
 * on to the remainder of the current chain.</p>
 *
 * @param context The <code>Context</code> for the current request
 *
 * @return <code>false</code> so that processing continues
 *//* www  .  ja  va 2  s  .c  om*/
public boolean execute(Context context) throws Exception {

    context.remove(getExceptionKey());
    return (false);

}