本文整理匯總了Java中org.reflections.ReflectionUtils.getFields方法的典型用法代碼示例。如果您正苦於以下問題:Java ReflectionUtils.getFields方法的具體用法?Java ReflectionUtils.getFields怎麽用?Java ReflectionUtils.getFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.reflections.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.getFields方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPluginConfigAndDisplayMap
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
* Gets the config and display map. Display map is a mapping from field name to how the field
* should be displayed in the UI
* @param remoteType The remote type that identifies what plugin to get
* @return
* @throws IOException
*/
@SuppressWarnings({ "unchecked" })
@RequestMapping(method = { RequestMethod.GET }, value = "/plugins/remote/cdm/{remoteType}")
@ResponseBody
public Map<String, Object> getPluginConfigAndDisplayMap(@PathVariable String remoteType) throws IOException {
PluginConfiguration config = getRemotePlugin(remoteType);
if (config == null) return null;
Map<String, String> displayMap = new HashMap<String, String>();
Set<Field> fields = ReflectionUtils.getFields(config.getClass(), ReflectionUtils.withAnnotation(PluginConfigValue.class));
for (Field field : fields) {
String disp = field.getAnnotation(PluginConfigValue.class).display();
if (StringUtils.isEmpty(disp)) {
disp = field.getName();
}
displayMap.put(field.getName(), disp);
}
Map<String, Object> configAndDM = new HashMap<>();
configAndDM.put("config", config);
configAndDM.put("displayMap", displayMap);
return configAndDM;
}
示例2: getEventStreamId
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public String getEventStreamId() {
Set<Field> fields =
ReflectionUtils.getFields(getClass(),
ReflectionUtils.withAnnotation(EventStreamId.class));
if (fields.size() != 1) {
throw new RuntimeException(
String.format("No aggregate id field found in class %s", getClass()));
}
Field first = fields.iterator().next();
first.setAccessible(true);
try {
return (String) first.get(this);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
示例3: setEventStreamId
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private void setEventStreamId(T aggregate, String id) {
Set<Field> fields =
ReflectionUtils.getFields(getAggregateClass(),
ReflectionUtils.withAnnotation(EventStreamId.class));
if (fields.size() != 1) {
throw new RuntimeException(
String.format("No aggregate id field found in class %s", getAggregateClass()));
}
Field first = fields.iterator().next();
try {
first.setAccessible(true);
first.set(aggregate, id);
} catch (IllegalAccessException e) {
throw new RuntimeException(
String.format("Could not set aggregate id on class %s", getAggregateClass()));
}
}