Exemplo n.º 1
0
  /**
   * Constructs a resource bundle with the supplied jar file.
   *
   * @param source a file object that references our source jar file.
   * @param delay if true, the bundle will wait until someone calls {@link #sourceIsReady} before
   *     allowing access to its resources.
   * @param unpack if true the bundle will unpack itself into a temporary directory
   */
  public FileResourceBundle(File source, boolean delay, boolean unpack) {
    _source = source;
    if (unpack) {
      String root = stripSuffix(source.getPath());
      _unpacked = new File(root + ".stamp");
      _cache = new File(root);
    }

    if (!delay) {
      sourceIsReady();
    }
  }
Exemplo n.º 2
0
 /** Creates a ResourceBundle based on the supplied definition information. */
 protected ResourceBundle createResourceBundle(
     String setType, String path, List<ResourceBundle> dlist) {
   if (setType.equals(FILE_SET_TYPE)) {
     FileResourceBundle bundle = createFileResourceBundle(getResourceFile(path), true, _unpack);
     if (!bundle.isUnpacked() || !bundle.sourceIsReady()) {
       dlist.add(bundle);
     }
     return bundle;
   } else if (setType.equals(NETWORK_SET_TYPE)) {
     return createNetworkResourceBundle(_networkRootPath, path, getResourceList());
   } else {
     throw new IllegalArgumentException("Unknown set type: " + setType);
   }
 }
Exemplo n.º 3
0
  /**
   * Resolve the specified bundle (the bundle file must already exist in the appropriate place on
   * the file system) and return it on the specified result listener. Note that the result listener
   * may be notified before this method returns on the caller's thread if the bundle is already
   * resolved, or it may be notified on a brand new thread if the bundle requires unpacking.
   */
  public void resolveBundle(String path, final ResultListener<FileResourceBundle> listener) {
    File bfile = getResourceFile(path);
    if (bfile == null) {
      String errmsg = "ResourceManager not configured with resource directory.";
      listener.requestFailed(new IOException(errmsg));
      return;
    }

    final FileResourceBundle bundle = new FileResourceBundle(bfile, true, _unpack);
    if (bundle.isUnpacked()) {
      if (bundle.sourceIsReady()) {
        listener.requestCompleted(bundle);
      } else {
        String errmsg = "Bundle initialization failed.";
        listener.requestFailed(new IOException(errmsg));
      }
      return;
    }

    // start a thread to unpack our bundles
    ArrayList<ResourceBundle> list = Lists.newArrayList();
    list.add(bundle);
    Unpacker unpack =
        new Unpacker(
            list,
            new InitObserver() {
              public void progress(int percent, long remaining) {
                if (percent == 100) {
                  listener.requestCompleted(bundle);
                }
              }

              public void initializationFailed(Exception e) {
                listener.requestFailed(e);
              }
            });
    unpack.start();
  }