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.el.unified.resolver.implicitobject;
20  
21  import java.beans.FeatureDescriptor;
22  import javax.el.ELContext;
23  import javax.el.ELResolver;
24  import javax.faces.context.ExternalContext;
25  import javax.faces.context.FacesContext;
26  
27  /**
28   * Implementors of this class encapsulate the information needed to resolve the implicit object.
29   * 
30   * @author Stan Silvert
31   */
32  public abstract class ImplicitObject
33  {
34  
35      public abstract Object getValue(ELContext context);
36  
37      public abstract FeatureDescriptor getDescriptor();
38  
39      /**
40       * Returns an interned String representing the name of the implicit object.
41       */
42      public abstract String getName();
43  
44      /**
45       * Returns the most general type allowed for a future call to setValue()
46       */
47      public abstract Class<?> getType();
48  
49      protected FeatureDescriptor makeDescriptor(String name, String description, Class<?> elResolverType)
50      {
51          FeatureDescriptor fd = new FeatureDescriptor();
52          fd.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
53          fd.setValue(ELResolver.TYPE, elResolverType);
54          fd.setName(name);
55          fd.setDisplayName(name);
56          fd.setShortDescription(description);
57          fd.setExpert(false);
58          fd.setHidden(false);
59          fd.setPreferred(true);
60          return fd;
61      }
62  
63      // get the FacesContext from the ELContext
64      protected FacesContext facesContext(ELContext context)
65      {
66          return (FacesContext) context.getContext(FacesContext.class);
67      }
68  
69      protected ExternalContext externalContext(ELContext context)
70      {
71          return facesContext(context).getExternalContext();
72      }
73  
74  }