xmlbeanreaderimpl.java

来自「一个关于tlms的一个小程序 看看能否帮助到别人」· Java 代码 · 共 58 行

JAVA
58
字号
/**
 * =============================================
 * Copyright 2005 TransFar
 *
 * Change Revision
 * --------------------------------
 *   Date        Author      Remarks
 *   2006-3-10     YHuang     Create class com.szmx.component.xml.rw.impl.XmlBeanReaderImpl
 * =============================================
 */
package com.szmx.component.xml.rw.impl;

import com.szmx.component.xml.rw.XmlBeanReader;
import com.szmx.component.xml.rw.AbstractXmlBean;
import com.szmx.component.xml.rw.XmlBeanException;
import com.wutka.jox.JOXBeanInputStream;

import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <TODO: Write a short description on the purpose of the program>
 *
 * @author YHuang
 * @version 1.0
 * @class com.szmx.component.xml.rw.impl.XmlBeanReaderImpl
 * @since 2006-3-10
 */
public class XmlBeanReaderImpl implements XmlBeanReader {
    private static Log log = LogFactory.getLog(XmlBeanReader.class);

    public AbstractXmlBean parseXmlFile(Class clazz, String xmlPath) throws XmlBeanException {
        FileInputStream in;
        try {
            in = new FileInputStream(xmlPath);
            return parseXmlFile(clazz,in);
        } catch (FileNotFoundException e) {
            log.error("file not found " + e.getMessage());
            throw new XmlBeanException("file not found " + e.getMessage());
        }
    }

    public AbstractXmlBean parseXmlFile(Class clazz, InputStream inputStream) throws XmlBeanException {
        try {
            JOXBeanInputStream joxIn = new JOXBeanInputStream(inputStream);
            return (AbstractXmlBean) joxIn.readObject(clazz);
        } catch (IOException e) {
            log.error("can't parse XML " + e.getMessage());
            throw new XmlBeanException("can't parse XML " + e.getMessage());
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?