XML建模

一.XML建模

1.概念:将XML配置文件中的元素、属性、文本信息转化成对象的一个过程。

2.关系:从里到外

3.思路:

3.1 分析需要被建模的文件中有哪几个对象

3.2 每个对象拥有的行为以及属性

3.3 根据XML中元素节点 情况定义 ConfigModel , ActionModel , ForwardModel 对象模型。 (定义对象从里到外)

   config节点下有多个子action节点,无节点属性
   action节点下有多个子forward节点,有节点属性
   forward下无子节点,有节点属性

3.4 通过32种的设计模式中的工厂模式,解析XML生产出指定对象(好处:提高代码复用性)

4.步骤:

4.1 以面向对象的编程思想,描述xml资源文件

4.2 将xml文件中内容封装进model实体对象

例:(  action标签里的path和forward标签里的name相当于ID)

         ForwardModel类

package com.lj.model;

import java.io.Serializable;

public class ForwardModel implements Serializable{
    private String name;
    private String path;
    private boolean redirect;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPath() {
        return path;
    }
    public void setPath(String path) {
        this.path = path;
    }
    public boolean isRedirect() {
        return redirect;
    }
    public void setRedirect(boolean redirect) {
        this.redirect = redirect;
    }
    @Override
    public String toString() {
        return "ForwardModel [name=" + name + ", path=" + path + ", redirect=" + redirect + "]";
    }
    public ForwardModel() {
        super();
        // TODO Auto-generated constructor stub
    }
    public ForwardModel(String name, String path, boolean redirect) {
        super();
        this.name = name;
        this.path = path;
        this.redirect = redirect;
    }
}

ActionModel类

package com.lj.model;
 
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
 
public class ActionModel implements Serializable{
    private String type;
    private String path;
    private Map<String, ForwardModel> forwards=new HashMap<String, ForwardModel>();
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getPath() {
        return path;
    }
    public void setPath(String path) {
        this.path = path;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值