Exemplo n.º 1
0
 /**
  * Register the "RecodeNoData" image operation to the operation registry of the specified JAI
  * instance.
  */
 public static void register(final JAI jai) {
   final OperationRegistry registry = jai.getOperationRegistry();
   try {
     registry.registerDescriptor(new Descriptor());
     registry.registerFactory(
         RenderedRegistryMode.MODE_NAME, OPERATION_NAME, "geotools.org", new CRIF());
   } catch (IllegalArgumentException exception) {
     final LogRecord record =
         Loggings.format(Level.SEVERE, LoggingKeys.CANT_REGISTER_JAI_OPERATION_$1, OPERATION_NAME);
     record.setSourceMethodName("<classinit>");
     record.setThrown(exception);
     record.setLoggerName(LOGGER.getName());
     LOGGER.log(record);
   }
 }
Exemplo n.º 2
0
 /** Invoked when a factory can't be loaded. Log a warning, but do not stop the process. */
 private static void loadingFailure(
     final Class<?> category, final Throwable error, final boolean showStackTrace) {
   final String name = Classes.getShortName(category);
   final StringBuilder cause = new StringBuilder(Classes.getShortClassName(error));
   final String message = error.getLocalizedMessage();
   if (message != null) {
     cause.append(": ");
     cause.append(message);
   }
   final LogRecord record =
       Loggings.format(Level.WARNING, LoggingKeys.CANT_LOAD_SERVICE_$2, name, cause.toString());
   if (showStackTrace) {
     record.setThrown(error);
   }
   record.setSourceClassName(FactoryRegistry.class.getName());
   record.setSourceMethodName("scanForPlugins");
   record.setLoggerName(LOGGER.getName());
   LOGGER.log(record);
 }
Exemplo n.º 3
0
 /**
  * Creates the backing store authority factory.
  *
  * @return The backing store to uses in {@code createXXX(...)} methods.
  * @throws FactoryNotFoundException if the no {@code epsg.properties} file has been found.
  * @throws FactoryException if the constructor failed to find or read the file. This exception
  *     usually has an {@link IOException} as its cause.
  */
 protected AbstractAuthorityFactory createBackingStore() throws FactoryException {
   try {
     URL url = getDefinitionsURL();
     if (url == null) {
       throw new FactoryNotFoundException(
           Errors.format(ErrorKeys.FILE_DOES_NOT_EXIST_$1, FILENAME));
     }
     final Iterator<? extends Identifier> ids = getAuthority().getIdentifiers().iterator();
     final String authority = ids.hasNext() ? ids.next().getCode() : "EPSG";
     final LogRecord record =
         Loggings.format(
             Level.CONFIG, LoggingKeys.USING_FILE_AS_FACTORY_$2, url.getPath(), authority);
     record.setLoggerName(LOGGER.getName());
     LOGGER.log(record);
     return new PropertyAuthorityFactory(factories, getAuthorities(), url);
   } catch (IOException exception) {
     throw new FactoryException(Errors.format(ErrorKeys.CANT_READ_$1, FILENAME), exception);
   }
 }
 /**
  * Returns {@code true} if this factory is available. The default implementation returns {@code
  * false} if no backing store were setup and {@link DeferredAuthorityFactory#createBackingStore}
  * throws an exception.
  */
 @Override
 synchronized boolean isAvailable() {
   try {
     return getBackingStore().isAvailable();
   } catch (FactoryNotFoundException exception) {
     /*
      * The factory is not available. This is error may be normal; it happens
      * for example if no gt2-epsg-hsql.jar (or similar JAR) are found in the
      * classpath, which is the case for example in GeoServer 1.3. Do not log
      * any stack trace,  since stack traces suggest more serious errors than
      * what we really have here.
      */
   } catch (FactoryException exception) {
     /*
      * The factory creation failed for an other reason, which may be more
      * serious. Now it is time to log a warning with a stack trace.
      */
     final Citation citation = getAuthority();
     final Collection titles = citation.getAlternateTitles();
     InternationalString title = citation.getTitle();
     if (titles != null) {
       for (final Iterator it = titles.iterator(); it.hasNext(); ) {
         /*
          * Uses the longuest title instead of the main one. In Geotools
          * implementation, the alternate title may contains usefull informations
          * like the EPSG database version number and the database engine.
          */
         final InternationalString candidate = (InternationalString) it.next();
         if (candidate.length() > title.length()) {
           title = candidate;
         }
       }
     }
     final LogRecord record =
         Loggings.format(Level.WARNING, LoggingKeys.UNAVAILABLE_AUTHORITY_FACTORY_$1, title);
     record.setSourceClassName(getClass().getName());
     record.setSourceMethodName("isAvailable");
     record.setThrown(exception);
     record.setLoggerName(LOGGER.getName());
     LOGGER.log(record);
   }
   return false;
 }
