本文整理汇总了Java中net.sf.cglib.reflect.FastClass.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java FastClass.newInstance方法的具体用法?Java FastClass.newInstance怎么用?Java FastClass.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.cglib.reflect.FastClass
的用法示例。
在下文中一共展示了FastClass.newInstance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import net.sf.cglib.reflect.FastClass; //导入方法依赖的package包/类
private void test() throws InvocationTargetException {
FastClass fastClass = FastClass.create(Source.class);
Source sourceClass = (Source) fastClass.newInstance();
fastClass.invoke("setIntValue", new Class[] { int.class }, sourceClass, new Object[] { 200 });
Object getIntValue = fastClass.invoke("getIntValue", new Class[] {}, sourceClass, new Object[] {});
System.out.println("intValue : " + getIntValue.toString());
FastMethod setIntValueMethod = fastClass.getMethod("setIntValue", new Class[] { int.class });
System.out.println("method name :" + setIntValueMethod.getJavaMethod().getName() + " index:"
+ setIntValueMethod.getIndex());
FastMethod getIntValueMethod = fastClass.getMethod("getIntValue", new Class[] {});
System.out.println("method name :" + getIntValueMethod.getJavaMethod().getName() + " index:"
+ getIntValueMethod.getIndex());
}
示例2: doconfirmorcancel
import net.sf.cglib.reflect.FastClass; //导入方法依赖的package包/类
private void doconfirmorcancel(Class<?> clazz, String lookup, String method, //
Class<?>[] mParamsTypes, Object[] args) throws Exception {
Class<?> confirmclass = GuiceDI.getInstance(ServiceInfosHolder.class).getImplClass(clazz, lookup);
FastClass confrimfast = FastClass.create(confirmclass);
// fast class反射调用
Object confirmtarget = confrimfast.newInstance();
FastMethod confirmmethod = confrimfast.getMethod(method, mParamsTypes);
confirmmethod.invoke(confirmtarget, args);
}
示例3: newInstance
import net.sf.cglib.reflect.FastClass; //导入方法依赖的package包/类
public static <T> T newInstance(Class<T> clazz) {
FastClass fastClass = getFastClass(clazz);
try {
//noinspection unchecked
return (T) fastClass.newInstance();
} catch (InvocationTargetException e) {
throw new InmemoException("Can't create new instance [class=" + clazz + "].", e);
}
}
示例4: invoke
import net.sf.cglib.reflect.FastClass; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public Object invoke(RemotingProtocol msg) throws Exception {
Stopwatch watch = Stopwatch.createStarted();
Object[] args = msg.getArgs();
Class<?> implClass = GuiceDI.getInstance(ServiceInfosHolder.class).getImplClass(msg.getDefineClass(), msg.getImplClass());
if (implClass == null) {
throw new NoImplClassException(msg.getDefineClass().getName());
}
logger.info(implClass.getName());
Tcc tcc = GuiceDI.getInstance(TccProvider.class).getCompensable(msg.getDefineClass());
// logger.info(JSON.toJSONString(tcc));
try {
FastClass fastClazz = FastClass.create(implClass);
// fast class反射调用
String mkey = String.format("%s_%s", implClass.getSimpleName(), msg.getMethod());
Tuple<Object, FastMethod> classmethod = map.get(mkey);
if (classmethod == null) {
Object target = fastClazz.newInstance();
FastMethod method = fastClazz.getMethod(msg.getMethod(), msg.getmParamsTypes());
if (method != null) {
map.put(mkey, new Tuple<Object, FastMethod>(target, method));
}
}
Object obj = classmethod.value.invoke(classmethod.key, args);
if (tcc != null) {
doconfirmorcancel(msg.getDefineClass(), tcc.getConfirm(), msg.getMethod(), msg.getmParamsTypes(), args);
}
logger.info(String.format("cglib invoke use:%s", watch.toString()));
return obj;
} catch (Exception e) {
if (tcc != null) {
doconfirmorcancel(msg.getDefineClass(), tcc.getCancel(), msg.getMethod(), msg.getmParamsTypes(), args);
return "do cancel";
} else {
throw e;
}
}
}
示例5: getReflectionOptimizer
import net.sf.cglib.reflect.FastClass; //导入方法依赖的package包/类
public ReflectionOptimizer getReflectionOptimizer(
Class clazz,
String[] getterNames,
String[] setterNames,
Class[] types) {
FastClass fastClass;
BulkBean bulkBean;
try {
fastClass = FastClass.create( clazz );
bulkBean = BulkBean.create( clazz, getterNames, setterNames, types );
if ( !clazz.isInterface() && !Modifier.isAbstract( clazz.getModifiers() ) ) {
if ( fastClass == null ) {
bulkBean = null;
}
else {
//test out the optimizer:
Object instance = fastClass.newInstance();
bulkBean.setPropertyValues( instance, bulkBean.getPropertyValues( instance ) );
}
}
}
catch( Throwable t ) {
fastClass = null;
bulkBean = null;
String message = "reflection optimizer disabled for: " +
clazz.getName() +
" [" +
StringHelper.unqualify( t.getClass().getName() ) +
": " +
t.getMessage();
if (t instanceof BulkBeanException ) {
int index = ( (BulkBeanException) t ).getIndex();
if (index >= 0) {
message += " (property " + setterNames[index] + ")";
}
}
log.debug( message );
}
if ( fastClass != null && bulkBean != null ) {
return new ReflectionOptimizerImpl(
new InstantiationOptimizerAdapter( fastClass ),
new AccessOptimizerAdapter( bulkBean, clazz )
);
}
else {
return null;
}
}