Example usage for org.apache.thrift.meta_data SetMetaData isStruct

List of usage examples for org.apache.thrift.meta_data SetMetaData isStruct

Introduction

In this page you can find the example usage for org.apache.thrift.meta_data SetMetaData isStruct.

Prototype

public boolean isStruct() 

Source Link

Usage

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONProtocol.java

License:Apache License

private Object getThriftObject(Object thriftObject, String fieldName) throws TException {
    try {//from   ww  w  .  j av a2  s. c  o  m
        Map<String, ThriftField> classFields = getClassFields(thriftObject);
        ThriftField thriftField = classFields.get(fieldName);

        if (thriftField != null) {
            switch (thriftField.fieldMetaData.valueMetaData.type) {
            case TType.LIST:
                ListMetaData listMetaData = (ListMetaData) thriftField.fieldMetaData.valueMetaData;
                if (listMetaData.elemMetaData.isStruct()) {
                    return ((StructMetaData) listMetaData.elemMetaData).structClass.newInstance();
                }
                return null;
            case TType.SET:
                SetMetaData setMetaData = (SetMetaData) thriftField.fieldMetaData.valueMetaData;
                if (setMetaData.isStruct()) {
                    return ((StructMetaData) setMetaData.elemMetaData).structClass.newInstance();
                }
                return null;
            case TType.MAP:
                MapMetaData mapMetaData = (MapMetaData) thriftField.fieldMetaData.valueMetaData;
                if (mapMetaData.valueMetaData.isStruct()) {
                    return ((StructMetaData) mapMetaData.valueMetaData).structClass.newInstance();
                }
                return null;
            case TType.STRUCT:
                return ((StructMetaData) thriftField.fieldMetaData.valueMetaData).structClass.newInstance();
            }
        }
        throw new Exception("FieldName not finded name=" + fieldName);
    } catch (Exception exp) {
        throw new TException("Unexpected getListThriftObject fieldName=" + fieldName, exp);
    }
}