Exemplo n.º 1
0
    @Override
    public void configure(ServicesFactory factory) {
      ClassLoader classLoader = Module.class.getClassLoader();

      Map<String, String> map = PropertiesUtil.loadProperties(TESTING_MODULE);

      for (Entry<String, String> entry : map.entrySet()) {
        try {
          Class<?> factoryClass = classLoader.loadClass(entry.getKey());
          Class<?> implementationClass = classLoader.loadClass(entry.getValue());
          Object implementationInstance = implementationClass.newInstance();

          Method method =
              factory
                  .getClass()
                  .getMethod("setInstance", new Class<?>[] {Class.class, Object.class});
          method.invoke(factory, factoryClass, implementationInstance);
        } catch (Exception e) {
          throw new IllegalStateException(e);
        }
      }
    }
  /*
   * (non-Javadoc)
   *
   * @see org.richfaces.application.Initializable#init()
   */
  @Override
  public void init() {
    final Map<ResourceKey, ExternalMapping> result = Maps.newHashMap();

    final List<String> mappingFiles = ResourceMappingFeature.getMappingFiles();
    for (String mappingFile : mappingFiles) {
      if (classpathResourceExistsForLocation(mappingFile)) {
        for (Entry<String, String> entry : PropertiesUtil.loadProperties(mappingFile).entrySet()) {
          final ResourceKey resourceKey = ResourceKey.create(entry.getKey());
          final String resourceLocation = entry.getValue();
          result.put(resourceKey, new ExternalMapping(resourceKey, resourceLocation));
        }
      } else {
        if (!isDefaultStaticResourceMappingLocation(mappingFile)) {
          LOGGER.warn(
              "Resource mapping is configured to load non-existent resource: '"
                  + mappingFile
                  + "'");
        }
      }
    }

    externalStaticResources = result;
  }