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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 package org
.apache
.thrift
.meta_data
;
22 import java
.util
.HashMap
;
24 import org
.apache
.thrift
.TBase
;
25 import org
.apache
.thrift
.TFieldIdEnum
;
28 * This class is used to store meta data about thrift fields. Every field in a
29 * a struct should have a corresponding instance of this class describing it.
32 public class FieldMetaData
implements java
.io
.Serializable
{
33 public final String fieldName
;
34 public final byte requirementType
;
35 public final FieldValueMetaData valueMetaData
;
36 private static Map
<Class
<?
extends TBase
>, Map
<?
extends TFieldIdEnum
, FieldMetaData
>> structMap
;
39 structMap
= new HashMap
<Class
<?
extends TBase
>, Map
<?
extends TFieldIdEnum
, FieldMetaData
>>();
42 public FieldMetaData(String name
, byte req
, FieldValueMetaData vMetaData
){
43 this.fieldName
= name
;
44 this.requirementType
= req
;
45 this.valueMetaData
= vMetaData
;
48 public static synchronized void addStructMetaDataMap(Class
<?
extends TBase
> sClass
, Map
<?
extends TFieldIdEnum
, FieldMetaData
> map
){
49 structMap
.put(sClass
, map
);
53 * Returns a map with metadata (i.e. instances of FieldMetaData) that
54 * describe the fields of the given class.
56 * @param sClass The TBase class for which the metadata map is requested
58 public static synchronized Map
<?
extends TFieldIdEnum
, FieldMetaData
> getStructMetaDataMap(Class
<?
extends TBase
> sClass
){
59 if (!structMap
.containsKey(sClass
)){ // Load class if it hasn't been loaded
62 } catch (InstantiationException e
){
63 throw new RuntimeException("InstantiationException for TBase class: " + sClass
.getName() + ", message: " + e
.getMessage());
64 } catch (IllegalAccessException e
){
65 throw new RuntimeException("IllegalAccessException for TBase class: " + sClass
.getName() + ", message: " + e
.getMessage());
68 return structMap
.get(sClass
);