xpdlhandler.java
来自「jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用」· Java 代码 · 共 494 行 · 第 1/2 页
JAVA
494 行
raf=new RandomAccessFile(f,"r"); } rndAccessFiles.put(pkg,raf); if (settings.isFileLockingEnabled()) { FileLock fl=raf.getChannel().tryLock(); //FileLock fl=raf.getChannel().tryLock(0L,Long.MAX_VALUE,true); // this happens if the file isn't already opened as // 'rw' and locked exclusivly if (fl!=null) { fileLocks.put(pkg,fl); // this happens if the file is opened as 'rw' and locked exclusivly } else { Set errorMessages = new HashSet(); errorMessages.add(ResourceManager.getLanguageDependentString("ErrorTheFileIsLocked")); parsingErrorMessages.put(pkgReference,errorMessages); return null; } } } // this exception happens if using jdk1.4.0 under Linux } catch (Exception ex) { //ex.printStackTrace(); } if (pkg!=null) { String pkgId=pkg.getId(); // check if package is already imported if (idToPackages.containsKey(pkgId)) { // check if this is the same package, or just the one with the same id if (xmlFileToPackage.containsKey(pkgReference)) { return getPackageById(pkgId); } throw new RuntimeException("Can't open two packages with the same Id"); } ArrayList l=(ArrayList)idToPackages.get(pkgId); if (l==null) { l=new ArrayList(); } l.add(pkg); idToPackages.put(pkgId,l); xmlFileToPackage.put(pkgReference,pkg); try { packageToParentDirectory.put(pkg,f.getParentFile().getCanonicalPath()); } catch (Exception ex) { packageToParentDirectory.put(pkg,f.getParentFile().getAbsolutePath()); } // open all external packages if handleExternalPackages is set to true, // otherwise, it assumes that if there are external packages, the // href element is similar to their Ids Iterator eps=pkg.getExternalPackages().toElements().iterator(); while (eps.hasNext()) { String pathToExtPackage=((ExternalPackage)eps.next()).getHref(); String extPkgId=null; if (handleExternalPackages) { // setting working dir to be the one of the current package String ptep=XMLUtil.getCanonicalPath(pathToExtPackage,baseDirectory,false); if (ptep==null) { Set fem=new HashSet(); fem.add("File does not exist"); parsingErrorMessages.put(pathToExtPackage,fem); continue; } //System.setProperty("user.dir",packageToParentDirectory.get(pkg).toString()); Package extPkg=openPackageRecursively(ptep,handleExternalPackages); extPkgId=extPkg.getId(); } else { extPkgId=XMLUtil.getExternalPackageId(pathToExtPackage); } pkg.addExternalPackageMapping(pathToExtPackage, extPkgId); } } else { System.err.println("Problems with opening file "+pkgReference); } return pkg; } public synchronized List closePackages (String pkgId) { Package main=getMainPackage(); List l=super.closePackages(pkgId); if (l!=null) { // removing file to package mapping Iterator itr=l.iterator(); while (itr.hasNext()) { Package toRemove=(Package)itr.next(); if (toRemove==main) { mainPackageReference=null; } // close file RandomAccessFile raf=(RandomAccessFile)rndAccessFiles.remove(toRemove); try { raf.close(); } catch (Exception ex) {} // unlock file FileLock fl=(FileLock)fileLocks.remove(toRemove); try { fl.release(); } catch (Exception ex) {} } } return l; } public synchronized Package closePackageVersion (String pkgId,String pkgVer) { Package main=getMainPackage(); ArrayList l=(ArrayList)idToPackages.get(pkgId); if (l.size()==1) { return (Package)this.closePackages(pkgId).get(0); } Package toRemove=super.closePackageVersion(pkgId, pkgVer);// System.out.println("TRID="+toRemove.getId()); if (toRemove!=null) { if (toRemove==main) { mainPackageReference=null; } // close file RandomAccessFile raf=(RandomAccessFile)rndAccessFiles.remove(toRemove); try { raf.close(); } catch (Exception ex) {} // unlock file FileLock fl=(FileLock)fileLocks.remove(toRemove); try { fl.release(); } catch (Exception ex) {} } return toRemove; } public void closeAllPackages () { // close all files super.closeAllPackages(); Iterator it=rndAccessFiles.values().iterator(); while (it.hasNext()) { RandomAccessFile raf=(RandomAccessFile)it.next(); try { raf.close(); } catch (Exception ex) {} } rndAccessFiles.clear(); unlockAllFiles(); mainPackageReference=null; } public void unlockAllFiles () { // unlock all files Iterator it=fileLocks.values().iterator(); while (it.hasNext()) { FileLock fl=(FileLock)it.next(); try { fl.release(); } catch (Exception ex) {} } fileLocks.clear(); } public void lockAllFiles () throws Exception { if (!settings.isFileLockingEnabled()) return; Iterator it=rndAccessFiles.entrySet().iterator(); Package main=(Package)xmlFileToPackage.get(mainPackageReference); while (it.hasNext()) { Map.Entry me=(Map.Entry)it.next(); Package pkg=(Package)me.getKey(); RandomAccessFile raf=(RandomAccessFile)me.getValue();// try { // lock main package exclusivly if (pkg.equals(main)) { FileLock fl=raf.getChannel().tryLock(); // this happens if the main package is not already locked if (fl!=null) { fileLocks.put(pkg,fl); // this happens if the file is already opened as 'rw' and locked // exclusivly, or if it is opened as 'r' and locked as shared } else { continue; } // lock external package exclusivly } else { FileLock fl=raf.getChannel().tryLock(0L,Long.MAX_VALUE,true); // this happens if the file isn't already opened as // 'rw' and locked exclusivly if (fl!=null) { fileLocks.put(pkg,fl); // this happens if the file is opened as 'rw' and locked exclusivly } else { continue; } } // this exception happens if using jdk1.4.0 under Linux// } catch (Exception ex) {// //ex.printStackTrace();// } } } public synchronized void synchronizePackages (XMLInterface xmlInterface) { Iterator it=xmlInterface.getAllPackages().iterator(); while (it.hasNext()) { Package pkg=(Package)it.next(); String pkgId=pkg.getId(); ArrayList l=(ArrayList)idToPackages.get(pkgId); if (l==null) { l=new ArrayList(); } else { continue; } l.add(pkg); idToPackages.put(pkgId,l); String fp=xmlInterface.getAbsoluteFilePath(pkg); if (fp!=null) { xmlFileToPackage.put(fp,pkg); } String pd=xmlInterface.getParentDirectory(pkg); if (pd!=null) { packageToParentDirectory.put(pkg,pd); } XPDLHandler xpdlh=(XPDLHandler)xmlInterface; RandomAccessFile raf = xpdlh.getRaf(pkg); if (raf!=null) { this.rndAccessFiles.put(pkg,raf); } FileLock fl=(FileLock)xpdlh.fileLocks.get(pkg); if (fl!=null) { if (xpdlh.getMainPackage()==pkg) { try { fl.release(); } catch (Exception ex) {System.err.println("Failed to release file lock for package "+pkg.getId());} fl=null; try { fl=raf.getChannel().tryLock(); } catch (Exception ex) {} } if (fl!=null) { this.fileLocks.put(pkg,fl); } } } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?