org.beangle.struts2.helper.PopulateHelper Maven / Gradle / Ivy
/*
* Beangle, Agile Development Scaffold and Toolkits.
*
* Copyright © 2005, The Beangle Software.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package org.beangle.struts2.helper;
import java.util.Map;
import org.beangle.commons.entity.metadata.EntityType;
import org.beangle.commons.entity.metadata.Model;
import org.beangle.commons.entity.util.EntityUtils;
public class PopulateHelper {
/**
* 将request中的参数设置到clazz对应的bean。
*
* @param clazz
* @param name
*/
@SuppressWarnings("unchecked")
public static T populate(Class clazz, String name) {
EntityType type = null;
if (clazz.isInterface()) {
type = Model.getType(clazz.getName());
} else {
type = Model.getType(clazz);
}
return (T) populate(type.newInstance(), type.getEntityName(), name);
}
@SuppressWarnings("unchecked")
public static T populate(Class clazz) {
EntityType type = null;
if (clazz.isInterface()) {
type = Model.getType(clazz.getName());
} else {
type = Model.getType(clazz);
}
String entityName = type.getEntityName();
return (T) populate(type.newInstance(), entityName, EntityUtils.getCommandName(entityName));
}
public static Object populate(String entityName) {
EntityType type = Model.getType(entityName);
return populate(type.newInstance(), type.getEntityName(), EntityUtils.getCommandName(entityName));
}
public static Object populate(String entityName, String name) {
EntityType type = Model.getType(entityName);
Map params = Params.sub(name);
return Model.getPopulator().populate(type.newInstance(), type, params);
}
public static Object populate(Object obj, String entityName, String name) {
Map params = Params.sub(name);
return Model.getPopulator().populate(obj, Model.getType(entityName), params);
}
}