Coverage Report - com.damnhandy.uri.template.impl.VarExploderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
VarExploderFactory
40%
2/5
50%
1/2
2
 
 1  
 /*
 2  
  * Copyright 2012, Ryan J. McDonough
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package com.damnhandy.uri.template.impl;
 17  
 
 18  
 import com.damnhandy.uri.template.DefaultVarExploder;
 19  
 import com.damnhandy.uri.template.VarExploder;
 20  
 import com.damnhandy.uri.template.VarExploderException;
 21  
 
 22  
 /**
 23  
  *
 24  
  *
 25  
  * @author <a href="ryan@damnhandy.com">Ryan J. McDonough</a>
 26  
  * @version $Revision: 1.1 $
 27  
  */
 28  
 public final class VarExploderFactory
 29  
 {
 30  
    //private static final String DEFAULT_MSG = "";
 31  
 
 32  
    private VarExploderFactory()
 33  0
    {
 34  0
    }
 35  
 
 36  
    /**
 37  
     *
 38  
     *
 39  
     * @param varValue
 40  
     * @return
 41  
     */
 42  
    public static VarExploder getExploder(Object varValue, VarSpec varSpec) throws VarExploderException
 43  
    {
 44  232
       if (varValue instanceof VarExploder)
 45  
       {
 46  0
          return (VarExploder) varValue;
 47  
       }
 48  
 
 49  
 //      if (varValue.getClass().isAnnotationPresent(ExplodeWith.class))
 50  
 //      {
 51  
 //         Class<?> exploderClass = varValue.getClass().getAnnotation(ExplodeWith.class).value();
 52  
 //         return fromCustom(exploderClass, varValue, varSpec);
 53  
 //      }
 54  232
       return new DefaultVarExploder(varValue);
 55  
    }
 56  
 
 57  
 
 58  
 //   private static VarExploder fromCustom(Class<?> exploderClass, Object varValue, VarSpec varSpec)
 59  
 //   {
 60  
 //      if (exploderClass.isAssignableFrom(VarExploder.class))
 61  
 //      {
 62  
 //         String msg = buildErrorMessage(
 63  
 //               exploderClass.getSimpleName() + " must be an instance of " + VarExploder.class.getSimpleName(),
 64  
 //               exploderClass, varValue, varSpec);
 65  
 //         throw new VariableExpansionException(msg);
 66  
 //      }
 67  
 //
 68  
 //      try
 69  
 //      {
 70  
 //         Constructor<?> constructor = exploderClass.getConstructor(Object.class);
 71  
 //         VarExploder exploder = (VarExploder) constructor.newInstance(varValue);
 72  
 //         return exploder;
 73  
 //      }
 74  
 //
 75  
 //      catch (IllegalArgumentException e)
 76  
 //      {
 77  
 //         throwException(DEFAULT_MSG, e, exploderClass, varValue, varSpec);
 78  
 //      }
 79  
 //      catch (NoSuchMethodException e)
 80  
 //      {
 81  
 //         throwException(DEFAULT_MSG, e, exploderClass, varValue, varSpec);
 82  
 //      }
 83  
 //      catch (InstantiationException e)
 84  
 //      {
 85  
 //         throwException(DEFAULT_MSG, e, exploderClass, varValue, varSpec);
 86  
 //      }
 87  
 //      catch (IllegalAccessException e)
 88  
 //      {
 89  
 //         throwException(DEFAULT_MSG, e, exploderClass, varValue, varSpec);
 90  
 //      }
 91  
 //      catch (InvocationTargetException e)
 92  
 //      {
 93  
 //         throwException(DEFAULT_MSG, e, exploderClass, varValue, varSpec);
 94  
 //      }
 95  
 //      return null;
 96  
 //   }
 97  
 
 98  
 
 99  
 //   private static void throwException(String message, Throwable e, Class<?> exploderClass, Object varValue,
 100  
 //         VarSpec varSpec) throws VariableExpansionException
 101  
 //   {
 102  
 //      String msg = buildErrorMessage(message, exploderClass, varValue, varSpec);
 103  
 //      throw new VariableExpansionException(msg, e);
 104  
 //   }
 105  
 
 106  
 //   private static String buildErrorMessage(String message, Class<?> exploderClass, Object varValue, VarSpec varSpec)
 107  
 //   {
 108  
 //      StringBuilder b = new StringBuilder();
 109  
 //      b.append(message)
 110  
 //       .append("[ varspec: ").append(varSpec)
 111  
 //       .append(" variable value:").append(varValue)
 112  
 //       .append(" exploder class: ").append(exploderClass.getName()).append("]");
 113  
 //      return b.toString();
 114  
 //   }
 115  
 }