📄 mbean.java
字号:
package cn.edu.buaa.ieguam.logmanage;
import cn.edu.buaa.ieguam.logmanage.Pojo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Define the bean for log management.
* @author tongxiaodong
* Creation time:Apr 23, 2007 9:16:53 PM
*/
public class MBean {
private Pojo pojo = null;
private String degree = "debug";//级别标示,用于MBeanTree的应用,初始级别为“debug”,应用级别为"work"-"sleep"
private String pojoName = null;//Pojo对象名
private String tableName = null;//数据库Table表名
private MBean father = null;//父结点
private List leftChildList = null;//左子节点集合,父子节点为多对一关系
private List rightChildList = null;//右子节点集合,父子节点为一对多关系
private int leftNum = -1;//左孩子序号
private int rightNum = -1;//右孩子序号
private List colViewList = null;//要显示的字段集合
private List colInsertList = null;//要插入的字段集合
private String pkName = null;//主键字段
private Map fkmMap = null;//外键-表实体映射图
private Map ormMap = null;//对象-关系映射图
private Map tcrmMap = null;//保存属性条件,包括Table-Column-Relation-Mapping两表间属性关系映射图(表1_属性a-表2_属性b,例如:A.name=B.user);以及属性-属性值映射关系(例如:A.name='Tom')
public MBean()
{
leftChildList = new ArrayList();
rightChildList = new ArrayList();
colViewList = new ArrayList();
colInsertList = new ArrayList();
fkmMap = new HashMap();
ormMap = new HashMap();
tcrmMap = new HashMap();
}
/**
* Getting and setting method for all properties
* @return
*/
public Pojo getPojo()
{
return this.pojo;
}
public void setPojo(Pojo pojo)
{
this.pojo = pojo;
}
public String getDegree()
{
return this.degree;
}
public void setDegree(String degree)
{
this.degree = degree;
}
public String getPojoName()
{
return this.pojoName;
}
public void setPojoName(String pojoName)
{
this.pojoName = pojoName;
}
public String getTableName()
{
return this.tableName;
}
public void setTableName(String tableName)
{
this.tableName = tableName;
}
public MBean getFather()
{
return this.father ;
}
public void setFather(MBean father)
{
this.father = father;
}
public List getLeftChildList()
{
return this.leftChildList ;
}
public void setLeftChildList(List leftChildList)
{
this.leftChildList = leftChildList;
}
public List getRightChildList()
{
return this.rightChildList ;
}
public void setRightChildList(List rightChildList)
{
this.rightChildList = rightChildList;
}
public List getColViewList()
{
return this.colViewList ;
}
public void setColViewList(List colViewList)
{
this.colViewList = colViewList;
}
public List getColInsertList()
{
return this.colInsertList;
}
public void setColInsertList(List colInsertList)
{
this.colInsertList = colInsertList;
}
public String getPkName()
{
return this.pkName ;
}
public void setPkName(String pkName)
{
this.pkName = pkName;
}
public Map getFkmMap()
{
return this.fkmMap ;
}
public void setFkmMap(Map fkmMap)
{
this.fkmMap = fkmMap ;
}
public Map getOrmMap()
{
return this.ormMap ;
}
public void setOrmMap(Map ormMap)
{
this.ormMap = ormMap;
}
public Map getTcrmMap()
{
return this.tcrmMap ;
}
public void setTcrmMap(Map tcrmMap)
{
this.tcrmMap = tcrmMap;
}
/**
* 判断是否含有左子节点
* @param null
* @return
*/
public boolean hasLeftChild()
{
boolean flag = false;
if(this.getLeftChildList() != null)
{
if(this.getLeftChildList().iterator().hasNext())
{
flag = true;
}
}
return flag;
}
/**
* 判断是否含有左子节点leftChild
* @param leftChild
* @return
*/
public MBean hasLeftChild(MBean leftChild)
{
MBean mBeanArg = null;
Iterator iter = null;
if(this.hasLeftChild())//若存在左子节点
{
iter = this.getLeftChildList().iterator();
while(iter.hasNext())
{
mBeanArg = (MBean) iter.next();
if(mBeanArg.getPojoName().equals(leftChild.getPojoName()))
{
return mBeanArg;
}
}
}
return null;
}
/**
* 判断是否有右子节点
* @param mBean
* @return
*/
public boolean hasRightChild()
{
boolean flag = false;
if(this.getRightChildList() != null)
{
if(this.getRightChildList().iterator().hasNext())
{
flag = true;
}
}
return flag;
}
/**
* 判断是否含有右子节点rightChild
* @param rightChild
* @return
*/
public MBean hasRightChild(MBean rightChild)
{
MBean mBeanArg = null;
Iterator iter = null;
if(this.hasRightChild())//若存在右子节点
{
iter = this.getRightChildList().iterator();
while(iter.hasNext())
{
mBeanArg = (MBean) iter.next();
if(mBeanArg.getPojoName().equals(rightChild.getPojoName()))
{
return mBeanArg;
}
}
}
return null;
}
/**
* 判别是否还有下一个左子节点或右子节点
* Judge whether has the next leftChild or rightChild
* @return
*/
public boolean hasNextLeft()
{
if(this.leftChildList == null)
{
return false;
}
this.leftNum++;
if(this.leftNum < this.leftChildList.size())
{
return true;
}
else
{
return false;
}
}
public boolean hasNextRight()
{
if(this.rightChildList == null)
{
return false;
}
this.rightNum++;
if(this.rightNum < this.rightChildList.size())
{
return true;
}
else
{
return false;
}
}
/**
* Return the index of next left or ritht child
* @return
*/
public int nextLeft()
{
return this.leftNum;
}
public int nextRight()
{
return this.rightNum;
}
/**
* leftNum 、rightNum自增或自减数值1
*
*/
public void increLeftNum()
{
this.leftNum++;
}
public void decreLeftNum()
{
this.leftNum--;
}
public void increRightNum()
{
this.rightNum++;
}
public void decreRightNum()
{
this.rightNum--;
}
/**
* 重置leftNum与rightNum的值
*
*/
public void refreshChildNum()
{
this.leftNum = -1;
this.rightNum =-1;
}
/**
* 去除左子节点leftChild
* @param leftChild
* @return 若存在此左子节点,删除后,则操作成功返回true;若不存在,则操作失败返回false
*/
public boolean removeLeftChild(MBean leftChild)
{
boolean flag = false;
MBean mBeanArg = null;
mBeanArg = this.hasLeftChild(leftChild);
if(mBeanArg != null)//若存在此左节点
{
this.getLeftChildList().remove(mBeanArg);
flag = true;
}
return flag;
}
/**
* 去除左子节点rightChild
* @param rightChild
* @return 若存在此右子节点,删除后,则操作成功返回true;若不存在,则操作失败返回false
*/
public boolean removeRightChild(MBean rightChild)
{
boolean flag = false;
MBean mBeanArg = null;
mBeanArg = this.hasRightChild(rightChild);
if(mBeanArg != null)//若存在此右节点
{
this.getRightChildList().remove(mBeanArg);
flag = true;
}
return flag;
}
/**
* 添加一个用于插入的属性名,pojoCol参数为用于插入的属性
*/
public void addOneColInsert(String pojoCol)
{
if(pojoCol==null || this.getColInsertList()==null)
{
return;
}
boolean flag = false;
Iterator iter = this.getColInsertList().iterator();
while(iter.hasNext())
{
if(pojoCol.equals((String)iter.next())==true)
{
flag = true;//该属性名已存在
break;
}
}
if(flag == false)//若该属性名不存在
{
this.getColInsertList().add(pojoCol);
}
}
/**
* 添加一个用于显示的字段名,pojoCol参数为表table对应的pojo的属性名
*/
public void addOneColView(String pojoCol)
{
if(pojoCol==null || this.getColViewList()==null)
{
return;
}
List colViewList = this.getColViewList();
MBean.SubBean subBean = (MBean.SubBean)this.getOrmMap().get(pojoCol);
if(subBean == null)
{
return;
}
/********************************/
//System.out.println("test1 ");
/**********************************/
if(colViewList.indexOf(subBean.getTableCol()) < 0)
{
//colViewList.add(subBean.getTableCol());
colViewList.add(subBean);
/********************************/
//System.out.println("add pojoCol :"+pojoCol);
/**********************************/
}
/********************************/
//System.out.println("test 2 ");
/**********************************/
this.setColViewList(colViewList);
}
/**
* 创建MBean中的内置类SubBean,为属性名-字段名-字段值的复合数据类型
* @author tongxiaodong
* Creation time:Nov 17, 2006 4:04:32 PM
*/
public class SubBean
{
private String pojoName = null;//pojo对象名
private String pojoCol = null;//pojo中属性名
private String tableCol = null;//数据库表中字段名
private String operChar = null;//比较运算符,“=、<、>、<=、>=”
private Object value = null;//字段值
public String getPojoName()
{
return this.pojoName;
}
public void setPojoName(String pojoName)
{
this.pojoName = pojoName;
}
public String getPojoCol()
{
return this.pojoCol;
}
public void setPojoCol(String pojoCol)
{
this.pojoCol = pojoCol;
}
public String getTableCol()
{
return this.tableCol;
}
public void setTableCol(String tableCol)
{
this.tableCol = tableCol;
}
public String getOperChar()
{
return this.operChar;
}
public void setOperChar(String operChar)
{
this.operChar = operChar;
}
public Object getValue()
{
return this.value;
}
public void setValue(Object value)
{
this.value = value;
}
}
/**
* 初始化该MBean
*
*/
public void init()
{
}
/**
* 创建属性名-SubBean(为属性名-表字段名-字段值的复合数据类型)的映射
*
*/
public void createOrmMap()
{
}
/**
* 创建外键-表实体映射图
*/
public void createFkmMap()
{
}
/**
* 在表间字段关系映射表(TcrmMap)中加入一条关系,即pojo属性名-SubBean List的形式
*
*/
public void addOneTcrm(String pojoCol,MBean.SubBean subBean)
{
List subBeanList = null;
if(subBean == null || this.tcrmMap==null)
{
return;
}
Map tcmpMap = this.getTcrmMap();
if(tcmpMap.get(pojoCol) != null)//如果SubBeanList已存在
{
subBeanList = (ArrayList) tcmpMap.get(pojoCol);
}
else
{
subBeanList = new ArrayList();
}
subBeanList.add(subBean);
tcmpMap.put(pojoCol,subBeanList);
this.setTcrmMap(tcmpMap);
}
/**
* 获取一条orm映射,以Object类型返回Pojo中名为pojoCol的SubBean
* return the value in Pojo as type of Object, of which the property name is param "pojoCol".
* @param pojoCol
* @return
*/
public Object getOneOrm(String pojoCol)
{
if(this.ormMap == null)
{
return null;
}
Object subBean = this.ormMap.get(pojoCol);
return subBean;
}
/**
* 加入一条新orm映射,设置Pojo中名为pojoCol的SubBean
* By param value,set the value of the Pojo's property ,of which the name is param "pojoCol"
* @param pojoCol
* @param subBean
*/
public void addOneOrm(String pojoCol,Object subBean)
{
if(this.ormMap == null)
{
return;
}
this.ormMap.put(pojoCol,subBean);
}
/**
* 获取一条fkm映射,以Object类型返回Pojo中名为pojoCol的属性值
* return the value in Pojo as type of Object, of which the property name is param "pojoCol".
* @param pojoCol
* @return
*/
public Object getOneFkm(String pojoCol)
{
if(this.fkmMap == null)
{
return null;
}
Object subBean = this.fkmMap.get(pojoCol);
return subBean;
}
/**
* 加入一条新orm映射,设置Pojo中名为pojoCol的属性值
* By param value,set the value of the Pojo's property ,of which the name is param "pojoCol"
* @param pojoCol
* @param subBean
*/
public void addOneFkm(String pojoCol,MBean toMBean,String toPojoCol)
{
if(this.fkmMap==null || pojoCol==null || toMBean==null || toPojoCol==null)
{
return;
}
MBean.SubBean subBean = (MBean.SubBean)toMBean.getOneOrm(toPojoCol);
String toTableCol = subBean.getTableCol();
subBean = this.initSubBean(toMBean.getPojoName(),toPojoCol,toTableCol,null,null);
this.fkmMap.put(pojoCol,subBean);
}
/**
* 初始化一个SubBean
* @param pojoCol
* @param tableCol
* @param value
* @return
*/
public SubBean initSubBean(String pojoName,String pojoCol,String tableCol,String operChar,Object value)
{
SubBean subBean = new SubBean();
subBean.setPojoName(pojoName);
subBean.setPojoCol(pojoCol);
subBean.setTableCol(tableCol);
subBean.setOperChar(operChar);
subBean.setValue(value);
return subBean;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -