xmlinterfaceforjdk13.java

来自「jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用」· Java 代码 · 共 534 行 · 第 1/2 页

JAVA
534
字号
package org.enhydra.shark.xpdl;import java.io.File;import java.io.FileInputStream;import java.io.StringReader;import java.util.ArrayList;import java.util.Collection;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Set;import org.apache.xerces.parsers.DOMParser;import org.enhydra.shark.utilities.SequencedHashMap;import org.enhydra.shark.xpdl.elements.ExternalPackage;import org.enhydra.shark.xpdl.elements.Package;import org.w3c.dom.Document;import org.xml.sax.InputSource;/** *  Implementation of XMLInterface that works with JDK1.3. * *  @author Sasa Bojanic */public class XMLInterfaceForJDK13 implements XMLInterface {   protected Map idToPackages=new SequencedHashMap();   protected Map xmlFileToPackage=new SequencedHashMap();   protected Map packageToParentDirectory=new SequencedHashMap();   protected String mainPackageReference;   protected Map parsingErrorMessages=new SequencedHashMap();   protected boolean isValidationON=true;      protected XPDLRepositoryHandler xpdlRep = null;      protected Locale locale=Locale.getDefault();      public void setValidation (boolean isActive) {      isValidationON=isActive;   }   public void clearParserErrorMessages () {      parsingErrorMessages.clear();   }   public synchronized boolean isPackageOpened (String pkgId) {      return idToPackages.containsKey(pkgId);   }   public synchronized Package getPackageById (String pkgId) {      ArrayList l=(ArrayList)idToPackages.get(pkgId);      Package toRet=null;      if (l!=null) {         Iterator it=l.iterator();         int lastVersion=-1;         while (it.hasNext()) {            Package p=(Package)it.next();            String v=p.getInternalVersion();            int vi=-1;            try {               vi=Integer.parseInt(v);            } catch (Exception ex) {                           }            if (vi>=lastVersion) {               lastVersion=vi;               toRet=p;            }         }         if (toRet==null && l.size()>0) {            toRet=(Package)l.get(l.size()-1);         }      }      return toRet;   }   public synchronized Package getPackageByIdAndVersion (String pkgId,String version) {      ArrayList l=(ArrayList)idToPackages.get(pkgId);      Package toRet=null;      if (l!=null) {         Iterator it=l.iterator();         while (it.hasNext()) {            Package p=(Package)it.next();            String v=p.getInternalVersion();            if (v.equals(version)) {               toRet=p;               break;            }         }      }      return toRet;   }   public synchronized Package getPackageByFilename (String filename) {      filename=XMLUtil.getCanonicalPath(filename,"",false);      return (Package)xmlFileToPackage.get(filename);   }   public synchronized Package getExternalPackageByRelativeFilePath (      String relativePathToExtPkg,Package rootPkg) {      File f=new File(relativePathToExtPkg);      if (!f.isAbsolute()) {         f=new File(getParentDirectory(rootPkg)+File.separator+relativePathToExtPkg);      }      if (f.exists()) {         //System.out.println("Pkg for "+relativePathToExtPkg+"->"+f.getAbsolutePath()+" is found");         return getPackageByFilename(f.getAbsolutePath());      }            //System.out.println("Pkg for "+relativePathToExtPkg+"->"+f.getAbsolutePath()+" is not found");      return null;   }   public synchronized String getAbsoluteFilePath (Package pkg) {      Iterator it=xmlFileToPackage.entrySet().iterator();      String fullPath=null;      while (it.hasNext()) {         Map.Entry me=(Map.Entry)it.next();         String u=(String)me.getKey();         Package p=(Package)me.getValue();         if (p.equals(pkg)) {            fullPath=u;            break;         }      }      return fullPath;   }   public synchronized Collection getAllPackages () {      ArrayList l=new ArrayList();      Iterator it=idToPackages.values().iterator();      while (it.hasNext()) {         l.addAll((ArrayList)it.next());      }      return l;   }   public synchronized Collection getAllPackageIds () {      return idToPackages.keySet();   }   public Collection getAllPackageVersions (String pkgId) {      ArrayList l=new ArrayList();      ArrayList all=(ArrayList)idToPackages.get(pkgId);      if (all!=null) {         Iterator it=all.iterator();         while (it.hasNext()) {            l.add(((Package)it.next()).getInternalVersion());         }      }      return l;   }   public synchronized Collection getAllPackageFilenames () {      return xmlFileToPackage.keySet();   }   public synchronized boolean doesPackageFileExists (String xmlFile) {      if (new File(xmlFile).exists()) {// || getPackageFileContent(xmlFile)!=null) {         return true;      }            return false;   }   public synchronized String getParentDirectory (Package pkg) {      return (String)packageToParentDirectory.get(pkg);   }   public Package openPackage (String pkgReference,                               boolean handleExternalPackages) {      //long t1,t2;      //t1=System.currentTimeMillis();      parsingErrorMessages.clear();      mainPackageReference=pkgReference;      // this method opens the package. It also opens all of it's external packages      // if handleExternalPackages is set to true      Package pkg=openPackageRecursively(pkgReference,handleExternalPackages);      //printDebug();      //t2=System.currentTimeMillis();      //System.out.println("OPT="+(t2-t1));      return pkg;   }   public void printDebug () {      System.out.println("idToPackage="+idToPackages);      System.out.println("xmlFileToPackage="+xmlFileToPackage);      System.out.println("packageToWorkingDirectory="+packageToParentDirectory);      //Package.printDebug();   }   // Recursive implementation   // pkgReference MUST be absolute path   protected Package openPackageRecursively (String pkgReference,                                   boolean handleExternalPackages) {      Package pkg=null;      File f=null;      String oldP=pkgReference;      String baseDirectory=null;      pkgReference=XMLUtil.getCanonicalPath(pkgReference,"",false);      if (pkgReference==null) {         Set fem=new HashSet();         fem.add("File does not exist");         parsingErrorMessages.put(oldP,fem);         return null;      }            f=new File(pkgReference);      try {         baseDirectory=f.getParentFile().getCanonicalPath();      } catch (Exception ex) {         baseDirectory=f.getParentFile().getAbsolutePath();      }      if (xmlFileToPackage.containsKey(pkgReference)) {         return getPackageByFilename(pkgReference);      }      pkg=parseDocument(pkgReference,true);      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);               //System.setProperty("user.dir",packageToParentDirectory.get(pkg).toString());               Package extPkg=openPackageRecursively(ptep,handleExternalPackages);               extPkgId=extPkg.getId();            } else {               extPkgId=XMLUtil.getExternalPackageId(pathToExtPackage);

⌨️ 快捷键说明

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