Java 包装类它是一种设计模式吗

Java 包装类它是一种设计模式吗,java,design-patterns,Java,Design Patterns,我是设计模式的新手,现在我正在开发一个开源代码:所以我试图理解代码的体系结构:层,使用的设计模式 因此,我找到了一个包含名为EntityWrapper.java的类的包,下面是一个示例: 包装类: 实体类: package org.objectweb.salome_tmf.data; 导入java.io.File; 导入java.io.Serializable; 导入java.util.Enumeration; 导入java.util.HashSet; 导入java.util.Hashtable

我是设计模式的新手,现在我正在开发一个开源代码:所以我试图理解代码的体系结构:层,使用的设计模式

因此,我找到了一个包含名为EntityWrapper.java的类的包,下面是一个示例:

包装类:

实体类:

package org.objectweb.salome_tmf.data;
导入java.io.File;
导入java.io.Serializable;
导入java.util.Enumeration;
导入java.util.HashSet;
导入java.util.Hashtable;
导入java.util.Iterator;
导入java.util.Vector;
导入org.objectweb.salome_tmf.api.api;
导入org.objectweb.salome_tmf.api.ApiConstants;
导入org.objectweb.salome_tmf.api.Util;
导入org.objectweb.salome_tmf.api.data.ActionWrapper;
导入org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
导入org.objectweb.salome_tmf.api.data.ParameterWrapper;
导入org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
导入org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
导入org.objectweb.salome_tmf.api.sql.ISQLAction;
公共集体诉讼以附件形式展开{
静态ISQLAction pISQLAction=null;
私有字符串等待结果;
公共字符串getAwaiteResult(){
返回等待结果;
}
public void setAwaitedResult(字符串awaitedResult){
this.awaitedResult=awaitedResult;
}
私有内部索引;
私有哈希表参数Hashtable;
私有测试pTest=null;
公共操作(测试pTest、字符串名称、字符串描述){
超级(名称、描述);
等待结果=”;
orderIndex=0;
参数Hashtable=新的Hashtable();
this.pTest=pTest;
如果(pISQLAction==null){
pISQLAction=Api.getISQLObjectFactory().getISQLAction();
}
}
公共行动(行动包装协议、测试测试){
这是(pTest,pAction.getName(),pAction.getDescription());
awaitedResult=pAction.getAwaitedResult();
orderIndex=pAction.getOrderIndex();
idBdd=pAction.getIdBDD();
} 
公共行动(行动协议、测试测试){
这是(pTest,pAction.getNameFromModel(),pAction.getDescriptionFromModel());
awaitedResult=pAction.getAwaitedResultFromModel();
}//建筑商行动财务/1
受保护的void reloadBaseFromDB()引发异常{
if(isInBase()){
抛出新异常(“操作“+name+”已在BDD中”);
}
ActionWrapper-pActionWrapper=pISQLAction.getActionWrapper(idBdd);
awaitedResult=pActionWrapper.getAwaitedResult();
orderIndex=pActionWrapper.getOrderIndex();
name=pActionWrapper.getName();
description=pActionWrapper.getDescription();
}
public void reloadFromDB(布尔基、哈希表paramsInModel、布尔附加)
抛出异常{
int transnumber=-1;
试一试{
transNuber=Api.beginTransaction(101,ApiconStats.LOADING);
如果(基本){
重载basefromdb();
}
从DB(paramsInModel)重新加载使用的参数;
如有的话(附上){
从DB重新加载AttachmentDataFromDB(false);
}
Api.commitTrans(transNuber);
}捕获(例外e){
Api.forceRollBackTrans(transNuber);
投掷e;
}
}
公共void clearCache(){
/*TODO ClearAttachement*/
}
/******************************************************************************/
/**辅助者
变异人***/
/******************************************************************************/
公共字符串GetWaitiedResultFromModel(){
返回等待结果;
}
public void setAwaitedResultInModel(字符串){
等待的结果=字符串;
}
public int getOrderIndexFromModel(){
退货订单索引;
}
公共无效setOrderIndex(int i){
orderIndex=i;
}
公共测试getTest(){
返回pTest;
}
///////////////////////////////基本操作/////////////////////////
/*由曼努埃尔测试使用*/
void addInDB(Test pTest)引发异常{
//布尔值needUpdate=false;
if(isInBase()){
抛出新异常(“操作“+name+”已在BDD中”);
}
如果(!pTest.isInBase()){
抛出新异常(“Test”+pTest.getNameFromModel()+“不在BDD中”);
}
int id=pISQLAction.insert(pTest.getIdBdd(),名称,描述,waitiedResult);
setIdBdd(id);
orderIndex=pISQLAction.getActionWrapper(id).getOrder();
/*if(orderIndex!=行数){
needUpdate=true;
}
返回需要更新*/
Project.pCurrentProject.notifyChanged(ApiConstants.INSERT_ACTION,this);
}
/*由曼努埃尔测试使用*/
无效addInModel(测试pTest){
this.pTest=pTest;
}
/*由曼努埃尔测试使用*/
void addInDBAndModel(测试pTest)引发异常{
//布尔res;
addInDB(pTest);
addInModel(pTest);
//返回res;
}
public void updateInDB(字符串newActionName、字符串newActionDesc、字符串newActionResAttendu)引发异常{
如果(!isInBase()){
抛出新异常(“操作“+name+”不在BDD中”);
}
更新(idBdd、newActionName、newActionDesc、newActionResAttendu);
Project.pCurrentProject.notifyChanged(ApiConstants.UPDATE_ACTION,this,新字符串(名称),newActionName);
}
public void updateInModel(字符串newActionName、字符串newActionDesc、字符串newActionResAttendu){
setNameInModel(newActionName);
更新的描述模型(newActionDesc);
SetWaitiedResultinModel(newActionResAttendu);
}
public void updateInDBAndModel(字符串newActionName、字符串newActionDesc、字符串newActionResAttendu)引发异常{
更新索引(newActionName、newActionDesc、newActionResAttendu);
updateInModel(newActionName、newActionDesc、newActionResAttendu);
} 
public void updateInDBAndModel(字符串newName,字符串newDesc)引发异常{
更新索引(newName、newDesc、waitiedResult);
updateInModel(newName、newDesc、WaitiedResult);
}
public void updateOrderInDBAndModel(布尔值inc)引发异常{
如果(!isInBase()){
抛出新异常(“操作”+名称+
 package org.objectweb.salome_tmf.api.data;

 /**
  * @author marchemi
  */
public class ActionWrapper extends DataWrapper{
 String awaitedResult;
 int orderIndex;
 int idTest;
/**
 * @return Returns the orderIndex.
 */
public int getOrderIndex() {
    return orderIndex;
}
/**
 * @param orderIndex The orderIndex to set.
 */
public void setOrderIndex(int orderIndex) {
    this.orderIndex = orderIndex;
}
/**
 * @return Returns the waitedResult.
 */
public String getAwaitedResult() {
    return awaitedResult;
}
/**
 * @param waitedResult The waitedResult to set.
 */
public void setAwaitedResult(String awaitedResult) {
    this.awaitedResult = awaitedResult;
}
/**
 * @return Returns the idTest.
 */
public int getIdTest() {
    return idTest;
}
/**
 * @param idTest The idTest to set.
 */
public void setIdTest(int idTest) {
    this.idTest = idTest;
}
 }
package org.objectweb.salome_tmf.data;

import java.io.File;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;

import org.objectweb.salome_tmf.api.Api;
import org.objectweb.salome_tmf.api.ApiConstants;
import org.objectweb.salome_tmf.api.Util;
import org.objectweb.salome_tmf.api.data.ActionWrapper;
import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
import org.objectweb.salome_tmf.api.data.ParameterWrapper;
import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
import org.objectweb.salome_tmf.api.sql.ISQLAction;

public class Action extends WithAttachment {
static ISQLAction pISQLAction = null;

private String awaitedResult;
public String getAwaitedResult() {
    return awaitedResult;
}

public void setAwaitedResult(String awaitedResult) {
    this.awaitedResult = awaitedResult;
}

private int orderIndex;
private Hashtable parameterHashTable;
private Test pTest = null;

public Action(Test pTest, String name, String description) {
    super(name, description);
    awaitedResult = "";
    orderIndex = 0;
    parameterHashTable = new Hashtable();
    this.pTest = pTest;
    if (pISQLAction == null){
        pISQLAction = Api.getISQLObjectFactory().getISQLAction();
    }
}

public Action(ActionWrapper pAction, Test pTest) {
    this(pTest, pAction.getName(), pAction.getDescription());
    awaitedResult = pAction.getAwaitedResult();
    orderIndex = pAction.getOrderIndex();
    idBdd = pAction.getIdBDD();
} 

public Action(Action pAction, Test pTest) {
    this(pTest,  pAction.getNameFromModel(), pAction.getDescriptionFromModel());
    awaitedResult = pAction.getAwaitedResultFromModel();
} // Fin du constructeur Action/1


protected void reloadBaseFromDB() throws Exception {
    if (isInBase()) {
        throw new Exception("Action " + name + " is already in BDD");
    }
    ActionWrapper pActionWrapper = pISQLAction.getActionWrapper(idBdd);
    awaitedResult = pActionWrapper.getAwaitedResult();
    orderIndex = pActionWrapper.getOrderIndex();
    name = pActionWrapper.getName();
    description = pActionWrapper.getDescription();
}


public void reloadFromDB(boolean base, Hashtable paramsInModel, boolean attach)  
  throws Exception {
    int transNuber = -1;
    try {
        transNuber = Api.beginTransaction(101, ApiConstants.LOADING);
        if (base){
            reloadBaseFromDB();
        }
        reloadUsedParameterFromDB(paramsInModel);
        if (attach){
            reloadAttachmentDataFromDB(false);
        }
        Api.commitTrans(transNuber);
    } catch (Exception e){
        Api.forceRollBackTrans(transNuber);
        throw e;
    }
}

public void clearCache() {
    /* TODO ClearAttachement */

}
/******************************************************************************/
/**                             ACCESSEURS ET 
     MUTATEURS                      ***/
/******************************************************************************/

public String getAwaitedResultFromModel() {
    return awaitedResult;
}

public void setAwaitedResultInModel(String string) {
    awaitedResult = string;
}


public int getOrderIndexFromModel() {
    return orderIndex;
}

public void setOrderIndex(int i) {
    orderIndex = i;
}

public Test getTest(){
    return pTest;
}

/////////////////////////////// Basic Operation /////////////////////////

/* Used by Manuel Test */
void addInDB(Test pTest) throws Exception {
    //boolean needUpdate = false;
    if (isInBase()) {
        throw new Exception("Action " + name + " is already in BDD");
    }
    if (!pTest.isInBase()){
        throw new Exception("Test " + pTest.getNameFromModel() + " is not in BDD");
    }
    int id = pISQLAction.insert(pTest.getIdBdd(), name, description, awaitedResult);
    setIdBdd(id);
    orderIndex =  pISQLAction.getActionWrapper(id).getOrder();
    /*if (orderIndex != rowCount){
        needUpdate = true; 
    }
    return needUpdate;*/
    Project.pCurrentProject.notifyChanged( ApiConstants.INSERT_ACTION ,this);

}

/* Used by Manuel Test */
void addInModel(Test pTest){
    this.pTest = pTest;
}

/* Used by Manuel Test */
void addInDBAndModel(Test pTest)throws Exception {
    //boolean res;
    addInDB(pTest);
    addInModel(pTest);
    //return res;
}



public void updateInDB(String newActionName, String newActionDesc, String newActionResAttendu) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    pISQLAction.update(idBdd, newActionName, newActionDesc,  newActionResAttendu );
    Project.pCurrentProject.notifyChanged( ApiConstants.UPDATE_ACTION ,this, new String(name), newActionName);

}

public void updateInModel(String newActionName, String newActionDesc, String newActionResAttendu) {
    setNameInModel(newActionName);
    updateDescriptionInModel(newActionDesc);
    setAwaitedResultInModel(newActionResAttendu);
}

public void updateInDBAndModel(String newActionName, String newActionDesc, String newActionResAttendu) throws Exception {
    updateInDB(newActionName, newActionDesc, newActionResAttendu);
    updateInModel(newActionName, newActionDesc, newActionResAttendu);
} 

public void updateInDBAndModel(String newName, String newDesc) throws Exception {
    updateInDB(newName, newDesc, awaitedResult);
    updateInModel(newName, newDesc, awaitedResult);
}

public void updateOrderInDBAndModel(boolean inc) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    orderIndex = pISQLAction.updateOrder(idBdd, inc);     
}

/* Used by Manuel Test */
void deleteInDB() throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    pISQLAction.delete(idBdd);
    Project.pCurrentProject.notifyChanged( ApiConstants.DELETE_ACTION ,this);
}

/* Used by Manuel Test */
 void deleteInModel(){
    pTest=null;
    parameterHashTable.clear();
    clearAttachInModel();
}

 /* Used by Manuel Test */
void deleteInDBAndModel() throws Exception {
    deleteInDB();
    deleteInModel();
}

//////////////// PARAMETERS ////////////////////////


public void setParameterHashSetInModel(HashSet set) {
    parameterHashTable.clear();
    for (Iterator iter = set.iterator(); iter.hasNext();) {
        Parameter param = (Parameter)iter.next();
        parameterHashTable.put(param.getNameFromModel(), param);
    }

}
public void setParameterHashtableInModel(Hashtable table) {
    parameterHashTable.clear();
    parameterHashTable = table;
}

public Hashtable getCopyOfParameterHashTableFromModel(){
    Hashtable copyParameter = new Hashtable();
    Enumeration enumKey = parameterHashTable.keys();
    while (enumKey.hasMoreElements()){
        Object key = enumKey.nextElement();
        copyParameter.put(key, parameterHashTable.get(key));
    }
    return copyParameter;
}

public void reloadUsedParameterFromDB(Hashtable parametersInModel) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    ParameterWrapper[] paramActionArray = pISQLAction.getParamsUses(idBdd);
    for (int i = 0; i < paramActionArray.length; i++) {
        Parameter param = null;
        ParameterWrapper pParameterWrapper = paramActionArray[i];
        if (parametersInModel != null){
            param = (Parameter)parametersInModel.get(pParameterWrapper.getName());
            if (param == null){
                param = new Parameter(pParameterWrapper);
            }
        }
        setUseParamInModel(param);
    }
}

public void setUseParamInModel(Parameter pParam) {
    parameterHashTable.put(pParam.getNameFromModel(), pParam);
    if (pTest != null) {
        if (pTest.getUsedParameterFromModel(pParam.getNameFromModel()) == null){
            pTest.setUseParamInModel(pParam);
        }
    }
}

public void setUseParamInDB(int paramId) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    pISQLAction.addUseParam(idBdd,paramId);
}

