当前位置: 首页>>代码示例>>Java>>正文


Java FieldUtils.getField方法代码示例

本文整理汇总了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);
		}
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:27,代码来源:ChatMessagePacketHandler.java

示例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();
  }
}
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:22,代码来源:ColumnNameConversionPlugin.java

示例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;
}
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:19,代码来源:PostgisGeoPlugin.java

示例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);
    }
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:17,代码来源:BasicPersistenceModule.java

示例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;
}
 
开发者ID:terrestris,项目名称:shogun2,代码行数:23,代码来源:EntityUtil.java

示例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);
        }
    };
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:LogEventFactoryTest.java

示例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());
    }
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:9,代码来源:AbstractRepository.java

示例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());
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:15,代码来源:MtlBaseTaskAction.java

示例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);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:9,代码来源:EntityMetadataImpl.java

示例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);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:13,代码来源:EntityManager.java

示例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;
    }
 
开发者ID:iazarny,项目名称:gitember,代码行数:28,代码来源:DiffViewController.java

示例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");
    }
}
 
开发者ID:ykrank,项目名称:S1-Next,代码行数:17,代码来源:LeaksUtil.java

示例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");
    }
}
 
开发者ID:ykrank,项目名称:S1-Next,代码行数:17,代码来源:LeaksUtil.java

示例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;
}
 
开发者ID:SourcePond,项目名称:release-maven-plugin-parent,代码行数:13,代码来源:ConfigurationAccessor.java

示例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;
}
 
开发者ID:SIGLUS,项目名称:lmis-moz-mobile,代码行数:11,代码来源:RobolectricUtils.java


注:本文中的org.apache.commons.lang3.reflect.FieldUtils.getField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。