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