下面列出了怎么用org.springframework.core.NestedIOException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Factory method to obtain a {@link SourceClass} from a class name.
*/
SourceClass asSourceClass(@Nullable String className) throws IOException {
if (className == null || className.startsWith("java.lang.annotation.")) {
return this.objectSourceClass;
}
if (className.startsWith("java")) {
// Never use ASM for core java types
try {
return new SourceClass(ClassUtils.forName(className,
this.resourceLoader.getClassLoader()));
}
catch (ClassNotFoundException ex) {
throw new NestedIOException(
"Failed to load class [" + className + "]", ex);
}
}
return new SourceClass(
this.metadataReaderFactory.getMetadataReader(className));
}
private SourceClass getRelated(String className) throws IOException {
if (this.source instanceof Class) {
try {
Class<?> clazz = ClassUtils.forName(className, ((Class<?>) this.source).getClassLoader());
return asSourceClass(clazz);
}
catch (ClassNotFoundException ex) {
// Ignore -> fall back to ASM next, except for core java types.
if (className.startsWith("java")) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
}
return new SourceClass(metadataReaderFactory.getMetadataReader(className));
}
}
return asSourceClass(className);
}
/**
* Factory method to obtain a {@link SourceClass} from a class name.
*/
SourceClass asSourceClass(@Nullable String className) throws IOException {
if (className == null) {
return new SourceClass(Object.class);
}
if (className.startsWith("java")) {
// Never use ASM for core java types
try {
return new SourceClass(ClassUtils.forName(className, this.resourceLoader.getClassLoader()));
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
}
}
return new SourceClass(this.metadataReaderFactory.getMetadataReader(className));
}
private SourceClass getRelated(String className) throws IOException {
if (this.source instanceof Class) {
try {
Class<?> clazz = ClassUtils.forName(className, ((Class<?>) this.source).getClassLoader());
return asSourceClass(clazz);
}
catch (ClassNotFoundException ex) {
// Ignore -> fall back to ASM next, except for core java types.
if (className.startsWith("java")) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
}
return new SourceClass(metadataReaderFactory.getMetadataReader(className));
}
}
return asSourceClass(className);
}
private SourceClass getRelated(String className) throws IOException {
if (this.source instanceof Class) {
try {
Class<?> clazz = ((Class<?>) this.source).getClassLoader().loadClass(className);
return asSourceClass(clazz);
}
catch (ClassNotFoundException ex) {
// Ignore -> fall back to ASM next, except for core java types.
if (className.startsWith("java")) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
}
return new SourceClass(metadataReaderFactory.getMetadataReader(className));
}
}
return asSourceClass(className);
}
private SourceClass getRelated(String className) throws IOException {
if (this.source instanceof Class<?>) {
try {
Class<?> clazz = resourceLoader.getClassLoader().loadClass(className);
return asSourceClass(clazz);
}
catch (ClassNotFoundException ex) {
// Ignore -> fall back to ASM next, except for core java types.
if (className.startsWith("java")) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
}
return new SourceClass(metadataReaderFactory.getMetadataReader(className));
}
}
return asSourceClass(className);
}
/**
* TODO 刷新
*
* @param inputStream
* @param resource
* @param configuration
* @throws NestedIOException
*/
public static void refresh(java.io.InputStream inputStream,
String resource, Configuration configuration)
throws NestedIOException {
try {
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(
inputStream, configuration, resource,
configuration.getSqlFragments());
xmlMapperBuilder.parse1();
} catch (Exception e) {
throw new NestedIOException("Failed to parse mapping resource: '"
+ resource + "'", e);
} finally {
ErrorContext.instance().reset();
}
}
/**
* Read from the supplied {@code InputStream} and deserialize the contents
* into an object.
* @see ObjectInputStream#readObject()
*/
@Override
@SuppressWarnings("resource")
public Object deserialize(InputStream inputStream) throws IOException {
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader);
try {
return objectInputStream.readObject();
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to deserialize object type", ex);
}
}
private static ClassReader getClassReader(Resource resource) throws IOException {
try (InputStream is = new BufferedInputStream(resource.getInputStream())) {
try {
return new ClassReader(is);
}
catch (IllegalArgumentException ex) {
throw new NestedIOException("ASM ClassReader failed to parse class file - " +
"probably due to a new Java class file version that isn't supported yet: " + resource, ex);
}
}
}
/**
* This implementation builds a URI based on the URL returned
* by {@link #getURL()}.
*/
@Override
public URI getURI() throws IOException {
URL url = getURL();
try {
return ResourceUtils.toURI(url);
}
catch (URISyntaxException ex) {
throw new NestedIOException("Invalid URI [" + url + "]", ex);
}
}
@Override
public URL getURL() throws IOException {
try {
return VfsUtils.getURL(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URL for file " + this.resource, ex);
}
}
@Override
public URI getURI() throws IOException {
try {
return VfsUtils.getURI(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URI for " + this.resource, ex);
}
}
/**
* Read from the supplied {@code InputStream} and deserialize the contents
* into an object.
* @see ObjectInputStream#readObject()
*/
@Override
@SuppressWarnings("resource")
public Object deserialize(InputStream inputStream) throws IOException {
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader);
try {
return objectInputStream.readObject();
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to deserialize object type", ex);
}
}
/**
* This implementation builds a URI based on the URL returned
* by {@link #getURL()}.
*/
@Override
public URI getURI() throws IOException {
URL url = getURL();
try {
return ResourceUtils.toURI(url);
}
catch (URISyntaxException ex) {
throw new NestedIOException("Invalid URI [" + url + "]", ex);
}
}
@Override
public URL getURL() throws IOException {
try {
return VfsUtils.getURL(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URL for file " + this.resource, ex);
}
}
@Override
public URI getURI() throws IOException {
try {
return VfsUtils.getURI(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URI for " + this.resource, ex);
}
}
private static Object deserialize(InputStream inputStream) throws IOException {
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, BeanUtils.class.getClassLoader());
try {
return objectInputStream.readObject();
}
catch (ClassNotFoundException ex) {
logger.error("Failed to deserialize object type", ex);
throw new NestedIOException("Failed to deserialize object type", ex);
}
}
/**
* Factory method to obtain a {@link SourceClass} from a class name.
*/
SourceClass asSourceClass(String className) throws IOException {
if (className.startsWith("java")) {
// Never use ASM for core java types
try {
return new SourceClass(this.resourceLoader.getClassLoader().loadClass(className));
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
}
}
return new SourceClass(this.metadataReaderFactory.getMetadataReader(className));
}
/**
* Read from the supplied {@code InputStream} and deserialize the contents
* into an object.
* @see ObjectInputStream#readObject()
*/
@Override
@SuppressWarnings("resource")
public Object deserialize(InputStream inputStream) throws IOException {
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader);
try {
return objectInputStream.readObject();
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to deserialize object type", ex);
}
}
/**
* This implementation builds a URI based on the URL returned
* by {@link #getURL()}.
*/
@Override
public URI getURI() throws IOException {
URL url = getURL();
try {
return ResourceUtils.toURI(url);
}
catch (URISyntaxException ex) {
throw new NestedIOException("Invalid URI [" + url + "]", ex);
}
}
@Override
public URL getURL() throws IOException {
try {
return VfsUtils.getURL(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URL for file " + this.resource, ex);
}
}
@Override
public URI getURI() throws IOException {
try {
return VfsUtils.getURI(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URI for " + this.resource, ex);
}
}
/**
* Factory method to obtain a {@link SourceClass} from a class name.
*/
public SourceClass asSourceClass(String className) throws IOException {
if (className.startsWith("java")) {
// Never use ASM for core java types
try {
return new SourceClass(this.resourceLoader.getClassLoader().loadClass(className));
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to load class [" + className + "]", ex);
}
}
return new SourceClass(this.metadataReaderFactory.getMetadataReader(className));
}
/**
* Read from the supplied {@code InputStream} and deserialize the contents
* into an object.
* @see ObjectInputStream#readObject()
*/
@Override
@SuppressWarnings("resource")
public Object deserialize(InputStream inputStream) throws IOException {
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader);
try {
return objectInputStream.readObject();
}
catch (ClassNotFoundException ex) {
throw new NestedIOException("Failed to deserialize object type", ex);
}
}
/**
* This implementation builds a URI based on the URL returned
* by {@link #getURL()}.
*/
@Override
public URI getURI() throws IOException {
URL url = getURL();
try {
return ResourceUtils.toURI(url);
}
catch (URISyntaxException ex) {
throw new NestedIOException("Invalid URI [" + url + "]", ex);
}
}
@Override
public URL getURL() throws IOException {
try {
return VfsUtils.getURL(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URL for file " + this.resource, ex);
}
}
@Override
public URI getURI() throws IOException {
try {
return VfsUtils.getURI(this.resource);
}
catch (Exception ex) {
throw new NestedIOException("Failed to obtain URI for " + this.resource, ex);
}
}
public void reloadXML() throws Exception {
SqlSessionFactory factory = context.getBean(SqlSessionFactory.class);
Configuration configuration = factory.getConfiguration();
// 移除加载项
removeConfig(configuration);
// 重新扫描加载
for (String basePackage : basePackages) {
Resource[] resources = getResource(basePackage, XML_RESOURCE_PATTERN);
if (resources != null) {
for (int i = 0; i < resources.length; i++) {
if (resources[i] == null) {
continue;
}
try {
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resources[i].getInputStream(),
configuration, resources[i].toString(), configuration.getSqlFragments());
xmlMapperBuilder.parse();
} catch (Exception e) {
throw new NestedIOException("Failed to parse mapping resource: '" + resources[i] + "'", e);
} finally {
ErrorContext.instance().reset();
}
}
}
}
}
public void init() throws Exception {
MqlMapConfigParser configParser = new MqlMapConfigParser();
for (Resource configLocation : configLocations) {
InputStream is = configLocation.getInputStream();
try {
configParser.parse(is);
logger.info("Mql configuration parse resource file. File name is " + configLocation.getFilename());
} catch (RuntimeException ex) {
throw new NestedIOException("Failed to parse config configuration. File name is " + configLocation.getFilename(), ex.getCause());
}
}
configParser.validateMapping();
this.configParser = configParser;
logger.info("Mongodb orm framework has ready.");
}
/**
* Begins parsing from the provided Reader.
*/
public void parse(Reader reader) throws NestedIOException {
try {
Document doc = createDocument(reader);
parse(doc.getLastChild());
} catch (Exception e) {
throw new NestedIOException("Error parsing XML. Cause: " + e, e);
}
}