Coverage Report - org.apache.commons.ognl.EnumerationPropertyAccessor
 
Classes in this File Line Coverage Branch Coverage Complexity
EnumerationPropertyAccessor
9%
1/11
0%
0/12
4.5
 
 1  
 package org.apache.commons.ognl;
 2  
 
 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  
 import java.util.Enumeration;
 23  
 import java.util.Map;
 24  
 
 25  
 /**
 26  
  * Implementation of PropertyAccessor that provides "property" reference to "nextElement" (aliases to "next" also) and
 27  
  * "hasMoreElements" (also aliased to "hasNext").
 28  
  * 
 29  
  * @author Luke Blanshard (blanshlu@netscape.net)
 30  
  * @author Drew Davidson (drew@ognl.org)
 31  
  */
 32  1
 public class EnumerationPropertyAccessor
 33  
     extends ObjectPropertyAccessor
 34  
     implements PropertyAccessor // This is here to make javadoc show this class as an implementor
 35  
 {
 36  
     @Override
 37  
     public Object getProperty( Map<String, Object> context, Object target, Object name )
 38  
         throws OgnlException
 39  
     {
 40  
         Object result;
 41  0
         Enumeration<?> e = (Enumeration<?>) target; // check performed by the invoker
 42  
 
 43  0
         if ( name instanceof String )
 44  
         {
 45  0
             if ( "next".equals( name ) || "nextElement".equals( name ) )
 46  
             {
 47  0
                 result = e.nextElement();
 48  
             }
 49  
             else
 50  
             {
 51  0
                 if ( "hasNext".equals( name ) || "hasMoreElements".equals( name ) )
 52  
                 {
 53  0
                     result = e.hasMoreElements() ? Boolean.TRUE : Boolean.FALSE;
 54  
                 }
 55  
                 else
 56  
                 {
 57  0
                     result = super.getProperty( context, target, name );
 58  
                 }
 59  
             }
 60  
         }
 61  
         else
 62  
         {
 63  0
             result = super.getProperty( context, target, name );
 64  
         }
 65  0
         return result;
 66  
     }
 67  
 
 68  
     @Override
 69  
     public void setProperty( Map<String, Object> context, Object target, Object name, Object value )
 70  
         throws OgnlException
 71  
     {
 72  0
         throw new IllegalArgumentException( "can't set property " + name + " on Enumeration" );
 73  
     }
 74  
 }