org.geotools.util.logging.Logging.unexpectedException()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.geotools.util.logging.Logging.unexpectedException()方法的一些代码示例,展示了Logging.unexpectedException()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logging.unexpectedException()方法的具体详情如下:
包路径:org.geotools.util.logging.Logging
类名称:Logging
方法名:unexpectedException

Logging.unexpectedException介绍

[英]Invoked when an unexpected error occurs. This method logs a message at the Level#WARNING level to a logger inferred from the given class.
[中]发生意外错误时调用。此方法将级别为#警告级别的消息记录到从给定类推断的记录器。

代码示例

代码示例来源:origin: geoserver/geoserver

/**
 * Invoked when an error occurs during the initialization.
 *
 * @param e the error that occured.
 */
private static void unexpectedException(final Exception e) {
  Logging.unexpectedException("org.geotools.resources", Log4JFormatter.class, "init", e);
}

代码示例来源:origin: geotools/geotools

/** Invoked when an error occurs during the initialization. */
  private static void unexpectedException(final Exception exception) {
    Logging.unexpectedException(MonolineFormatter.class, "configureConsoleHandler", exception);
  }
}

代码示例来源:origin: geotools/geotools

/** Invoked when an exception occured. This method just log a warning. */
static void unexpectedException(
    final Class<?> classe, final String method, final SQLException exception) {
  Logging.unexpectedException(classe, method, exception);
}

代码示例来源:origin: geotools/geotools

/**
 * Invoked when an unexpected exception occured. Those exceptions must be non-fatal, i.e. the
 * caller <strong>must</strong> have a raisonable fallback (otherwise it should propagate the
 * exception).
 */
static void unexpectedException(final String methodName, final Exception exception) {
  Logging.unexpectedException(CRS.class, methodName, exception);
}

代码示例来源:origin: geotools/geotools

/** Invoked when an exception occured. This method just log a warning. */
void unexpectedException(
    final Class classe, final String method, final SQLException exception) {
  Logging.unexpectedException(LOGGER, classe, method, exception);
}

代码示例来源:origin: geotools/geotools

/**
 * Logs an exception as if it originated from {@link Hints#scanSystemProperties}, since it is
 * the public API that may invokes this method.
 */
private static void unexpectedException(final Exception exception) {
  Logging.unexpectedException(Hints.class, "scanSystemProperties", exception);
}

代码示例来源:origin: geotools/geotools

/** Invoked when an unexpected exception occured in the {@link #format} method. */
private static void unexpectedException(final RuntimeException exception) {
  Logging.unexpectedException(IndexedResourceBundle.class, "format", exception);
}

代码示例来源:origin: geotools/geotools

/**
 * Invoked when an unexpected error occurs. This method logs a message at the {@link
 * Level#WARNING WARNING} level to a logger inferred from the given class.
 *
 * @param classe The class where the error occurred.
 * @param method The method where the error occurred, or {@code null}.
 * @param error The error.
 * @return {@code true} if the error has been logged, or {@code false} if the logger doesn't log
 *     anything at the {@link Level#WARNING WARNING} level.
 * @since 2.5
 */
public static boolean unexpectedException(Class<?> classe, String method, Throwable error) {
  return unexpectedException((Logger) null, classe, method, error);
}

代码示例来源:origin: geotools/geotools

/**
 * Invoked when an unexpected error occurs. This method logs a message at the {@link
 * Level#WARNING WARNING} level to the specified logger. The originating class name and method
 * name are inferred from the error stack trace, using the first {@linkplain StackTraceElement
 * stack trace element} for which the class name is inside a package or sub-package of the
 * logger name. For example if the logger name is {@code "org.geotools.image"}, then this method
 * will uses the first stack trace element where the fully qualified class name starts with
 * {@code "org.geotools.image"} or {@code "org.geotools.image.io"}, but not {@code
 * "org.geotools.imageio"}.
 *
 * @param logger Where to log the error.
 * @param error The error that occured.
 * @return {@code true} if the error has been logged, or {@code false} if the logger doesn't log
 *     anything at the {@link Level#WARNING WARNING} level.
 */
public static boolean unexpectedException(final Logger logger, final Throwable error) {
  return unexpectedException(logger, null, null, error, Level.WARNING);
}

代码示例来源:origin: geotools/geotools

/**
 * Returns the expected class for values stored under this key.
 *
 * @return The class of values stored under this key.
 */
