Coverage Report - javax.faces.application.Application
 
Classes in this File Line Coverage Branch Coverage Complexity
Application
0%
0/51
0%
0/26
0
 
 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.application;
 20  
 
 21  
 import java.util.Collection;
 22  
 import java.util.Iterator;
 23  
 import java.util.Locale;
 24  
 import java.util.ResourceBundle;
 25  
 
 26  
 import javax.el.ELContextListener;
 27  
 import javax.el.ELException;
 28  
 import javax.el.ELResolver;
 29  
 import javax.el.ExpressionFactory;
 30  
 import javax.el.ValueExpression;
 31  
 import javax.faces.FacesException;
 32  
 import javax.faces.component.UIComponent;
 33  
 import javax.faces.context.ExternalContext;
 34  
 import javax.faces.context.FacesContext;
 35  
 import javax.faces.el.ReferenceSyntaxException;
 36  
 
 37  
 /**
 38  
  * Holds webapp-wide resources for a JSF application. There is a single one of
 39  
  * these for a web application, accessable via
 40  
  * <pre>
 41  
  * FacesContext.getCurrentInstance().getApplication()
 42  
  * </pre>
 43  
  * In particular, this provides a factory for UIComponent objects.
 44  
  * It also provides convenience methods for creating ValueBinding objects.
 45  
  *
 46  
  * See Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
 47  
  * 
 48  
  * @author Manfred Geiler (latest modification by $Author: lu4242 $)
 49  
  * @author Stan Silvert
 50  
  * @version $Revision: 775008 $ $Date: 2009-05-15 00:23:20 -0500 (Fri, 15 May 2009) $
 51  
  */
 52  
 @SuppressWarnings("deprecation")
 53  0
 public abstract class Application
 54  
 {
 55  
     
 56  
     /**
 57  
      * Retrieve the current Myfaces Application Instance, lookup
 58  
      * on the application map. All methods introduced on jsf 1.2
 59  
      * for Application interface should thrown by default
 60  
      * UnsupportedOperationException, but the ri scan and find the
 61  
      * original Application impl, and redirect the call to that
 62  
      * method instead throwing it, allowing application implementations
 63  
      * created before jsf 1.2 continue working.   
 64  
      */
 65  
     private Application getMyfacesApplicationInstance()
 66  
     {
 67  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 68  0
         if (facesContext != null)
 69  
         {
 70  0
             ExternalContext externalContext = facesContext.getExternalContext();
 71  0
             if (externalContext != null)
 72  
             {
 73  0
                 return (Application) externalContext.getApplicationMap().get("org.apache.myfaces.application.ApplicationImpl");
 74  
             }
 75  
         }
 76  0
         return null;
 77  
     }
 78  
     
 79  
     private Application getMyfacesApplicationInstance(FacesContext facesContext)
 80  
     {
 81  0
         if (facesContext != null)
 82  
         {
 83  0
             ExternalContext externalContext = facesContext.getExternalContext();
 84  0
             if (externalContext != null)
 85  
             {
 86  0
                 return (Application) externalContext.getApplicationMap().get("org.apache.myfaces.application.ApplicationImpl");
 87  
             }
 88  
         }
 89  0
         return null;
 90  
     }    
 91  
     
 92  
     // The following concrete methods were added for JSF 1.2.  They supply default 
 93  
     // implementations that throw UnsupportedOperationException.  
 94  
     // This allows old Application implementations to still work.
 95  
     public void addELResolver(ELResolver resolver) {
 96  0
         Application application = getMyfacesApplicationInstance();
 97  0
         if (application != null)
 98  
         {
 99  0
             application.addELResolver(resolver);
 100  0
             return;
 101  
         }
 102  0
         throw new UnsupportedOperationException();
 103  
     }
 104  
     
 105  
     public ELResolver getELResolver() {
 106  0
         Application application = getMyfacesApplicationInstance();
 107  0
         if (application != null)
 108  
         {
 109  0
             return application.getELResolver();
 110  
         }
 111  0
         throw new UnsupportedOperationException();
 112  
     }
 113  
     
 114  
     public ResourceBundle getResourceBundle(FacesContext ctx, String name) 
 115  
             throws FacesException, NullPointerException {
 116  0
         Application application = getMyfacesApplicationInstance(ctx);
 117  0
         if (application != null)
 118  
         {
 119  0
             return application.getResourceBundle(ctx, name);
 120  
         }
 121  0
         throw new UnsupportedOperationException();
 122  
     }
 123  
     
 124  
     public UIComponent createComponent(ValueExpression componentExpression,
 125  
                                        FacesContext facesContext,
 126  
                                        String componentType) 
 127  
             throws FacesException, NullPointerException {
 128  0
         Application application = getMyfacesApplicationInstance(facesContext);
 129  0
         if (application != null)
 130  
         {
 131  0
             return application.createComponent(componentExpression, facesContext, componentType);
 132  
         }
 133  0
         throw new UnsupportedOperationException();
 134  
     }
 135  
 
 136  
     public ExpressionFactory getExpressionFactory() {
 137  0
         Application application = getMyfacesApplicationInstance();
 138  0
         if (application != null)
 139  
         {
 140  0
             return application.getExpressionFactory();
 141  
         }
 142  0
         throw new UnsupportedOperationException();
 143  
     }
 144  
     
 145  
     public void addELContextListener(ELContextListener listener) {
 146  0
         Application application = getMyfacesApplicationInstance();
 147  0
         if (application != null)
 148  
         {
 149  0
             application.addELContextListener(listener);
 150  0
             return;
 151  
         }
 152  0
         throw new UnsupportedOperationException();
 153  
     }
 154  
     
 155  
     public void removeELContextListener(ELContextListener listener) {
 156  0
         Application application = getMyfacesApplicationInstance();
 157  0
         if (application != null)
 158  
         {
 159  0
             application.removeELContextListener(listener);
 160  0
             return;
 161  
         }
 162  0
         throw new UnsupportedOperationException();
 163  
     }
 164  
     
 165  
     public ELContextListener[] getELContextListeners() {
 166  0
         Application application = getMyfacesApplicationInstance();
 167  0
         if (application != null)
 168  
         {
 169  0
             return application.getELContextListeners();
 170  
         }
 171  0
         throw new UnsupportedOperationException();
 172  
     }
 173  
     
 174  
     public Object evaluateExpressionGet(FacesContext context,
 175  
                                         String expression,
 176  
                                         Class expectedType)
 177  
              throws ELException {
 178  0
         Application application = getMyfacesApplicationInstance(context);
 179  0
         if (application != null)
 180  
         {
 181  0
             return application.evaluateExpressionGet(context, expression, expectedType);
 182  
         }
 183  0
         throw new UnsupportedOperationException();
 184  
     }
 185  
     
 186  
     // -------- abstract methods -------------------
 187  
     public abstract javax.faces.event.ActionListener getActionListener();
 188  
 
 189  
     public abstract void setActionListener(javax.faces.event.ActionListener listener);
 190  
 
 191  
     public abstract Locale getDefaultLocale();
 192  
 
 193  
     public abstract void setDefaultLocale(Locale locale);
 194  
 
 195  
     public abstract String getDefaultRenderKitId();
 196  
 
 197  
     public abstract void setDefaultRenderKitId(String renderKitId);
 198  
 
 199  
     public abstract String getMessageBundle();
 200  
 
 201  
     public abstract void setMessageBundle(String bundle);
 202  
 
 203  
     /**
 204  
      * Return the NavigationHandler object which is responsible for mapping from
 205  
      * a logical (viewid, fromAction, outcome) to the URL of a view to be rendered.
 206  
      */
 207  
     public abstract javax.faces.application.NavigationHandler getNavigationHandler();
 208  
 
 209  
     public abstract void setNavigationHandler(javax.faces.application.NavigationHandler handler);
 210  
 
 211  
     /**
 212  
      * Get the object used by the VariableResolver to read and write named properties
 213  
      * on java beans, Arrays, Lists and Maps. This object is used by the ValueBinding
 214  
      * implementation, and during the process of configuring "managed bean" properties.
 215  
      *
 216  
      * @deprecated
 217  
      */
 218  
     public abstract javax.faces.el.PropertyResolver getPropertyResolver();
 219  
 
 220  
     /**
 221  
      * @deprecated
 222  
      */
 223  
     public abstract void setPropertyResolver(javax.faces.el.PropertyResolver resolver);
 224  
 
 225  
     /**
 226  
      * Get the object used to resolve expressions of form "#{...}".
 227  
      *
 228  
      * @deprecated
 229  
      */
 230  
     public abstract javax.faces.el.VariableResolver getVariableResolver();
 231  
 
 232  
     /**
 233  
      * @deprecated
 234  
      */
 235  
     public abstract void setVariableResolver(javax.faces.el.VariableResolver resolver);
 236  
     
 237  
     public abstract javax.faces.application.ViewHandler getViewHandler();
 238  
 
 239  
     public abstract void setViewHandler(javax.faces.application.ViewHandler handler);
 240  
 
 241  
     public abstract javax.faces.application.StateManager getStateManager();
 242  
 
 243  
     public abstract void setStateManager(javax.faces.application.StateManager manager);
 244  
 
 245  
     /**
 246  
      * Define a new mapping from a logical "component type" to an actual java class name.
 247  
      * This controls what type is created when method createComponent of this class is
 248  
      * called.
 249  
      * <p>
 250  
      * Param componentClass must be the fully-qualified class name of some class
 251  
      * extending the UIComponent class. The class must have a default constructor,
 252  
      * as instances of it will be created using Class.newInstance.
 253  
      * <p> 
 254  
      * It is permitted to override a previously defined mapping, ie to call this
 255  
      * method multiple times with the same componentType string. The createComponent
 256  
      * method will simply use the last defined mapping.
 257  
      */
 258  
     public abstract void addComponent(String componentType,
 259  
                                       String componentClass);
 260  
 
 261  
     
 262  
     /**
 263  
      * Create a new UIComponent subclass, using the mappings defined by previous
 264  
      * calls to the addComponent method of this class.
 265  
      * <p>
 266  
      * @throws FacesException if there is no mapping defined for the specified
 267  
      * componentType, or if an instance of the specified type could not be
 268  
      * created for any reason.
 269  
      */
 270  
     public abstract javax.faces.component.UIComponent createComponent(String componentType)
 271  
             throws FacesException;
 272  
 
 273  
     /**
 274  
      * Create an object which has an associating "binding" expression tying the component
 275  
      * to a user property.
 276  
      * <p>
 277  
      * First the specified value-binding is evaluated; if it returns a non-null value then
 278  
      * the component "already exists" and so the resulting value is simply returned.
 279  
      * <p>
 280  
      * Otherwise a new UIComponent instance is created using the specified componentType,
 281  
      * and the new object stored via the provided value-binding before being returned.
 282  
      *
 283  
      * @deprecated
 284  
      */
 285  
     public abstract javax.faces.component.UIComponent createComponent(
 286  
             javax.faces.el.ValueBinding componentBinding,
 287  
             javax.faces.context.FacesContext context,
 288  
             String componentType)
 289  
             throws FacesException;
 290  
     
 291  
     public abstract Iterator<String> getComponentTypes();
 292  
 
 293  
     public abstract void addConverter(String converterId,
 294  
                                       String converterClass);
 295  
 
 296  
     public abstract void addConverter(Class targetClass,
 297  
                                       String converterClass);
 298  
 
 299  
     public abstract javax.faces.convert.Converter createConverter(String converterId);
 300  
 
 301  
     public abstract javax.faces.convert.Converter createConverter(Class targetClass);
 302  
 
 303  
     public abstract Iterator<String> getConverterIds();
 304  
 
 305  
     public abstract Iterator<Class> getConverterTypes();
 306  
 
 307  
     /**
 308  
      * Create an object which can be used to invoke an arbitrary method via an
 309  
      * EL expression at a later time. This is similar to createValueBinding 
 310  
      * except that it can invoke an arbitrary method (with parameters) rather
 311  
      * than just get/set a javabean property.
 312  
      * <p>
 313  
      * This is used to invoke ActionListener method, and ValueChangeListener
 314  
      * methods.
 315  
      *
 316  
      * @deprecated
 317  
      */
 318  
     public abstract javax.faces.el.MethodBinding createMethodBinding(
 319  
             String ref, Class[] params)
 320  
             throws ReferenceSyntaxException;
 321  
 
 322  
     public abstract Iterator<Locale> getSupportedLocales();
 323  
 
 324  
     public abstract void setSupportedLocales(Collection<Locale> locales);
 325  
 
 326  
     public abstract void addValidator(String validatorId,
 327  
                                       String validatorClass);
 328  
 
 329  
     public abstract javax.faces.validator.Validator createValidator(String validatorId)
 330  
             throws FacesException;
 331  
 
 332  
     public abstract Iterator<String> getValidatorIds();
 333  
 
 334  
     /**
 335  
      * Create an object which can be used to invoke an arbitrary method via an
 336  
      * EL expression at a later time. This is similar to createValueBinding 
 337  
      * except that it can invoke an arbitrary method (with parameters) rather
 338  
      * than just get/set a javabean property.
 339  
      * <p>
 340  
      * This is used to invoke ActionListener method, and ValueChangeListener
 341  
      * methods.
 342  
      *
 343  
      * @deprecated
 344  
      */
 345  
     public abstract javax.faces.el.ValueBinding createValueBinding(String ref)
 346  
             throws ReferenceSyntaxException;
 347  
 }