public void setUseParamInDBAndModel(Parameter pParam) throws Exception {
    //DB
    setUseParamInDB(pParam.getIdBdd());
    //model
    setUseParamInModel(pParam);
}

public void deleteUseParamInDB(int paramId) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    pISQLAction.deleteParamUse(idBdd, paramId);
}

public void deleteUseParamInDBAndModel(Parameter pParam)  throws Exception {
    deleteUseParamInDB(pParam.getIdBdd());
    deleteUseParamInModel(pParam);
}

public void deleteUseParamInModel(Parameter pParam) {
    // Clean Action
    String newDesc = null ;
    if (getDescriptionFromModel()!=null)
       newDesc = clearStringOfParameter(getDescriptionFromModel(), pParam);
    String newResult = null;
    if (getAwaitedResultFromModel()!=null)
        newResult = clearStringOfParameter(getAwaitedResultFromModel(), pParam);
    description = newDesc;
    awaitedResult = newResult;
    Object o= parameterHashTable.remove(pParam.getNameFromModel());
    Util.log("[Action->deleteUseParamInModel] Delete Use Parameter " + pParam + ", in Action " + name + " res is " +o);

}



public Parameter getParameterFromModel(String name) {
    Enumeration paramList = parameterHashTable.elements();
    while (paramList.hasMoreElements()){
        Parameter param = (Parameter)paramList.nextElement();
        if (param.getNameFromModel().equals(name)) {
            return param;
        }
    }
    return null;
}