public Class<?> getValueClass() {
  if (valueClass == null) {
    try {
      valueClass = Class.forName(className);
    } catch (ClassNotFoundException exception) {
      Logging.unexpectedException(Key.class, "getValueClass", exception);
      valueClass = Object.class;
    }
  }
  return valueClass;
}

代码示例来源:origin: geotools/geotools

/**
 * Invoked when a recoverable error occurs. This method is similar to {@link
 * #unexpectedException(Logger,Class,String,Throwable) unexpectedException} except that it
 * doesn't log the stack trace and uses a lower logging level.
 *
 * @param logger Where to log the error.
 * @param classe The class where the error occurred.
 * @param method The method name where the error occurred.
 * @param error The error.
 * @return {@code true} if the error has been logged, or {@code false} if the logger doesn't log
 *     anything at the specified level.
 * @since 2.5
 */
public static boolean recoverableException(
    final Logger logger,
    final Class<?> classe,
    final String method,
    final Throwable error) {
  final String classname = (classe != null) ? classe.getName() : null;
  return unexpectedException(logger, classname, method, error, Level.FINE);
}

代码示例来源:origin: geotools/geotools

final Throwable error) {
final String classname = (classe != null) ? classe.getName() : null;
return unexpectedException(logger, classname, method, error, Level.WARNING);

代码示例来源:origin: geotools/geotools

/**
 * Returns the URL to the property file that contains CRS definitions. The default
 * implementation performs the following search path:
 *
 * <ul>
 *   <li>If a value is set for the {@value #CRS_DIRECTORY_KEY} system property key, then the
 *       {@value #FILENAME} file will be searched in this directory.
 *   <li>If no value is set for the above-cited system property, or if no {@value #FILENAME}
 *       file was found in that directory, then the first {@value #FILENAME} file found in any
 *       {@code org/geotools/referencing/factory/epsg} directory on the classpath will be used.
 *   <li>If no file was found on the classpath neither, then this factory will be disabled.
 * </ul>
 *
 * @return The URL, or {@code null} if none.
 */
protected URL getDefinitionsURL() {
  try {
    if (directory != null) {
      final File file = new File(directory, FILENAME);
      if (file.isFile()) {
        return file.toURI().toURL();
      }
    }
  } catch (SecurityException exception) {
    Logging.unexpectedException(LOGGER, exception);
  } catch (MalformedURLException exception) {
    Logging.unexpectedException(LOGGER, exception);
  }
  return FactoryUsingWKT.class.getResource(FILENAME);
}

代码示例来源:origin: geotools/geotools

/**
 * Returns the URL to the property file that contains Operation definitions. The default
 * implementation performs the following search path:
 *
 * <ul>
 *   <li>If a value is set for the {@value GeoTools#CRS_AUTHORITY_EXTRA_DIRECTORY} system
 *       property key, then the {@value #FILENAME} file will be searched in this directory.
 *   <li>If no value is set for the above-cited system property, or if no {@value #FILENAME}
 *       file was found in that directory, then the first {@value #FILENAME} file found in any
 *       {@code org/geotools/referencing/factory/epsg} directory on the classpath will be used.
 *   <li>If no file was found on the classpath neither, then this factory will be disabled.
 * </ul>
 *
 * @return The URL, or {@code null} if none.
 */
protected URL getDefinitionsURL() {
  try {
    if (directory != null) {
      final File file = new File(directory, FILENAME);
      if (file.isFile()) {
        return file.toURI().toURL(); // TODO
      }
    }
  } catch (SecurityException exception) {
    Logging.unexpectedException(LOGGER, exception);
  } catch (MalformedURLException exception) {
    Logging.unexpectedException(LOGGER, exception);
  }
  return this.getClass().getResource(FILENAME);
}

代码示例来源:origin: geotools/geotools

/**
 * Creates a responsible party metadata entry for OGC involvement. The organisation name is
 * automatically set to "Open Geospatial Consortium".
 *
 * @param role The OGC role (point of contact, owner, etc.) for a resource.
 * @param function The OGC function (information, download, etc.) for a resource.
 * @param onlineResource The URI on the resource.
 * @return Responsible party describing OGC involvement.
 */
static ResponsibleParty OGC(
    final Role role, final OnLineFunction function, final String onlineResource) {
  try {
    return OGC(role, function, new URI(onlineResource));
  } catch (URISyntaxException badContact) {
    Logging.unexpectedException(
        "org.geotools.metadata.iso", ResponsibleParty.class, "OGC", badContact);
    return OGC;
  }
}

代码示例来源:origin: geotools/geotools

/**
 * Invoked when an unexpected error occurs. This method logs a message at the {@link
 * Level#WARNING WARNING} level to the logger for the specified package name. The originating
 * class name and method name can optionnaly be specified. If any of them is {@code null}, then
 * it will be inferred from the error stack trace as in {@link #unexpectedException(Logger,
 * Throwable)}.
 *
 * @param paquet The package where the error occurred, or {@code null}. This information is used
 *     for fetching an appropriate {@link Logger} for logging the error.
 * @param classe The class where the error occurred, or {@code null}.
 * @param method The method where the error occurred, or {@code null}.
 * @param error The error.
 * @return {@code true} if the error has been logged, or {@code false} if the logger doesn't log
 *     anything at the {@link Level#WARNING WARNING} level.
 * @deprecated Use one of the other {@code unexpectedException} methods instead.
 */
public static boolean unexpectedException(
    final String paquet,
    final Class<?> classe,
    final String method,
    final Throwable error) {
  final Logger logger = (paquet != null) ? getLogger(paquet) : null;
  return unexpectedException(logger, classe, method, error);
}

代码示例来源:origin: geotools/geotools

/** Loads the {@linkplain #CONFIGURATION_FILE configuration file}. */
private static Properties load() {
  final Properties p = new Properties();
  File file = new File(CONFIGURATION_FILE);
  if (!file.isFile()) {
    File home = new File(System.getProperty("user.home", "."));
    file = new File(home, CONFIGURATION_FILE);
    if (!file.isFile()) {
      // support online testing
      File epsgFixtures = new File(new File(home, ".geotools"), "epsg");
      file = new File(epsgFixtures, "postgresql.properties");
      if (!file.isFile()) {
        // Returns an empty set of properties.
        return p;
      }
    }
  }
  try {
    final InputStream in = new FileInputStream(file);
    p.load(in);
    in.close();
  } catch (IOException exception) {
    Logging.unexpectedException(
        "org.geotools.referencing.factory", DataSource.class, "<init>", exception);
    // Continue. We will try to work with whatever properties are available.
  }
  return p;
}

代码示例来源:origin: geotools/geotools

/**
 * Implementation of {@code fixName} method. If the context is {@code null}, then the
 * {@linkplain #getInitialContext GeoTools initial context} will be fetch only when first
 * needed.
 */
private static String fixName(Context context, final String name, final Hints hints) {
  String fixed = null;
  if (name != null) {
    final StringTokenizer tokens = new StringTokenizer(name, ":/");
    while (tokens.hasMoreTokens()) {
      final String part = tokens.nextToken();
      if (fixed == null) {
        fixed = part;
      } else
        try {
          if (context == null) {
            context = getInitialContext(hints);
          }
          fixed = context.composeName(fixed, part);
        } catch (NamingException e) {
          Logging.unexpectedException(GeoTools.class, "fixName", e);
          return name;
        }
    }
  }
  return fixed;
}

代码示例来源:origin: geotools/geotools

Logging.unexpectedException(WeakCollectionCleaner.class, "remove", exception);
} catch (AssertionError exception) {
  Logging.unexpectedException(WeakCollectionCleaner.class, "remove", exception);

代码示例来源:origin: geotools/geotools

/** Returns a data source for the PostgreSQL database. */
protected DataSource createDataSource() throws SQLException {
  DataSource candidate = super.createDataSource();
  if (candidate instanceof BaseDataSource) {
    // Any kind of DataSource from the PostgreSQL driver.
    return candidate;
  }
  final PGSimpleDataSource source = new PGSimpleDataSource();
  final Properties p = load();
  int portNumber;
  try {
    portNumber = Integer.parseInt(p.getProperty("portNumber", "5432"));
  } catch (NumberFormatException exception) {
    portNumber = 5432;
    Logging.unexpectedException(
        "org.geotools.referencing.factory", DataSource.class, "<init>", exception);
  }
  source.setPortNumber(portNumber);
  source.setServerName(p.getProperty("serverName", "localhost"));
  source.setDatabaseName(p.getProperty("databaseName", "EPSG"));
  source.setUser(p.getProperty("user", "Geotools"));
  source.setPassword(p.getProperty("password", "Geotools"));
  source.setProperty("stringtype", "unspecified");
  schema = p.getProperty("schema", null);
  return source;
}

相关文章