]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/src/org/apache/thrift/meta_data/FieldMetaData.java
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / java / src / org / apache / thrift / meta_data / FieldMetaData.java
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.meta_data;
21
22 import java.util.HashMap;
23 import java.util.Map;
24 import org.apache.thrift.TBase;
25 import org.apache.thrift.TFieldIdEnum;
26
27 /**
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.
30 *
31 */
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;
37
38 static {
39 structMap = new HashMap<Class<? extends TBase>, Map<? extends TFieldIdEnum, FieldMetaData>>();
40 }
41
42 public FieldMetaData(String name, byte req, FieldValueMetaData vMetaData){
43 this.fieldName = name;
44 this.requirementType = req;
45 this.valueMetaData = vMetaData;
46 }
47
48 public static synchronized void addStructMetaDataMap(Class<? extends TBase> sClass, Map<? extends TFieldIdEnum, FieldMetaData> map){
49 structMap.put(sClass, map);
50 }
51
52 /**
53 * Returns a map with metadata (i.e. instances of FieldMetaData) that
54 * describe the fields of the given class.
55 *
56 * @param sClass The TBase class for which the metadata map is requested
57 */
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
60 try{
61 sClass.newInstance();
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());
66 }
67 }
68 return structMap.get(sClass);
69 }
70 }