View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidad.event;
20  
21  import java.util.Collections;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import javax.faces.component.UIComponent;
26  
27  import javax.faces.event.FacesEvent;
28  import javax.faces.event.FacesListener;
29  
30  
31  /**
32   * Event delivered when a dialog has returned.
33   * <p>
34   * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/event/ReturnEvent.java#0 $) $Date: 10-nov-2005.19:09:06 $
35   * @see org.apache.myfaces.trinidad.component.DialogSource
36   * @see org.apache.myfaces.trinidad.component.UIXCommand
37   * @see org.apache.myfaces.trinidad.event.ReturnListener
38   */
39  public class ReturnEvent extends FacesEvent
40  {
41    public ReturnEvent(UIComponent source, Object returnValue)
42    {
43      this(source, returnValue, null);
44    }
45  
46    public ReturnEvent(
47        UIComponent source, 
48        Object returnValue, 
49        Map<Object, Object> returnParams)
50    {
51      super(source);
52      _returnValue = returnValue;
53      if (returnParams == null)
54        _returnParams = Collections.emptyMap();
55      else
56        _returnParams = new HashMap<Object, Object>(returnParams);
57    }
58  
59  
60    public Object getReturnValue()
61    {
62      return _returnValue;
63    }
64  
65    public Map<Object, Object> getReturnParameters()
66    {
67      return Collections.unmodifiableMap(_returnParams);
68    }
69  
70    @Override
71    public void processListener(FacesListener listener)
72    {
73      ((ReturnListener) listener).processReturn(this);
74    }
75  
76    @Override
77    public boolean isAppropriateListener(FacesListener listener)
78    {
79      return (listener instanceof ReturnListener);
80    }
81  
82  
83    @Override
84    public int hashCode()
85    {
86      return ((getComponent() == null) ? 0 : getComponent().hashCode()) +
87             (37 * (((_returnValue == null) ? 0 : _returnValue.hashCode()) +
88              37 * ((_returnParams == null) ? 0 : _returnParams.hashCode())));
89    }
90  
91    @Override
92    public boolean equals(Object o)
93    {
94      if (o == this)
95        return true;
96  
97      if (o instanceof ReturnEvent)
98      {
99        ReturnEvent that = (ReturnEvent)o;
100       if (!this.getComponent().equals(that.getComponent()))
101         return false;
102 
103       if (_returnValue == null)
104       {
105         if (that._returnValue != null)
106           return false;
107       }
108       else
109       {
110         if (!_returnValue.equals(that._returnValue))
111           return false;
112       }
113 
114       if (_returnParams == null)
115       {
116         if (that._returnParams != null)
117           return false;
118       }
119       else
120       {
121         if (!_returnParams.equals(that._returnParams))
122           return false;
123       }
124 
125       return true;
126     }
127 
128     return false;
129   }
130 
131   @Override
132   public String toString()
133   {
134     StringBuffer sb = new StringBuffer();
135     sb.append(getClass().getName());
136     sb.append("[component=");
137     sb.append(getComponent());
138     sb.append(", returnValue=");
139     sb.append(getReturnValue());
140     if ((_returnParams != null) && 
141         !_returnParams.isEmpty())
142     {
143       sb.append(", returnParams=");
144       sb.append(_returnParams);
145     }
146 
147     sb.append(']');
148     return sb.toString();
149   }
150 
151   private Object _returnValue;
152   private Map<Object, Object> _returnParams;
153   private static final long serialVersionUID = 1L;
154 }
155