本文整理匯總了Java中org.apache.commons.lang3.reflect.FieldUtils.writeDeclaredField方法的典型用法代碼示例。如果您正苦於以下問題:Java FieldUtils.writeDeclaredField方法的具體用法?Java FieldUtils.writeDeclaredField怎麽用?Java FieldUtils.writeDeclaredField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang3.reflect.FieldUtils
的用法示例。
在下文中一共展示了FieldUtils.writeDeclaredField方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sqlMapGenerated
import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
try {
// use reflect to fix the root comment
Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true);
ExtendedDocument extendedDocument = new ExtendedDocument(document);
FieldUtils.writeDeclaredField(sqlMap, "document", extendedDocument, true);
if (context.getCommentGenerator() instanceof CommentGenerator) {
CommentGenerator cg = (CommentGenerator) context.getCommentGenerator();
cg.addSqlMapFileComment(extendedDocument);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return true;
}
示例2: checkAndReplaceInput
import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
protected void checkAndReplaceInput(List<IntrospectedColumn> columns, TextElement te) {
String sql = te.getContent();
for(IntrospectedColumn column : columns){
if(column.getFullyQualifiedJavaType().getShortName().equals("Geometry")){
String paramStr = MyBatis3FormattingUtilities.getParameterClause(column);
sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace no prefix geo relate column
paramStr = MyBatis3FormattingUtilities.getParameterClause(column, "record.");
sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace mbg generate prefix geo relate column
paramStr = MyBatis3FormattingUtilities.getParameterClause(column, "item.");
sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace mbg batch plugin generate prefix geo relate column
// System.out.println();
// System.out.println(sql);
}
}
try {
FieldUtils.writeDeclaredField(te, "content", sql, true);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
示例3: checkAndReplaceOutput
import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
protected void checkAndReplaceOutput(List<IntrospectedColumn> columns, TextElement te) {
String sql = te.getContent();
for(IntrospectedColumn column : columns){
if(column.getFullyQualifiedJavaType().getShortName().equals("Geometry")){
String columnStr = null;
if(column.isColumnNameDelimited()){
columnStr = "\""+column.getActualColumnName()+"\"";
}else{
columnStr = column.getActualColumnName();
}
sql = StringUtils.replaceOnce(sql, columnStr, "ST_AsText("+columnStr+") as " + columnStr);
//sql = sql.replace(column.getActualColumnName(), "ST_AsText("+column.getActualColumnName()+")");
// System.out.println();
// System.out.println(sql);
}
}
try {
FieldUtils.writeDeclaredField(te, "content", sql, true);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
示例4: writeField
import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"})
public void writeField(Object target, String fieldName, Object value)
{
try
{
Object oldValue = readField(target, fieldName);
if(usesMap)
((Map) target).put(fieldName, value);
else
FieldUtils.writeDeclaredField(target, fieldName, value, true);
pcs.firePropertyChange(fieldName, oldValue, value);
}
catch(IllegalAccessException e)
{
throw new RuntimeException(e);
}
}
示例5: bind
import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
public void bind(ApplicationContext applicationContext, Bindable bean) throws IllegalAccessException {
Field[] fields = bean.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(BXML.class)) {
String fieldName = field.getName();
int fieldModifiers = field.getModifiers();
BXML bindingAnnotation = field.getAnnotation(BXML.class);
if ((fieldModifiers & Modifier.FINAL) > 0) {
throw new IllegalAccessException(fieldName + " is final.");
}
if ((fieldModifiers & Modifier.PUBLIC) == 0) {
field.setAccessible(true);
}
String id = bindingAnnotation.id();
if (StringUtils.isBlank(id) || id.equals("\0")) {
id = field.getName();
}
if (applicationContext.containsBean(id)) {
Object value = applicationContext.getBean(id);
FieldUtils.writeDeclaredField(target, id, value, true);
}
}
}
}
示例6: write
import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
public void write(Object value)
{
try
{
FieldUtils.writeDeclaredField(o, field, value, true);
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
}
示例7: setAbsoluteName
import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
/**
* Allows the absoluteName of the given service to be explicitly defined.
* Normally this is determined by the object's location in the Nucleus
* hierarchy. For test items that are not really bound to Nucleus, it's
* convenient to just give it an absolute name rather than going through
* the whole configuration and binding process.
*
* @param absoluteName
* The absolute name value to set
* @param service
* The service whose absolute name should be set.
*/
public static void setAbsoluteName(String absoluteName, GenericService service)
throws IllegalAccessException {
FieldUtils.writeDeclaredField(service, "mAbsoluteName", absoluteName, true);
}
示例8: testPutAndGet
import org.apache.commons.lang3.reflect.FieldUtils; //導入方法依賴的package包/類
@Test
public void testPutAndGet() throws IllegalAccessException {
final UUID uuid = UUIDGenerator.newTimeUUID();
final UUID version = UUIDGenerator.newTimeUUID();
final String type = "test";
final Id simpleId = new SimpleId( uuid, type );
Entity entity = new Entity(simpleId );
FieldUtils.writeDeclaredField( entity, "version", version, true );
assertEquals( uuid, entity.getId().getUuid() );
assertEquals( type, entity.getId().getType() );
assertEquals( version, entity.getVersion());
BooleanField boolField = new BooleanField( "boolean", false );
DoubleField doubleField = new DoubleField( "double", 1d );
IntegerField intField = new IntegerField( "long", 1 );
LongField longField = new LongField( "int", 1l );
StringField stringField = new StringField( "name", "test" );
UUIDField uuidField = new UUIDField( "uuid", UUIDGenerator.newTimeUUID() );
NullField nullField = new NullField("null");
entity.setField( boolField );
entity.setField( doubleField );
entity.setField( intField );
entity.setField( longField );
entity.setField( stringField );
entity.setField( uuidField );
entity.setField( nullField );
Field<Boolean> boolFieldReturned = entity.getField( boolField.getName() );
assertSame( boolField, boolFieldReturned );
Field<Double> doubleFieldReturned = entity.getField( doubleField.getName() );
assertSame( doubleField, doubleFieldReturned );
Field<Integer> intFieldReturned = entity.getField( intField.getName() );
assertSame( intField, intFieldReturned );
Field<Long> longFieldReturned = entity.getField( longField.getName() );
assertSame( longField, longFieldReturned );
Field<String> stringFieldReturned = entity.getField( stringField.getName() );
assertSame( stringField, stringFieldReturned );
Field<UUID> uuidFieldReturned = entity.getField( uuidField.getName() );
assertSame( uuidField, uuidFieldReturned );
Field<Object> nullFieldReturned = entity.getField( nullField.getName());
assertSame( nullField, nullFieldReturned);
Set<Field> results = new HashSet<Field>();
results.addAll( entity.getFields() );
assertTrue( results.contains( boolField ) );
assertTrue( results.contains( doubleField ) );
assertTrue( results.contains( intField ) );
assertTrue( results.contains( longField ) );
assertTrue( results.contains( stringField ) );
assertTrue( results.contains( uuidField ) );
assertTrue( results.contains( nullField ) );
assertEquals( 7, results.size() );
assertEquals( simpleId, entity.getId() );
assertEquals( version, entity.getVersion() );
}