1/*
2 * Copyright (C) 2009 Google Inc.  All rights reserved.
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
17package com.google.polo.wire;
18
19import com.google.polo.pairing.PairingContext;
20import com.google.polo.wire.json.JsonWireAdapter;
21import com.google.polo.wire.protobuf.ProtobufWireAdapter;
22import com.google.polo.wire.xml.XmlWireAdapter;
23
24/**
25 * Represents the various wire formats available.
26 */
27public enum WireFormat {
28  PROTOCOL_BUFFERS,   // Protocol Buffers, implemented by ProtobufWireInterface
29  JSON,               // JSON, implemented by JsonWireInterface
30  XML;                // XML, implemented by XmlWireInterface
31
32  /**
33   * Returns a new {@link PoloWireInterface} for this enum value.
34   *
35   * @param context  the {@link PairingContext} to use in construction
36   * @return         the new {@link PoloWireInterface}
37   */
38  public PoloWireInterface getWireInterface(PairingContext context) {
39    switch (this) {
40      case PROTOCOL_BUFFERS:
41        return ProtobufWireAdapter.fromContext(context);
42      case JSON:
43        return JsonWireAdapter.fromContext(context);
44      case XML:
45        return XmlWireAdapter.fromContext(context);
46    }
47    return null;
48  }
49}
50