openamf/src/java/org/openamf/translator Translator.java,NONE,1.1 TranslationException.java,NONE,1.1 BeanListToRecordSet.java,NONE,1.1

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

Added Files:
	Translator.java TranslationException.java 
	BeanListToRecordSet.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

--- NEW FILE: Translator.java ---
package org.openamf.translator;

import org.openamf.config.TranslatorConfig;

public interface Translator {
	
	public Object translate(Object value, TranslatorConfig config) throws TranslationException;

}

--- NEW FILE: TranslationException.java ---
package org.openamf.translator;

public class TranslationException extends Exception {
	
	public TranslationException(String message) {
		super(message);
	}

	public TranslationException(Throwable cause) {
		super(cause);
	}

	public TranslationException(String message, Throwable cause) {
		super(message, cause);
	}
	
}

--- NEW FILE: BeanListToRecordSet.java ---
package org.openamf.translator;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openamf.config.TranslatorConfig;
import org.openamf.recordset.ASRecordSet;

public class BeanListToRecordSet implements Translator {

	private static Log log = LogFactory.getLog(BeanListToRecordSet.class);

	public Object translate(Object value, TranslatorConfig config)
		throws TranslationException {
		
		log.debug("Translating BeanListToRecordSet");
		
		ASRecordSet recordSet = null;
		if (value instanceof List) {
			String[] ignoreProperties = config.getParameterValues("ignore");
			recordSet = new ASRecordSet();	
			try {	
				recordSet.populate((List)value, ignoreProperties);
			} catch (Exception e) {
				throw new TranslationException(e);
			}
		} else {
			throw new TranslationException("value is not an instance of List");
		}
	
		return recordSet;	
	}

}




-------------------------------------------------------
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.