add file type

This commit is contained in:
fanfuxiaoran 2014-04-22 15:46:12 +08:00
parent afc30d0052
commit 5963e394c8
9 changed files with 147 additions and 81 deletions

View File

@ -7,6 +7,7 @@ import org.bench4q.master.domain.service.PluginService;
import org.bench4q.master.domain.service.UserService;
import org.bench4q.master.exception.Bench4QException;
import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.plugin.BehaviorInfoModel;
import org.bench4q.share.models.master.plugin.PluginResponseModel;
import org.bench4q.share.models.master.plugin.PluginUIModel;
@ -18,7 +19,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/plugin")
public class PluginController extends BaseController {
@ -107,6 +107,8 @@ public class PluginController extends BaseController {
pluginResponseModel.setBehaviorInfoModels(behaviorInfoModels);
}
logger.info(MarshalHelper.marshal(PluginResponseModel.class,
pluginResponseModel));
return pluginResponseModel;
} catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e));

View File

@ -0,0 +1,21 @@
package org.bench4q.master.domain.entity.plugin;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "fieldType")
public class FileType extends ParamType {
private String text;
@Column(name = "text")
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

View File

@ -12,6 +12,7 @@ import org.bench4q.master.domain.entity.plugin.CheckBoxType;
import org.bench4q.master.domain.entity.plugin.ChoiceType;
import org.bench4q.master.domain.entity.plugin.ComboType;
import org.bench4q.master.domain.entity.plugin.FieldType;
import org.bench4q.master.domain.entity.plugin.FileType;
import org.bench4q.master.domain.entity.plugin.NFieldType;
import org.bench4q.master.domain.entity.plugin.ParamInfo;
import org.bench4q.master.domain.entity.plugin.ParamType;
@ -25,6 +26,7 @@ import org.bench4q.share.models.master.plugin.CheckBoxModel;
import org.bench4q.share.models.master.plugin.ChoiceModel;
import org.bench4q.share.models.master.plugin.ComboModel;
import org.bench4q.share.models.master.plugin.FieldModel;
import org.bench4q.share.models.master.plugin.FileModel;
import org.bench4q.share.models.master.plugin.NFieldModel;
import org.bench4q.share.models.master.plugin.ParamInfoModel;
import org.bench4q.share.models.master.plugin.ParamTypeModel;
@ -59,12 +61,12 @@ public class PluginDomainFactory {
ParamInfoModel paramInfoModel = new ParamInfoModel();
paramInfoModel.setLable(paramInfo.getLable());
paramInfoModel.setName(paramInfo.getName());
paramInfoModel.setType(paramInfo.getParamType().getType());
try {
ParamTypeModelFactory paramTypeModelFactory = new ParamTypeModelFactory();
paramInfoModel.setParamTypeModel(paramTypeModelFactory
.createParamTypeClassAndContnet(paramInfo));
.createParamModel(paramInfo));
} catch (JAXBException e) {
// TODO Auto-generated catch block
logger.info(ExceptionLog.getStackTrace(e));
@ -110,32 +112,35 @@ public class PluginDomainFactory {
@Component
class ParamTypeModelFactory {
public ParamTypeModel createParamTypeClassAndContnet(ParamInfo paramInfo)
public ParamTypeModel createParamModel(ParamInfo paramInfo)
throws JAXBException {
ParamType paramType = paramInfo.getParamType();
ParamTypeModel paramTypeModel = null;
if (paramType instanceof FieldType) {
return createFieldModel((FieldType) paramType);
paramTypeModel = createFieldModel((FieldType) paramType);
}
else if (paramType instanceof NFieldType) {
return createNFieldModel((NFieldType) paramType);
paramTypeModel = createNFieldModel((NFieldType) paramType);
} else if (paramType instanceof TableType) {
return createTableModel((TableType) paramType);
paramTypeModel = createTableModel((TableType) paramType);
} else if (paramType instanceof CheckBoxType) {
return createCheckBoxModel((CheckBoxType) paramType);
paramTypeModel = createCheckBoxModel((CheckBoxType) paramType);
} else if (paramType instanceof ComboType) {
return createComboModel((ComboType) paramType);
paramTypeModel = createComboModel((ComboType) paramType);
} else if (paramType instanceof RadioButtonType) {
return createRadioButton((RadioButtonType) paramType);
} else
return null;
paramTypeModel = createRadioButton((RadioButtonType) paramType);
} else if (paramType instanceof FileType) {
paramTypeModel = createFileModel((FileType) paramType);
}
paramTypeModel.setType(paramType.getType());
return paramTypeModel;
}
private FieldModel createFieldModel(FieldType fieldType) {
FieldModel fieldModel = new FieldModel();
fieldModel.setSize(fieldType.getSize());
fieldModel.setText(fieldType.getText());
return fieldModel;
}
@ -177,6 +182,13 @@ class ParamTypeModelFactory {
}
private FileModel createFileModel(FileType fileType) {
FileModel fileModel = new FileModel();
fileModel.setText(fileType.getText());
return fileModel;
}
private List<ChoiceModel> createChoiceModels(List<ChoiceType> choiceTypes) {
List<ChoiceModel> choiceModels = new LinkedList<ChoiceModel>();
for (ChoiceType choiceType : choiceTypes) {

View File

@ -6,6 +6,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.entity.plugin.BehaviorInfo;
import org.bench4q.master.domain.entity.plugin.BehaviorParamInfo;
@ -13,6 +14,7 @@ import org.bench4q.master.domain.entity.plugin.CheckBoxType;
import org.bench4q.master.domain.entity.plugin.ChoiceType;
import org.bench4q.master.domain.entity.plugin.ComboType;
import org.bench4q.master.domain.entity.plugin.FieldType;
import org.bench4q.master.domain.entity.plugin.FileType;
import org.bench4q.master.domain.entity.plugin.NFieldType;
import org.bench4q.master.domain.entity.plugin.ParamType;
import org.bench4q.master.domain.entity.plugin.PluginInfo;
@ -54,7 +56,6 @@ public class PluginEntityFactory {
return behaviorInfos;
}
private BehaviorInfo createBehaviorInfoWithOutId(Element element,
PluginUI pluginUI) {
BehaviorInfo behaviorInfo = new BehaviorInfo();
@ -68,7 +69,7 @@ public class PluginEntityFactory {
return behaviorInfo;
}
//combine this code with the pluginParamInfo
// combine this code with the pluginParamInfo
private Set<BehaviorParamInfo> createBehaviorParamInfos(
List<Element> elements, BehaviorInfo behaviorInfo) {
@ -84,8 +85,6 @@ public class PluginEntityFactory {
return paramInfos;
}
private Document getDocument(String pluginUI) {
try {
return DocumentHelper.parseText(pluginUI);
@ -121,13 +120,14 @@ public class PluginEntityFactory {
paramInfos = null;
return paramInfos;
}
private BehaviorParamInfo createBehaviorParamInfo(Element element,
BehaviorInfo behaviorInfo) {
if (XmlParseHelper.getAttribute(element, "name") == null)
return null;
BehaviorParamInfo behaviorParamInfo = new BehaviorParamInfo();
behaviorParamInfo.setLable(XmlParseHelper
.getAttribute(element, "lable"));
.getAttribute(element, "label"));
behaviorParamInfo.setName(XmlParseHelper.getAttribute(element, "name"));
ParamTypeFactory paramTypeFactory = new ParamTypeFactory();
behaviorParamInfo.setParamType(paramTypeFactory
@ -137,6 +137,7 @@ public class PluginEntityFactory {
System.out.println(behaviorParamInfo.getName());
return behaviorParamInfo;
}
private PluginParamInfo createPluginParamInfoWithOutId(Element element,
PluginInfo pluginInfo) {
if (XmlParseHelper.getAttribute(element, "name") == null)
@ -158,7 +159,7 @@ class ParamTypeFactory {
String type = element.getName();
switch (type) {
case "field":
return createFileType(element);
return createFieldType(element);
case "nfield":
return createNFieldType(element);
case "table":
@ -169,12 +170,14 @@ class ParamTypeFactory {
return createCheckBoxType(element);
case "combo":
return createComboType(element);
case "file":
return createFileType(element);
}
return null;
}
private FieldType createFileType(Element element) {
private FieldType createFieldType(Element element) {
FieldType fieldType = new FieldType();
fieldType.setType("field");
fieldType.setSize(Integer.parseInt(XmlParseHelper.getAttribute(element,
@ -244,6 +247,15 @@ class ParamTypeFactory {
return choiceType;
}
private FileType createFileType(Element element) {
FileType fileType = new FileType();
fileType.setText(XmlParseHelper.getAttribute(element, "text"));
fileType.setType("file");
return fileType;
}
}
class XmlParseHelper {

View File

@ -42,5 +42,6 @@
<mapping class="org.bench4q.master.domain.entity.plugin.RadioButtonType" />
<mapping class="org.bench4q.master.domain.entity.plugin.ComboType" />
<mapping class="org.bench4q.master.domain.entity.plugin.ChoiceType" />
<mapping class="org.bench4q.master.domain.entity.plugin.FileType" />
</session-factory>
</hibernate-configuration>

View File

@ -175,10 +175,6 @@ public class PluginControllerTest extends TestBase {
pluginResponseModel = (PluginResponseModel) MarshalHelper
.unmarshal(PluginResponseModel.class,
httpResponse.getContent());
System.out
.println(pluginResponseModel.getPluginUIModels().get(0)
.getPluginInfoModel().getParamInfoModels().get(0)
.getType());
} catch (Exception e) {
logger.info(ExceptionLog.getStackTrace(e));
}

View File

@ -0,0 +1,19 @@
package org.bench4q.share.models.master.plugin;
import com.sun.xml.internal.txw2.annotation.XmlElement;
@XmlElement
public class FileModel extends ParamTypeModel {
private String text;
@XmlElement
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

View File

@ -9,7 +9,6 @@ public class ParamInfoModel {
private String name;
private String lable;
private String type;
private ParamTypeModel paramTypeModel;
@XmlElement
@ -30,21 +29,13 @@ public class ParamInfoModel {
this.lable = lable;
}
@XmlElement
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@XmlElements({ @XmlElement(name = "field", type = FieldModel.class),
@XmlElement(name = "table", type = TableModel.class),
@XmlElement(name = "checkbox", type = CheckBoxModel.class),
@XmlElement(name = "nfield", type = NFieldModel.class),
@XmlElement(name = "combo", type = ComboModel.class),
@XmlElement(name = "radio", type = RadioButtonModel.class) })
@XmlElement(name = "radio", type = RadioButtonModel.class),
@XmlElement(name = "file", type = FileModel.class) })
public ParamTypeModel getParamTypeModel() {
return paramTypeModel;
}

View File

@ -2,8 +2,20 @@ package org.bench4q.share.models.master.plugin;
import javax.xml.bind.annotation.XmlRootElement;
import com.sun.xml.internal.txw2.annotation.XmlElement;
@XmlRootElement
public class ParamTypeModel {
private String type;
@XmlElement
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}