Clover coverage report - Ivory - 1.0-alpha-5
Coverage timestamp: Sun Nov 9 2003 22:02:40 EST
file stats: LOC: 154   Methods: 7
NCLOC: 100   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
IvoryServiceDesc.java 62.5% 75.7% 100% 73.5%
coverage coverage
 1   
 package org.codehaus.ivory;
 2   
 
 3   
 import java.lang.reflect.Method;
 4   
 import java.util.Collection;
 5   
 import java.util.Iterator;
 6   
 import java.util.List;
 7   
 
 8   
 import org.apache.axis.description.OperationDesc;
 9   
 import org.apache.axis.description.ParameterDesc;
 10   
 import org.apache.axis.description.ServiceDesc;
 11   
 import org.apache.commons.attributes.Attributes;
 12   
 import org.codehaus.ivory.attributes.NonWebMethod;
 13   
 import org.codehaus.ivory.attributes.ParameterType;
 14   
 
 15   
 /**
 16   
  * Adds meta-data capabilities to Axis's ServiceDesc class.
 17   
  * 
 18   
  * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
 19   
  * @since May 5, 2003
 20   
  */
 21   
 public class IvoryServiceDesc
 22   
     extends ServiceDesc
 23   
 {
 24   
     private boolean loadingServiceDesc = false;
 25   
     
 26   
     /**
 27   
      * Load the meta data for the class being exposed as a service and take
 28   
      * apropriate action.
 29   
      */
 30  5
     public void loadMetaData()
 31   
     {      
 32  5
         for ( Iterator itr = getOperations().iterator(); itr.hasNext(); )
 33   
         {
 34  10
             OperationDesc operation = ( OperationDesc ) itr.next();
 35   
             
 36  10
             customizeOperation( operation );
 37   
             
 38  10
             if ( !isValidOperation( operation ) ||
 39   
                  hideOperation( operation ) )
 40   
             {
 41  0
                 itr.remove();
 42   
             }
 43   
         }
 44   
     }
 45   
 
 46   
     /**
 47   
      * Whether or an Operation on the services should not be exposed.
 48   
      * 
 49   
      * @param operation
 50   
      * @return
 51   
      */
 52  10
     protected boolean hideOperation(OperationDesc operation)
 53   
     {
 54  10
         Method method = operation.getMethod();
 55   
         
 56  10
         return Attributes.hasAttribute( method, NonWebMethod.class );
 57   
     }
 58   
 
 59  10
     protected void customizeOperation( OperationDesc operation )
 60   
     {
 61  10
         for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
 62   
         {
 63  4
             ParameterDesc parameter = (ParameterDesc) itr.next();
 64   
             
 65  4
             customizeParameter( operation, parameter ); 
 66   
         }
 67   
         
 68  10
         customizeParameter( operation, operation.getReturnParamDesc() );
 69   
     }
 70   
 
 71  14
     protected void customizeParameter( OperationDesc operation, 
 72   
                                      ParameterDesc parameter )
 73   
     {
 74  14
         Method method = operation.getMethod();
 75   
         
 76  14
         String name = parameter.getName();
 77   
         
 78  14
         if ( name == null &&
 79   
              Attributes.hasReturnAttributeType( method, ParameterType.class ) )
 80   
         {
 81  1
             Collection allAttrs = Attributes.getReturnAttributes(method);
 82   
             
 83  1
             for ( Iterator itr = allAttrs.iterator(); itr.hasNext(); )
 84   
             {
 85  1
                 Object attr = itr.next();
 86  1
                 if ( attr instanceof ParameterType )
 87   
                 {
 88  1
                     changeParameterType( parameter, (ParameterType) attr );        
 89   
                 }
 90   
             }
 91   
         }
 92  13
         else if (Attributes.hasReturnAttributeType( method, ParameterType.class ))
 93   
         {
 94   
             // parameters are named "in0", "in1" and so on.
 95   
             // get everything after "in"
 96  0
             int num = new Integer(name.substring( 2 )).intValue();
 97  0
             Collection allAttrs = Attributes.getParameterAttributes(method, num);
 98   
             
 99  0
             for ( Iterator itr = allAttrs.iterator(); itr.hasNext(); )
 100   
             {
 101  0
                 Object attr = itr.next();
 102  0
                 if ( attr instanceof ParameterType )
 103   
                 {
 104  0
                     changeParameterType( parameter, (ParameterType) attr );        
 105   
                 }
 106   
             }
 107   
         }
 108   
     }
 109   
 
 110   
     /**
 111   
      * @param parameter
 112   
      * @param type
 113   
      */
 114  1
     private void changeParameterType(ParameterDesc parameter, ParameterType type)
 115   
     {            
 116  1
         String clazz = type.getParameterType().getName();
 117   
 
 118  1
         log.debug( "Changing parameter type to " + clazz );
 119   
             
 120  1
         parameter.setJavaType( type.getParameterType() );
 121   
     }
 122   
 
 123  10
     protected boolean isValidOperation( OperationDesc operation )
 124   
     {
 125  10
         for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
 126   
         {
 127  4
             ParameterDesc parameter = (ParameterDesc) itr.next();
 128   
             
 129  4
             if ( !isValidParameter( parameter ) )
 130  0
                 return false;   
 131   
         }
 132   
         
 133  10
         return isValidParameter( operation.getReturnParamDesc() );
 134   
     }
 135   
 
 136   
     /**
 137   
      * Checks whether or not Axis will work with this parameter.  The only
 138   
      * criterion is that it not be a List or inherit from the List type.
 139   
      * 
 140   
      * @param parameter
 141   
      * @return
 142   
      */
 143  14
     protected boolean isValidParameter( ParameterDesc parameter )
 144   
     {
 145  14
         if ( parameter.getJavaType().equals( java.util.List.class.getClass() )
 146   
              || List.class.isAssignableFrom( parameter.getJavaType() ) )
 147   
         {
 148  0
             return false;
 149   
         }
 150   
         
 151  14
         return true;
 152   
     }
 153   
 }
 154