commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Tripodi <simonetrip...@apache.org>
Subject Re: [digester] why addCallMethod doesn't work?
Date Fri, 01 Apr 2011 13:05:08 GMT
Holy cow, Kurt!!! :D
can you be more precise and highlight which is the part that doesn't
work? For what I see, there's one assCallParam() set in your Digetser
and that's for the Handler
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



2011/4/1 Kurt Xu <fxbird1978@163.com>:
>
> Hi all digester users & developers:
>
>   Today I use addCallMethod but it doesn't work as before.
>
> the xml is below:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <Project name="project1">
>    <Functionality description="add comment" url="">
>        <Action class="com.mygame.action.UserAction" method="entry"/>
>        <BasicInfo kpiCategoryId="K01002" contentType="thread"
> statisticsType="处理日"/>
>        <Class name="com.mygame.bo.UserBOImpl" method="entry">
>            <TextTable type="insert" name="MOCO_CODICMT">
>                <Handler
> class="com.mytest.siamon.util.DefaultSiamonHandler"/>
>                <Main>
>                    <Constant column="DeviceType" value="pc"/>
>                    <Mutable property="cmtno" argidx="0"
> column="PrimaryKey1"/>
>                </Main>
>                <Sub>
>                    <Mutable property="writeid" argidx="0"
> column="WriterId"/>
>                    <Mutable property="contents" argidx="0"
> column="Content"/>
>                    <Constant column="TestType" value="test"/>
>                </Sub>
>            </TextTable>
>        </Class>
>    </Functionality>
> </Project>
>
>   there's a code about Mutable and Constant that they both can show up under
> Main or Sub, the former represents a mutable property and the latter
> represents a constant property in out business logic.  But the question is
> when TextTable element shows up, I want to set TableMap(XXXTable related
> class, pojo)'s type as "txt" through addCallMethod. I research on official
> sample but it is not right in my code, it looks just the same as the sample.
>
> related java file:
>
> 1)ClassItem.java
> package com.siamon.model.config;
>
> import java.util.ArrayList;
> import java.util.List;
>
> public class ClassItem {
>
>        private String method;
>        private String name;
>    private List<TableMap> tableMapList=new ArrayList<TableMap>();
>
>    public ClassItem(String name, String method, List<TableMap> tableMapList)
> {
>        this.name = name;
>        this.method = method;
>        this.tableMapList = tableMapList;
>    }
>
>
>    public ClassItem() {
>    }
>
>    public String getMethod() {
>        return method;
>    }
>
>    public void setMethod(String method) {
>        this.method = method;
>    }
>
>    public String getName() {
>        return name;
>    }
>
>    public void setName(String name) {
>        this.name = name;
>    }
>
>
>    public void addTableMap(TableMap tm){
>        getTableMapList().add(tm);
>    }
>
>    public List<TableMap> getTableMapList() {
>        return tableMapList;
>    }
> }
>
> 2)Project.java
> package com.siamon.model;
>
> import com.siamon.model.config.Functionality;
>
> import java.util.ArrayList;
> import java.util.List;
>
> public class Project {
>    private String name;
>    private List<Functionality> functionalities=new
> ArrayList<Functionality>();
>
>    public void addFunctionality(Functionality func){
>        functionalities.add(func);
>    }
>
>    public String getName() {
>        return name;
>    }
>
>    public void setName(String name) {
>        this.name = name;
>    }
>
>    public List<Functionality> getFunctionalities() {
>        return functionalities;
>    }
>
>
> }
>
> 3)ConstantProp.java
> package com.siamon.model.config;
>
> public class ConstantProp {
>    private String column;
>    private String value;
>
>    public String getColumn() {
>        return column;
>    }
>
>    public void setColumn(String column) {
>        this.column = column;
>    }
>
>    public String getValue() {
>        return value;
>    }
>
>    public void setValue(String value) {
>        this.value = value;
>    }
>
>    @Override
>    public String toString() {
>        return "ConstantProp [ " +
>                "column='" + column + '\'' +
>                ", value='" + value + '\'' +
>                " ] ";
>    }
> }
>
> 4)MutableProp.java
> package com.siamon.model.config;
>
> public class MutableProp {
>    private String property;
>    private int argIndex;
>    private String column;
>    private String value;
>
>    public String getProperty() {
>        return property;
>    }
>
>    public void setProperty(String property) {
>        this.property = property;
>    }
>
>    public int getArgIndex() {
>        return argIndex;
>    }
>
>    public void setArgIndex(int argIndex) {
>        this.argIndex = argIndex;
>    }
>
>    public String getColumn() {
>        return column;
>    }
>
>    public void setColumn(String column) {
>        this.column = column;
>    }
>
>    public String getValue() {
>        return value;
>    }
>
>    public void setValue(String value) {
>        this.value = value;
>    }
>
>    @Override
>    public String toString() {
>        return "MutableProp [ " +
>                "property='" + property + '\'' +
>                ", argIndex=" + argIndex +
>                ", column='" + column + '\'' +
>                ", value='" + value + '\'' +
>                " ] ";
>    }
> }
>
> 5)TableMap.java
> package com.siamon.model.config;
>
> import java.util.ArrayList;
> import java.util.List;
>
> public class TableMap {
>    private String type;
>    private String handler="com.nhstcorp.siamon.util.DefaultSiamonHandler";
>    private List<ConstantProp> constantPropList=new
> ArrayList<ConstantProp>();
>    private List<MutableProp> mutablePropList=new ArrayList<MutableProp>();
>
>    public String getType() {
>        return type;
>    }
>
>    public void setType(String type) {
>        this.type = type;
>    }
>
>    public List<MutableProp> getMutablePropList() {
>        return mutablePropList;
>    }
>
>    public List<ConstantProp> getConstantPropList() {
>        return constantPropList;
>    }
>
>    public void addMutableProp(MutableProp prop){
>       getMutablePropList().add(prop);
>    }
>
>    public void addConstantProp(ConstantProp prop){
>        getConstantPropList().add(prop);
>    }
>
>    public String getHandler() {
>        return handler;
>    }
>
>    public void setHandler(String handler) {
>        this.handler = handler;
>    }
> }
>
> 6)Functionality.java
> package com.siamon.model.config;
>
> import java.util.*;
>
> public class Functionality {
>
>        private String url;
>    private String description;
>    private String actionName;
>    private String actionMethod;
>    private String kpiCategoryId;
>    private String contentType;
>    private String statisticsType;
>    private List<ClassItem> classItems=new ArrayList<ClassItem>();
>    private String projectName;
>
>    public Functionality(String projectName, String kpiCategoryId, String
> contentType, String statisticsType) {
>        this.projectName = projectName;
>        this.kpiCategoryId = kpiCategoryId;
>        this.contentType = contentType;
>        this.statisticsType = statisticsType;
>    }
>
>    public Functionality() {
>    }
>
>    public String getUrl() {
>        return url;
>    }
>
>    public void setUrl(String url) {
>        this.url = url;
>    }
>
>    public String getDescription() {
>        return description;
>    }
>
>    public void setDescription(String description) {
>        this.description = description;
>    }
>
>    public String getActionName() {
>        return actionName;
>    }
>
>    public void setActionName(String actionName) {
>        this.actionName = actionName;
>    }
>
>    public String getActionMethod() {
>        return actionMethod;
>    }
>
>    public void setActionMethod(String actionMethod) {
>        this.actionMethod = actionMethod;
>    }
>
>    public String getKpiCategoryId() {
>        return kpiCategoryId;
>    }
>
>    public void setKpiCategoryId(String kpiCategoryId) {
>        this.kpiCategoryId = kpiCategoryId;
>    }
>
>    public String getContentType() {
>        return contentType;
>    }
>
>    public void setContentType(String contentType) {
>        this.contentType = contentType;
>    }
>
>    public String getStatisticsType() {
>        return statisticsType;
>    }
>
>    public void setStatisticsType(String statisticsType) {
>        this.statisticsType = statisticsType;
>    }
>
>    public List<ClassItem> getClassItems() {
>        return classItems;
>    }
>
>    public void setClassItems(List<ClassItem> classItems) {
>        this.classItems = classItems;
>    }
>
>    public String getProjectName() {
>        return projectName;
>    }
>
>    public void setProjectName(String projectName) {
>        this.projectName = projectName;
>    }
>
>    public ClassItem findClassItem(String clazz,String method){
>        for (ClassItem ci:classItems){
>            if (ci.getName().equals(clazz) && ci.getMethod().equals(method)){
>                return ci;
>            }
>        }
>
>        return null;
>    }
>
>    public void addClassItem(ClassItem ci){
>        getClassItems().add(ci);
>    }
> }
>
>
> 7)parser method
>  private Project parseProject2(URL url) throws IOException, SAXException {
>        Digester d = new Digester();
>
>        String pathFunc = "Project/Functionality";
>        String pathClass = pathFunc + "/Class";
>
>
>        d.addObjectCreate("Project", Project.class);
>        d.addSetProperties("Project");
>
>        d.addObjectCreate(pathFunc, Functionality.class);
>        d.addSetNext(pathFunc, "addFunctionality");
>        d.addSetProperties(pathFunc);
>        d.addSetProperties(pathFunc + "/BasicInfo");
>
>        d.addObjectCreate(pathClass, ClassItem.class);
>        d.addSetNext(pathClass, "addClassItem");
>
>        String pathTextTable = pathClass + "/TextTable";
>        d.addSetProperties(pathClass);
>        d.addObjectCreate(pathTextTable, TableMap.class);
>        d.addSetNext(pathTextTable,"addTableMap");
>
>
>        setTable(d, pathClass,"TextTable","txt");
>
>        d.parse(url);
>        Project project = (Project) d.getRoot();
>
>        System.out.println();
>
>        return project;
>    }
>
>   private void setTable(Digester d, String pathClass, String tableElem,
> String type){
>        String pattern=pathClass + "/"+tableElem;
>
>        d.addObjectCreate(pattern+"/Main/Constant",ConstantProp.class);
>        d.addSetNext(pattern+"/Main/Constant", "addConstantProp");
>        d.addSetProperties(pattern+ "/Main/Constant");
>
>        d.addObjectCreate(pattern+"/Main/Mutable",MutableProp.class);
>        d.addSetNext(pattern + "/Main/Mutable", "addMutableProp");
>        d.addSetProperties(pattern+ "/Main/Mutable");
>
>        d.addObjectCreate(pattern+"/Sub/Constant",ConstantProp.class);
>        d.addSetNext(pattern+"/Sub/Constant", "addConstantProp");
>        d.addSetProperties(pattern+ "/Sub/Constant");
>
>        d.addObjectCreate(pattern+"/Sub/Mutable",MutableProp.class);
>        d.addSetNext(pattern + "/Sub/Mutable", "addMutableProp");
>        d.addSetProperties(pattern+ "/Sub/Mutable");
>
>
>        d.addSetProperties(pathClass + "/Handler", "class", "handler");
>        d.addCallMethod(pattern, "setType", 1);
>        d.addCallParam(pattern, 0, type);
>
>        d.addSetProperties(pattern + "/Handler", "class", "handler");
>    }
>
>   that's all source, the issue is the method setTable can't setType for a
> TableMap class successfully. It looks very normal, nothing seem wrong,but
> just doesn't work. I also attach the source to the email, don't know if it's
> allowed.
>
>   Thanks a lot
> Kurt
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message