예제 #1
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);
   }
 }
예제 #2
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();
  }