⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlutilities.java

📁 本程序是有IBM开发的一个基于数据表格的组件,里面有相关的例子和DOC,本站资料仅为大家学习之用
💻 JAVA
字号:

package com.ibm.j2x.util;

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

import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.InputSource;

/**
 * The XMLUtilities provides helper methods for dealing with the Castor XML framework.
 * @author MAbernethy
 *
 */
public class XMLUtilities
{
	/**
	 * Returns an Object from the specified xmlFileName, using the Castor XML
	 * parsing framework.
	 * @param xmlFileName the XML file containing the XML information
	 * @param mappingFileName the Castor mapping file used for decoding
	 * @param cls the base class to be decoded
	 * @return the Object created by the Castor XML parsing
	 */	
   public static Object decode(String xmlFileName, String mappingFileName, Class cls)
   {
	   try
	   {	
			InputStream stream = XMLUtilities.class.getClassLoader().getResourceAsStream(mappingFileName);
	
			Mapping mapping = new Mapping();
			mapping.loadMapping(new InputSource(stream));
			stream.close();
			Unmarshaller un = new Unmarshaller(cls);
			un.setMapping(mapping);
	
			InputStreamReader reader = new InputStreamReader(new FileInputStream(xmlFileName));
			Object obj = un.unmarshal(reader);
			reader.close();
			return obj;
	   }
	   catch (MappingException ex)
	   {
			ex.printStackTrace();
	   }
	   catch (MarshalException ex)
	   {
			ex.printStackTrace();
	   }
	   catch (ValidationException ex)
	   {
			ex.printStackTrace();
	   }
	   catch (IOException ex)
	   {
			ex.printStackTrace();
	   }
	   return null;
   }

}

⌨️ 快捷键说明

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