Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied. See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
 
20
package org.apache.thrift;
21
 
22
import org.apache.thrift.protocol.TField;
23
import org.apache.thrift.protocol.TProtocol;
24
import org.apache.thrift.protocol.TProtocolUtil;
25
import org.apache.thrift.protocol.TStruct;
26
import org.apache.thrift.protocol.TType;
27
 
28
/**
29
 * Application level exception
30
 *
31
 */
32
public class TApplicationException extends TException {
33
 
34
  private static final TStruct TAPPLICATION_EXCEPTION_STRUCT = new TStruct("TApplicationException");
35
  private static final TField MESSAGE_FIELD = new TField("message", TType.STRING, (short)1);
36
  private static final TField TYPE_FIELD = new TField("type", TType.I32, (short)2);
37
 
38
  private static final long serialVersionUID = 1L;
39
 
40
  public static final int UNKNOWN = 0;
41
  public static final int UNKNOWN_METHOD = 1;
42
  public static final int INVALID_MESSAGE_TYPE = 2;
43
  public static final int WRONG_METHOD_NAME = 3;
44
  public static final int BAD_SEQUENCE_ID = 4;
45
  public static final int MISSING_RESULT = 5;
46
  public static final int INTERNAL_ERROR = 6;
47
 
48
  protected int type_ = UNKNOWN;
49
 
50
  public TApplicationException() {
51
    super();
52
  }
53
 
54
  public TApplicationException(int type) {
55
    super();
56
    type_ = type;
57
  }
58
 
59
  public TApplicationException(int type, String message) {
60
    super(message);
61
    type_ = type;
62
  }
63
 
64
  public TApplicationException(String message) {
65
    super(message);
66
  }
67
 
68
  public int getType() {
69
    return type_;
70
  }
71
 
72
  public static TApplicationException read(TProtocol iprot) throws TException {
73
    TField field;
74
    iprot.readStructBegin();
75
 
76
    String message = null;
77
    int type = UNKNOWN;
78
 
79
    while (true) {
80
      field = iprot.readFieldBegin();
81
      if (field.type == TType.STOP) {
82
        break;
83
      }
84
      switch (field.id) {
85
      case 1:
86
        if (field.type == TType.STRING) {
87
          message = iprot.readString();
88
        } else {
89
          TProtocolUtil.skip(iprot, field.type);
90
        }
91
        break;
92
      case 2:
93
        if (field.type == TType.I32) {
94
          type = iprot.readI32();
95
        } else {
96
          TProtocolUtil.skip(iprot, field.type);
97
        }
98
        break;
99
      default:
100
        TProtocolUtil.skip(iprot, field.type);
101
        break;
102
      }
103
      iprot.readFieldEnd();
104
    }
105
    iprot.readStructEnd();
106
 
107
    return new TApplicationException(type, message);
108
  }
109
 
110
  public void write(TProtocol oprot) throws TException {
111
    oprot.writeStructBegin(TAPPLICATION_EXCEPTION_STRUCT);
112
    if (getMessage() != null) {
113
      oprot.writeFieldBegin(MESSAGE_FIELD);
114
      oprot.writeString(getMessage());
115
      oprot.writeFieldEnd();
116
    }
117
    oprot.writeFieldBegin(TYPE_FIELD);
118
    oprot.writeI32(type_);
119
    oprot.writeFieldEnd();
120
    oprot.writeFieldStop();
121
    oprot.writeStructEnd();
122
  }
123
}