Skip to content

Commit

Permalink
WW-3714 Deprecate and migrate ActionEventListener
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Oct 17, 2024
1 parent 36a890b commit 5e704de
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 20 deletions.
47 changes: 28 additions & 19 deletions core/src/main/java/com/opensymphony/xwork2/ActionEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,33 @@
import com.opensymphony.xwork2.util.ValueStack;

/**
* Provides hooks for handling key action events
* {@inheritDoc}
*
* @deprecated since 6.7.0, use {@link org.apache.struts2.ActionEventListener} instead.
*/
public interface ActionEventListener {
/**
* Called after an action has been created.
*
* @param action The action
* @param stack The current value stack
* @return The action to use
*/
public Object prepare(Object action, ValueStack stack);

/**
* Called when an exception is thrown by the action
*
* @param t The exception/error that was thrown
* @param stack The current value stack
* @return A result code to execute, can be null
*/
public String handleException(Throwable t, ValueStack stack);
@Deprecated
public interface ActionEventListener extends org.apache.struts2.ActionEventListener {

static ActionEventListener adapt(org.apache.struts2.ActionEventListener actualListener) {
return actualListener != null ? new LegacyAdapter(actualListener) : null;
}

class LegacyAdapter implements ActionEventListener {

private final org.apache.struts2.ActionEventListener adaptee;

private LegacyAdapter(org.apache.struts2.ActionEventListener adaptee) {
this.adaptee = adaptee;
}

@Override
public Object prepare(Object action, ValueStack stack) {
return adaptee.prepare(action, stack);
}

@Override
public String handleException(Throwable t, ValueStack stack) {
return adaptee.handleException(t, stack);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ default void addPreResultListener(org.apache.struts2.interceptor.PreResultListen

void addPreResultListener(PreResultListener listener);

@Override
default void setActionEventListener(org.apache.struts2.ActionEventListener listener) {
setActionEventListener(ActionEventListener.adapt(listener));
}

void setActionEventListener(ActionEventListener listener);

static ActionInvocation adapt(org.apache.struts2.ActionInvocation actualInvocation) {
return actualInvocation != null ? new LegacyAdapter(actualInvocation) : null;
}
Expand Down
44 changes: 44 additions & 0 deletions core/src/main/java/org/apache/struts2/ActionEventListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2;

import com.opensymphony.xwork2.util.ValueStack;

/**
* Provides hooks for handling key action events
*/
public interface ActionEventListener {
/**
* Called after an action has been created.
*
* @param action The action
* @param stack The current value stack
* @return The action to use
*/
Object prepare(Object action, ValueStack stack);

/**
* Called when an exception is thrown by the action
*
* @param t The exception/error that was thrown
* @param stack The current value stack
* @return A result code to execute, can be null
*/
String handleException(Throwable t, ValueStack stack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.struts2;

import com.opensymphony.xwork2.ActionChainResult;
import com.opensymphony.xwork2.ActionEventListener;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.interceptor.PreResultListener;
Expand Down

0 comments on commit 5e704de

Please sign in to comment.