Exemplo n.º 5
0
 /** Prepares a message to be logged if any provider has been registered. */
 private static StringBuilder getLogHeader(final Class<?> category) {
   return new StringBuilder(
       Loggings.getResources(null).getString(LoggingKeys.FACTORY_IMPLEMENTATIONS_$1, category));
 }
  /**
   * Returns the backing-store factory for HSQL syntax. If the cached tables are not available, they
   * will be created now from the SQL scripts bundled in this plugin.
   *
   * @param hints A map of hints, including the low-level factories to use for CRS creation.
   * @return The EPSG factory using HSQL syntax.
   * @throws SQLException if connection to the database failed.
   */
  protected AbstractAuthorityFactory createBackingStore(final Hints hints) throws SQLException {
    final DataSource source = getDataSource();
    final File directory = getDirectory(source);
    directory.mkdirs();
    if (!dataExists(directory)) {
      FileLock lock = null;
      try {
        // get an exclusive lock
        lock = acquireLock(directory);

        // if after getting the lock the database is still incomplete let's work on it
        if (!dataExists(directory)) {
          /*
           * HSQL has created automatically an empty database. We need to populate it.
           * Executes the SQL scripts bundled in the JAR. In theory, each line contains
           * a full SQL statement. For this plugin however, we have compressed "INSERT
           * INTO" statements using Compactor class in this package.
           */
          final Logger logger = Logging.getLogger(LOGGER);
          final LogRecord record =
              Loggings.format(Level.INFO, LoggingKeys.CREATING_CACHED_EPSG_DATABASE_$1, VERSION);
          record.setLoggerName(logger.getName());
          logger.log(record);

          ZipInputStream zin =
              new ZipInputStream(ThreadedH2EpsgFactory.class.getResourceAsStream(ZIP_FILE));
          ZipEntry ze = null;
          byte[] buf = new byte[1024];
          int read = 0;
          while ((ze = zin.getNextEntry()) != null) {
            File file = new File(directory, ze.getName());
            if (file.exists()) {
              file.delete();
            }
            FileOutputStream fout = new FileOutputStream(file);
            while ((read = zin.read(buf)) > 0) {
              fout.write(buf, 0, read);
            }
            zin.closeEntry();
            fout.close();
          }
          zin.close();

          // mark the successful creation
          File marker = new File(directory, MARKER_FILE);
          if (marker.exists()) {
            marker.delete();
          }
          marker.createNewFile();

          setReadOnly(directory);
        }
      } catch (IOException exception) {
        SQLException e = new SQLException(Errors.format(ErrorKeys.CANT_READ_$1, ZIP_FILE));
        e.initCause(exception); // TODO: inline cause when we will be allowed to target Java 6.
        throw e;
      } finally {
        if (lock != null) {
          try {
            lock.release();
            lock.channel().close();
            new File(directory, LOCK_FILE).delete();
          } catch (IOException e) {
            // does not matter, was just cleanup
          }
        }
      }
    }
    FactoryUsingAnsiSQL factory = new FactoryUsingAnsiSQL(hints, getDataSource().getConnection());
    factory.setValidationQuery("CALL NOW()");
    return factory;
  }