本文整理匯總了Java中org.springframework.util.ClassUtils類的典型用法代碼示例。如果您正苦於以下問題:Java ClassUtils類的具體用法?Java ClassUtils怎麽用?Java ClassUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClassUtils類屬於org.springframework.util包,在下文中一共展示了ClassUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: commaSeparatedStringToThrowablesCollection
import org.springframework.util.ClassUtils; //導入依賴的package包/類
@ConfigurationPropertiesBinding
@Bean
public Converter<String, List<Class<? extends Throwable>>> commaSeparatedStringToThrowablesCollection() {
return new Converter<String, List<Class<? extends Throwable>>>() {
@Override
public List<Class<? extends Throwable>> convert(final String source) {
try {
final List<Class<? extends Throwable>> classes = new ArrayList<>();
for (final String className : StringUtils.commaDelimitedListToStringArray(source)) {
classes.add((Class<? extends Throwable>) ClassUtils.forName(className.trim(), getClass().getClassLoader()));
}
return classes;
} catch (final Exception e) {
throw new IllegalStateException(e);
}
}
};
}
示例2: forMethod
import org.springframework.util.ClassUtils; //導入依賴的package包/類
/**
* Creates a {@link PublicationTargetIdentifier} for the given {@link Method}.
*
* @param method must not be {@literal null}.
* @return
*/
public static PublicationTargetIdentifier forMethod(Method method) {
String typeName = ClassUtils.getUserClass(method.getDeclaringClass()).getName();
String methodName = method.getName();
String parameterTypes = StringUtils.arrayToDelimitedString(method.getParameterTypes(), ", ");
return PublicationTargetIdentifier.of(String.format("%s.%s(%s)", typeName, methodName, parameterTypes));
}
示例3: getSingletonInstance
import org.springframework.util.ClassUtils; //導入依賴的package包/類
/**
* Return the singleton instance of this class's proxy object,
* lazily creating it if it hasn't been created already.
* @return the shared singleton proxy
*/
private synchronized Object getSingletonInstance() {
if (this.singletonInstance == null) {
this.targetSource = freshTargetSource();
if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) {
// Rely on AOP infrastructure to tell us what interfaces to proxy.
Class<?> targetClass = getTargetClass();
if (targetClass == null) {
throw new FactoryBeanNotInitializedException("Cannot determine target class for proxy");
}
setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
}
// Initialize the shared singleton instance.
super.setFrozen(this.freezeProxy);
this.singletonInstance = getProxy(createAopProxy());
}
return this.singletonInstance;
}
示例4: getNumberConversionMethodName
import org.springframework.util.ClassUtils; //導入依賴的package包/類
private static String getNumberConversionMethodName(Class<?> objectClass) {
objectClass = ClassUtils.resolvePrimitiveIfNecessary(objectClass);
if (Integer.class.isAssignableFrom(objectClass)) {
return INT_VALUE;
}
if (Long.class.isAssignableFrom(objectClass)) {
return LONG_VALUE;
}
if (Float.class.isAssignableFrom(objectClass)) {
return FLOAT_VALUE;
}
if (Double.class.isAssignableFrom(objectClass)) {
return DOUBLE_VALUE;
}
throw new IllegalArgumentException(
"Cannot get conversion number for class " + objectClass);
}
示例5: parseTargetMapping
import org.springframework.util.ClassUtils; //導入依賴的package包/類
private static FlowExecutor.TargetMappingExecutor parseTargetMapping(Method method) {
logger.debug("解析目標對象映射方法:{}", method);
// 校驗方法類型
if (!Modifier.isPublic(method.getModifiers())) {
throw new IllegalArgumentException("目標對象映射方法" + ClassUtils.getQualifiedMethodName(method) + "必須是public類型");
}
// 校驗入參
Class[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length != 1) {
throw new IllegalArgumentException("目標對象映射方法" + ClassUtils.getQualifiedMethodName(method) + "必須隻能有一個入參");
}
// 校驗返回參數
if (method.getReturnType() != String.class) {
throw new IllegalArgumentException("目標對象映射方法" + ClassUtils.getQualifiedMethodName(method) + "返回參數必須是String類型");
}
return new FlowExecutor.TargetMappingExecutor(method, parameterTypes[0]);
}
示例6: newPrototypeInstance
import org.springframework.util.ClassUtils; //導入依賴的package包/類
/**
* Create a new prototype instance of this class's created proxy object,
* backed by an independent AdvisedSupport configuration.
* @return a totally independent proxy, whose advice we may manipulate in isolation
*/
private synchronized Object newPrototypeInstance() {
// In the case of a prototype, we need to give the proxy
// an independent instance of the configuration.
// In this case, no proxy will have an instance of this object's configuration,
// but will have an independent copy.
if (logger.isTraceEnabled()) {
logger.trace("Creating copy of prototype ProxyFactoryBean config: " + this);
}
ProxyCreatorSupport copy = new ProxyCreatorSupport(getAopProxyFactory());
// The copy needs a fresh advisor chain, and a fresh TargetSource.
TargetSource targetSource = freshTargetSource();
copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain());
if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) {
// Rely on AOP infrastructure to tell us what interfaces to proxy.
copy.setInterfaces(
ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
}
copy.setFrozen(this.freezeProxy);
if (logger.isTraceEnabled()) {
logger.trace("Using ProxyCreatorSupport copy: " + copy);
}
return getProxy(copy.createAopProxy());
}
示例7: getBeanName
import org.springframework.util.ClassUtils; //導入依賴的package包/類
private static String getBeanName(AnnotationMetadata annotationMetadata, Map<String, Object> attributes) {
// name & value are aliases
String beanName = (String) attributes.get("value");
if (!StringUtils.isEmpty(beanName)) {
return beanName;
} else {
// generate bean name from class name
String shortName = ClassUtils.getShortName(annotationMetadata.getClassName());
return StringUtils.uncapitalize(shortName);
}
}
示例8: createProxy
import org.springframework.util.ClassUtils; //導入依賴的package包/類
/**
* Actually create the EntityManager proxy.
* @param rawEm raw EntityManager
* @param emIfc the (potentially vendor-specific) EntityManager
* interface to proxy, or {@code null} for default detection of all interfaces
* @param cl the ClassLoader to use for proxy creation (maybe {@code null})
* @param exceptionTranslator the PersistenceException translator to use
* @param jta whether to create a JTA-aware EntityManager
* (or {@code null} if not known in advance)
* @param containerManaged whether to follow container-managed EntityManager
* or application-managed EntityManager semantics
* @param synchronizedWithTransaction whether to automatically join ongoing
* transactions (according to the JPA 2.1 SynchronizationType rules)
* @return the EntityManager proxy
*/
private static EntityManager createProxy(
EntityManager rawEm, Class<? extends EntityManager> emIfc, ClassLoader cl,
PersistenceExceptionTranslator exceptionTranslator, Boolean jta,
boolean containerManaged, boolean synchronizedWithTransaction) {
Assert.notNull(rawEm, "EntityManager must not be null");
Set<Class<?>> ifcs = new LinkedHashSet<Class<?>>();
if (emIfc != null) {
ifcs.add(emIfc);
}
else {
ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(rawEm.getClass(), cl));
}
ifcs.add(EntityManagerProxy.class);
return (EntityManager) Proxy.newProxyInstance(
(cl != null ? cl : ExtendedEntityManagerCreator.class.getClassLoader()),
ifcs.toArray(new Class<?>[ifcs.size()]),
new ExtendedEntityManagerInvocationHandler(
rawEm, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction));
}
示例9: scanForEntities
import org.springframework.util.ClassUtils; //導入依賴的package包/類
protected Set<Class<?>> scanForEntities(String basePackage) throws ClassNotFoundException {
if (!StringUtils.hasText(basePackage)) {
return Collections.emptySet();
}
final Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();
if (StringUtils.hasText(basePackage)) {
final ClassPathScanningCandidateComponentProvider componentProvider =
new ClassPathScanningCandidateComponentProvider(false);
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
for (final BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
initialEntitySet
.add(ClassUtils.forName(candidate.getBeanClassName(),
DocumentDbConfigurationSupport.class.getClassLoader()));
}
}
return initialEntitySet;
}
示例10: HandlerMethodService
import org.springframework.util.ClassUtils; //導入依賴的package包/類
public HandlerMethodService(ConversionService conversionService,
List<HandlerMethodArgumentResolver> customArgumentResolvers,
ObjectMapper objectMapper, ApplicationContext applicationContext) {
this.conversionService = conversionService;
this.parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
ConfigurableBeanFactory beanFactory = ClassUtils.isAssignableValue(
ConfigurableApplicationContext.class, applicationContext)
? ((ConfigurableApplicationContext) applicationContext)
.getBeanFactory()
: null;
this.argumentResolvers.addResolver(
new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
this.argumentResolvers.addResolver(new HeadersMethodArgumentResolver());
this.argumentResolvers.addResolver(new WampMessageMethodArgumentResolver());
this.argumentResolvers.addResolver(new PrincipalMethodArgumentResolver());
this.argumentResolvers.addResolver(new WampSessionIdMethodArgumentResolver());
this.argumentResolvers.addResolvers(customArgumentResolvers);
this.objectMapper = objectMapper;
}
示例11: invoke
import org.springframework.util.ClassUtils; //導入依賴的package包/類
/**
* Invoke the method after resolving its argument values in the context of the given
* message.
* <p>
* Argument values are commonly resolved through
* {@link HandlerMethodArgumentResolver}s. The {@code providedArgs} parameter however
* may supply argument values to be used directly, i.e. without argument resolution.
* @param message the current message being processed
* @param arguments
* @param argumentsKw
* @return the raw value returned by the invoked method
* @exception Exception raised if no suitable argument resolver can be found, or if
* the method raised an exception
*/
@Nullable
public Object invoke(WampMessage message, List<Object> arguments,
Map<String, Object> argumentsKw) throws Exception {
Object[] args = getMethodArgumentValues(message, arguments, argumentsKw);
if (this.logger.isTraceEnabled()) {
this.logger.trace("Invoking '"
+ ClassUtils.getQualifiedMethodName(getMethod(), getBeanType())
+ "' with arguments " + Arrays.toString(args));
}
Object returnValue = doInvoke(args);
if (this.logger.isTraceEnabled()) {
this.logger.trace("Method ["
+ ClassUtils.getQualifiedMethodName(getMethod(), getBeanType())
+ "] returned [" + returnValue + "]");
}
return returnValue;
}
示例12: getSpecificmethod
import org.springframework.util.ClassUtils; //導入依賴的package包/類
private Method getSpecificmethod(ProceedingJoinPoint pjp) {
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod();
// The method may be on an interface, but we need attributes from the
// target class. If the target class is null, the method will be
// unchanged.
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(pjp.getTarget());
if (targetClass == null && pjp.getTarget() != null) {
targetClass = pjp.getTarget().getClass();
}
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
// If we are dealing with method with generic parameters, find the
// original method.
specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
return specificMethod;
}
示例13: equals
import org.springframework.util.ClassUtils; //導入依賴的package包/類
@Override
public boolean equals(Object obj) {
if (null == obj) {
return false;
}
if (this == obj) {
return true;
}
if (!getClass().equals(ClassUtils.getUserClass(obj))) {
return false;
}
AbstractPersistable<?> that = (AbstractPersistable<?>) obj;
return null != this.getId() && this.getId().equals(that.getId());
}
示例14: getEmbeddedServletContainer
import org.springframework.util.ClassUtils; //導入依賴的package包/類
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers) {
ClassLoader parentClassLoader = resourceLoader != null ? resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader();
Package nettyPackage = Bootstrap.class.getPackage();
String title = nettyPackage.getImplementationTitle();
String version = nettyPackage.getImplementationVersion();
logger.info("Running with " + title + " " + version);
NettyEmbeddedContext context = new NettyEmbeddedContext(getContextPath(), new URLClassLoader(new URL[]{}, parentClassLoader), SERVER_INFO);
if (isRegisterDefaultServlet()) {
logger.warn("This container does not support a default servlet");
}
/*if (isRegisterJspServlet()) {
logger.warn("This container does not support a JSP servlet");
}*/
for (ServletContextInitializer initializer : initializers) {
try {
initializer.onStartup(context);
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
int port = getPort() > 0 ? getPort() : new Random().nextInt(65535 - 1024) + 1024;
InetSocketAddress address = new InetSocketAddress(port);
logger.info("Server initialized with port: " + port);
return new NettyEmbeddedServletContainer(address, context);
}
示例15: getURL
import org.springframework.util.ClassUtils; //導入依賴的package包/類
public static URL getURL(String resourceLocation)
throws FileNotFoundException {
Assert.notNull(resourceLocation, "Resource location must not be null");
if (resourceLocation.startsWith("classpath:")) {
String path = resourceLocation.substring("classpath:".length());
ClassLoader cl = ClassUtils.getDefaultClassLoader();
URL url = cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path);
if (url == null) {
String description = "class path resource [" + path + "]";
throw new FileNotFoundException(description + " cannot be resolved to URL because it does not exist");
}
return url;
}
try {
return new URL(resourceLocation);
} catch (MalformedURLException ex) {
try {
return new File(resourceLocation).toURI().toURL();
} catch (MalformedURLException ex2) {
}
}
throw new FileNotFoundException("Resource location [" + resourceLocation + "] is neither a URL not a well-formed file path");
}