Author: craigmcc
Date: Mon Dec 4 16:04:26 2006
New Revision: 482418
URL: http://svn.apache.org/viewvc?view=rev&rev=482418
Log:
Implement the remainder of the functionality needed for event processing in
shale-dialog (SHALE-251):
* A new listener interface (DialogLifecycleListener) and associated
abstract base class. If the application defines an application scoped
(not required, but conventional) managed bean that implements this
interface under a reserved managed bean name (Constants.LIFECYCLE_ATTR),
this listener will be notified when new DialogContextManager instances
are created (placed into session scope) or removed (removed from session
scope either deliberatly or because the session timed out). This gives
the application a hook to add listeners anywhere and everywhere it needs to.
* As a convenience, modify the contract for DialogContext.setData() such that,
if the specified "data" object is of a class that implements
DialogContextListener, automatically register it (upon entry) and
deregister it (upon completion of the dialog). This makes it extremely
simple for applications that want to be notified as states change, since
the app will most likely have a "data" object to maintain conversational
state anyway.
I did not see anywhere else that shale-dialog-scxml messed with the
data field directly; if there are such places, they will need to have the
listener related logic added there as well.
Added:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ContextListener.java
(with props)
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/LifecycleListener.java
(with props)
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ManagerListener.java
(with props)
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogLifecycleListener.java
(with props)
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManagerListener.java
(with props)
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogLifecycleListener.java
(with props)
Modified:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/faces-config.xml
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
Added:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ContextListener.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ContextListener.java?view=auto&rev=482418
==============================================================================
---
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ContextListener.java
(added)
+++
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ContextListener.java
Mon Dec 4 16:04:26 2006
@@ -0,0 +1,101 @@
+/*
+ * 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.shale.examples.test.dialog.basic;
+
+import java.io.Serializable;
+import org.apache.shale.dialog.base.AbstractDialogContextListener;
+
+/**
+ * <p>Test implementation of DialogContextListener.</p>
+ */
+public class ContextListener extends AbstractDialogContextListener
+ implements Serializable {
+
+
+ public void onStart() {
+
+ // Log the fact that we are processing this event
+ System.out.println("ContextListener.onStart(name="
+ + getDialogContext().getName() + ", id="
+ + getDialogContext().getId() + ")");
+
+ }
+
+
+ public void onStop() {
+
+ // Log the fact that we are processing this event
+ System.out.println("ContextListener.onStop(name="
+ + getDialogContext().getName() + ", id="
+ + getDialogContext().getId() + ")");
+
+ }
+
+
+ public void onException(Exception e) {
+
+ // Log the fact that we are processing this event
+ System.out.println("ContextListener.onException(name="
+ + getDialogContext().getName() + ", id="
+ + getDialogContext().getId() + ")");
+ e.printStackTrace(System.out);
+
+ // In a real application, you might also want to modify some
+ // state in your "data" property to reflect the fact that an
+ // exception occurred
+
+ }
+
+
+ public void onEntry(String stateId) {
+
+ // Log the fact that we are processing this event
+ System.out.println("ContextListener.onEntry(name="
+ + getDialogContext().getName() + ", id="
+ + getDialogContext().getId() + ", stateId="
+ + stateId + ")");
+
+ // In a real application, you might also want to record the
+ // fact that this state was just entered
+
+ }
+
+
+ public void onExit(String stateId) {
+
+ // Log the fact that we are processing this event
+ System.out.println("ContextListener.onExit(name="
+ + getDialogContext().getName() + ", id="
+ + getDialogContext().getId() + ", stateId="
+ + stateId + ")");
+
+ }
+
+
+ public void onTransition(String fromStateId, String toStateId) {
+
+ // Log the fact that we are processing this event
+ System.out.println("ContextListener.onEntry(name="
+ + getDialogContext().getName() + ", id="
+ + getDialogContext().getId() + ", fromStateId="
+ + fromStateId + ", toStateId=" + toStateId + ")");
+
+ }
+
+
+}
Propchange:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ContextListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ContextListener.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/LifecycleListener.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/LifecycleListener.java?view=auto&rev=482418
==============================================================================
---
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/LifecycleListener.java
(added)
+++
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/LifecycleListener.java
Mon Dec 4 16:04:26 2006
@@ -0,0 +1,58 @@
+/*
+ * 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.shale.examples.test.dialog.basic;
+
+import org.apache.shale.dialog.DialogContextManager;
+import org.apache.shale.dialog.DialogContextManagerListener;
+import org.apache.shale.dialog.base.AbstractDialogLifecycleListener;
+
+/**
+ * <p>Test implementation of DialogLifecycleListener.</p>
+ */
+public class LifecycleListener extends AbstractDialogLifecycleListener {
+
+
+ // The DialogContextManagerListener we use to handle manager events
+ private DialogContextManagerListener listener = new ManagerListener();
+
+
+ public void onInstall(DialogContextManager manager) {
+
+ // Log the fact that we are processing this event
+ System.out.println("LifecycleListener.onInstall(manager="
+ + manager + ")");
+
+ // Register our manager listener on this instance
+ manager.addDialogContextManagerListener(listener);
+
+ }
+
+
+ public void onRemove(DialogContextManager manager) {
+
+ // Log the fact that we are processing this event
+ System.out.println("LifecycleListener.onRemove(manager="
+ + manager + ")");
+
+ // Deregister our manager listener on this instance
+ manager.removeDialogContextManagerListener(listener);
+
+ }
+
+
+}
Propchange:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/LifecycleListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/LifecycleListener.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ManagerListener.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ManagerListener.java?view=auto&rev=482418
==============================================================================
---
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ManagerListener.java
(added)
+++
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ManagerListener.java
Mon Dec 4 16:04:26 2006
@@ -0,0 +1,66 @@
+/*
+ * 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.shale.examples.test.dialog.basic;
+
+import java.io.Serializable;
+import org.apache.shale.dialog.DialogContext;
+import org.apache.shale.dialog.DialogContextListener;
+import org.apache.shale.dialog.base.AbstractDialogContextManagerListener;
+
+/**
+ * <p>Test implementation of DialogContextManagerListener.</p>
+ */
+public class ManagerListener extends AbstractDialogContextManagerListener
+ implements Serializable {
+
+
+ // THe DialogContextListener we use to handle context events
+ private DialogContextListener listener = new ContextListener();
+
+
+ public void onCreate(DialogContext context) {
+
+ // Log the fact that we are processing this event
+ System.out.println("ManagerListener.onCreate(name=" + context.getName()
+ + ", id=" + context.getId() + ")");
+
+ // Register our manager listener on this instance
+ context.addDialogContextListener(listener);
+
+ // In a real application, you might also do some intialization
+ // here to set up the "data" property on this context
+
+ }
+
+
+ public void onRemove(DialogContext context) {
+
+ // Log the fact that we are processing this event
+ System.out.println("ManagerListener.onInstall(name=" +
context.getName()
+ + ", id=" + context.getId() + ")");
+
+ // In a real application, you might also do some cleanup here
+ // to finish things up in the "data" property of this context
+
+ // Register our manager listener on this instance
+ context.removeDialogContextListener(listener);
+
+ }
+
+
+}
Propchange:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ManagerListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/java/org/apache/shale/examples/test/dialog/basic/ManagerListener.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/faces-config.xml
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/faces-config.xml?view=diff&rev=482418&r1=482417&r2=482418
==============================================================================
---
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/faces-config.xml
(original)
+++
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/faces-config.xml
Mon Dec 4 16:04:26 2006
@@ -27,6 +27,15 @@
<faces-config>
+ <!-- Listen to events on the installation and removal of
DialogContextListeners -->
+ <managed-bean>
+
<managed-bean-name>org.apache.shale.dialog.LIFECYCLE_LISTENER</managed-bean-name>
+ <managed-bean-class>
+ org.apache.shale.examples.test.dialog.basic.LifecycleListener
+ </managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
+ </managed-bean>
+
<managed-bean>
<managed-bean-name>popup</managed-bean-name>
<managed-bean-class>org.apache.shale.examples.test.dialog.basic.Popup</managed-bean-class>
Modified:
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java?view=diff&rev=482418&r1=482417&r2=482418
==============================================================================
---
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java
(original)
+++
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java
Mon Dec 4 16:04:26 2006
@@ -33,6 +33,7 @@
import org.apache.shale.dialog.Constants;
import org.apache.shale.dialog.DialogContext;
+import org.apache.shale.dialog.DialogContextListener;
import org.apache.shale.dialog.DialogContextManager;
import org.apache.shale.dialog.base.AbstractDialogContext;
import org.apache.shale.dialog.basic.model.ActionState;
@@ -219,7 +220,14 @@
throw new IllegalStateException("Cannot set data when no
positions are stacked");
}
Position position = (Position) positions.get(index);
+ Object old = position.getData();
+ if ((old != null) && (old instanceof DialogContextListener)) {
+ removeDialogContextListener((DialogContextListener) old);
+ }
position.setData(data);
+ if ((data != null) && (data instanceof DialogContextListener)) {
+ addDialogContextListener((DialogContextListener) data);
+ }
}
}
@@ -461,6 +469,9 @@
*/
void deactivate() {
+ while (positions.size() > 0) {
+ pop();
+ }
this.active = false;
}
@@ -567,6 +578,10 @@
if (index < 0) {
throw new IllegalStateException("No position to be popped");
}
+ Object data = ((Position) positions.get(index)).getData();
+ if ((data != null) && (data instanceof DialogContextListener)) {
+ removeDialogContextListener((DialogContextListener) data);
+ }
positions.remove(index);
if (index > 0) {
return (Position) positions.get(index - 1);
@@ -588,6 +603,10 @@
if (position == null) {
throw new IllegalArgumentException();
+ }
+ Object data = position.getData();
+ if ((data != null) && (data instanceof DialogContextListener)) {
+ addDialogContextListener((DialogContextListener) data);
}
synchronized (positions) {
positions.add(position);
Modified:
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java?view=diff&rev=482418&r1=482417&r2=482418
==============================================================================
---
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
(original)
+++
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
Mon Dec 4 16:04:26 2006
@@ -184,7 +184,14 @@
/** [EMAIL PROTECTED] */
public void setData(Object data) {
+ Object old = this.data;
+ if ((old != null) && (old instanceof DialogContextListener)) {
+ removeDialogContextListener((DialogContextListener) old);
+ }
this.data = data;
+ if ((data != null) && (data instanceof DialogContextListener)) {
+ addDialogContextListener((DialogContextListener) data);
+ }
}
@@ -329,6 +336,7 @@
* [EMAIL PROTECTED] DialogContextManager}.</p>
*/
void deactivate() {
+ setData(null);
this.active = false;
}
Modified:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java?view=diff&rev=482418&r1=482417&r2=482418
==============================================================================
---
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
(original)
+++
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
Mon Dec 4 16:04:26 2006
@@ -65,6 +65,16 @@
"org.apache.shale.dialog.DIALOG_NAME";
+ /**
+ * <p>Application scope attribute under which the application may
optionally
+ * define an instance of [EMAIL PROTECTED] DialogLifecycleListener} to
receive
+ * notification of the creation and removal of [EMAIL PROTECTED]
DialogContextManager}
+ * instances.
+ */
+ public static final String LIFECYCLE_ATTR =
+ "org.apache.shale.dialog.LIFECYCLE_LISTENER";
+
+
/**
* <p>Prefix on a logical outcome that indicates a new dialog instance
* should be initiated.</p>
Modified:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java?view=diff&rev=482418&r1=482417&r2=482418
==============================================================================
---
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java
(original)
+++
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java
Mon Dec 4 16:04:26 2006
@@ -54,7 +54,11 @@
/**
* <p>Set the generic data object representing model state for this
- * dialog instance.</p>
+ * dialog instance. As a value added feature, if the class of the
+ * specified data object implements [EMAIL PROTECTED]
DialogContextListener},
+ * ensure that the data object is registered as a listener with this
+ * [EMAIL PROTECTED] DialogContext}, and deregistered when the [EMAIL
PROTECTED] DialogContext}
+ * is completed (or this instance is replaced).</p>
*
* @param data The new data instance
*/
Added:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogLifecycleListener.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogLifecycleListener.java?view=auto&rev=482418
==============================================================================
---
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogLifecycleListener.java
(added)
+++
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogLifecycleListener.java
Mon Dec 4 16:04:26 2006
@@ -0,0 +1,51 @@
+/*
+ * 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.shale.dialog;
+
+/**
+ * <p>JavaBeans event listener for notification of the installation and
+ * removal of [EMAIL PROTECTED] DialogContextManager} instances (which are
stored
+ * in session scope).</p>
+ *
+ * @since 1.0.4
+ */
+public interface DialogLifecycleListener {
+
+
+ // -------------------------------------------------------- Lifecycle
Events
+
+
+ /**
+ * <p>Handle notification that the specified [EMAIL PROTECTED]
DialogContextManager}
+ * instance has been placed into service.</p>
+ *
+ * @param manager The [EMAIL PROTECTED] DialogContextManager} instance
placed into service
+ */
+ public void onInstall(DialogContextManager manager);
+
+
+ /**
+ * <p>Handle notification that the specified [EMAIL PROTECTED]
DialogContextManager}
+ * instance has been removed from service.</p>
+ *
+ * @param manager The [EMAIL PROTECTED] DialogContextManager} instance
removed from service
+ */
+ public void onRemove(DialogContextManager manager);
+
+
+}
Propchange:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogLifecycleListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogLifecycleListener.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java?view=diff&rev=482418&r1=482417&r2=482418
==============================================================================
---
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
(original)
+++
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
Mon Dec 4 16:04:26 2006
@@ -19,9 +19,14 @@
import java.util.ArrayList;
import java.util.List;
+import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+import org.apache.shale.dialog.Constants;
import org.apache.shale.dialog.DialogContext;
import org.apache.shale.dialog.DialogContextManager;
import org.apache.shale.dialog.DialogContextManagerListener;
+import org.apache.shale.dialog.DialogLifecycleListener;
/**
* <p>Abstract base class for [EMAIL PROTECTED] DialogContextManager}
implementations.
@@ -29,7 +34,8 @@
*
* @since 1.0.4
*/
-public abstract class AbstractDialogContextManager implements
DialogContextManager {
+public abstract class AbstractDialogContextManager
+ implements DialogContextManager, HttpSessionBindingListener {
// ------------------------------------------------------ Instance
Variables
@@ -42,6 +48,39 @@
private List listeners = new ArrayList();
+ // -------------------------------------- HttpSessionBindingListener
Methods
+
+
+ /**
+ * <p>Handle an instance of this class being bound into an HttpSession.</p>
+ *
+ * @param event HttpSessionBindingEvent to be handled
+ */
+ public void valueBound(HttpSessionBindingEvent event) {
+
+ DialogLifecycleListener listener = lifecycleListener();
+ if (listener != null) {
+ listener.onInstall(this);
+ }
+
+ }
+
+
+ /**
+ * <p>Handle an instance of this class being unbound from an
HttpSession.</p>
+ *
+ * @param event HttpSessionBindingEvent to be handled
+ */
+ public void valueUnbound(HttpSessionBindingEvent event) {
+
+ DialogLifecycleListener listener = lifecycleListener();
+ if (listener != null) {
+ listener.onRemove(this);
+ }
+
+ }
+
+
// --------------------------------------------------- Listener
Registration
@@ -134,6 +173,31 @@
getDialogContextManagerListeners();
for (int i = 0; i < listeners.length; i++) {
listeners[i].onRemove(context);
+ }
+
+ }
+
+
+ // --------------------------------------------------------- Private
Methods
+
+
+ /**
+ * <p>Return the [EMAIL PROTECTED] DialogLifecycleListener} for this
application
+ * (if any); otherwise, return <code>null</code>.</p>
+ */
+ private DialogLifecycleListener lifecycleListener() {
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ if (context == null) {
+ return null;
+ }
+ Object result =
+ context.getApplication().getVariableResolver().
+ resolveVariable(context, Constants.LIFECYCLE_ATTR);
+ if ((result != null) && (result instanceof DialogLifecycleListener)) {
+ return (DialogLifecycleListener) result;
+ } else {
+ return null;
}
}
Added:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManagerListener.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManagerListener.java?view=auto&rev=482418
==============================================================================
---
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManagerListener.java
(added)
+++
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManagerListener.java
Mon Dec 4 16:04:26 2006
@@ -0,0 +1,77 @@
+/*
+ * 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.shale.dialog.base;
+
+import org.apache.shale.dialog.DialogContext;
+import org.apache.shale.dialog.DialogContextManager;
+import org.apache.shale.dialog.DialogContextManagerListener;
+
+/**
+ * <p>Convenience abstract base class for [EMAIL PROTECTED]
DialogContextManagerListener}
+ * instances. The default event handling methods do nothing.</p>
+ *
+ * @since 1.0.4
+ */
+public class AbstractDialogContextManagerListener
+ implements DialogContextManagerListener {
+
+
+ // ------------------------------------------------------ Instance
Variables
+
+
+ /**
+ * <p>The [EMAIL PROTECTED] DialogContextManager} instance we are
associated with.</p>
+ */
+ private DialogContextManager instance = null;
+
+
+ // -------------------------------------------------- Event Handling
Methods
+
+
+ /** [EMAIL PROTECTED] */
+ public void onCreate(DialogContext context) {
+
+ ; // Do nothing
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void onRemove(DialogContext context) {
+
+ ; // Do nothing
+
+ }
+
+
+ // ---------------------------------------------------------------
Ownership
+
+
+ /** [EMAIL PROTECTED] */
+ public DialogContextManager getDialogContextManager() {
+ return this.instance;
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void setDialogContextManager(DialogContextManager instance) {
+ this.instance = instance;
+ }
+
+
+}
Propchange:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManagerListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManagerListener.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogLifecycleListener.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogLifecycleListener.java?view=auto&rev=482418
==============================================================================
---
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogLifecycleListener.java
(added)
+++
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogLifecycleListener.java
Mon Dec 4 16:04:26 2006
@@ -0,0 +1,51 @@
+/*
+ * 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.shale.dialog.base;
+
+import org.apache.shale.dialog.DialogContextManager;
+import org.apache.shale.dialog.DialogLifecycleListener;
+
+/**
+ * <p>Convenience abstract base class for [EMAIL PROTECTED]
DialogLifecycleListener}
+ * instances. The default event handling methods do nothing.</p>
+ *
+ * @since 1.0.4
+ */
+public abstract class AbstractDialogLifecycleListener implements
DialogLifecycleListener {
+
+
+ // -------------------------------------------------- Event Handling
Methods
+
+
+ /** [EMAIL PROTECTED] */
+ public void onInstall(DialogContextManager manager) {
+
+ ; // Do nothing
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void onRemove(DialogContextManager manager) {
+
+ ; // Do nothing
+
+ }
+
+
+}
Propchange:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogLifecycleListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogLifecycleListener.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL