本文整理汇总了Java中org.openyu.commons.lang.ClassHelper类的典型用法代码示例。如果您正苦于以下问题:Java ClassHelper类的具体用法?Java ClassHelper怎么用?Java ClassHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassHelper类属于org.openyu.commons.lang包,在下文中一共展示了ClassHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: audit
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
/**
* 設定稽核欄位
*
* 原則:
*
* 1.implements AuditEntity
*
* 2.有 AuditEntity 的 field
*
* @param entity
* @param modifiedUser
*/
public static <T> boolean audit(T entity, String modifiedUser) {
boolean result = false;
if (entity instanceof AuditEntity) {
result = audit((AuditEntity) entity, modifiedUser);
} else if (entity != null) {
Field[] fields = ClassHelper.getDeclaredField(entity.getClass(), AuditEntity.class);
if (fields.length > 0) {
result = true;
for (Field field : fields) {
AuditEntity auditEntity = (AuditEntity) ClassHelper.getFieldValue(entity, field);
result &= audit(auditEntity, modifiedUser);
}
}
}
return result;
}
示例2: buildUnsafe
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
/**
* 使用Field來取得, 較省資源
*/
protected static void buildUnsafe() {
try {
// #issue
// Field field = Unsafe.class.getDeclaredField("theUnsafe");
// #fix
Field field = ClassHelper.getDeclaredField(Unsafe.class, "theUnsafe");
field.setAccessible(true);
unsafe = (Unsafe) field.get(null);
int boo = unsafe.arrayBaseOffset(byte[].class);
// It seems not all Unsafe implementations implement the following
// method.
unsafe.copyMemory(new byte[1], boo, new byte[1], boo, 1);
//
BYTE_ARRAY_OFFSET = unsafe.arrayBaseOffset(byte[].class);
LONG_ARRAY_OFFSET = unsafe.arrayBaseOffset(long[].class);
DOUBLE_ARRAY_OFFSET = unsafe.arrayBaseOffset(double[].class);
OBJECT_ARRAY_OFFSET = unsafe.arrayBaseOffset(Object[].class);
} catch (Exception ex) {
throw new RuntimeException("UnsafeHelper Failed to " + "get unsafe", ex);
}
}
示例3: delete
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
@CommonTx
@SuppressWarnings("unchecked")
public <T> T delete(Class<?> entityClass, Serializable seq, String modifiedUser) {
T result = null;
// 此時為po
Object entity = findReturnVoOrNot(entityClass, seq, false);
int del = delete(entity, modifiedUser);
if (del > 0) {
boolean isVoClass = ClassHelper.isVoClass(entityClass);
if (isVoClass) {
result = ClassHelper.copyProperties(entity, entityClass);// po->vo
} else {
result = (T) entity;
}
}
return result;
}
示例4: rowCount
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
public long rowCount(Class<?> entityClass) {
long result = 0L;
try {
boolean isVoClass = ClassHelper.isVoClass(entityClass);
if (isVoClass) {
Class<?> poClass = ClassHelper.vo2PoClass(entityClass);
if (poClass != null) {
result = commonDao.rowCount(poClass);
}
} else {
result = commonDao.rowCount(entityClass);
}
} catch (Exception ex) {
throw new CommonServiceException(ex);
}
return result;
}
示例5: typeOf
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
/**
* 利用反射,由名稱取得int.
*
* @param name
* the name
* @return the int
*/
public int typeOf(String name) {
int result = UNKNOWN;
// 不要用cache,因會被繼承使用此class
// Field[] fields =
// ClassHelper.getDeclaredFieldsAndCache(EventObjectSupporter.class);
Field[] fields = getClass().getFields();
for (Field field : fields) {
try {
// #issue 有錯
// #fix ok
if (field.getName().equals(name)
&& ClassHelper.isConstantField(field)
&& field.getType().equals(int.class)) {
result = field.getInt(this);
}
} catch (Exception ex) {
// ex.printStackTrace();
}
}
return result;
}
示例6: checkBaseEditor
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
/**
* 檢查collector名稱, 是否可以建構
*
* @param editorName
* @return
*/
protected static BaseEditor checkBaseEditor(String editorName) {
BaseEditor result = null;
if (StringHelper.isBlank(editorName)) {
LOGGER.error("[" + editorName + "] Is null");
return result;
}
Class<?> clazz = ClassHelper.forName(editorName);
if (clazz == null) {
LOGGER.error("Can not forName(" + editorName + ")");
return result;
}
Object object = ClassHelper.newInstance(clazz);
if (!(object instanceof BaseEditor)) {
LOGGER.error("Can not newInstance(" + editorName + "). It is not instance of BaseEditor");
return result;
}
//
result = (BaseEditor) object;
return result;
}
示例7: copyNames2Po
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
@Test
// 1000000 times: 8924 mills.
// 1000000 times: 8910 mills.
// 1000000 times: 8851 mills.
public void copyNames2Po() {
NamesBean namesBean = new NamesBeanSupporter();
namesBean.addName(Locale.TRADITIONAL_CHINESE, "拉拉");
System.out.println(namesBean);
//
Class<?> result = ClassHelper.getConventionClass(namesBean);
System.out.println(result);// NamesEntitySupporter
//
NamesEntity namesEntity = null;
int count = 1000000;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
namesEntity = ClassHelper.copyProperties(namesBean);
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
System.out.println(namesEntity);
}
示例8: syncRoleField
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
/**
* 同步, 同步角色的欄位
*
* @param syncRoleId
* @param fieldName
* @param value
* @return
*/
public Object syncRoleField(String syncRoleId, String fieldName, Object value) {
// LOGGER.info("syncRoleField: " + syncRoleId
// +", "+syncRoleId+", "+value);
// 檢查條件
Role syncRole = roleRepository.getSyncRole(syncRoleId);
if (syncRole == null) {
return null;
}
//
// 取field來set
Field field = ClassHelper.getDeclaredField(RoleImpl.class, fieldName);
if (field != null) {
// System.out.println(ClassHelper.getFieldValue(syncRole, field));
//
ClassHelper.setFieldValue(syncRole, field, value);
//
// System.out.println(ClassHelper.getFieldValue(syncRole, field));
} else {
LOGGER.warn("Can't synchronize syncRole field [" + fieldName + "]");
}
return value;
}
示例9: copy2RolePo
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
@Test
public void copy2RolePo() {
final String ROLE_ID = "TEST_ROLE" + randomUnique();
Role orig = new RoleImpl();
orig.setId(ROLE_ID);
// orig.setCareerType(CareerType.WARRIOR_1);
orig.getAttributeGroup().setAttributes(randomAttributes());
//
RolePo dest = ClassHelper.copyProperties(orig);
// attrubutes
System.out.println("dest.getAttributes: " + dest.getAttributeGroup().getAttributes());
assertAttrubutes(orig.getAttributeGroup().getAttributes(), dest.getAttributeGroup().getAttributes());
}
示例10: setValue
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
@Test
public void setValue() {
Role role = mockRole();
System.out.println(role.getVipType());
//
String fieldName = "vipType";
String setterName = ClassHelper.setterName(fieldName);
//
VipType fieldValue = VipType._0;
//
Method method = ClassHelper.getDeclaredMethod(Role.class, setterName, fieldValue.getClass());
System.out.println(method);
//
ClassHelper.invokeDeclaredMethod(role, setterName, fieldValue.getClass(), VipType._1);
System.out.println(role.getVipType());
//
}
示例11: PoolableXmppConnection
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
public PoolableXmppConnection(XMPPConnection delegate, ObjectPool<XMPPConnection> pool) {
this.delegate = delegate;
this.pool = pool;
//
if (delegate != null) {
if (delegate instanceof XMPPTCPConnection) {
socket = ClassHelper.getDeclaredFieldValue(delegate, "socket");
}
}
}
示例12: values
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
/**
* 取得所有列舉元素.
*
* @param <T>
* the generic type
* @param enumType
* the enum type
* @return the t[]
*/
public static <T extends Enum<T>> T[] values(Class<T> enumType) {
T[] result = null;
//
if (enumType != null) {
// result = enumType.getEnumConstants();
result = ClassHelper.getEnumConstantsAndCache(enumType);
}
return result;
}
示例13: sizeOf
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
/**
* 这个实现返回class的自身内存大小
*
* @param clazz
* @return
*/
public static long sizeOf(Class<?> clazz) {
long maximumOffset = 0;
Field[] fields = ClassHelper.getDeclaredFieldsAndCache(clazz);
// do {
// for (Field f : clazz.getDeclaredFields()) {
for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers())) {
// int=12, long=16
maximumOffset = Math.max(maximumOffset, unsafe.objectFieldOffset(field));
}
}
// } while ((clazz = clazz.getSuperclass()) != null);
return maximumOffset == 0 ? 0 : maximumOffset + 8;
}
示例14: getName
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
/**
* 利用反射,由int取得名稱
*
* 取常數項int,當作事件常數項判斷.
*
* @return the name
*/
public String getName() {
if (name == null) {
// 不要用cache,因會被繼承使用此class
// Field[] fields =
// ClassHelper.getDeclaredFieldsAndCache(EventObjectSupporter.class);
Field[] fields = getClass().getFields();
for (Field field : fields) {
try {
// #issue 有錯
// #fix ok
// 取 public static final int 的 field 作為事件常數項判斷
if (ClassHelper.isConstantField(field)
&& field.getType().equals(int.class)) {
// System.out.println(field.getName());
Integer value = ClassHelper.getFieldValue(this, field);
if (value != null && type == value) {
name = field.getName();
break;
}
}
} catch (Exception ex) {
// ex.printStackTrace();
}
}
}
return name;
}
示例15: getDisplayName
import org.openyu.commons.lang.ClassHelper; //导入依赖的package包/类
protected String getDisplayName() {
if (displayName == null) {
StringBuilder buff = new StringBuilder();
buff.append(ClassHelper.getSimpleName(getClass()));
buff.append(" @" + Integer.toHexString(hashCode()));
displayName = buff.toString();
}
return displayName;
}