Java Code Examples for org.springframework.core.io.ResourceLoader#CLASSPATH_URL_PREFIX

The following examples show how to use org.springframework.core.io.ResourceLoader#CLASSPATH_URL_PREFIX . 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: SimpleMetadataReaderFactory.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public MetadataReader getMetadataReader(String className) throws IOException {
	try {
		String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
				ClassUtils.convertClassNameToResourcePath(className) + ClassUtils.CLASS_FILE_SUFFIX;
		Resource resource = this.resourceLoader.getResource(resourcePath);
		return getMetadataReader(resource);
	}
	catch (FileNotFoundException ex) {
		// Maybe an inner class name using the dot name syntax? Need to use the dollar syntax here...
		// ClassUtils.forName has an equivalent check for resolution into Class references later on.
		int lastDotIndex = className.lastIndexOf('.');
		if (lastDotIndex != -1) {
			String innerClassName =
					className.substring(0, lastDotIndex) + '$' + className.substring(lastDotIndex + 1);
			String innerClassResourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
					ClassUtils.convertClassNameToResourcePath(innerClassName) + ClassUtils.CLASS_FILE_SUFFIX;
			Resource innerClassResource = this.resourceLoader.getResource(innerClassResourcePath);
			if (innerClassResource.exists()) {
				return getMetadataReader(innerClassResource);
			}
		}
		throw ex;
	}
}
 
Example 2
Source File: MethodMetadataReadingVisitorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected AnnotationMetadata get(Class<?> source) {
	try {
		ClassLoader classLoader = source.getClassLoader();
		String className = source.getName();
		String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX
				+ ClassUtils.convertClassNameToResourcePath(className)
				+ ClassUtils.CLASS_FILE_SUFFIX;
		Resource resource = new DefaultResourceLoader().getResource(resourcePath);
		try (InputStream inputStream = new BufferedInputStream(
				resource.getInputStream())) {
			ClassReader classReader = new ClassReader(inputStream);
			AnnotationMetadataReadingVisitor metadata = new AnnotationMetadataReadingVisitor(
					classLoader);
			classReader.accept(metadata, ClassReader.SKIP_DEBUG);
			return metadata;
		}
	}
	catch (Exception ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example 3
Source File: AnnotationMetadataReadingVisitorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected AnnotationMetadata get(Class<?> source) {
	try {
		ClassLoader classLoader = source.getClassLoader();
		String className = source.getName();
		String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX
				+ ClassUtils.convertClassNameToResourcePath(className)
				+ ClassUtils.CLASS_FILE_SUFFIX;
		Resource resource = new DefaultResourceLoader().getResource(resourcePath);
		try (InputStream inputStream = new BufferedInputStream(
				resource.getInputStream())) {
			ClassReader classReader = new ClassReader(inputStream);
			AnnotationMetadataReadingVisitor metadata = new AnnotationMetadataReadingVisitor(
					classLoader);
			classReader.accept(metadata, ClassReader.SKIP_DEBUG);
			return metadata;
		}
	}
	catch (Exception ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example 4
Source File: SimpleMetadataReaderFactory.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public MetadataReader getMetadataReader(String className) throws IOException {
	try {
		String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
				ClassUtils.convertClassNameToResourcePath(className) + ClassUtils.CLASS_FILE_SUFFIX;
		Resource resource = this.resourceLoader.getResource(resourcePath);
		return getMetadataReader(resource);
	}
	catch (FileNotFoundException ex) {
		// Maybe an inner class name using the dot name syntax? Need to use the dollar syntax here...
		// ClassUtils.forName has an equivalent check for resolution into Class references later on.
		int lastDotIndex = className.lastIndexOf('.');
		if (lastDotIndex != -1) {
			String innerClassName =
					className.substring(0, lastDotIndex) + '$' + className.substring(lastDotIndex + 1);
			String innerClassResourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
					ClassUtils.convertClassNameToResourcePath(innerClassName) + ClassUtils.CLASS_FILE_SUFFIX;
			Resource innerClassResource = this.resourceLoader.getResource(innerClassResourcePath);
			if (innerClassResource.exists()) {
				return getMetadataReader(innerClassResource);
			}
		}
		throw ex;
	}
}
 
Example 5
Source File: SimpleMetadataReaderFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MetadataReader getMetadataReader(String className) throws IOException {
	String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
			ClassUtils.convertClassNameToResourcePath(className) + ClassUtils.CLASS_FILE_SUFFIX;
	Resource resource = this.resourceLoader.getResource(resourcePath);
	if (!resource.exists()) {
		// Maybe an inner class name using the dot name syntax? Need to use the dollar syntax here...
		// ClassUtils.forName has an equivalent check for resolution into Class references later on.
		int lastDotIndex = className.lastIndexOf('.');
		if (lastDotIndex != -1) {
			String innerClassName =
					className.substring(0, lastDotIndex) + '$' + className.substring(lastDotIndex + 1);
			String innerClassResourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
					ClassUtils.convertClassNameToResourcePath(innerClassName) + ClassUtils.CLASS_FILE_SUFFIX;
			Resource innerClassResource = this.resourceLoader.getResource(innerClassResourcePath);
			if (innerClassResource.exists()) {
				resource = innerClassResource;
			}
		}
	}
	return getMetadataReader(resource);
}
 
Example 6
Source File: SimpleMetadataReaderFactory.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataReader getMetadataReader(String className) throws IOException {
	String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
			ClassUtils.convertClassNameToResourcePath(className) + ClassUtils.CLASS_FILE_SUFFIX;
	Resource resource = this.resourceLoader.getResource(resourcePath);
	if (!resource.exists()) {
		// Maybe an inner class name using the dot name syntax? Need to use the dollar syntax here...
		// ClassUtils.forName has an equivalent check for resolution into Class references later on.
		int lastDotIndex = className.lastIndexOf('.');
		if (lastDotIndex != -1) {
			String innerClassName =
					className.substring(0, lastDotIndex) + '$' + className.substring(lastDotIndex + 1);
			String innerClassResourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
					ClassUtils.convertClassNameToResourcePath(innerClassName) + ClassUtils.CLASS_FILE_SUFFIX;
			Resource innerClassResource = this.resourceLoader.getResource(innerClassResourcePath);
			if (innerClassResource.exists()) {
				resource = innerClassResource;
			}
		}
	}
	return getMetadataReader(resource);
}