All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.frameworkset.common.poolman.handle.XMLRowHandler Maven / Gradle / Ivy

Go to download

bboss is a j2ee framework include aop/ioc,mvc,persistent,taglib,rpc,event ,bean-xml serializable and so on.http://www.bbossgroups.com

The newest version!
package com.frameworkset.common.poolman.handle;

import com.frameworkset.common.poolman.Record;
import com.frameworkset.common.poolman.util.SQLUtil;
import com.frameworkset.orm.engine.model.SchemaType;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * 
 * 
 * 

Title: XMLRowHandler.java

* *

Description: xml行处理器

* *

Copyright: Copyright (c) 2007

* * @Date Oct 24, 2008 2:29:31 PM * @author biaoping.yin * @version 1.0 */ public class XMLRowHandler extends BaseRowHandler { /** * rowValue类型为StringBuffer */ public void handleRow(StringBuilder rowValue,Record origine) { if(meta == null) { throw new RowHandlerException("源数据对象[meta]未初始化,无法进行行处理."); } StringBuilder record = (StringBuilder)rowValue; record.append(" \r\n"); try { for (int i = 0; i < meta.getColumnCounts(); i++) { String columnName = meta.getColumnLabelUpperByIndex(i ); int sqltype = meta.getColumnTypeByIndex(i ); String typename = meta.getColumnTypeNameByIndex(i); String object = origine.getString(columnName); SchemaType schemaType = SQLUtil.getSchemaType(dbname, sqltype,typename); record.append(buildNode("column", columnName, schemaType.getName(), schemaType.getJavaType(), object, "\r\n")); // record.append("\r\n\t\t\r\n") // .append("\t\t\t\r\n").append( // "\t\t"); } } catch(Exception e) { throw new RowHandlerException(e); } record.append(" \r\n"); } /** * 返回xml串的根节点名称 * 缺省为records,用户可以扩展这个方法 * @return */ public String getRootName() { return "records"; } /** * 返回xml的编码字符集 * 缺省为UTF-8,用户可以扩展这个方法 * @return */ public String getEncoding() { return "UTF-8"; } /** * 返回xml语法的版本号 * 缺省为1.0,用户可以扩展这个方法 * @return */ public String getVersion() { return "1.0"; } public static String buildNode(String columnNodeName, String columnName, String columnType, String columnJavaType, String value, String split) { Map attributes = new HashMap(); attributes.put("name", columnName); attributes.put("type", columnType); attributes.put("javatype", columnJavaType); return buildNode(columnNodeName, attributes, value, split); // StringBuilder record = new StringBuilder(); // record.append("\t\t<").append(columnNodeName).append(" name=\"") // .append(columnName) // .append("\" type=\"").append(columnType) // .append("\" javatype=\"") // .append(columnJavaType) // .append("\"") // .append(">\r\n") // .append("\t\t\t\r\n") // .append("\t\t") // .append(split); // return record.toString(); } public static String buildNode(String columnNodeName, Map attributes, String value, String split) { StringBuilder record = new StringBuilder(); record.append("\t<").append(columnNodeName); if(attributes != null && attributes.size() > 0) { Set entrys = attributes.entrySet(); Iterator it = entrys.iterator(); while(it.hasNext()) { Map.Entry e = (Map.Entry)it.next(); String aname = e.getKey().toString(); record.append(" ").append(aname).append("=\"") .append(e.getValue()) .append("\""); // .append("\" type=\"").append(columnType) } } record.append(">"); if(value != null) { record.append("\r\n\t \r\n") .append("\t") .append(split); } else { record.append("") .append(split); } return record.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy