Exemplo n.º 1
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;
 }