openamf/src/java/org/openamf/recordset ASRecordSet.java,1.7,1.8

[email protected]
Newsgroups gmane.comp.java.openamf.cvs
Message-ID <[email protected]>
Update of /cvsroot/openamf/openamf/src/java/org/openamf/recordset
In directory sc8-pr-cvs1:/tmp/cvs-serv11447/src/java/org/openamf/recordset

Modified Files:
	ASRecordSet.java 
Log Message:
added the ability to have the AdvancedGateway translate the service result 
based on an the xml config


The first Translator is BeanListToRecordSet

Index: ASRecordSet.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/recordset/ASRecordSet.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ASRecordSet.java	28 Apr 2003 06:03:09 -0000	1.7
--- ASRecordSet.java	30 Apr 2003 19:40:31 -0000	1.8
***************
*** 1,5 ****
--- 1,8 ----
  package org.openamf.recordset;
  
+ import java.beans.PropertyDescriptor;
  import java.io.IOException;
+ import java.lang.reflect.InvocationTargetException;
+ import java.lang.reflect.Method;
  import java.sql.ResultSet;
  import java.sql.ResultSetMetaData;
***************
*** 7,15 ****
  import java.util.ArrayList;
  import java.util.HashMap;
  
  import org.openamf.ASObject;
  
  public class ASRecordSet extends ASObject {
! 	
  	public static final String SERVICE_NAME = "OpenAMFPageableRecordSet";
  
--- 10,25 ----
  import java.util.ArrayList;
  import java.util.HashMap;
+ import java.util.Iterator;
+ import java.util.List;
  
+ import org.apache.commons.beanutils.PropertyUtils;
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
  import org.openamf.ASObject;
  
  public class ASRecordSet extends ASObject {
! 
! 	private static Log log = LogFactory.getLog(ASRecordSet.class);
! 
  	public static final String SERVICE_NAME = "OpenAMFPageableRecordSet";
  
***************
*** 22,28 ****
  	private static final String SI_COLUMN_NAMES = "columnNames";
  	private static final String SI_VERSION = "version";
! 	
  	private HashMap serverInfo;
! 	
  	public ASRecordSet() {
  		super("RecordSet");
--- 32,38 ----
  	private static final String SI_COLUMN_NAMES = "columnNames";
  	private static final String SI_VERSION = "version";
! 
  	private HashMap serverInfo;
! 
  	public ASRecordSet() {
  		super("RecordSet");
***************
*** 34,49 ****
  		setVersion(1);
  	}
! 	
  	public String getId() {
! 		return (String)serverInfo.get(SI_ID);
  	}
  	public void setId(String id) {
  		serverInfo.put(SI_ID, id);
  	}
! 	
  	public int getTotalCount() {
  		Object value = serverInfo.get(SI_TOTAL_COUNT);
  		if (value != null) {
! 			return ((Integer)value).intValue();
  		} else {
  			return 0;
--- 44,59 ----
  		setVersion(1);
  	}
! 
  	public String getId() {
! 		return (String) serverInfo.get(SI_ID);
  	}
  	public void setId(String id) {
  		serverInfo.put(SI_ID, id);
  	}
! 
  	public int getTotalCount() {
  		Object value = serverInfo.get(SI_TOTAL_COUNT);
  		if (value != null) {
! 			return ((Integer) value).intValue();
  		} else {
  			return 0;
***************
*** 53,68 ****
  		serverInfo.put(SI_TOTAL_COUNT, new Integer(totalCount));
  	}
! 	
  	public ArrayList getInitialData() {
! 		return (ArrayList)serverInfo.get(SI_INITIAL_DATA);
  	}
  	public void setInitialData(ArrayList initialData) {
  		serverInfo.put(SI_INITIAL_DATA, initialData);
  	}
! 	
  	public int getCursor() {
  		Object value = serverInfo.get(SI_CURSOR);
  		if (value != null) {
! 			return ((Integer)value).intValue();
  		} else {
  			return 0;
--- 63,78 ----
  		serverInfo.put(SI_TOTAL_COUNT, new Integer(totalCount));
  	}
! 
  	public ArrayList getInitialData() {
! 		return (ArrayList) serverInfo.get(SI_INITIAL_DATA);
  	}
  	public void setInitialData(ArrayList initialData) {
  		serverInfo.put(SI_INITIAL_DATA, initialData);
  	}
! 
  	public int getCursor() {
  		Object value = serverInfo.get(SI_CURSOR);
  		if (value != null) {
! 			return ((Integer) value).intValue();
  		} else {
  			return 0;
***************
*** 72,94 ****
  		serverInfo.put(SI_CURSOR, new Integer(cursor));
  	}
! 	
  	public String getServiceName() {
! 		return (String)serverInfo.get(SI_SERVICE_NAME);
  	}
  	public void setServiceName(String serviceName) {
  		serverInfo.put(SI_SERVICE_NAME, serviceName);
  	}
! 	
  	public String[] getColumnNames() {
! 		return (String[])serverInfo.get(SI_COLUMN_NAMES);
  	}
  	public void setColumnNames(String[] columnNames) {
  		serverInfo.put(SI_COLUMN_NAMES, columnNames);
  	}
! 	
  	public double getVersion() {
  		Object value = serverInfo.get(SI_VERSION);
  		if (value != null) {
! 			return ((Double)value).doubleValue();
  		} else {
  			return 0;
--- 82,104 ----
  		serverInfo.put(SI_CURSOR, new Integer(cursor));
  	}
! 
  	public String getServiceName() {
! 		return (String) serverInfo.get(SI_SERVICE_NAME);
  	}
  	public void setServiceName(String serviceName) {
  		serverInfo.put(SI_SERVICE_NAME, serviceName);
  	}
! 
  	public String[] getColumnNames() {
! 		return (String[]) serverInfo.get(SI_COLUMN_NAMES);
  	}
  	public void setColumnNames(String[] columnNames) {
  		serverInfo.put(SI_COLUMN_NAMES, columnNames);
  	}
! 
  	public double getVersion() {
  		Object value = serverInfo.get(SI_VERSION);
  		if (value != null) {
! 			return ((Double) value).doubleValue();
  		} else {
  			return 0;
***************
*** 98,102 ****
  		serverInfo.put(SI_VERSION, new Double(version));
  	}
! 	
  	public void populate(ResultSet rs) throws IOException {
  
--- 108,112 ----
  		serverInfo.put(SI_VERSION, new Double(version));
  	}
! 
  	public void populate(ResultSet rs) throws IOException {
  
***************
*** 105,109 ****
  			int columnCount = rsmd.getColumnCount();
  			String[] columnNames = new String[columnCount];
! 			
  			int rowIndex = 0;
  			ArrayList rows = new ArrayList();
--- 115,119 ----
  			int columnCount = rsmd.getColumnCount();
  			String[] columnNames = new String[columnCount];
! 
  			int rowIndex = 0;
  			ArrayList rows = new ArrayList();
***************
*** 113,134 ****
  				for (int column = 0; column < columnCount; column++) {
  					if (rowIndex == 1) {
! 						columnNames[column] = rsmd.getColumnName(column+1);
  					}
! 					row.add(rs.getObject(column+1));
  				}
  				if (rowIndex == 1) {
  					setColumnNames(columnNames);
! 				}			
  				rows.add(row);
  			}
  			setTotalCount(rowIndex);
  			setInitialData(rows);
! 			setColumnNames(columnNames);			
  		} catch (SQLException e) {
  			throw new IOException(e.getMessage());
  		}
! 		
  	}
! 	
  	/**
  	 * @param columnNames
--- 123,144 ----
  				for (int column = 0; column < columnCount; column++) {
  					if (rowIndex == 1) {
! 						columnNames[column] = rsmd.getColumnName(column + 1);
  					}
! 					row.add(rs.getObject(column + 1));
  				}
  				if (rowIndex == 1) {
  					setColumnNames(columnNames);
! 				}
  				rows.add(row);
  			}
  			setTotalCount(rowIndex);
  			setInitialData(rows);
! 			setColumnNames(columnNames);
  		} catch (SQLException e) {
  			throw new IOException(e.getMessage());
  		}
! 
  	}
! 
  	/**
  	 * @param columnNames
***************
*** 138,148 ****
  		setInitialData(rows);
  		setTotalCount(rows.size());
! 		setColumnNames(columnNames);			
  	}
! 	
! 	public String toString() {
  		
  		StringBuffer info = new StringBuffer();
! 				
  		addInfo(info, SI_ID, getId());
  		addInfo(info, SI_TOTAL_COUNT, getTotalCount());
--- 148,229 ----
  		setInitialData(rows);
  		setTotalCount(rows.size());
! 		setColumnNames(columnNames);
  	}
! 
! 	/**
! 	 * @param list List of JavaBeans, all bean should be of the same type
! 	 * @param ignoreProperties properties that should not be added to the RecordSet
! 	 */
! 	public void populate(List list, String[] ignoreProperties)
! 		throws
! 			IllegalArgumentException,
! 			IllegalAccessException,
! 			InvocationTargetException {
! 
! 		ArrayList names = new ArrayList();
! 
! 		Object firstBean = list.get(0);
! 		PropertyDescriptor[] properties =
! 			PropertyUtils.getPropertyDescriptors(firstBean);
! 
! 		for (int i = 0; i < properties.length; i++) {
! 			PropertyDescriptor descriptor = properties[i];
! 			if (!ignoreProperty(descriptor, ignoreProperties)) {
! 				names.add(descriptor.getDisplayName());
! 			}
! 		}
! 		String[] columnNames = new String[names.size()];
! 		columnNames = (String[]) names.toArray(columnNames);
! 		setColumnNames(columnNames);
! 
! 		ArrayList rows = new ArrayList(list.size());
! 		for (Iterator iter = list.iterator(); iter.hasNext();) {
! 			Object bean = (Object) iter.next();
! 			ArrayList row = new ArrayList();
! 			for (int i = 0; i < properties.length; i++) {
! 				PropertyDescriptor descriptor = properties[i];
! 				if (!ignoreProperty(descriptor, ignoreProperties)) {
! 					Object value = null;
! 					Method readMethod = descriptor.getReadMethod();
! 					if (readMethod == null) {
! 					} else {
! 						value = readMethod.invoke(bean, new Object[0]);
! 					}
! 					row.add(value);
! 				}
! 			}
! 			rows.add(row);
! 		}
! 		setInitialData(rows);
! 		setTotalCount(rows.size());
  		
+ 		log.debug(this);
+ 	}
+ 
+ 	private boolean ignoreProperty(
+ 		PropertyDescriptor descriptor,
+ 		String[] ignoreProperties) {
+ 
+ 		boolean ignore = false;
+ 
+ 		if (descriptor.getName().equals("class")) {
+ 			ignore = true;
+ 		} else {
+ 			for (int i = 0; i < ignoreProperties.length; i++) {
+ 				String ignoreProp = ignoreProperties[i];
+ 				if (ignoreProp.equals(descriptor.getName())) {
+ 					log.debug("Ignoring " + descriptor.getName());
+ 					ignore = true;
+ 					break;
+ 				}
+ 			}
+ 		}
+ 		return ignore;
+ 	}
+ 
+ 	public String toString() {
+ 
  		StringBuffer info = new StringBuffer();
! 
  		addInfo(info, SI_ID, getId());
  		addInfo(info, SI_TOTAL_COUNT, getTotalCount());
***************
*** 150,154 ****
  		addInfo(info, SI_SERVICE_NAME, getServiceName());
  		addInfo(info, SI_VERSION, getVersion());
! 		
  		StringBuffer names = new StringBuffer();
  		String[] columnNames = getColumnNames();
--- 231,235 ----
  		addInfo(info, SI_SERVICE_NAME, getServiceName());
  		addInfo(info, SI_VERSION, getVersion());
! 
  		StringBuffer names = new StringBuffer();
  		String[] columnNames = getColumnNames();
***************
*** 156,164 ****
  			String name = columnNames[i];
  			if (i > 0) {
! 				names.append(", ");				
  			}
  			names.append(name);
  		}
! 		
  		addInfo(info, SI_COLUMN_NAMES, names);
  		addInfo(info, SI_INITIAL_DATA, getInitialData().toString());
--- 237,245 ----
  			String name = columnNames[i];
  			if (i > 0) {
! 				names.append(", ");
  			}
  			names.append(name);
  		}
! 
  		addInfo(info, SI_COLUMN_NAMES, names);
  		addInfo(info, SI_INITIAL_DATA, getInitialData().toString());
***************
*** 170,178 ****
  		addInfo(info, name, new Integer(value));
  	}
! 	
  	private void addInfo(StringBuffer info, String name, double value) {
  		addInfo(info, name, new Double(value));
  	}
! 	
  	private void addInfo(StringBuffer info, String name, Object value) {
  		info.append(name);
--- 251,259 ----
  		addInfo(info, name, new Integer(value));
  	}
! 
  	private void addInfo(StringBuffer info, String name, double value) {
  		addInfo(info, name, new Double(value));
  	}
! 
  	private void addInfo(StringBuffer info, String name, Object value) {
  		info.append(name);




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.