public static SVNAdminArea open(File path, Level logLevel) throws SVNException {
    SVNErrorMessage error = null;
    int wcFormatVersion = -1;
    Collection enabledFactories = getSelector().getEnabledFactories(path, ourFactories, false);
    File adminDir = new Resource(path, SVNFileUtil.getAdminDirectoryName());
    File entriesFile = new Resource(adminDir, "entries");
    if (adminDir.isDirectory() && entriesFile.isFile()) {
      for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) {
        SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next();
        try {
          wcFormatVersion = factory.getVersion(path);
          if (wcFormatVersion > factory.getSupportedVersion()) {
            SVNErrorMessage err =
                SVNErrorMessage.create(
                    SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                    "The path ''{0}'' appears to be part of a Subversion 1.7 or greater\n"
                        + "working copy.  Please upgrade your Subversion client to use this\n"
                        + "working copy.",
                    path);
            SVNErrorManager.error(err, SVNLogType.WC);
          } else if (wcFormatVersion < factory.getSupportedVersion()) {
            SVNErrorMessage err =
                SVNErrorMessage.create(
                    SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                    "Working copy format of {0} is too old ({1}); please check out your working copy again",
                    new Object[] {path, new Integer(wcFormatVersion)});
            SVNErrorManager.error(err, SVNLogType.WC);
          }
        } catch (SVNException e) {
          if (error != null) {
            error.setChildErrorMessage(e.getErrorMessage());
          } else {
            error = e.getErrorMessage();
          }
          continue;
        }

        SVNAdminArea adminArea = factory.doOpen(path, wcFormatVersion);
        if (adminArea != null) {
          adminArea.setWorkingCopyFormatVersion(wcFormatVersion);
          return adminArea;
        }
      }
    }
    if (error == null) {
      if (path != null) {
        checkWCNG(path.getAbsoluteFile(), path);
      }
      error =
          SVNErrorMessage.create(
              SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", path);
    }
    if (error.getErrorCode() == SVNErrorCode.WC_UNSUPPORTED_FORMAT) {
      error.setChildErrorMessage(null);
    }
    SVNErrorManager.error(error, logLevel, SVNLogType.WC);
    return null;
  }
  public static int checkWC(File path, boolean useSelector, Level logLevel) throws SVNException {
    Collection enabledFactories = ourFactories;
    if (useSelector) {
      enabledFactories = getSelector().getEnabledFactories(path, enabledFactories, false);
    }
    SVNErrorMessage error = null;
    int version = -1;
    for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) {
      SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next();
      try {
        version = factory.doCheckWC(path, logLevel);
        if (version == 0) {
          return version;
        }

        if (version > factory.getSupportedVersion()) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                  "The path ''{0}'' appears to be part of a Subversion 1.7 or greater\n"
                      + "working copy.  Please upgrade your Subversion client to use this\n"
                      + "working copy.",
                  path);
          SVNErrorManager.error(err, SVNLogType.WC);
        } else if (version < factory.getSupportedVersion()) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                  "Working copy format of {0} is too old ({1}); please check out your working copy again",
                  new Object[] {path, new Integer(version)});
          SVNErrorManager.error(err, SVNLogType.WC);
        }
      } catch (SVNException e) {
        if (error != null) {
          error.setChildErrorMessage(e.getErrorMessage());
        } else {
          error = e.getErrorMessage();
        }
        continue;
      }
      return version;
    }
    if (error == null) {
      if (path != null) {
        checkWCNG(path.getAbsoluteFile(), path);
      }
      error =
          SVNErrorMessage.create(
              SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", path);
    }
    if (error.getErrorCode() == SVNErrorCode.WC_UNSUPPORTED_FORMAT) {
      error.setChildErrorMessage(null);
    }
    SVNErrorManager.error(error, logLevel, SVNLogType.WC);
    return 0;
  }
  private static boolean checkAdminAreaExists(File dir, String url, long revision)
      throws SVNException {
    File adminDir = new Resource(dir, SVNFileUtil.getAdminDirectoryName());
    if (adminDir.exists() && !adminDir.isDirectory()) {
      SVNErrorMessage err =
          SVNErrorMessage.create(
              SVNErrorCode.WC_OBSTRUCTED_UPDATE, "''{0}'' is not a directory", dir);
      SVNErrorManager.error(err, SVNLogType.WC);
    } else if (!adminDir.exists()) {
      return false;
    }

    boolean wcExists = false;
    try {
      readFormatVersion(adminDir);
      wcExists = true;
    } catch (SVNException svne) {
      return false;
    }

    if (wcExists) {
      SVNWCAccess wcAccess = SVNWCAccess.newInstance(null);
      SVNAdminArea adminArea = null;
      SVNEntry entry = null;
      try {
        adminArea = wcAccess.open(dir, false, 0);
        entry = adminArea.getVersionedEntry(adminArea.getThisDirName(), false);
      } finally {
        wcAccess.closeAdminArea(dir);
      }
      if (!entry.isScheduledForDeletion()) {
        if (entry.getRevision() != revision) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_OBSTRUCTED_UPDATE,
                  "Revision {0} doesn''t match existing revision {1} in ''{2}''",
                  new Object[] {new Long(revision), new Long(entry.getRevision()), dir});
          SVNErrorManager.error(err, SVNLogType.WC);
        }
        if (!url.equals(entry.getURL())) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_OBSTRUCTED_UPDATE,
                  "URL ''{0}'' doesn''t match existing URL ''{1}'' in ''{2}''",
                  new Object[] {url, entry.getURL(), dir});
          SVNErrorManager.error(err, SVNLogType.WC);
        }
      }
    }
    return wcExists;
  }
  private static int readFormatVersion(File adminDir) throws SVNException {
    SVNErrorMessage error = null;
    int version = -1;

    Collection enabledFactories =
        getSelector().getEnabledFactories(adminDir.getParentFile(), ourFactories, false);
    for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) {
      SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next();
      try {
        version = factory.getVersion(adminDir);
      } catch (SVNException e) {
        error = e.getErrorMessage();
        continue;
      }
      return version;
    }

    if (error == null) {
      error =
          SVNErrorMessage.create(
              SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", adminDir);
    }
    SVNErrorManager.error(error, SVNLogType.WC);
    return -1;
  }
 private static SVNAdminAreaFactory getAdminAreaFactory(int wcFormat) throws SVNException {
   if (wcFormat == SVNXMLAdminAreaFactory.WC_FORMAT) {
     return new SVNXMLAdminAreaFactory();
   }
   if (wcFormat == SVNAdminArea14Factory.WC_FORMAT) {
     return new SVNAdminArea14Factory();
   }
   if (wcFormat == SVNAdminArea15Factory.WC_FORMAT) {
     return new SVNAdminArea15Factory();
   }
   if (wcFormat == SVNAdminArea16Factory.WC_FORMAT) {
     return new SVNAdminArea16Factory();
   }
   SVNErrorManager.error(
       SVNErrorMessage.create(SVNErrorCode.WC_UNSUPPORTED_FORMAT), SVNLogType.DEFAULT);
   return null;
 }
 private static void checkWCNG(File path, File targetPath) throws SVNException {
   if (path == null) {
     return;
   }
   File dbFile = new Resource(path, ".svn/wc.db");
   SVNFileType type = SVNFileType.getType(dbFile);
   if (type == SVNFileType.FILE) {
     SVNErrorMessage err =
         SVNErrorMessage.create(
             SVNErrorCode.WC_UNSUPPORTED_FORMAT,
             "The path ''{0}'' appears to be part of Subversion 1.7 (SVNKit 1.4) or greater\n"
                 + "working copy rooted at ''{1}''.\n"
                 + "Please upgrade your Subversion (SVNKit) client to use this working copy.",
             new Object[] {targetPath, path});
     SVNErrorManager.error(err, SVNLogType.WC);
   }
   checkWCNG(path.getParentFile(), targetPath);
 }