⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accessrule.java

📁 《Java网络程序设计.rar》包括三个网络程序的源代码。
💻 JAVA
字号:
/* * AccessRule.java * * Created on October 23, 2001, 11:57 PM */package org.impact.stars.control.web.checker;import org.impact.stars.control.exceptions.*;import javax.swing.tree.DefaultMutableTreeNode;import org.impact.stars.util.*;import java.util.*;import java.io.*;/** * * @author  cai * @version * Defined the Access Rule for Updating the DataTreeModel * Provide stateless service */public class AccessRule implements Serializable{        //private DataTreeModel datatree;    public static final int CREATE = 1; // client asked for create new node    public static final int MODIFY = 2; // client asked for update only this node    public static final int RESTRUCT = 3; // client asked for update node and all children    public static final int DELETE = 4; // client asked for delete        /** Creates new AccessRule */    public AccessRule() {    }    /*    public void setDataTree( DataTreeModel adatatree)    {        datatree = adatatree;    }     */    /* this method returns the root node of a datanode vector     */        public Datanode getTreeRoot(Vector avector, String rootID) {        Debug.println("AccessRule: getTreeRoot");                int size = avector.size();                //String lastID = "0";        Datanode aData = null;        Datanode rootnode = null;        /*        int root = 0;                if (!rootID.equals("root"))                {                    root = Integer.valueOf(rootID).intValue();                }                  */        for (Enumeration enum = avector.elements(); enum.hasMoreElements() ;) {            aData=(Datanode)enum.nextElement();            //find last ID            /*            if (Integer.valueOf(lastID).compareTo(Integer.valueOf(aData.getDataID()))<0) {                lastID = aData.getDataID();                Debug.println("AccessRule: lastID "+lastID);            }             */            // find root node            if (rootID.equals("root")) {                if (aData.getDataID().equals(aData.getParentID())) {                    rootnode=aData;                    Debug.println("rootnode: "+ aData.getDataID());                }            }            else //root is a branch node, not the root one            {                if (aData.getDataID().equals(rootID)) {                    rootnode=aData;                    Debug.println("rootnode: "+ aData.getDataID());                }            }        }                for (int i=0; i< size;i++) {            Datanode anode1 = (Datanode)avector.elementAt(i);            Debug.println("Datanode : " + anode1.getDataID());            for (int j=0; j< size;j++) {                Datanode anode2 = (Datanode)avector.elementAt(j);                Debug.println("Inside for, Datanode:" + anode2.getDataID());                if ((anode2.getParentID().equals(anode1.getDataID()))&&(i!=j)) {                    // Datanode.linkFamily((Datanode)avector.elementAt(i),(Datanode)avector.elementAt(j));                    try {                        //Debug.println("AccessRule: set parent for: " + anode2.getDataID());                        //anode2.setParent((DefaultMutableTreeNode)anode1);                        anode1.add(anode2);                        Debug.println("node "+anode2.getDataID()+"'s parent add as"+ ((Datanode)(anode2.getParent())).getDataID());                    }                    catch (Exception ce) {                        Debug.println(ce.toString());                    }                }            }        }        //return (Datanode)avector.elementAt(0);        return rootnode;    }        public String checkPermition(DataTreeModel datatree, int aoperation, String adataid) {        Debug.println("AccessRule: checkPermition node id:"+adataid);        Datanode root = (Datanode)datatree.getRoot();        Datanode invest = null;        String Read = "0";        String Write = "0";        String UperBranch = "0";        Debug.println("AccessRule: find datanode " + adataid);        invest = root.findDatanode(adataid);        int currentMin =(new GregorianCalendar()).get(Calendar.MINUTE);        if (invest!=null) {            if (Math.abs(invest.getLastWriteMin()-currentMin)>4) {                Write = "0";                invest.setWrite("0");                invest.cleanBranch();                            }                        Read = invest.getRead();            Write = invest.getWrite();            UperBranch = invest.getUperBranch();        }        else {            Debug.println("CANNOT find datanode");        }        switch (aoperation) {            case CREATE:{                // if someone is creating node for the same tree, deny the request                if(root.getDownBranch().equals("0")) {                    return "OK";                }                else {                    return "Someone is creating concept, please reload";                }            }            case MODIFY: {                Debug.println("AcessRule.MODIFY ");                                                if (Write.equals("0")&&Read.equals("0")) {                    return "OK";                }                else if (Write.equals("1")) {                    return "CANNOT modify: Someoneelse is wrting";                }                else {                    return "OK" + " WARN: Someone is reading the data";                }            }            case RESTRUCT: {                Debug.println("AcessRule.RESTRUCT");                if (Write.equals("0")&&UperBranch.equals("0"))                {    return "OK"; }                else if (Write.equals("1")) {                    return "CANNOT restruct: Someoneelse is writing to the same model";                }                else {                    return "CANNOT restruct: Someoneelse is operating the children of this model";                }            }            case DELETE: {                Debug.println("AcessRule.DETELE");                if (Write.equals("0")&&UperBranch.equals("0"))                {    return "OK"; }                else if (Write.equals("1")) {                    return "CANNOT DELET: Someoneelse is writing to the same model";                }                else {                    return "CANNOT restruct: Someoneelse is operating the children of this model";                }                            }            default:                Debug.print("Error: not implemented yet");                return "BLOCK";        }    }            public synchronized void doStart(DataTreeModel datatree, int aoperation, String adataid) {        Debug.println("AccessRule: doStart");                Datanode root = (Datanode)datatree.getRoot();        Datanode invest = null;        invest = root.findDatanode(adataid);        if (invest==null) {            Debug.println("AccessRule Error: Unable to find datanode :"+adataid+" in doStart");        }        switch (aoperation) {            case CREATE: {                Debug.println("AcessRule.CREATE");                root.setDownBranch("1");            } break;                        case MODIFY: {                Debug.println("AcessRule.MODIFY");                if (invest!=null) {                    invest.setWrite("1");                    invest.setallUperBranch("1");                }            } break;            case RESTRUCT: {                Debug.println("AcessRule.RESTRUCT");                if (invest!=null) {                    invest.setallUperBranch("1");                    invest.setWrite("1");                    invest.setallDownWrite("1");                }            } break;            case DELETE: {                // delete does not have time inverval here                // after checking the permition, delete right way                            } break;            default:                Debug.print("Error: not implemented yet");        }    }        public synchronized void doEnd(DataTreeModel datatree, int aoperation, String adataid) {        Debug.println("AccessRule: doEnd: " + adataid);        Datanode root = (Datanode)datatree.getRoot();        Datanode invest = null;                invest = root.findDatanode(adataid);                if (invest==null) {            Debug.println("AccessRule Error: Unable to find datanode in doEnd");        }        switch (aoperation) {            case CREATE: {                root.setDownBranch("0");            }            case MODIFY: {                Debug.println("AcessRule.MODIFY");                if (invest!=null) {                    invest.setWrite("0");                    invest.cleanBranch();                }            } break;            case RESTRUCT: {                if (invest!=null) {                    Debug.println("AcessRule.RESTRUCT");                    invest.setallDownWrite("0");                    invest.cleanBranch();                                        // here the tree need to be reload                }            } break;            case DELETE: {                // delete does not have time inverval here                // after checking the permition, delete right way                Debug.println("AcessRule.DELETE");                if (invest!=null) {                    invest.removeAllChildren();                    datatree.removeNodeFromParent(invest);                }            } break;            default:                Debug.print("Error: not implemented yet");        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -