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 javax.faces.component.behavior;
20  
21  import java.util.Collection;
22  
23  import javax.faces.component.UIComponent;
24  import javax.faces.context.FacesContext;
25  
26  /**
27   * @author Simon Lessard (latest modification by $Author: struberg $)
28   * @version $Revision: 1188415 $ $Date: 2011-10-24 17:13:21 -0500 (Mon, 24 Oct 2011) $
29   * 
30   * @since 2.0
31   */
32  public abstract class ClientBehaviorContext
33  {
34  
35      public static ClientBehaviorContext createClientBehaviorContext(FacesContext context,
36                                                                      UIComponent component,
37                                                                      String eventName,
38                                                                      String sourceId,
39                                                                      Collection<Parameter> parameters)
40      {
41          // This method is weird... Creating a dummy impl class seems stupid, yet I don't see any other way...
42          if(context == null)
43          {
44              throw new NullPointerException("context argument must not be null");
45          }
46          if(component == null)
47          {
48              throw new NullPointerException("component argument must not be null");
49          }
50          if(eventName == null)
51          {
52              throw new NullPointerException("eventName argument must not be null");
53          }
54  
55          return new ClientBehaviorContextImpl(context,component,eventName,sourceId, parameters);
56      }
57  
58      public abstract UIComponent getComponent();
59  
60      public abstract String getEventName();
61  
62      public abstract FacesContext getFacesContext();
63  
64      public abstract Collection<Parameter> getParameters();
65  
66      public abstract String getSourceId();
67  
68      /**
69       * @author Simon Lessard (latest modification by $Author: struberg $)
70       * @version $Revision: 1188415 $ $Date: 2011-10-24 17:13:21 -0500 (Mon, 24 Oct 2011) $
71       * 
72       * @since 2.0
73       */
74      public static class Parameter
75      {
76          private String _name;
77          private Object _value;
78  
79          public Parameter(String name, Object value)
80          {
81              if (name == null)
82              {
83                  throw new NullPointerException("name");
84              }
85  
86              _name = name;
87              _value = value;
88          }
89  
90          public String getName()
91          {
92              return _name;
93          }
94  
95          public Object getValue()
96          {
97              return _value;
98          }
99      }
100     
101     private static final class ClientBehaviorContextImpl extends ClientBehaviorContext
102     {
103         private FacesContext _facesContext;
104         private UIComponent _component;
105         private String _eventName;
106         private String _sourceId;
107         private Collection<ClientBehaviorContext.Parameter> _parameters;
108         
109         public ClientBehaviorContextImpl(FacesContext context, UIComponent component, String eventName,
110                 String sourceId, Collection<ClientBehaviorContext.Parameter> parameters)
111         {
112             _facesContext = context;
113             _component = component;
114             _eventName = eventName;
115             _sourceId = sourceId;
116             _parameters = parameters;            
117         }
118 
119         @Override
120         public UIComponent getComponent()
121         {
122             return _component;
123         }
124 
125         @Override
126         public String getEventName()
127         {
128             return _eventName;
129         }
130 
131         @Override
132         public FacesContext getFacesContext()
133         {
134             return _facesContext;
135         }
136 
137         @Override
138         public Collection<Parameter> getParameters()
139         {
140             return _parameters;
141         }
142 
143         @Override
144         public String getSourceId()
145         {
146             return _sourceId;
147         }
148     }
149 }