/** * 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(); }
/** * Get the version of the stored node key name * * @return the version */ public NDNTime nodeKeyVersion() { try { return VersioningProfile.getLastVersionAsTimestamp(storedNodeKeyName()); } catch (VersionMissingException e) { if (Log.isLoggable(Log.FAC_ACCESSCONTROL, Level.WARNING)) { Log.warning( Log.FAC_ACCESSCONTROL, "Unexpected: name that was confirmed to have a version on construction throws a VersionMissingException: " + storedNodeKeyName()); } throw new IllegalStateException( "Unexpected: name that was confirmed to have a version on construction throws a VersionMissingException: " + storedNodeKeyName()); } }