Coverage Report - org.apache.tiles.mvel.TilesContextBeanVariableResolverFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
TilesContextBeanVariableResolverFactory
100%
9/9
100%
4/4
2.333
TilesContextBeanVariableResolverFactory$TilesContextBeanVariableResolver
100%
14/14
100%
6/6
2.333
 
 1  
 /*
 2  
  * $Id: TilesContextBeanVariableResolverFactory.java 1049688 2010-12-15 20:15:41Z apetrelli $
 3  
  *
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  * http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 package org.apache.tiles.mvel;
 23  
 
 24  
 import org.apache.tiles.context.TilesRequestContextHolder;
 25  
 import org.apache.tiles.request.Request;
 26  
 import org.mvel2.integration.VariableResolver;
 27  
 
 28  
 /**
 29  
  * Resolves beans stored in request, session and application scopes.
 30  
  *
 31  
  * @version $Rev: 1049688 $ $Date: 2010-12-16 07:15:41 +1100 (Thu, 16 Dec 2010) $
 32  
  * @since 2.2.0
 33  
  */
 34  
 public class TilesContextBeanVariableResolverFactory extends
 35  
         ReadOnlyVariableResolverFactory {
 36  
 
 37  
     /**
 38  
      * Constructor.
 39  
      *
 40  
      * @param requestHolder The Tiles request holder.
 41  
      * @since 2.2.0
 42  
      */
 43  
     public TilesContextBeanVariableResolverFactory(TilesRequestContextHolder requestHolder) {
 44  5
         super(requestHolder);
 45  5
     }
 46  
 
 47  
     /** {@inheritDoc} */
 48  
     @Override
 49  
     public VariableResolver createVariableResolver(String name) {
 50  12
         return new TilesContextBeanVariableResolver(name);
 51  
     }
 52  
 
 53  
     /** {@inheritDoc} */
 54  
     public boolean isTarget(String name) {
 55  36
         Request request = requestHolder.getTilesRequestContext();
 56  36
         for (String scope : request.getAvailableScopes()) {
 57  65
             if (request.getContext(scope).containsKey(name)) {
 58  35
                 return true;
 59  
             }
 60  30
         }
 61  1
         return false;
 62  
     }
 63  
 
 64  
     /**
 65  
      * Resolves a single attribute stored in request, session or application scope.
 66  
      *
 67  
      * @version $Rev: 1049688 $ $Date: 2010-12-16 07:15:41 +1100 (Thu, 16 Dec 2010) $
 68  
      * @since 2.2.0
 69  
      */
 70  
     private class TilesContextBeanVariableResolver extends ReadOnlyVariableResolver {
 71  
 
 72  
         /**
 73  
          * Constructor.
 74  
          *
 75  
          * @param name The name of the attribute.
 76  
          * @since 2.2.0
 77  
          */
 78  12
         public TilesContextBeanVariableResolver(String name) {
 79  12
             super(name);
 80  12
         }
 81  
 
 82  
         /** {@inheritDoc} */
 83  
         @SuppressWarnings("rawtypes")
 84  
         public Class getType() {
 85  2
             Object value = getValue();
 86  2
             if (value != null) {
 87  1
                 return value.getClass();
 88  
             }
 89  1
             return Object.class;
 90  
         }
 91  
 
 92  
         /** {@inheritDoc} */
 93  
         public Object getValue() {
 94  14
             Request request = requestHolder.getTilesRequestContext();
 95  14
             for (String scope : request.getAvailableScopes()) {
 96  27
                 Object value = request.getContext(scope).get(name);
 97  27
                 if (value != null) {
 98  12
                     return value;
 99  
                 }
 100  15
             }
 101  2
             return null;
 102  
         }
 103  
     }
 104  
 }