📄 map2dynabeanfactory.java
字号:
/*
* Created on 30/07/2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package ar.com.koalas.providers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.beanutils.BasicDynaBean;
import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
/**
* @author namorrortu
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Map2DynaBeanFactory implements BeanFactory {
public Object create(Object oldRow) {
Map map = (Map) oldRow;
try {
DynaBean db = new BasicDynaClass(BasicDynaClass.class.getName(), BasicDynaBean.class, this.getProperties( map ) ).newInstance();
this.populate(db, map);
return db;
} catch (IllegalAccessException e) {
// XXX Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// XXX Auto-generated catch block
e.printStackTrace();
}
return null;
}
private void populate(DynaBean db, Map map) {
Iterator it = map.entrySet().iterator();
while( it.hasNext() ){
Map.Entry current = (Entry) it.next();
db.set( (String) current.getKey(), current.getValue() );
}
}
private DynaProperty[] getProperties(Map map) {
Collection dynaProperties = new ArrayList();
Iterator properties = map.entrySet().iterator();
while( properties.hasNext() ){
Map.Entry current = (Entry) properties.next();
dynaProperties.add( this.getProperty( current.getKey(), current.getValue() ) );
}
return (DynaProperty[]) dynaProperties.toArray( new DynaProperty[0] );
}
private DynaProperty getProperty(Object key, Object value) {
return new DynaProperty(key.toString(), value.getClass() );
}
private class MapDynaBean extends BasicDynaBean {
public MapDynaBean() {
super( new BasicDynaClass() );
}
}
// private class MapDynaClass extends BasicDynaClass{
// private Map map;
// private Map properties;
//
// private MapDynaClass( Map map ){
// this.map = map;
// this.properties = new HashMap();
// Iterator properties = map.entrySet().iterator();
// while( properties.hasNext() ){
// Map.Entry current = (Entry) properties.next();
// this.properties.put( current.getKey(), this.getProperty( current.getKey(), current.getValue() ) );
// }
// }
//
// private DynaProperty getProperty(Object value, Object object) {
// return new DynaProperty(value.toString(), object.getClass() );
// }
//
// public DynaProperty[] getDynaProperties() {
// return (DynaProperty[]) this.properties.values().toArray( new DynaProperty[0] );
// }
//
// public DynaProperty getDynaProperty(String arg) {
// return (DynaProperty) this.properties.get( arg );
// }
//
// public Class getDynaBeanClass() {
// return MapDynaBean.class;
// }
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -