org.springframework.objenesis.instantiator.ObjectInstantiator Java Examples

The following examples show how to use org.springframework.objenesis.instantiator.ObjectInstantiator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringObjenesis.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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;
}
 
Example #2
Source File: SpringObjenesis.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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);
	}
}
 
Example #3
Source File: SpringObjenesis.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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;
}
 
Example #4
Source File: SpringObjenesis.java    From java-technology-stack with MIT License 5 votes vote down vote up
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);
	}
}
 
Example #5
Source File: SpringObjenesis.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #6
Source File: SpringObjenesis.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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);
	}
}
 
Example #7
Source File: SpringObjenesis.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #8
Source File: SpringObjenesis.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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);
	}
}