/*
 * Copyright 2008-2009 LinkedIn, Inc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package voldemort.client.protocol;

import java.util.EnumMap;

import voldemort.VoldemortException;
import voldemort.client.protocol.pb.ProtoBuffClientRequestFormat;
import voldemort.client.protocol.vold.VoldemortNativeClientRequestFormat;

/**
 * A factory for producing the appropriate client request format given a
 * {@link voldemort.client.protocol.RequestFormatType}
 * 
 * @author jay
 * 
 */
public class RequestFormatFactory {

    private EnumMap<RequestFormatType, RequestFormat> typeToInstance;

    public RequestFormatFactory() {
        this.typeToInstance = new EnumMap<RequestFormatType, RequestFormat>(RequestFormatType.class);
        this.typeToInstance.put(RequestFormatType.VOLDEMORT_V1,
                                new VoldemortNativeClientRequestFormat());
        this.typeToInstance.put(RequestFormatType.PROTOCOL_BUFFERS,
                                new ProtoBuffClientRequestFormat());
    }

    public RequestFormat getRequestFormat(RequestFormatType type) {
        RequestFormat format = this.typeToInstance.get(type);
        if(type == null)
            throw new VoldemortException("Unknown wire format " + type);
        return format;
    }

}

@@ -635,72 +635,8 @@
 l;%0A%0A
-import java.util.EnumMap;%0A%0Aimport voldemort.VoldemortException;%0A
 impo
@@ -977,152 +977,65 @@
    p
-rivate EnumMap%3CRequestFormatType, RequestFormat%3E typeToInstance;%0A%0A    public RequestFormatFactory() %7B%0A        this.typeToInstance = new EnumMap%3C
+ublic RequestFormatFactory() %7B%7D%0A%0A    public synchronized 
 Requ
@@ -1047,14 +1047,12 @@
 rmat
-Type, 
+ get
 Requ
@@ -1064,9 +1064,8 @@
 rmat
-%3E
 (Req
@@ -1082,16 +1082,16 @@
 Type
-.class);
+ type) %7B
 %0A   
@@ -1099,50 +1099,40 @@
     
-this.typeToInstance.put(RequestFormatType.
+switch(type) %7B%0A            case 
 VOLD
@@ -1139,17 +1139,17 @@
 EMORT_V1
-,
+:
 %0A       
@@ -1153,39 +1153,30 @@
             
-               
+return
  new Voldemo
@@ -1200,25 +1200,24 @@
 uestFormat()
-)
 ;%0A        th
@@ -1218,50 +1218,17 @@
     
-this.typeToInstance.put(RequestFormatType.
+    case 
 PROT
@@ -1243,13 +1243,10 @@
 FERS
-,%0A   
+:%0A
     
@@ -1257,28 +1257,22 @@
         
-            
+return
  new Pro
@@ -1302,173 +1302,35 @@
 at()
-)
 ;%0A    
-%7D%0A%0A    public RequestFormat getRequestFormat(RequestFormatType type) %7B%0A        RequestFormat format = this.typeToInstance.get(type);%0A        if(type == null)%0A
+        default:%0A    
     
@@ -1347,24 +1347,30 @@
 row new 
-Voldemor
+IllegalArgumen
 tExcepti
@@ -1385,19 +1385,28 @@
 own 
-wi
 re
+quest
  format
+ type:
  %22 +
@@ -1425,22 +1425,9 @@
     
-return format;
+%7D
 %0A   

Remove hard client dependency on protocol buffers.