Exemplo n.º 1
0
  /**
   * Returns the appropriate icon for the specified store.
   *
   * @param storeInfo
   * @return
   * @see #getStoreIcon(Class)
   */
  public ResourceReference getStoreIcon(final StoreInfo storeInfo) {

    Class<?> factoryClass = null;

    Catalog catalog = storeInfo.getCatalog();
    final ResourcePool resourcePool = catalog.getResourcePool();

    if (storeInfo instanceof DataStoreInfo) {
      DataAccessFactory dataStoreFactory = null;
      try {
        dataStoreFactory = resourcePool.getDataStoreFactory((DataStoreInfo) storeInfo);
      } catch (IOException e) {
        LOGGER.log(
            Level.INFO, "factory class for storeInfo " + storeInfo.getName() + " not found", e);
      }

      if (dataStoreFactory != null) {
        return getStoreIcon(dataStoreFactory.getClass());
      }

    } else if (storeInfo instanceof CoverageStoreInfo) {
      AbstractGridFormat format = resourcePool.getGridCoverageFormat((CoverageStoreInfo) storeInfo);
      if (format != null) {
        return getStoreIcon(format.getClass());
      }
    } else if (storeInfo instanceof WMSStoreInfo) {
      return MAP_STORE_ICON;
    } else {
      throw new IllegalStateException(storeInfo.getClass().getName());
    }

    LOGGER.info(
        "Could not determine icon for StoreInfo "
            + storeInfo.getName()
            + ". Using 'unknown' icon.");
    return UNKNOWN_ICON;
  }
Exemplo n.º 2
0
  /**
   * @param storeInfo
   * @param app
   * @return the extension point descriptor for the given storeInfo, or {@code null} if there's no
   *     contribution specific for the given storeInfo's type
   */
  private static DataStorePanelInfo findPanelInfo(
      final StoreInfo storeInfo, final GeoServerApplication app) {

    final Catalog catalog = storeInfo.getCatalog();
    final ResourcePool resourcePool = catalog.getResourcePool();

    Class<?> factoryClass = null;
    if (storeInfo instanceof DataStoreInfo) {
      DataAccessFactory storeFactory;
      try {
        storeFactory = resourcePool.getDataStoreFactory((DataStoreInfo) storeInfo);
      } catch (IOException e) {
        throw new IllegalArgumentException("no factory found for StoreInfo " + storeInfo);
      }
      if (storeFactory != null) {
        factoryClass = storeFactory.getClass();
      }
    } else if (storeInfo instanceof CoverageStoreInfo) {
      AbstractGridFormat gridFormat;
      gridFormat = resourcePool.getGridCoverageFormat((CoverageStoreInfo) storeInfo);
      if (gridFormat != null) {
        factoryClass = gridFormat.getClass();
      }
    } else {
      throw new IllegalArgumentException("Unknown store type: " + storeInfo.getClass().getName());
    }

    if (factoryClass == null) {
      throw new IllegalArgumentException("Can't locate the factory for the store");
    }

    final List<DataStorePanelInfo> providers = app.getBeansOfType(DataStorePanelInfo.class);

    List<DataStorePanelInfo> fallbacks = new ArrayList<DataStorePanelInfo>();
    for (DataStorePanelInfo provider : providers) {
      Class<?> providerFactoryClass = provider.getFactoryClass();
      if (providerFactoryClass == null) {
        continue;
      }
      if (factoryClass.equals(providerFactoryClass)) {
        return provider;
      } else if (providerFactoryClass.isAssignableFrom(factoryClass)) {
        fallbacks.add(provider);
      }
    }

    if (fallbacks.size() == 1) {
      return fallbacks.get(0);
    } else if (fallbacks.size() > 1) {
      // sort by class hierarchy, pick the closest match
      Collections.sort(
          fallbacks,
          new Comparator<DataStorePanelInfo>() {
            public int compare(DataStorePanelInfo o1, DataStorePanelInfo o2) {
              Class c1 = o1.getFactoryClass();
              Class c2 = o2.getFactoryClass();

              if (c1.equals(c2)) {
                return 0;
              }

              if (c1.isAssignableFrom(c2)) {
                return 1;
              }

              if (c2.isAssignableFrom(c1)) {;
              }

              return -1;
            }
          });
      // check first two and make sure bindings are not equal
      DataStorePanelInfo f1 = fallbacks.get(0);
      DataStorePanelInfo f2 = fallbacks.get(1);

      if (f1.getFactoryClass().equals(f2.getFactoryClass())) {
        String msg =
            "Multiple editor panels for : (" + f1.getFactoryClass() + "): " + f1 + ", " + f2;
        throw new RuntimeException(msg);
      }

      return f1;
    }

    // ok, we don't have a specific one
    return null;
  }