/**
   * Initialize internal policy state, from file if policyFile != null This method is intended to be
   * called at the beginning of a subclass initialize() method to handle the generic policy setup,
   * after which the subclass initialize() should adjust policy (including calling readPolicy) as
   * appropriate. If both "policy file" and "initial namespace" are non-null the policy file takes
   * precedence
   *
   * @param policyFile policy file
   * @param initial namespace
   * @throws RepositoryException
   * @throws FileNotFoundException
   * @throws ContentDecodingException
   * @throws MalformedContentNameStringException
   */
  public PolicyXML startInitPolicy(File policyFile, String nameSpace) throws RepositoryException {
    BasicPolicy policy = new BasicPolicy(null);
    policy.setVersion(getVersion());

    if (null != policyFile) {
      try {
        FileInputStream fis = new FileInputStream(policyFile);
        try {
          policy.updateFromInputStream(fis);
        } finally {
          try {
            fis.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      } catch (FileNotFoundException e) {
        throw new RepositoryException(e.getMessage());
      }
    } else if (null != nameSpace) { // Try setting an initial namespace from the namespace parameter
      ArrayList<ContentName> nameSpaceAL = new ArrayList<ContentName>(1);
      try {
        nameSpaceAL.add(ContentName.fromNative(nameSpace));
      } catch (MalformedContentNameStringException e) {
        Log.warning(Log.FAC_REPO, "Invalid namespace specified: {0}", nameSpace);
      }
      policy.setNamespace(nameSpaceAL);
    }
    return policy.getPolicyXML();
  }
  /**
   * Read policy from persistent storage under standard naming convention. This method may be called
   * optionally during initialization by a subclass after it is initialized enough to process
   * getContent() calls
   *
   * @param globalPrefix - used to find our policy file
   * @return XML for the current policy or null if no current policy
   * @throws MalformedContentNameStringException
   * @throws IOException
   */
  public PolicyXML readPolicy(ContentName globalPrefix)
      throws MalformedContentNameStringException, IOException {
    if (Log.isLoggable(Log.FAC_REPO, Level.INFO))
      Log.info(
          Log.FAC_REPO,
          "REPO: reading policy from network: {0}/{1}/{2}",
          REPO_NAMESPACE,
          globalPrefix,
          REPO_POLICY);
    ContentName policyName = BasicPolicy.getPolicyName(globalPrefix);

    // We can't use the regular repo handle for this because we need ndnd to communicate across the
    // faces
    NDNHandle readHandle;
    readHandle = NDNHandle.open(_km);
    PolicyObject policyObject = new PolicyObject(policyName, readHandle);
    try {
      return policyObject.policyInfo();
    } catch (ContentNotReadyException cge) {
    } finally {
      readHandle.close();
    }
    return null;
  }