本文整理汇总了Java中org.apache.commons.lang3.reflect.FieldUtils.getField方法的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils.getField方法的具体用法?Java FieldUtils.getField怎么用?Java FieldUtils.getField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.FieldUtils
的用法示例。
在下文中一共展示了FieldUtils.getField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, ChatMessagePacket packet)
{
Field connectionsField = FieldUtils.getField(Server.class, "connections", true);
Connection[] connections;
try
{
connections = (Connection[])FieldUtils.readField(connectionsField, server, true);
} catch (IllegalAccessException e)
{
throw new RuntimeException(e);
}
ChatMessageReplyPacket newPacket = new ChatMessageReplyPacket();
Character sender = gameData.getUserCharacterByConnectionId(connection.getID());
String nickname = sender.getNickname();
newPacket.setMessage(packet.getMessage());
newPacket.setNickname(nickname);
Character character;
for(Connection client : connections)
if((character = gameData.getUserCharacterByConnectionId(client.getID())) != null)
{
newPacket.setSourceCharacterId(character.getId());
server.sendToTCP(client.getID(), newPacket);
}
}
示例2: convertUseReflect
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void convertUseReflect(IntrospectedTable introspectedTable) {
if (baseColumnsField == null || blobColumnsField == null) {
baseColumnsField = FieldUtils.getField(IntrospectedTable.class, "baseColumns", true);
blobColumnsField = FieldUtils.getField(IntrospectedTable.class, "blobColumns", true);
}
List<IntrospectedColumn> introspectedColumns = null;
try {
introspectedColumns = (List<IntrospectedColumn>) baseColumnsField.get(introspectedTable);
convertForAll(introspectedColumns);
//print("after calculate for base", introspectedColumns);
baseColumnsField.set(introspectedTable, introspectedColumns);
introspectedColumns = (List<IntrospectedColumn>) blobColumnsField.get(introspectedTable);
convertForAll(introspectedColumns);
//print("after calculate for blob", introspectedColumns);
blobColumnsField.set(introspectedTable, introspectedColumns);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
示例3: validate
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Override
public boolean validate(List<String> warnings) {
boolean valid = true;
srid = properties.getProperty(SRID_NAME);
if(StringUtils.isEmpty(srid)){
srid = "3857";
}
if(connection == null){
try {
connection = ConnectionFactory.getInstance().getConnection(context.getJdbcConnectionConfiguration());
} catch (SQLException e) {
e.printStackTrace();
valid = false;
}
}
elementsList = FieldUtils.getField(XmlElement.class, "elements", true);
return valid;
}
示例4: cleanupFailedPersistenceAttempt
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
protected void cleanupFailedPersistenceAttempt(Serializable instance) throws IllegalAccessException {
//Remove the entity from ORM management - no further attempts to persist
if (getPersistenceManager().getDynamicEntityDao().getStandardEntityManager().contains(instance)) {
getPersistenceManager().getDynamicEntityDao().getStandardEntityManager().detach(instance);
}
//Remove the id field value, if it's set
String idFieldName = (String) getPersistenceManager().getDynamicEntityDao().getIdMetadata(instance.getClass()).get("name");
Field idField = FieldUtils.getField(instance.getClass(), idFieldName, true);
if (idField == null) {
throw ExceptionHelper.refineException(new NoSuchFieldException("Entity " + instance.getClass().getName() + " does not contain id field " + idFieldName));
}
idField.setAccessible(true);
if (idField.get(instance) != null) {
idField.set(instance, null);
}
}
示例5: isField
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* @param clazz
* @param fieldName
* @param fieldEntityType
* @param forceAccess
* @return
*/
public static boolean isField(Class<?> clazz, String fieldName, Class<?> fieldEntityType, boolean forceAccess) {
Field field = FieldUtils.getField(clazz, fieldName, forceAccess);
if (field == null) {
return false;
}
final Class<?> fieldType = field.getType();
// we'll also return true if the fieldEntityType is null, i.e. "unknown"
if(fieldEntityType == null || fieldType.isAssignableFrom(fieldEntityType)) {
return true;
}
return false;
}
示例6: apply
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
System.setProperty(Constants.LOG4J_LOG_EVENT_FACTORY, TestLogEventFactory.class.getName());
resetLogEventFactory(new TestLogEventFactory());
try {
base.evaluate();
} finally {
System.clearProperty(Constants.LOG4J_LOG_EVENT_FACTORY);
resetLogEventFactory(new DefaultLogEventFactory());
}
}
private void resetLogEventFactory(final LogEventFactory logEventFactory) throws IllegalAccessException {
final Field field = FieldUtils.getField(LoggerConfig.class, "LOG_EVENT_FACTORY", true);
FieldUtils.removeFinalModifier(field, true);
FieldUtils.writeStaticField(field, logEventFactory, false);
}
};
}
示例7: idField
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
protected Field idField(Class<E> entityType) {
try {
String idFieldName = ObjectifyService.factory().getMetadata(entityType).getKeyMetadata().getIdFieldName();
return FieldUtils.getField(entityType, idFieldName, true);
} catch (IllegalArgumentException | SecurityException e) {
throw new RepositoryException(e, "Unable to determine id field for type %s: %s", entityType.getClass().getName(), e.getMessage());
}
}
示例8: setFieldValueByReflection
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
protected void setFieldValueByReflection(Task task, String fieldName, Object value) {
Field field = FieldUtils.getField(task.getClass(), fieldName, true);
if (null == field) {
throw new StopExecutionException("The field with name:" +
fieldName +
" does not existed in class:" +
task.getClass().getName());
}
try {
FieldUtils.writeField(field, task, value, true);
} catch (IllegalAccessException e) {
throw new StopExecutionException(e.getMessage());
}
}
示例9: getIdFieldFromObjectify
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
protected <E> Field getIdFieldFromObjectify(Class<E> entityClass) {
String idFieldName = objectify.ofy()
.factory()
.getMetadata(entityClass)
.getKeyMetadata()
.getIdFieldName();
return FieldUtils.getField(entityClass, idFieldName, true);
}
示例10: getIdField
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Return the id field for the managed entity type.
*
* @return Managed entity id field.
*/
@Nonnull
default Field getIdField() {
Class<E> entityType = getEntityType();
String idFieldName = ofy().factory().getMetadata(entityType).getKeyMetadata().getIdFieldName();
return FieldUtils.getField(entityType, idFieldName, true);
}
示例11: getParagraphBeginPints
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private List<Pair<Integer, Pair<Double, Double>>> getParagraphBeginPints(final VirtualFlow flow) {
final List<Pair<Integer, Pair<Double, Double>>> paragraphBeginPoints;
if (flow.visibleCells().isEmpty()) {
paragraphBeginPoints = Collections.singletonList(
new Pair<>(Integer.valueOf(0), new Pair<>(Double.valueOf(0), Double.valueOf(0)))
);
} else {
paragraphBeginPoints = new ArrayList<>(flow.visibleCells().size());
for (Object o : flow.visibleCells()) {
Node node = ((Cell) o).getNode();
Field field = FieldUtils.getField(node.getClass(), "index", true);
try {
Var<Integer> index = (Var<Integer>) field.get(node);
Pair<Integer, Pair<Double, Double>> rez = new Pair<>(
index.getValue(),
new Pair<>(node.getLayoutX(), node.getLayoutY())
);
paragraphBeginPoints.add(rez);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return paragraphBeginPoints;
}
示例12: releaseGestureBoostManagerLeaks
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* leaks in huawei emui5.0
*/
public static void releaseGestureBoostManagerLeaks(Activity activity) {
try {
Class clazz = Class.forName("android.gestureboost.GestureBoostManager");
Object sGestureBoostManager = FieldUtils.readDeclaredStaticField(clazz, "sGestureBoostManager", true);
Field contextField = FieldUtils.getField(clazz, "mContext", true);
Object mContext = FieldUtils.readField(contextField, sGestureBoostManager, true);
if (mContext == activity) {
FieldUtils.writeField(contextField, sGestureBoostManager, null, true);
}
} catch (Exception e) {
L.d("releaseGestureBoostManagerLeaks exception");
}
}
示例13: releaseFastgrabConfigReaderLeaks
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* leaks in huawei emui5.0
*/
public static void releaseFastgrabConfigReaderLeaks(Activity activity) {
try {
Class clazz = Class.forName("android.rms.iaware.FastgrabConfigReader");
Object mFastgrabConfigReader = FieldUtils.readDeclaredStaticField(clazz, "mFastgrabConfigReader", true);
Field contextField = FieldUtils.getField(clazz, "mContext", true);
Context mContext = (Context) FieldUtils.readField(contextField, mFastgrabConfigReader, true);
if (ContextUtils.getBaseContext(mContext) == activity) {
FieldUtils.writeField(contextField, mFastgrabConfigReader, null, true);
}
} catch (Exception e) {
L.d("releaseFastgrabConfigReaderLeaks exception");
}
}
示例14: getFieldOrNull
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private Field getFieldOrNull(final String pName, final Class<?> pExpectedReturnType) {
Field field = fields.get(pName);
if (field == null) {
field = FieldUtils.getField(mojo.getClass(), pName, true);
if (field != null) {
isTrue(field.getType().equals(pExpectedReturnType), "Field %s is not compatible with return type %s",
field, pExpectedReturnType);
fields.put(pName, field);
}
}
return field;
}
示例15: getErrorTextView
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static TextView getErrorTextView(TextInputLayout inputLayout) {
// Will use getError() method after support design library upgraded
TextView errorText = null;
Field field = FieldUtils.getField(TextInputLayout.class, "mErrorView", true);
try {
errorText = (TextView) field.get(inputLayout);
} catch (IllegalAccessException ignored) {
}
return errorText;
}