2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shale.dialog.scxml.action;
19  
20  import java.util.Collection;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.commons.scxml.ErrorReporter;
25  import org.apache.commons.scxml.EventDispatcher;
26  import org.apache.commons.scxml.SCInstance;
27  import org.apache.commons.scxml.SCXMLExpressionException;
28  import org.apache.commons.scxml.model.Action;
29  import org.apache.commons.scxml.model.ModelException;
30  import org.apache.shale.dialog.scxml.DialogProperties;
31  import org.apache.shale.dialog.scxml.Globals;
32  
33  /***
34   * <p>Custom Commons SCXML action to set the JSF view identifier of the
35   * next view to be rendered by this dialog.</p>
36   *
37   * @since 1.0.4
38   *
39   * $Id: ViewAction.java 486006 2006-12-12 03:46:29Z rahul $
40   */
41  public class ViewAction extends Action {
42  
43      /***
44       * <p>Set nextViewId in dialog properties, which will be the next view
45       * rendered by this dialog.</p>
46       *
47       * @param evtDispatcher The EventDispatcher for this execution instance
48       * @param errRep        The ErrorReporter
49       * @param scInstance    The state machine execution instance information
50       * @param appLog        The application log
51       * @param derivedEvents The collection of internal events
52       * @throws ModelException If execution causes a non-deterministic state
53       * @throws SCXMLExpressionException Bad expression
54       */
55      public void execute(EventDispatcher evtDispatcher, ErrorReporter errRep,
56              SCInstance scInstance, Log appLog, Collection derivedEvents)
57      throws ModelException, SCXMLExpressionException {
58  
59          DialogProperties dp = (DialogProperties) scInstance.getRootContext().
60              get(Globals.DIALOG_PROPERTIES);
61          dp.setNextViewId(viewId);
62  
63          if (log().isDebugEnabled()) {
64              log().debug("<view>: Setting next view ID to '" + viewId + "'");
65          }
66  
67      }
68  
69      /***
70       * The JSF view identifier for the next view to be rendered by
71       * this dialog.
72       */
73      private String viewId = null;
74  
75      /***
76       * Get the view identifier.
77       *
78       * @return The view identifier
79       */
80      public String getViewId() {
81          return viewId;
82      }
83  
84      /***
85       * Set the view identifier.
86       *
87       * @param viewId The view identifier
88       */
89      public void setViewId(String viewId) {
90          this.viewId = viewId;
91      }
92  
93      // --------------------------------------------------------------- Logging
94  
95      /***
96       * <p>The <code>Log</code> instance for this class.  This value is lazily
97       * instantiated, and is also transient and may need to be regenerated.</p>
98       */
99      private transient Log log = null;
100 
101 
102     /***
103      * <p>Return the <code>Log</code> instance for this instance.</p>
104      *
105      * @return The {@link Log} instance used by this manager
106      */
107     private Log log() {
108         if (this.log == null) {
109             this.log = LogFactory.getLog(ViewAction.class);
110         }
111         return this.log;
112     }
113 
114 }