1 4 package com.tc.object.logging; 5 6 import java.lang.reflect.Field ; 7 import java.lang.reflect.Modifier ; 8 import java.util.ArrayList ; 9 import java.util.List ; 10 11 14 public class Keys { 15 16 public static String [] getKeys(Class clazz) { 17 if (clazz == null) { return new String [] {}; } 18 19 List keys = new ArrayList (); 20 Field [] fields = clazz.getDeclaredFields(); 21 for (int i = 0; i < fields.length; i++) { 22 Field field = fields[i]; 23 field.setAccessible(true); 24 int access = field.getModifiers(); 25 if ((field.getType().equals(String .class)) && Modifier.isStatic(access) && Modifier.isFinal(access)) { 26 String fieldName = field.getName(); 27 if (fieldName.toUpperCase().equals(fieldName)) { 28 try { 29 keys.add(field.get(clazz)); 30 } catch (IllegalAccessException e) { 31 e.printStackTrace(); 32 } 33 } 34 } 35 } 36 37 String [] rv = new String [keys.size()]; 38 return (String []) keys.toArray(rv); 39 } 40 41 } 42 | Popular Tags |