Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.skife.jdbi.v2;
  
  
  import java.net.URL;
  import java.sql.Blob;
 import java.sql.Clob;
 import java.sql.Time;
 import java.util.List;
 import java.util.Map;
 
 class Foreman
 {
 
     private final List<ArgumentFactoryfactories = new CopyOnWriteArrayList<ArgumentFactory>();
 
     public Foreman()
     {
         .add();
     }
 
     public Foreman(List<ArgumentFactoryfactories)
     {
         this..addAll(factories);
     }
 
     Argument waffle(Class expectedTypeObject itStatementContext ctx)
     {
         for (int i = .size() - 1; i >= 0; i--) {
             ArgumentFactory factory = .get(i);
             if (factory.accepts(expectedTypeitctx)) {
                 return factory.build(expectedTypeitctx);
             }
         }
         throw new IllegalStateException("Unbindable argument passed: " + String.valueOf(it));
     }
 
     private static final ArgumentFactory BUILT_INS = new BuiltInArgumentFactory();
 
     public void register(ArgumentFactory<?> argumentFactory)
     {
         .add(argumentFactory);
     }
 
     public Foreman createChild()
     {
         return new Foreman();
     }
 
     private static final class BuiltInArgumentFactory implements ArgumentFactory
     {
         private static final Map<ClassPb = new IdentityHashMap<ClassP>();
 
         static {
             .put(BigDecimal.classnew P(BigDecimalArgument.class));
             .put(Blob.classnew P(BlobArgument.class));
             .put(Boolean.classnew P(BooleanArgument.class));
             .put(boolean.classnew P(BooleanArgument.class));
             .put(Byte.classnew P(ByteArgument.class));
             .put(byte.classnew P(ByteArgument.class));
             .put(byte[].classnew P(ByteArrayArgument.class));
             .put(Character.classnew P(CharacterArgument.class));
             .put(char.classnew P(CharacterArgument.class));
             .put(Clob.classnew P(ClobArgument.class));
             .put(Double.classnew P(DoubleArgument.class));
             .put(double.classnew P(DoubleArgument.class));
             .put(Float.classnew P(FloatArgument.class));
             .put(float.classnew P(FloatArgument.class));
             .put(Integer.classnew P(IntegerArgument.class));
             .put(int.classnew P(IntegerArgument.class));
             .put(java.util.Date.classnew P(JavaDateArgument.class));
             .put(Long.classnew P(LongArgument.class));
             .put(long.classnew P(LongArgument.class));
             .put(Object.classnew P(ObjectArgument.class));
             .put(Short.classnew P(ShortArgument.class));
             .put(short.classnew P(ShortArgument.class));
             .put(java.sql.Date.classnew P(SqlDateArgument.class));
             .put(String.classnew P(StringArgument.class));
             .put(Time.classnew P(TimeArgument.class));
             .put(Timestamp.classnew P(TimestampArgument.class));
             .put(URL.classnew P(URLArgument.class));
         }
 
         public boolean accepts(Class expectedTypeObject valueStatementContext ctx)
         {
             return .containsKey(expectedType);
         }
 
         public Argument build(Class expectedTypeObject valueStatementContext ctx)
         {
             return .get(expectedType).build(value);
         }
 
        private static class P
        {
            private final Constructor<?> ctor;
            public P(Class<? extends ArgumentargType)
            {
                this. = argType.getDeclaredConstructors()[0];
            }
            public Argument build(Object value)
            {
                try {
                    return (Argument.newInstance(value);
                }
                catch (Exception e) {
                    throw new IllegalStateException(e);
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X