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

📄 coordservice.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            int index2 = 0;
            String newparam = new String();
            while (index1<len) {
                index2 = param.indexOf(" ",index1+1);
                String t=null;
                if (index1+1<index2) {
                    t=param.substring(index1+1,index2);
                    try {
                        String tt;
                        if (t.equals(this.cadt)) tt=t;
                        else tt=handler.getTableName(handler.getDb(),t);
                        if (tt==null) throw new RemoteException("cannot find "+t+" in coordination description");
                        newparam +=tt+" ";
                    } catch (CoordDatabaseException pe) {
                        throw new RemoteException("SQL error:"+pe);
                    }
                    index1=index2;
                    index2 = param.indexOf(",",index1+1);
                    if (index1+1<index2) {
                        t=param.substring(index1+1,index2);
                        newparam +=t+",";
                        index1=index2;
                    } else if (index1+1<len) {
                        t=param.substring(index1+1);
                        newparam +=t;
                        index1=len;
                    }
                } else throw new RemoteException("invalid input:"+param);
            }
            return newparam;
        }
        // this is for wed service version
        private ArrayList convert(String param, String type) throws RemoteException {
            int len = param.length();
            int index1 = 0;
            int index2 = 0;
            ArrayList newparam = new ArrayList();
            while (index1<len) {
                index2 = param.indexOf(" ",index1);
                String t=null;
                if (index1<index2) {
                    t=param.substring(index1,index2);
                    index1=index2+1;
                    if (index1+type.length()<len) {
                        if (type.equals(param.substring(index1,index1+type.length()))) {
                            newparam.add(t);
                        }
                    } else {
                        if (type.equals(param.substring(index1))) {
                            newparam.add(t);
                        }
                    } 
                    index1 += type.length()+1;
                } else throw new RemoteException("invalid input:"+param);
            }
            return newparam;
        }
        
	private CoordinationHandler getHandler(String name) throws RemoteException {
            CoordinationHandler handler = null;
            String dbURL;
            try {
                int index1 = name.indexOf("//");
                int index2 = name.lastIndexOf("/");
                if (index2-index1>2) dbURL = name.substring(index1,index2);
                else dbURL = new String("//localhost:3306");
                boolean found = false;
                for (Iterator i=this.handlers.iterator();i.hasNext();) {
                    HandlerLocation hl = (HandlerLocation)i.next();
                    if (hl.getURL().equals(dbURL)) {
                        found = true;
                        handler = hl.getHandler();
                        handler.reset(name);
                        break;
                    }
                }
                if (found) return handler;
                handler = new CoordinationHandler(this.config,this.cadt);
                handler.initialise(name);
                HandlerLocation pair = new HandlerLocation(handler,dbURL);
                this.handlers.add(pair);
                return handler;
            } catch (CoordDatabaseException pe) {
                throw new RemoteException("failure to get a handler:"+pe);
            }
	}
        
	private CoordinationHandler getHandler(String dbURL,String name) throws RemoteException {
            CoordinationHandler handler = null;
            try {
                boolean found = false;
                for (Iterator i=this.handlers.iterator();i.hasNext();) {
                    HandlerLocation hl = (HandlerLocation)i.next();
                    if (hl.getURL().equals(dbURL)) {
                        found = true;
                        handler = hl.getHandler();
                        break;
                    }
                }
                if (found) return handler;
                handler = new CoordinationHandler(this.config,this.cadt);
                handler.initialise(name);
                HandlerLocation pair = new HandlerLocation(handler,dbURL);
                this.handlers.add(pair);
                return handler;
            } catch (CoordDatabaseException pe) {
                throw new RemoteException("failure to get a handler:"+pe);
            }
	}
        
	private void destroyHandler(String name) {
            String dbURL = null;
            int index1 = name.indexOf("//");
            int index2 = name.lastIndexOf("/");
            if (index2-index1>2) dbURL = name.substring(index1,index2);
            else dbURL = new String("//localhost:3306");
            for (Iterator i=this.handlers.iterator();i.hasNext();) {
                HandlerLocation hl = (HandlerLocation)i.next();
                if (hl.getURL().equals(dbURL)) {
                    hl.getHandler().dispose();
                    this.handlers.remove(hl);
                    break;
                }
            }
	}
        
	public String get(Get context) throws RemoteException {
            String attrName = context.getAttributeName();
            Element defCtx = context.getDefiningContext();
            try {
                CoordinationHandler handler = this.getHandler(attrName);
                String coordValue = handler.getCoordinationData(defCtx);
                if (coordValue==null) {
                    coordValue = handler.addCoordinationData(defCtx);
                    if (coordValue==null) throw new RemoteException("failure to add a new row in the table ("+attrName+")");
                }
                return coordValue;
            } catch (CoordDatabaseException pe) {
                throw new RemoteException("Error in access to a coordination data base:"+pe);
            }
	}
        
	public boolean isCoord(String name) throws RemoteException {
            try {
                CoordinationHandler handler = this.getHandler(name);
                String res = handler.getInitialValue(handler.getDb());
                if (res==null) return false;
                else return true;
            } catch (CoordDatabaseException pe) {
                throw new RemoteException("Error in access to a coordination data base:"+pe);
            }
	}
        
	public Element getAttributeDefinition(String name) throws RemoteException {
            try {
                CoordinationHandler handler = this.getHandler(name);
                Element res = handler.getDefiningAttributes(handler.getDb());
                return res;
            } catch (CoordDatabaseException pe) {
                throw new RemoteException("Error in access to a coordination data base:"+pe);
            }
	}
        
	public SetResponse set(org.globus.stubs.CoordService_instance.Set params) throws RemoteException {
            String attrName = params.getAttributeName();
            String valueIn = params.getValue();  
            String dataType = params.getDataType();
            Element msg = params.getDefiningContext();
            try {
                CoordinationHandler handler = this.getHandler(attrName);
                if (dataType.equals("http://www.w3.org/2001/XMLSchema#integer")) {
                    Integer integer = new Integer(valueIn);                   
                    if (!handler.updateCoordinationData(msg,integer))
                        throw new RemoteException("failure to update data base");
                } else if (dataType.equals("http://www.w3.org/2001/XMLSchema#double")) {
                    Float flt = new Float(valueIn);
                    if (!handler.updateCoordinationData(msg,flt))
                        throw new RemoteException("failure to update data base");
                } else if (dataType.equals("http://www.w3.org/2001/XMLSchema#string")) {
                    if (!handler.updateCoordinationData(msg,valueIn))
                        throw new RemoteException("failure to update data base");
                } else throw new RemoteException("the value is going to be set to data base with invalid data type");
            } catch (CoordDatabaseException pe) {
                throw new RemoteException("Error in the coordination data base:"+pe);
            }
            return new SetResponse();
	}
        
	public Element execute(Execute obl) throws RemoteException {
            Element obligations = obl.getObligations();
            Element request = obl.getReqCtx();
            try {
                Engine engine = new Engine(obligations,request);
                return engine.execute();
            } catch (EngineException pe) {
                throw new RemoteException("Error in obligation engine:"+pe);
            }
	}
        
 	/* Required by interface ResourceProperties */
	public ResourcePropertySet getResourcePropertySet() {
		return this.propSet;
	}
}

⌨️ 快捷键说明

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