public Parameter getParameterFromDB(String name) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    HashSet result = getParameterHashSetFromDB();
    for (Iterator iter = result.iterator(); iter.hasNext(); ) {
        Parameter param = (Parameter)iter.next();
        if (param.getNameFromModel().equals(name)) {
            return param;
        }
    }
    return null;
}

public HashSet getParameterHashSetFromDB() throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    HashSet result = new HashSet();
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    ParameterWrapper[] listParamWrapper =  pISQLAction.getParamsUses(idBdd);
    for (int i = 0; i <  listParamWrapper.length; i++){
        result.add(new Parameter(listParamWrapper[i]));
    }
    return result;
}

public Vector getParameterVectorFromDB() throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    Vector result = new Vector();
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    ParameterWrapper[] listParamWrapper =  pISQLAction.getParamsUses(idBdd);
    for (int i = 0; i <  listParamWrapper.length; i++){
        result.add(new Parameter(listParamWrapper[i]));
    }
    return result;
}
public Hashtable getParameterHashSetFromModel() {
    return parameterHashTable;
} 

////////////// ATTACHEMENT ///////////////////////

public void addAttachementInDB (Attachment attach )throws Exception {
    if (attach instanceof FileAttachment) {
        addAttachFileInDB((FileAttachment) attach);
    } else {
        addAttachUrlInDB((UrlAttachment) attach);
    }
}

void addAttachFileInDB(FileAttachment file) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    File f = file.getLocalFile();
    int id = pISQLAction.addFileAttach(idBdd,new SalomeFileWrapper(f),file.getDescriptionFromModel());
    file.setIdBdd(id);
}

void addAttachUrlInDB(UrlAttachment url) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    int id = pISQLAction.addUrlAttach(idBdd, url.getNameFromModel(),url.getDescriptionFromModel());
    url.setIdBdd(id);
}


public void deleteAttachementInDB(int attachId) throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    pISQLAction.deleteAttachment(idBdd, attachId);
}




public void deleteAttachementInDBAndModel(Attachment attach)throws Exception {
    deleteAttachementInDB(attach.getIdBdd());
    deleteAttachmentInModel(attach);

}

public Vector getAttachFilesFromDB() throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    FileAttachementWrapper[] fawArray = pISQLAction.getAllAttachFile(idBdd);
    Vector result = new Vector();
    for(int i = 0; i < fawArray.length; i++) {
        result.add(fawArray[i]);
    }
    return result;
}


public Vector getAttachUrlsFromDB() throws Exception {
    if (!isInBase()) {
        throw new Exception("Action " + name + " is not in BDD");
    }
    UrlAttachementWrapper[] uawArray = pISQLAction.getAllAttachUrl(idBdd);
    Vector result = new Vector();
    for(int i = 0; i < uawArray.length; i++) {
        result.add(uawArray[i]);
    }
    return result;
}


//////// PROTECTED //////////////
protected String clearStringOfParameter(String prtString, Parameter pParam) {
    String result = prtString;
    result = result.replaceAll("[$]" + pParam.getNameFromModel() + "[$]", "");
    return result;
}

public static boolean isInBase(Test pTest, String actionName) {
    try  {
        int id = pISQLAction.getID(pTest.getIdBdd(), actionName);
        if (id > 0){
            return true;
        }
        return false;
    } catch (Exception e) {

    }
    return false;
} // Fin de la methode isInBase/1

public boolean existeInBase() throws Exception {
    if (!isInBase()) {
        return false;
    }
    return  pISQLAction.getID(pTest.getIdBdd(), name) == idBdd;
}
}