本文整理汇总了Java中org.springframework.objenesis.instantiator.ObjectInstantiator类的典型用法代码示例。如果您正苦于以下问题:Java ObjectInstantiator类的具体用法?Java ObjectInstantiator怎么用?Java ObjectInstantiator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectInstantiator类属于org.springframework.objenesis.instantiator包,在下文中一共展示了ObjectInstantiator类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstantiatorOf
import org.springframework.objenesis.instantiator.ObjectInstantiator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> ObjectInstantiator<T> getInstantiatorOf(Class<T> clazz) {
ObjectInstantiator<?> instantiator = this.cache.get(clazz);
if (instantiator == null) {
ObjectInstantiator<T> newInstantiator = newInstantiatorOf(clazz);
instantiator = this.cache.putIfAbsent(clazz, newInstantiator);
if (instantiator == null) {
instantiator = newInstantiator;
}
}
return (ObjectInstantiator<T>) instantiator;
}
示例2: newInstantiatorOf
import org.springframework.objenesis.instantiator.ObjectInstantiator; //导入依赖的package包/类
protected <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> clazz) {
Boolean currentWorthTrying = this.worthTrying;
try {
ObjectInstantiator<T> instantiator = this.strategy.newInstantiatorOf(clazz);
if (currentWorthTrying == null) {
this.worthTrying = Boolean.TRUE;
}
return instantiator;
}
catch (ObjenesisException ex) {
if (currentWorthTrying == null) {
Throwable cause = ex.getCause();
if (cause instanceof ClassNotFoundException || cause instanceof IllegalAccessException) {
// Indicates that the chosen instantiation strategy does not work on the given JVM.
// Typically a failure to initialize the default SunReflectionFactoryInstantiator.
// Let's assume that any subsequent attempts to use Objenesis will fail as well...
this.worthTrying = Boolean.FALSE;
}
}
throw ex;
}
catch (NoClassDefFoundError err) {
// Happening on the production version of Google App Engine, coming out of the
// restricted "sun.reflect.ReflectionFactory" class...
if (currentWorthTrying == null) {
this.worthTrying = Boolean.FALSE;
}
throw new ObjenesisException(err);
}
}
示例3: instanceOfClass
import org.springframework.objenesis.instantiator.ObjectInstantiator; //导入依赖的package包/类
/**
* <b>Don't copy paste this stuff, cuz its evil.</b><br>
* Creates ANY object from simple class name. With any i mean ANY, no restrictions.<br>
* Used to call class methods on that object in JSP, because classes can't be used in JSP.<br>
* Use carefully, because this is probably slow as fuck.
*/
public static <T> T instanceOfClass(String clazz) throws ClassNotFoundException {
@SuppressWarnings("unchecked")
Class<T> resolvedClass = (Class<T>) getClassFromSimpleString(clazz);
ObjectInstantiator<T> instantiator = objenesis.getInstantiatorOf(resolvedClass);
return resolvedClass.cast(instantiator.newInstance());
}